PDF aus Smartforms via Mail mit CL_BCS

Die Objektorientierung mit ABAP®: Vererbung, Dynamische Programmierung, GUI Controls (u.a. ALV im OO).

PDF aus Smartforms via Mail mit CL_BCS

Postby Pauline4260 » Tue Aug 25, 2015 3:25 pm

Hallo,
ich versuche verzweifelt, ein mit Smartforms erstelltes Formular über die CL_BCS-Klasse als PDF zu senden.
Meine Schritte:
1) Aufruf des Smartform-Formulars mit Rückgabe des OTF
2) CALL FUNCTION 'CONVERT_OTF_2_PDF'...
3) Aufbau der Mail über CL_BCS.

Aus dem CONVERT_OTF_2_PDF bekomme ich eine Tabelle mit "TDFORMAT und TDLINE". Damit kann eine "SOLI_TAB" oder "SOLIX_TAB" natürlich nichts anfangen.
Es scheitert also daran, die "ADD_ATTACHMENT" richtig zu befüllen.

Ich habe versucht, die TDFORMAT/TDLINE-Tabelle zu concatenaten in eine SOLI_TAB, aber der Mail-Anhang der erzeugt wird, kann nicht geöffnet werden.

Ich hoffe, jemand kann mir sagen, wie es nach dem CONVERT_OTF_2_PDF weiter geht.

Danke und Gruß
Dirk
Pauline4260
.
.
 
Posts: 3
Joined: Tue Aug 25, 2015 3:25 pm

Re: PDF aus Smartforms via Mail mit CL_BCS

Postby Tron » Wed Aug 26, 2015 7:42 pm

Moin Dirk.
so sollte es funktionieren :
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *&---------------------------------------------------------------------*
  2. *& Report  YBC_SF_GENPDF
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8.  
  9. REPORT  YBC_SF_GENPDF.
  10.  
  11.  
  12. data FORMNAME TYPE  TDSFNAME value 'ZTEST_ZEBRA'.
  13. data FM_NAME TYPE  RS38L_FNAM.
  14. data OTF_output type SSFCRESCL.
  15.  
  16. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  17.   EXPORTING
  18.     formname           = FORMNAME
  19.   IMPORTING
  20.     fm_name            = FM_NAME
  21.   EXCEPTIONS
  22.     no_form            = 1
  23.     no_function_module = 2
  24.     OTHERS             = 3.
  25.  
  26. data ls_cp TYPE  SSFCTRLOP.
  27.  
  28. ls_cp-NO_DIALOG = ' '.
  29. ls_cp-GETOTF = 'X'.
  30.  
  31. *CALL FUNCTION '/1BCDWB/SF00000002'
  32. CALL FUNCTION FM_NAME
  33.   EXPORTING
  34.     CONTROL_PARAMETERS = ls_cp
  35.   IMPORTING
  36.     JOB_OUTPUT_INFO    = OTF_output
  37.   EXCEPTIONS
  38.     FORMATTING_ERROR   = 1
  39.     INTERNAL_ERROR     = 2
  40.     SEND_ERROR         = 3
  41.     USER_CANCELED      = 4
  42.     OTHERS             = 5.
  43.  
  44. IF SY-SUBRC <> 0.
  45.  
  46. DATA: BEGIN OF lt_pdf OCCURS 0,
  47.       t(134),
  48.       END OF lt_pdf.
  49.  
  50.  
  51. data DTAB type table of DOCS.
  52. data lv_len type i.
  53.  
  54. CALL FUNCTION 'CONVERT_OTF_2_PDF'
  55.   IMPORTING
  56.     BIN_FILESIZE           = lv_len
  57.     OTF                    = OTF_output-OTFDATA[]
  58.     DOCTAB_ARCHIVE         = DTAB
  59.     LINES                  = lt_pdf[]
  60.   EXCEPTIONS
  61.     ERR_CONV_NOT_POSSIBLE  = 1
  62.     ERR_OTF_MC_NOENDMARKER = 2
  63.     OTHERS                 = 3.
  64.  
  65. IF SY-SUBRC <> 0.
  66. * Implement suitable error handling here
  67.  
  68. data pdf_xstring type xstring.
  69. CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  70.   EXPORTING
  71.     INPUT_LENGTH = lv_len
  72.   IMPORTING
  73.     BUFFER       = pdf_xstring
  74.     BINARY_TAB   = lt_pdf[]
  75.   EXCEPTIONS
  76.     FAILED       = 1
  77.     OTHERS       = 2.
  78.  
  79. IF SY-SUBRC <> 0.
  80. * Implement suitable error handling here
  81.  
  82. *     -------- convert document -------------------------------
  83. data pdf_content TYPE table of solix.
  84. pdf_content = cl_document_bcs=>xstring_to_solix( pdf_xstring ).
  85.  
  86. * TEST TEST
  87.  
  88. data fnam type RLGRAP-FILENAME value 'c:\temp\000.pdf'.
  89.  
  90.  
  91. CALL FUNCTION 'WS_DOWNLOAD'
  92.  EXPORTING
  93.     BIN_FILESIZE                  = lv_len
  94.     FILENAME                      = fnam
  95.     FILETYPE                      = 'BIN'
  96.     DATA_TAB                      = pdf_content[]
  97.  EXCEPTIONS
  98.    FILE_OPEN_ERROR               = 1
  99.    FILE_WRITE_ERROR              = 2
  100.    INVALID_FILESIZE              = 3
  101.    INVALID_TYPE                  = 4
  102.    NO_BATCH                      = 5
  103.    UNKNOWN_ERROR                 = 6
  104.    INVALID_TABLE_WIDTH           = 7
  105.    GUI_REFUSE_FILETRANSFER       = 8
  106.    CUSTOMER_ERROR                = 9
  107.    NO_AUTHORITY                  = 10
  108.    OTHERS                        = 11.
  109.  
  110. IF SY-SUBRC <> 0.
  111. * Implement suitable error handling here
  112.  
GeSHi ©


Besser noch mit CONVERT_OTF (liefert sofort Xstring in bin_file ):

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *&---------------------------------------------------------------------*
  2. *& Report  YBC_CONVERT_OTF_PDF
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8. REPORT ybc_convert_otf_pdf2.
  9.  
  10. DATA formname TYPE  tdsfname VALUE 'ZTEST_ZEBRA'.
  11. DATA fm_name TYPE  rs38l_fnam.
  12. DATA otf_output TYPE ssfcrescl.
  13.  
  14. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  15.   EXPORTING
  16.     formname           = formname
  17.   IMPORTING
  18.     fm_name            = fm_name
  19.   EXCEPTIONS
  20.     no_form            = 1
  21.     no_function_module = 2
  22.     OTHERS             = 3.
  23.  
  24. DATA ls_cp TYPE  ssfctrlop.
  25.  
  26. ls_cp-no_dialog = ' '.
  27. ls_cp-getotf = 'X'.
  28.  
  29. *CALL FUNCTION '/1BCDWB/SF00000002'
  30. CALL FUNCTION fm_name
  31.   EXPORTING
  32.     control_parameters = ls_cp
  33.   IMPORTING
  34.     job_output_info    = otf_output
  35.   EXCEPTIONS
  36.     formatting_error   = 1
  37.     internal_error     = 2
  38.     send_error         = 3
  39.     user_canceled      = 4
  40.     OTHERS             = 5.
  41.  
  42. IF sy-subrc <> 0.
  43.  
  44. DATA lv_len TYPE i.
  45. DATA pdf_xstring TYPE xstring.
  46. DATA lt_lines TYPE TABLE OF tline. " ist muss Parameter
  47.  
  48. CALL FUNCTION 'CONVERT_OTF'
  49.  EXPORTING
  50.    format                      = 'PDF'
  51.    pdf_delete_otftab           = 'X'
  52.  IMPORTING
  53.    bin_filesize                = lv_len
  54.    bin_file                    = pdf_xstring
  55.     otf                         = otf_output-otfdata[]
  56.     lines                       = lt_lines
  57.  EXCEPTIONS
  58.    err_max_linewidth           = 1
  59.    err_format                  = 2
  60.    err_conv_not_possible       = 3
  61.    err_bad_otf                 = 4
  62.    OTHERS                      = 5
  63.           .
  64. IF sy-subrc <> 0.
  65. * Implement suitable error handling here
  66.  
  67.  
  68. *     -------- convert document -------------------------------
  69. DATA pdf_content TYPE TABLE OF solix.
  70. pdf_content = cl_document_bcs=>xstring_to_solix( pdf_xstring ).
  71.  
  72. * TEST TEST
  73.  
  74. DATA fnam TYPE rlgrap-filename VALUE 'c:\temp\000.pdf'.
  75.  
  76.  
  77. CALL FUNCTION 'WS_DOWNLOAD'
  78. EXPORTING
  79.     bin_filesize                  = lv_len
  80.     filename                      = fnam
  81.     filetype                      = 'BIN'
  82.     data_tab                      = pdf_content[]
  83. EXCEPTIONS
  84.    file_open_error               = 1
  85.    file_write_error              = 2
  86.    invalid_filesize              = 3
  87.    invalid_type                  = 4
  88.    no_batch                      = 5
  89.    unknown_error                 = 6
  90.    invalid_table_width           = 7
  91.    gui_refuse_filetransfer       = 8
  92.    customer_error                = 9
  93.    no_authority                  = 10
  94.    OTHERS                        = 11.
  95.  
  96. IF sy-subrc <> 0.
  97. * Implement suitable error handling here
  98.  
GeSHi ©


lg Jens
Tron
.....
.....
 
Posts: 1112
Joined: Sat Aug 04, 2007 10:21 pm

Re: PDF aus Smartforms via Mail mit CL_BCS

Postby Pauline4260 » Thu Aug 27, 2015 6:55 am

Hallo Jens,

vielen Dank für deine Antwort, aber es geht mir nicht um das Sichern via WS_DOWNLOAD, sondern ich möchte das PDF mailen über die Methoden der Klasse CL_BCS.

Danke und Gruß
Dirk
Pauline4260
.
.
 
Posts: 3
Joined: Tue Aug 25, 2015 3:25 pm

Re: PDF aus Smartforms via Mail mit CL_BCS

Postby Pauline4260 » Mon Aug 31, 2015 9:58 am

Hallo,

es ging mir nicht um das Sichern des PDF, sondern um das mailen über die BCS-Klasse!

Danke und Gruß
Dirk
Pauline4260
.
.
 
Posts: 3
Joined: Tue Aug 25, 2015 3:25 pm

Re: PDF aus Smartforms via Mail mit CL_BCS

Postby Tron » Sat Sep 05, 2015 7:23 pm

Moin.
es ging mir nicht um das Sichern des PDF, sondern um das mailen über die BCS-Klasse!

Das war mir bewusst. Ich nahm an, das Du lediglich die Wandlung des PDFs in SOLIX_TAB
suchst. (Der Download war nur ein Test)

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *&---------------------------------------------------------------------*
  2. *& Report  YBC_CONVERT_OTF_PDF
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8. REPORT ybc_convert_otf_pdf2.
  9.  
  10. DATA formname TYPE  tdsfname VALUE 'ZTEST_ZEBRA'.
  11. DATA fm_name TYPE  rs38l_fnam.
  12. DATA otf_output TYPE ssfcrescl.
  13.  
  14. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  15.   EXPORTING
  16.     formname           = formname
  17.   IMPORTING
  18.     fm_name            = fm_name
  19.   EXCEPTIONS
  20.     no_form            = 1
  21.     no_function_module = 2
  22.     OTHERS             = 3.
  23.  
  24. DATA ls_cp TYPE  ssfctrlop.
  25.  
  26. ls_cp-no_dialog = ' '.
  27. ls_cp-getotf = 'X'.
  28.  
  29. *CALL FUNCTION '/1BCDWB/SF00000002'
  30. CALL FUNCTION fm_name
  31.   EXPORTING
  32.     control_parameters = ls_cp
  33.   IMPORTING
  34.     job_output_info    = otf_output
  35.   EXCEPTIONS
  36.     formatting_error   = 1
  37.     internal_error     = 2
  38.     send_error         = 3
  39.     user_canceled      = 4
  40.     OTHERS             = 5.
  41.  
  42. IF sy-subrc <> 0.
  43.  
  44. DATA lv_len TYPE i.
  45. DATA pdf_xstring TYPE xstring.
  46. DATA lt_lines TYPE TABLE OF tline. " ist muss Parameter
  47.  
  48. CALL FUNCTION 'CONVERT_OTF'
  49.  EXPORTING
  50.    format                      = 'PDF'
  51.    pdf_delete_otftab           = 'X'
  52.  IMPORTING
  53.    bin_filesize                = lv_len
  54.    bin_file                    = pdf_xstring
  55.     otf                         = otf_output-otfdata[]
  56.     lines                       = lt_lines
  57.  EXCEPTIONS
  58.    err_max_linewidth           = 1
  59.    err_format                  = 2
  60.    err_conv_not_possible       = 3
  61.    err_bad_otf                 = 4
  62.    OTHERS                      = 5
  63.           .
  64. IF sy-subrc <> 0.
  65. * Implement suitable error handling here
  66.  
  67.  
  68. *     -------- convert document -------------------------------
  69. DATA pdf_content TYPE TABLE OF solix.
  70. pdf_content = cl_document_bcs=>xstring_to_solix( pdf_xstring ).
  71.  
  72.  
  73.  
  74. * For Email contents
  75.   DATA lv_internetadr TYPE adr6-smtp_addr.
  76.   DATA lv_subject TYPE so_obj_des.
  77.   DATA lv_attname TYPE sood-objdes.
  78.  
  79.   DATA  send_request       TYPE REF TO cl_bcs.
  80.   DATA  lt_text            TYPE bcsy_text.
  81.   DATA  ls_SOLI            TYPE soli.
  82.   DATA  document           TYPE REF TO cl_document_bcs.
  83.   DATA  recipient          TYPE REF TO if_recipient_bcs.
  84.   DATA  bcs_exception      TYPE REF TO cx_bcs.
  85.   DATA  sent_to_all        TYPE os_boolean.
  86.   DATA  sender             TYPE REF TO if_sender_bcs.
  87.   DATA  l_sendadr          TYPE adr6-smtp_addr.
  88.  
  89. * Email content
  90.     ls_SOLI-LINE = 'Dear Cusomer.'.
  91.     append ls_soli to lt_text.
  92.     ls_SOLI-LINE = 'Thank you for your order.'.
  93.     append ls_soli to lt_text.
  94.  
  95.   TRY.
  96. *     create the send request
  97.       send_request = cl_bcs=>create_persistent( ).
  98.  
  99. * Email subject
  100.       lv_subject = 'Test-Email mit Anhang'.
  101.       document = cl_document_bcs=>create_document(
  102.                                 i_type    = 'RAW'
  103.                                 i_text    = lt_text
  104.                                 i_subject = lv_subject ).
  105.  
  106. *     add list attachment to document
  107.       CONCATENATE 'Test' '.pdf' INTO lv_attname.
  108.       document->add_attachment( i_attachment_type    = 'PDF'
  109.                                 i_attachment_subject = lv_attname
  110.                                 i_att_content_hex    = pdf_content ).
  111.  
  112. *=============== Prep Send
  113.  
  114. *     add document to send request
  115.       send_request->set_document( document ).
  116.  
  117. *     create recipient and add to send request
  118.  
  119.         recipient = cl_cam_address_bcs=>create_internet_address( 'Deine@Email.de' ).
  120.  
  121.       send_request->add_recipient( i_recipient = recipient ).
  122.  
  123. *    create sender and add to send request
  124.       CONCATENATE 'Noreply@' sy-sysid '-' sy-mandt '.de' INTO l_sendadr.
  125.       sender = cl_cam_address_bcs=>create_internet_address( l_sendadr ).
  126.       send_request->set_sender( EXPORTING i_sender = sender ).
  127.  
  128.  
  129. *     send
  130.       send_request->set_send_immediately( i_send_immediately = 'X' ).
  131.       sent_to_all = send_request->send( i_with_error_screen = 'X' ).
  132.       IF sent_to_all = 'X'.
  133.         MESSAGE s022(so).
  134.       ENDIF.
  135.  
  136.     CATCH cx_bcs INTO bcs_exception.
  137.       MESSAGE e865(so) WITH bcs_exception->error_type.
  138.   ENDTRY.
  139.  
  140. commit work and wait.
  141.  
  142.  
GeSHi ©


lg Jens
Tron
.....
.....
 
Posts: 1112
Joined: Sat Aug 04, 2007 10:21 pm


Return to ABAP Objects®

Who is online

Users browsing this forum: No registered users and 2 guests

cron