Skip to Content
author's profile photo Former Member
Former Member

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Nov 19, 2007 at 11:23 PM

    I have a doubt about this piece of code:

    * 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 '~ '.

    If you don't know the exact reason for this code, try to comment out this and test it.

    Regards,

    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 20, 2007 at 04:21 AM

    Hi Sagar,

    The piece of code pointed out is required to Transfer the 132-long strings to 255-long strings.

    So please uncomment that code. It is required.

    Regarding logo not displayed properly in PDF, please pass the spool number to program RSTXPDF4 & check whether it is coming properly.

    Also check whether the logo is displayed in spool properly through transaction SP01.

    Best regards,

    Prashant

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello prashantji, thank u for your reply,

      but i m not getting any problem in pdf format... logo is coming properly in pdf.. but the problem is occuring during mailing the pdf....

      so pls suggest some solution to this..

      thanks

  • Posted on Nov 20, 2007 at 06:37 AM
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.