Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

SAP script

this is my code..

m converting script output to pdf and sending as attachment... my pdf conatains LOGO.. when i received the mail,text is coming properly but LOGO is not getting printed properly..

pls suggest any solution to this...

thanking u in advance...

&----


*& Report ZZGBTEST_PDF

*&

&----


*&

*&

&----


REPORT ZZGBTEST_PDF.

TABLES: PA0105.

DATA: LF_FM_NAME TYPE RS38L_FNAM.

DATA: WA_CTRLOP TYPE SSFCTRLOP,

WA_OUTOPT TYPE SSFCOMPOP,

WA_STXH LIKE STXH.

DATA: T_OTFDATA TYPE SSFCRESCL,

T_PDF_TAB LIKE TLINE OCCURS 0 WITH HEADER LINE,

T_LINE LIKE TLINE OCCURS 0 WITH HEADER LINE.

DATA : T_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

W_FILESIZE TYPE I,

W_BIN_FILESIZE TYPE I.

*OBJECTS TO SEND MAIL.

DATA : I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

I_OBJBIN LIKE SOLIX OCCURS 0 WITH HEADER LINE,

I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

W_OBJHEAD TYPE SOLI_TAB,

W_DOC_CHNG TYPE SODOCCHGI1,

W_BUFFER TYPe STRING. "TO CONVERT FROM 132 TO 255.

DATA : V_LINES_TXT TYPE I,

V_LINES_BIN TYPE I.

SELECTION-SCREEN BEGIN OF BLOCK SCR WITH FRAME TITLE TEXT-900.

SELECT-OPTIONS: MAILTO FOR PA0105-USRID_LONG NO INTERVALS.

PARAMETERS : WDATE LIKE SY-DATUM DEFAULT SY-DATUM,

TESTRUN AS CHECKBOX .

SELECTION-SCREEN END OF BLOCK SCR.

DATA: DATAB TYPE TABLE OF ITCOO WITH HEADER LINE,

PDFTAB TYPE TABLE OF TLINE WITH HEADER LINE,

BINFILESIZE TYPE I.

DATA: FNAME TYPE STRING,

FPATH TYPE STRING,

FULL_PATH TYPE STRING.

DATA: STRUCT TYPE ITCPO.

START-OF-SELECTION.

WA_CTRLOP-GETOTF = 'X'.

WA_CTRLOP-NO_DIALOG = 'X'.

WA_OUTOPT-TDNOPREV = 'X'.

STRUCT-TDDEST = 'LP01'.

STRUCT-TDNOPREV = 'X'.

STRUCT-TDGETOTF = 'X'.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

DEVICE = 'PRINTER'

DIALOG = SPACE

FORM = 'ZGBTEST'

LANGUAGE = SY-LANGU

OPTIONS = STRUCT

EXCEPTIONS

CANCELED = 1

DEVICE = 2

FORM = 3

OPTIONS = 4

UNCLOSED = 5

MAIL_OPTIONS = 6

ARCHIVE_ERROR = 7

INVALID_FAX_NUMBER = 8

MORE_PARAMS_NEEDED_IN_BATCH = 9

SPOOL_ERROR = 10

CODEPAGE = 11

OTHERS = 12

.

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 'WRITE_FORM'

EXPORTING

ELEMENT = 'MAIN'

WINDOW = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

EXCEPTIONS

ELEMENT = 1

FUNCTION = 2

TYPE = 3

UNOPENED = 4

UNSTARTED = 5

WINDOW = 6

BAD_PAGEFORMAT_FOR_PRINT = 7

SPOOL_ERROR = 8

CODEPAGE = 9

OTHERS = 10

.

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 'CLOSE_FORM'

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'

IMPORTING

BIN_FILESIZE = BINFILESIZE

TABLES

OTF = DATAB[]

LINES = T_PDF_TAB[]

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

ERR_BAD_OTF = 4

OTHERS = 5

.

IF SY-SUBRC EQ 0.

MESSAGE 'SCRIPT SUCCESSFULLY CONVERT IN TO PDF' TYPE 'I'.

ENDIF.

LOOP AT T_PDF_TAB.

  • REPLACING SPACE BY ~

TRANSLATE T_PDF_TAB USING ' ~'.

CONCATENATE W_BUFFER T_PDF_TAB INTO W_BUFFER.

ENDLOOP.

  • REPLACING ~ BY SPACE

TRANSLATE W_BUFFER USING '~ '.

DO.

I_RECORD = W_BUFFER.

  • APPENDING 255 CHARACTERS AS A RECORD

APPEND I_RECORD.

SHIFT W_BUFFER LEFT BY 255 PLACES.

IF W_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

REFRESH : I_RECLIST, I_OBJTXT, I_OBJBIN, I_OBJPACK.

CLEAR W_OBJHEAD.

  • OBJECT WITH PDF.

I_OBJBIN[] = I_RECORD[].

DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

    • MAIL TEXT TO BE FILLED UP HERE

SELECT SINGLE TDID TDSPRAS TDNAME TDOBJECT FROM STXH INTO

CORRESPONDING FIELDS OF WA_STXH

WHERE TDOBJECT ='TEXT' AND TDNAME = 'ZGBTEST'.

IF SY-SUBRC = 0.

CALL FUNCTION 'READ_TEXT'

EXPORTING

  • CLIENT = SY-MANDT

ID = WA_STXH-TDID

LANGUAGE = WA_STXH-TDSPRAS

NAME = WA_STXH-TDNAME

OBJECT = WA_STXH-TDOBJECT

TABLES

LINES = T_LINE.

LOOP AT T_LINE.

I_OBJTXT = T_LINE-TDLINE.

APPEND I_OBJTXT.

ENDLOOP.

ENDIF.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

  • DOCUMENT INFORMATION.

W_DOC_CHNG-OBJ_NAME = 'FORM'.

W_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

W_DOC_CHNG-SENSITIVTY = 'F'. "FUNCTIONAL OBJECT

W_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

  • PACK TO MAIN BODY AS RAW.

  • OBJ. TO BE TRANSPORTED NOT IN BINARY FORM

CLEAR I_OBJPACK-TRANSF_BIN.

  • START LINE OF OBJECT HEADER IN TRANSPORT PACKET

I_OBJPACK-HEAD_START = 1.

  • NUMBER OF LINES OF AN OBJECT HEADER IN OBJECT PACKET

I_OBJPACK-HEAD_NUM = 0.

  • START LINE OF OBJECT CONTENTS IN AN OBJECT PACKET

I_OBJPACK-BODY_START = 1.

  • NUMBER OF LINES OF THE OBJECT CONTENTS IN AN OBJECT PACKET

I_OBJPACK-BODY_NUM = V_LINES_TXT.

  • CODE FOR DOCUMENT CLASS

I_OBJPACK-DOC_TYPE = 'RAW'.

APPEND I_OBJPACK.

  • PACKING AS PDF.

I_OBJPACK-TRANSF_BIN = 'X'.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 1.

I_OBJPACK-BODY_START = 1.

I_OBJPACK-BODY_NUM = V_LINES_BIN.

I_OBJPACK-DOC_TYPE = 'PDF'.

I_OBJPACK-OBJ_NAME = 'FORM'.

I_OBJPACK-OBJ_DESCR = 'temp.PDF'.

I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255.

APPEND I_OBJPACK.

  • DOCUMENT INFORMATION.

CLEAR I_RECLIST.

CLEAR I_RECLIST[].

  • E-MAIL RECEIVERS.

.

LOOP AT MAILTO.

I_RECLIST-RECEIVER = MAILTO-LOW.

I_RECLIST-EXPRESS = 'X'.

I_RECLIST-REC_TYPE = 'U'. "INTERNET ADDRESS

APPEND I_RECLIST.

ENDLOOP.

  • SENDING MAIL.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = W_DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = I_OBJPACK

OBJECT_HEADER = W_OBJHEAD

CONTENTS_HEX = 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 :/ 'MAIL SENT SUCCESSFULLY...'.

ENDIF.

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question