Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

send mail with attachment

Former Member
0 Likes
365

Hi,

I created a PDF from a sapscript, but when I want to send it trough mail, the attachment won 't open....

I sarched the forum several times, but didn 't found a solution..

This is my code


DATA: struct TYPE ITCPO.
DATA: PDFTAB TYPE TABLE OF TLINE WITH HEADER LINE,
DATAB TYPE TABLE OF ITCOO WITH HEADER LINE.
DATA: BINFILESIZE TYPE I,
FILE_NAME TYPE STRING,
FILE_PATH TYPE STRING,
FULL_PATH TYPE STRING.
****************************END DECLARATIONS***************************
*To specify Printer name*
*To specify no Print Preview*
struct-tdnoprev = 'X'.
struct-TDnoprint = 'X'.
*To access the SAP Script output in OTF format*
struct-tdgetotf = 'X'.
***************************SAPSCRIPTSGENERATION*************************
*******

CALL FUNCTION 'OPEN_FORM'
     EXPORTING
          form     = 'YBA34_MA_INVOICE'
          dialog   = ' '
          options = struct
     EXCEPTIONS
          canceled = 1
          device   = 2
          form     = 3
          options  = 4
          unclosed = 5
          OTHERS   = 6.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.

TABLES : vbrp ,
         vbrk ,
         vbak ,
         vbap ,
         t880 ,
         t005 ,
         t005t,
         t001 ,
         tvak ,
         tvakt,
         t001n,
         kna1,
         vbpa,
         knvk.

DATA : wa_bd TYPE vbeln,
       wa_parnr type parnr.


PARAMETERS : wa_vbeln TYPE vbeln.




*data selection
SELECT  * FROM vbrp
WHERE aubel = wa_vbeln.
ENDSELECT.

CLEAR wa_bd.
LOOP AT vbrp.
  wa_bd = vbrp-vbeln.
  EXIT.
ENDLOOP.

SELECT SINGLE * FROM vbrk
WHERE vbeln = vbrp-vbeln.

SELECT SINGLE * FROM vbak
WHERE vbeln = wa_vbeln.

SELECT SINGLE * FROM tvakt
WHERE auart = vbak-auart.

SELECT SINGLE * FROM t880
  WHERE rcomp = vbrk-vkorg.

SELECT SINGLE * FROM t005t
WHERE land1 = t880-cntry.

SELECT SINGLE * FROM t005
WHERE land1 = t880-cntry.

  SELECT SINGLE * FROM t001
  WHERE bukrs = 'BE30'.

  SELECT SINGLE * FROM t001n
  WHERE bukrs LIKE 'BE3%'
  AND land1 = vbak-landtx.


  SELECT SINGLE * FROM kna1
  WHERE kunnr = vbrk-kunag.

  SELECT SINGLE parnr FROM vbpa
  INTO wa_parnr
  WHERE vbeln = vbrp-aubel
  AND parvw = 'AG'.

  SELECT SINGLE * FROM knvk
  WHERE parnr = wa_parnr.

CALL FUNCTION 'WRITE_FORM'
     EXPORTING
          function = 'SET'
          type     = 'BODY'
          window   = 'MAIN'
     EXCEPTIONS
          OTHERS   = 1.
IF sy-subrc <> 0.
 
ENDIF.

* Close customer form
CALL FUNCTION 'END_FORM'
     EXCEPTIONS
          OTHERS = 1.
IF sy-subrc <> 0.
  WRITE 'Error in end_form'(006).
  EXIT.
ENDIF.

CALL FUNCTION 'CLOSE_FORM'
* IMPORTING
* RESULT =
* RDI_RESULT =
TABLES
OTFDATA = datab[]
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SEND_ERROR = 3
SPOOL_ERROR = 4
CODEPAGE = 5
OTHERS = 6
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
 MAX_LINEWIDTH = 132
* ARCHIVE_INDEX = ' '
* COPYNUMBER = 0
* ASCII_BIDI_VIS2LOG = ' '
* PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = BINFILESIZE
* BIN_FILE =
TABLES
otf = DATAB[]
lines = PDFTAB[]
* EXCEPTIONS
* ERR_MAX_LINEWIDTH = 1
* ERR_FORMAT = 2
* ERR_CONV_NOT_POSSIBLE = 3
* ERR_BAD_OTF = 4
* OTHERS = 5

When I save the table PDFTAB[], I can open the PDF, but ailing won 't work...

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
337

Possibly caused by length of fields.

PDF returned from SAPscript is in a table with lines 134 long (2 + 132) and is binary data. Email send mainly uses attachments in internal tables of 255 char length.

so to email a PDF need to merge lines from table into longer format to maintain binary file integrity.

that is -

line 1 of output (255) = first 255 char of [ line1 of input(134) line2 of input(134) ]

line 2 of output (255) = first 255 char of [ remains of line2 of input+ line3 of input + line4 ]

etc.

fairly simple to do in a loop - but take care using CONCATENATE as this can drop / shorten spaces which will break the PDF again.

possible code:

loop at in_tab into in_tab_wa.

temp_str+len(134) = in_tab_wa.

len = len + 134.

if len > 255.

out_tab_wa = temp_str+0(255).

append out_tab_wa to out_tab.

temp_str = temp_str+255.

len = len - 255.

endif.

endloop.

  • Add final bit of file

if not temp_str is initial.

out_tab_wa = temp_str+0(255).

append out_tab_wa to out_tab.

endif.

this code not tested.

Andrew

Possibly caused by length of fields.

PDF returned from SAPscript is in a table with lines 134 long (2 + 132) and is binary data. Email send mainly uses attachments in internal tables of 255 char length.

so to email a PDF need to merge lines from table into longer format to maintain binary file integrity.

that is -

line 1 of output (255) = first 255 char of [ line1 of input(134) line2 of input(134) ]

line 2 of output (255) = first 255 char of [ remains of line2 of input+ line3 of input + line4 ]

etc.

fairly simple to do in a loop - but take care using CONCATENATE as this can drop / shorten spaces which will break the PDF again.

possible code:

loop at in_tab into in_tab_wa.

temp_str+len(134) = in_tab_wa.

len = len + 134.

if len > 255.

out_tab_wa = temp_str+0(255).

append out_tab_wa to out_tab.

temp_str = temp_str+255.

len = len - 255.

endif.

endloop.

  • Add final bit of file

if not temp_str is initial.

out_tab_wa = temp_str+0(255).

append out_tab_wa to out_tab.

endif.

this code not tested.

Andrew

1 REPLY 1
Read only

Former Member
0 Likes
338

Possibly caused by length of fields.

PDF returned from SAPscript is in a table with lines 134 long (2 + 132) and is binary data. Email send mainly uses attachments in internal tables of 255 char length.

so to email a PDF need to merge lines from table into longer format to maintain binary file integrity.

that is -

line 1 of output (255) = first 255 char of [ line1 of input(134) line2 of input(134) ]

line 2 of output (255) = first 255 char of [ remains of line2 of input+ line3 of input + line4 ]

etc.

fairly simple to do in a loop - but take care using CONCATENATE as this can drop / shorten spaces which will break the PDF again.

possible code:

loop at in_tab into in_tab_wa.

temp_str+len(134) = in_tab_wa.

len = len + 134.

if len > 255.

out_tab_wa = temp_str+0(255).

append out_tab_wa to out_tab.

temp_str = temp_str+255.

len = len - 255.

endif.

endloop.

  • Add final bit of file

if not temp_str is initial.

out_tab_wa = temp_str+0(255).

append out_tab_wa to out_tab.

endif.

this code not tested.

Andrew