Skip to Content
avatar image
Former Member

pdf

how to convert smartform into pdf format.plz

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • avatar image
    Former Member
    Mar 12, 2008 at 01:13 PM

    Check below code...

    Here is the code to send the Smartform to mail as PDF attachment.

    &----


    *& Report ZTEST_NREDDY_PDF_MAIL

    *&

    &----


    REPORT ZTEST_NREDDY_PDF_MAIL.

    • 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.

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    FORMNAME = 'ZTEST'

    IMPORTING

    FM_NAME = V_FORM_NAME

    EXCEPTIONS

    NO_FORM = 1

    NO_FUNCTION_MODULE = 2

    OTHERS = 3.

    IF SY-SUBRC <> 0.

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

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

    ENDIF.

    W_CTRLOP-GETOTF = 'X'.

    W_CTRLOP-NO_DIALOG = 'X'.

    W_COMPOP-TDNOPREV = 'X'.

    CALL FUNCTION V_FORM_NAME

    EXPORTING

    CONTROL_PARAMETERS = W_CTRLOP

    OUTPUT_OPTIONS = W_COMPOP

    USER_SETTINGS = 'X'

    IMPORTING

    JOB_OUTPUT_INFO = W_RETURN

    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 = 'nareshreddy.k@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.

    If you want to send some text as Body of the Mail then follow this once

    when u r callin the FM'SO_NEW_DOCUMENT_ATT_SEND_API1'.. points to remember

    1.u have to pass the body of content in table CONTENTS_TXT(ia m using I_OBJBIN) (each line a record) then. suppose i have appended 11 records to the table CONTENTS_TXT .

    2.PACKING_LIST(iam usign I_OBJPACK) table u ahve to append a redord as follows

    I_OBJPACK-TRANSF_BIN = ' '.

    I_OBJPACK-HEAD_START = 000000000000001.

    I_OBJPACK-HEAD_NUM = 000000000000001.

    I_OBJPACK-BODY_START = 000000000000002

    I_OBJPACK-BODY_NUM = 000000000000010.

    I_OBJPACK-DOC_TYPE = 'RAW'.

    append I_OBJPACK-.

    by the above code system treat the first line in table I_OBJBIN as header and the 2nd line to 10 lines tread as body.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = WA_DOC_CHNG

    PUT_IN_OUTBOX = '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.

    leave code which is been used to send as email...

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 12, 2008 at 01:14 PM

    Check out the below link

    http://www.saptechnical.com/Tutorials/Smartforms/OTF2PDF.htm

    * Function Module CONVERT_OTF is used to convert the OTF format to PDF
    
    CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
    FORMAT = 'PDF'
    MAX_LINEWIDTH = 132
    * ARCHIVE_INDEX = ' '
    * COPYNUMBER = 0
    * ASCII_BIDI_VIS2LOG = ' '
    * PDF_DELETE_OTFTAB = ' '
    IMPORTING
    BIN_FILESIZE = W_bin_filesize
    * BIN_FILE =
    TABLES
    otf = T_OTF
    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 <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
     

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 12, 2008 at 01:14 PM

    Hi,

    see this link:

    Creation of Smart Forms for PDF

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 12, 2008 at 01:15 PM

    You can use Function Module 'CONVERT_OTF_2_PDF' or print the smart form to a spool and download the spool into a PDF.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 12, 2008 at 02:28 PM

    Hi JayaSankar,

    REPORT ZPDF_TEST2 .

    data: i_otf LIKE itcoo OCCURS 100 WITH HEADER LINE,

    i_pdf LIKE tline OCCURS 100 WITH HEADER LINE.

    data: op_option type SSFCTRLOP,

    job_output type SSFCRESCL.

    op_option-getotf = 'X'.

    CALL FUNCTION '/1BCDWB/SF00000005'

    EXPORTING

    • ARCHIVE_INDEX =

    • ARCHIVE_INDEX_TAB =

    • ARCHIVE_PARAMETERS =

    CONTROL_PARAMETERS = op_option

    • MAIL_APPL_OBJ =

    • MAIL_RECIPIENT =

    • MAIL_SENDER =

    • OUTPUT_OPTIONS =

    • USER_SETTINGS = 'X'

    • itab1 = itab1

    IMPORTING

    • DOCUMENT_OUTPUT_INFO =

    JOB_OUTPUT_INFO = job_output

    • JOB_OUTPUT_OPTIONS =

    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.

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    FORMAT = 'PDF'

    • MAX_LINEWIDTH = 132

    • ARCHIVE_INDEX = ' '

    • COPYNUMBER = 0

    • ASCII_BIDI_VIS2LOG = ' '

    • PDF_DELETE_OTFTAB = ' '

    • IMPORTING

    • BIN_FILESIZE =

    • BIN_FILE =

    TABLES

    otf = job_output-otfdata

    lines = i_pdf

    • EXCEPTIONS

    • ERR_MAX_LINEWIDTH = 1

    • ERR_FORMAT = 2

    • ERR_CONV_NOT_POSSIBLE = 3

    • ERR_BAD_OTF = 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.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    • BIN_FILESIZE =

    filename = 'c:\test_pdf_sf.pdf'

    FILETYPE = 'BIN'

    tables

    data_tab = i_pdf

    • FIELDNAMES =

    EXCEPTIONS

    FILE_WRITE_ERROR = 1

    NO_BATCH = 2

    GUI_REFUSE_FILETRANSFER = 3

    INVALID_TYPE = 4

    NO_AUTHORITY = 5

    UNKNOWN_ERROR = 6

    HEADER_NOT_ALLOWED = 7

    SEPARATOR_NOT_ALLOWED = 8

    FILESIZE_NOT_ALLOWED = 9

    HEADER_TOO_LONG = 10

    DP_ERROR_CREATE = 11

    DP_ERROR_SEND = 12

    DP_ERROR_WRITE = 13

    UNKNOWN_DP_ERROR = 14

    ACCESS_DENIED = 15

    DP_OUT_OF_MEMORY = 16

    DISK_FULL = 17

    DP_TIMEOUT = 18

    FILE_NOT_FOUND = 19

    DATAPROVIDER_EXCEPTION = 20

    CONTROL_FLUSH_ERROR = 21

    OTHERS = 22

    .

    IF sy-subrc 0.

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

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

    ENDIF.

    Regards.

    Eshwar.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 12, 2008 at 02:36 PM

    Hi

    There is a way to download smartform in PDF format.

    Please do the following:

    1. Print the smartform to the spool.

    2. Note the spool number.

    3. Download a PDF file (Acrobat Reader) version of the spool by running Program RSTXPDFT4 and entering the

    noted spool number.

    or use this program:

    &----


    *& Report ZPDF_DNLD_TEST2 *

    *& *

    &----


    *& DEVK904540 *

    *& *

    &----


    REPORT ZPDF_DNLD_TEST2 .

    data: i_otf LIKE itcoo OCCURS 100 WITH HEADER LINE,

    i_pdf LIKE tline OCCURS 100 WITH HEADER LINE.

    data: op_option type SSFCTRLOP,

    job_output type SSFCRESCL.

    op_option-getotf = 'X'.

    CALL FUNCTION '/1BCDWB/SF00000005'

    EXPORTING

    ARCHIVE_INDEX =

    ARCHIVE_INDEX_TAB =

    ARCHIVE_PARAMETERS =

    CONTROL_PARAMETERS = op_option

    MAIL_APPL_OBJ =

    MAIL_RECIPIENT =

    MAIL_SENDER =

    OUTPUT_OPTIONS =

    USER_SETTINGS = 'X'

    itab1 = itab1

    IMPORTING

    DOCUMENT_OUTPUT_INFO =

    JOB_OUTPUT_INFO = job_output

    JOB_OUTPUT_OPTIONS =

    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.

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    FORMAT = 'PDF'

    MAX_LINEWIDTH = 132

    ARCHIVE_INDEX = ' '

    COPYNUMBER = 0

    ASCII_BIDI_VIS2LOG = ' '

    PDF_DELETE_OTFTAB = ' '

    IMPORTING

    BIN_FILESIZE =

    BIN_FILE =

    TABLES

    otf = job_output-otfdata

    lines = i_pdf

    EXCEPTIONS

    ERR_MAX_LINEWIDTH = 1

    ERR_FORMAT = 2

    ERR_CONV_NOT_POSSIBLE = 3

    ERR_BAD_OTF = 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.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    BIN_FILESIZE =

    filename = 'c:\test_pdf_sf.pdf'

    FILETYPE = 'BIN'

    tables

    data_tab = i_pdf

    FIELDNAMES =

    EXCEPTIONS

    FILE_WRITE_ERROR = 1

    NO_BATCH = 2

    GUI_REFUSE_FILETRANSFER = 3

    INVALID_TYPE = 4

    NO_AUTHORITY = 5

    UNKNOWN_ERROR = 6

    HEADER_NOT_ALLOWED = 7

    SEPARATOR_NOT_ALLOWED = 8

    FILESIZE_NOT_ALLOWED = 9

    HEADER_TOO_LONG = 10

    DP_ERROR_CREATE = 11

    DP_ERROR_SEND = 12

    DP_ERROR_WRITE = 13

    UNKNOWN_DP_ERROR = 14

    ACCESS_DENIED = 15

    DP_OUT_OF_MEMORY = 16

    DISK_FULL = 17

    DP_TIMEOUT = 18

    FILE_NOT_FOUND = 19

    DATAPROVIDER_EXCEPTION = 20

    CONTROL_FLUSH_ERROR = 21

    OTHERS = 22

    .

    IF sy-subrc 0.

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

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

    ENDIF.

    Add comment
    10|10000 characters needed characters exceeded