cancel
Showing results for 
Search instead for 
Did you mean: 

Smartform to PDF to EMAIL

Former Member
0 Kudos

hi,

my code is like that...

i am getting blank pdf in email...

can anybody tell me why the material numbers r not populating in pdf?

i got some code from SDN forums.. with that i build the program..

code.....................

REPORT ZSF_TEST .

tables mara.

data itab like mara occurs 0 with header line.

Data fnam type rs38l_fnam.

  • Internal Table declarations

DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,

I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

  • Objects to send mail.

I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

I_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

  • Work Area declarations

WA_OBJHEAD TYPE SOLI_TAB,

W_CTRLOP TYPE SSFCTRLOP,

W_COMPOP TYPE SSFCOMPOP,

W_RETURN TYPE SSFCRESCL,

WA_DOC_CHNG TYPE SODOCCHGI1,

W_DATA TYPE SODOCCHGI1,

WA_BUFFER TYPE STRING, "To convert from 132 to 255

  • Variables declarations

V_FORM_NAME TYPE RS38L_FNAM,

V_LEN_IN LIKE SOOD-OBJLEN,

V_LEN_OUT LIKE SOOD-OBJLEN,

V_LEN_OUTN TYPE I,

V_LINES_TXT TYPE I,

V_LINES_BIN TYPE I,

XDOC TYPE XSTRING.

select * from mara into table itab.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZTEST'

IMPORTING

FM_NAME = fnam.

W_CTRLOP-GETOTF = 'X'.

W_CTRLOP-NO_DIALOG = ' '.

W_COMPOP-TDNOPREV = ' '.

CALL FUNCTION '/1BCDWB/SF00000023'

EXPORTING

CONTROL_PARAMETERS = W_CTRLOP

OUTPUT_OPTIONS = W_COMPOP

USER_SETTINGS = 'X'

IMPORTING

JOB_OUTPUT_INFO = W_RETURN

TABLES

itab_mara = itab

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

I_OTF[] = W_RETURN-OTFDATA[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

IMPORTING

BIN_FILESIZE = V_LEN_IN

TABLES

OTF = I_OTF

LINES = I_TLINE

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

ENDIF.

LOOP AT I_TLINE.

TRANSLATE I_TLINE USING '~'.

CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.

ENDLOOP.

TRANSLATE WA_BUFFER USING '~'.

DO.

I_RECORD = WA_BUFFER.

APPEND I_RECORD.

SHIFT WA_BUFFER LEFT BY 255 PLACES.

IF WA_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

  • Attachment

REFRESH: I_RECLIST,

I_OBJTXT,

I_OBJBIN,

I_OBJPACK.

CLEAR WA_OBJHEAD.

I_OBJBIN[] = I_RECORD[].

  • Create Message Body Title and Description

I_OBJTXT = 'test with pdf-Attachment!'.

APPEND I_OBJTXT.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

READ TABLE I_OBJTXT INDEX V_LINES_TXT.

WA_DOC_CHNG-OBJ_NAME = 'smartform'.

*WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

WA_DOC_CHNG-OBJ_DESCR = 'smartform'.

WA_DOC_CHNG-SENSITIVTY = 'F'.

WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

  • Main Text

CLEAR I_OBJPACK-TRANSF_BIN.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

I_OBJPACK-BODY_NUM = V_LINES_TXT.

I_OBJPACK-DOC_TYPE = 'RAW'.

APPEND I_OBJPACK.

  • Attachment (pdf-Attachment)

I_OBJPACK-TRANSF_BIN = 'X'.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

READ TABLE I_OBJBIN INDEX V_LINES_BIN.

I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

I_OBJPACK-BODY_NUM = V_LINES_BIN.

I_OBJPACK-DOC_TYPE = 'PDF'.

I_OBJPACK-OBJ_NAME = 'smart'.

I_OBJPACK-OBJ_DESCR = 'test'.

APPEND I_OBJPACK.

CLEAR I_RECLIST.

I_RECLIST-RECEIVER = 'mymail_id'.

I_RECLIST-REC_TYPE = 'U'.

APPEND I_RECLIST.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WA_DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = I_OBJPACK

OBJECT_HEADER = WA_OBJHEAD

CONTENTS_BIN = I_OBJBIN

CONTENTS_TXT = I_OBJTXT

RECEIVERS = I_RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

DOCUMENT_TYPE_NOT_EXIST = 3

OPERATION_NO_AUTHORIZATION = 4

PARAMETER_ERROR = 5

X_ERROR = 6

ENQUEUE_ERROR = 7

OTHERS = 8.

IF SY-SUBRC <> 0.

WRITE:/ 'Error When Sending the File', SY-SUBRC.

ELSE.

WRITE:/ 'Mail sent'.

ENDIF.

Regards

Giri

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

hi Probably u r not checking the table W_RETURN-OTFDATA[] is initial or not...

may be it is initial.. once chek it in debugging..

and r u able to see it in normal output.. once change the code and check whether the desired output is coming or not...

and check the sy-subrc after calling the FM CALL FUNCTION '/1BCDWB/SF00000023'

whether every thing is fine or not?

Former Member
0 Kudos

HI Naresh,

W_RETURN-OTFDATA[] is not initial. For testing purpose i used GUI_DOWNLOAD FM for downloading the PDF after the CONVERT_OTF FM.

Its downloading the PDF of smartform.

the modified code:

<b>I_OTF[] = W_RETURN-OTFDATA[].

                        • converting OTF data into pdf

  • data**************************

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

IMPORTING

BIN_FILESIZE = V_LEN_IN

TABLES

OTF = I_OTF

LINES = I_TLINE

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

ENDIF.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE = V_LEN_IN

filename = 'E:\TEST.PDF'

FILETYPE = 'BIN'

  • IMPORTING

  • FILELENGTH = FILE_SIZE

tables

data_tab = I_TLINE.

</b>

LOOP AT I_TLINE.

TRANSLATE I_TLINE USING '~'.

CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.

ENDLOOP.

TRANSLATE WA_BUFFER USING '~'.

DO.

I_RECORD = WA_BUFFER.

APPEND I_RECORD.

SHIFT WA_BUFFER LEFT BY 255 PLACES.

IF WA_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

  • Attachment

REFRESH: I_RECLIST,

I_OBJTXT,

I_OBJBIN,

I_OBJPACK.

CLEAR WA_OBJHEAD.

I_OBJBIN[] = I_RECORD[].

  • Create Message Body Title and Description

I_OBJTXT = 'test with pdf-Attachment!'.

APPEND I_OBJTXT.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

READ TABLE I_OBJTXT INDEX V_LINES_TXT.

WA_DOC_CHNG-OBJ_NAME = 'smartform'.

WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

WA_DOC_CHNG-OBJ_DESCR = 'smartform'.

WA_DOC_CHNG-SENSITIVTY = 'F'.

WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

  • Main Text

CLEAR I_OBJPACK-TRANSF_BIN.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

I_OBJPACK-BODY_NUM = V_LINES_TXT.

I_OBJPACK-DOC_TYPE = 'RAW'.

APPEND I_OBJPACK.

  • Attachment (pdf-Attachment)

I_OBJPACK-TRANSF_BIN = 'X'.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

READ TABLE I_OBJBIN INDEX V_LINES_BIN.

I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255.

I_OBJPACK-BODY_NUM = V_LINES_BIN.

I_OBJPACK-DOC_TYPE = 'PDF'.

I_OBJPACK-OBJ_NAME = 'email'.

I_OBJPACK-OBJ_DESCR = 'test'.

APPEND I_OBJPACK.

CLEAR I_RECLIST.

I_RECLIST-RECEIVER = 'mymail@gmail.com'.

I_RECLIST-REC_TYPE = 'U'.

APPEND I_RECLIST.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WA_DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = I_OBJPACK

OBJECT_HEADER = WA_OBJHEAD

CONTENTS_BIN = I_OBJBIN

CONTENTS_TXT = I_OBJTXT

RECEIVERS = I_RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

DOCUMENT_TYPE_NOT_EXIST = 3

OPERATION_NO_AUTHORIZATION = 4

PARAMETER_ERROR = 5

X_ERROR = 6

ENQUEUE_ERROR = 7

OTHERS = 8.

IF SY-SUBRC <> 0.

WRITE:/ 'Error When Sending the File', SY-SUBRC.

ELSE.

WRITE:/ 'Mail sent'.

ENDIF.

the code in bold working fine and i can see the pdf as in smartform. i think the problem is for attachment. cos i can see the attachment file size is same as pdf size downloaded. But when i try to open it says reading error of document (110).

if i add the below code before COVERT_OTF FM to the above code.. i can open the pdf in attachment but smartform data as pages... 1 1 2 3 2 3. coming twice.

<b>****removing the initial and final markers from the OTF data*********

DELETE W_RETURN-OTFDATA WHERE TDPRINTCOM = '//'.

*

                                    • searching for the end-of-page in OTF

*table***********

READ TABLE I_OTF WITH KEY TDPRINTCOM = 'EP'. MY_TABIX = SY-TABIX + 1.

**

                            • appending the modified OTF table to the final OTF

*table***

INSERT LINES OF W_RETURN-OTFDATA INTO I_OTF INDEX MY_TABIX.</b>

i am not sure where it is going wrong..

Regards

Giri

Former Member
0 Kudos

Problem has been solved.

Problem is with converting 132 to 255 characters.

Regards

Giri

Former Member
0 Kudos

Hi Giri,

how do you solve the this issue.

I've encountered the same problem.

thanks

Former Member
0 Kudos

HI Gokhan,

Use the FM to convert 132 char to 255 char for PDF.

SX_TABLE_LINE_WIDTH_CHANGE

Regards

Giri

Former Member
0 Kudos

Hi Giri,

Could you please send me the entire code (after resolving your earlier issue).

Many thanks in anticipation.

Vijay

Former Member
0 Kudos

hi...

I am encountering the same problem. Can you send me the correct code for it.

former_member671224
Participant
0 Kudos

Hi Giri,

Instead of using CALL FUNCTION '/1BCDWB/SF00000023' , try using CALL FUNCTION fnam.

And ur not getting in mail or not getting in PDF?

Try to download to local PC in PDF format. if it works fine u can try to send it in e-mail.

Regards,

Amal

Former Member
0 Kudos

hi Amal,

i downloaded the PDF and it is showing the smartform as it is.. i think the problem is when sending the email.

can u look at code for email pls?

i am not getting in PDF in email.

i am getting only blank PDF in email as attachment.

can anybody help me?

Regards

Giri