Skip to Content
avatar image
Former Member

Sap script to pdf

Hi,

We have a sap script and I want that script to be converted into a pdf...so can you please tell me how can I do that.

Thannks.

Rjaeev

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 10, 2009 at 02:04 PM

    hi,

    see example code from my print program:

      DATA: otf_data       LIKE itcoo OCCURS 0 WITH HEADER LINE,
            doctab_archive LIKE docs  OCCURS 0 WITH HEADER LINE,
            pdf_lines      LIKE tline OCCURS 0 WITH HEADER LINE.
    
      DATA: bin_filesize TYPE i.
    
        CALL FUNCTION 'CLOSE_FORM'
          IMPORTING
            RESULT  = i_itcpp
          TABLES
            otfdata = otf_data
          EXCEPTIONS
            OTHERS  = 1.
    
        CALL FUNCTION 'CONVERT_OTF_2_PDF'
          IMPORTING
            bin_filesize           = bin_filesize
          TABLES
            otf                    = otf_data
            doctab_archive         = doctab_archive
            lines                  = pdf_lines
          EXCEPTIONS
            err_conv_not_possible  = 1
            err_otf_mc_noendmarker = 2
            OTHERS                 = 3.
    
        CALL FUNCTION 'SCMS_DOWNLOAD'
          EXPORTING
            filename = 'C:\TEST_PDF.PDF'
            filesize = bin_filesize
            binary   = 'X'
            frontend = 'X'
          TABLES
            data     = pdf_lines
          EXCEPTIONS
            error    = 1
            OTHERS   = 2.
    

    regards,darek

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 10, 2009 at 03:45 PM

    Also,

    you can send the document on the spool, and after from spool :

    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    EXPORTING

    src_spoolid = '10302' " Spool Request Number

    IMPORTING

    pdf_bytecount = pdf_bytecount

    TABLES

    pdf = pdf.

    to download it into a PDF file.

    regards.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 06, 2009 at 12:11 PM

    Hello Rajeev,

    Do you want to display the PDF form in the portal? or in SAP R/3 system?

    Best Regards,

    Prashanth J R

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 06, 2009 at 12:16 PM

    HI,

    
    DATA:it_scr TYPE STANDARD TABLE OF st_scr,
          w_r type st_scr,
          struct type itcpo,
          pdftab type standard TABLE OF tline,
          datab TYPE standard TABLE OF itcoo.
    
    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                = BINFILE
         TABLES
          otf                         = datab
          lines                       = pdftab
        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.
    

    Regards,

    Manish

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 08, 2009 at 11:35 AM

    first u convert data into otf then after use folloiwng FM

    CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'

    EXPORTING

    i_otf = it_otfdata.

    Edited by: krupa jani on Aug 8, 2009 1:36 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 06, 2009 at 12:18 PM

    Hi ,

    Refer the fallowing code

    TABLES: likp, lips,itcpo.

    DATA: pdftab type standard TABLE OF tline,

    datab TYPE standard TABLE OF itcoo.

    itcpo-tdgetotf = 'X'.

    CALL FUNCTION 'OPEN_FORM'

    EXPORTING

    DEVICE = 'PRINTER'

    DIALOG = 'X'

    FORM = 'Z1989_PRAC'

    LANGUAGE = SY-LANGU

    OPTIONS = itcpo

    // call script using start_form and write_form.

    CALL FUNCTION 'END_FORM'

    IMPORTING

    RESULT = gi_ofc

    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

    .

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    FORMAT = 'PDF'

    IMPORTING

    BIN_FILESIZE = BINFILE

    TABLES

    otf = datab

    lines = pdftab

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    BIN_FILESIZE = binfile

    filename = 'D:\MYFILE.PDF' //give the address where u want output.

    FILETYPE = 'BIN'

    tables

    data_tab = pdftab

    i think it will solve your problem.

    Regards,

    Vijay

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 06, 2009 at 01:04 PM

    Hi rajeev,

    Here is the code for converting script into pdf with detailed description.

    REPORT Z1SCRIPT_TO_PDF .

    ****************************DECLARATIONS******************************** 
    
    DATA: BEGIN OF ITAB OCCURS 0, 
    
     CARRID TYPE SFLIGHT-CARRID, 
    
     CONNID TYPE SFLIGHT-CONNID, 
    
     PRICE TYPE SFLIGHT-PRICE, 
    
     END OF ITAB. 
    
     
    
    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 OF DECLARATIONS********************************

    *To specify Printer name* 
    
    struct-tddest = 'LP01'. 
    
     
    
    *To specify no Print Preview* 
    
    struct-tdnoprev = 'X'. 
    
     
    
    *To access the SAP Script output in OTF format* 
    
    struct-tdgetotf = 'X'. 
    
     
    
    ***************************SAPSCRIPT GENERATION******************************** 
    
     
    
    CALL FUNCTION 'OPEN_FORM' 
    
     EXPORTING 
    
    * APPLICATION = 'TX' 
    
    * ARCHIVE_INDEX = 
    
    * ARCHIVE_PARAMS = 
    
     DEVICE = 'PRINTER' 
    
     DIALOG = space 
    
     FORM = 'ZSCRIPT' 
    
    * LANGUAGE = SY-LANGU 
    
     OPTIONS = struct 
    
    * MAIL_SENDER = 
    
    * MAIL_RECIPIENT = 
    
    * MAIL_APPL_OBJECT = 
    
    * RAW_DATA_INTERFACE = '*' 
    
    * SPONUMIV = 
    
    * IMPORTING 
    
    * LANGUAGE = 
    
    * NEW_ARCHIVE_PARAMS = 
    
    * RESULT = 
    
     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 'START_FORM' 
    
     EXPORTING 
    
    * ARCHIVE_INDEX = 
    
     FORM = 'ZSCRIPT' 
    
    * LANGUAGE = ' ' 
    
    * STARTPAGE = ' ' 
    
    * PROGRAM = ' ' 
    
    * MAIL_APPL_OBJECT = 
    
    * IMPORTING 
    
    * LANGUAGE = 
    
     EXCEPTIONS 
    
     FORM = 1 
    
     FORMAT = 2 
    
     UNENDED = 3 
    
     UNOPENED = 4 
    
     UNUSED = 5 
    
     SPOOL_ERROR = 6 
    
     CODEPAGE = 7 
    
     OTHERS = 8 
    
     . 
    
     
    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 = 'ELEM1' 
    
     FUNCTION = 'SET' 
    
     TYPE = 'BODY' 
    
     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.

    SELECT CARRID CONNID PRICE FROM SFLIGHT INTO TABLE ITAB. 
    
     
    
    LOOP AT ITAB. 
    
    CALL FUNCTION 'WRITE_FORM' 
    
     
     EXPORTING 
    
     ELEMENT = 'ELEM2' 
    
     FUNCTION = 'SET' 
    
     TYPE = 'BODY' 
    
     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. 
    
    ENDLOOP. 
    
     
    
    CALL FUNCTION 'END_FORM' 
    
    * IMPORTING 
    
    * RESULT = 
    
     EXCEPTIONS 
    
     UNOPENED = 1 
    
     BAD_PAGEFORMAT_FOR_PRINT = 2 
    
     SPOOL_ERROR = 3 
    
     CODEPAGE = 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 '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. 
    
     
    
    ***************************END OF SAPSCRIPT 
    GENERATION********************************

    ***************************CONVERTING OTF DATA TO PDF 
    DATA**************************** 
    
     
    
    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 
    
     . 
    
    IF sy-subrc <> 0. 
    
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 
    
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
    
    ENDIF.

    *****************TAKING THE DOWNLOAD FILE PATH AS USER 
    INPUT************************* 
    
     
    
    CALL METHOD cl_gui_frontend_services=>file_save_dialog 
    
    * EXPORTING 
    
    * WINDOW_TITLE = 
    
    * DEFAULT_EXTENSION = 
    
    * DEFAULT_FILE_NAME = 
    
    * FILE_FILTER = 
    
    * INITIAL_DIRECTORY = 
    
    * WITH_ENCODING = 
    
    * PROMPT_ON_OVERWRITE = 'X' 
    
     CHANGING 
    
     
     filename = FILE_NAME 
    
     path = FILE_PATH 
    
     fullpath = FULL_PATH 
    
    * USER_ACTION = 
    
    * FILE_ENCODING = 
    
    * EXCEPTIONS 
    
    * CNTL_ERROR = 1 
    
    * ERROR_NO_GUI = 2 
    
    * NOT_SUPPORTED_BY_GUI = 3 
    
    * others = 4 
    
     . 
    
    IF sy-subrc <> 0. 
    
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 
    
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
    
    ENDIF.

    ****************************DOWNLOADING THE PDF 
    DATA********************************** 
    
    CALL FUNCTION 'GUI_DOWNLOAD' 
    
     EXPORTING 
    
     BIN_FILESIZE = binfilesize 
    
     FILENAME = 'D:\myfile.pdf' 
    
     FILETYPE = 'BIN' 
    
    * APPEND = ' ' 
    
    * WRITE_FIELD_SEPARATOR = ' ' 
    
    * HEADER = '00' 
    
    * TRUNC_TRAILING_BLANKS = ' ' 
    
    * WRITE_LF = 'X' 
    
    * COL_SELECT = ' ' 
    
    * COL_SELECT_MASK = ' ' 
    
    * DAT_MODE = ' ' 
    
    * CONFIRM_OVERWRITE = ' ' 
    
    * NO_AUTH_CHECK = ' ' 
    
    * CODEPAGE = ' ' 
    
     
    * IGNORE_CERR = ABAP_TRUE 
    
    * REPLACEMENT = '#' 
    
    * WRITE_BOM = ' ' 
    
    * TRUNC_TRAILING_BLANKS_EOL = 'X' 
    
    * WK1_N_FORMAT = ' ' 
    
    * WK1_N_SIZE = ' ' 
    
    * WK1_T_FORMAT = ' ' 
    
    * WK1_T_SIZE = ' ' 
    
    * IMPORTING 
    
    * FILELENGTH = 
    
     tables 
    
     data_tab = PDFTAB[] 
    
    * 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.

    This is the step by step process for converting script into pdf.

    Thank you,

    Pavan.

    Add comment
    10|10000 characters needed characters exceeded