Skip to Content
avatar image
Former Member

Script to PDF

Hi guys,

I have created a driver pgm and script inorder to convert the script o/p to pdf.

-


REPORT ZPDF.

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."""""""""""""""""""" ITCPO:-SAPscript output interface

DATA: PDFTAB TYPE TABLE OF TLINE WITH HEADER LINE, """"""""""""TLINE:-SAPscript: Text Lines

DATAB TYPE TABLE OF ITCOO WITH HEADER LINE.""""""""""""""ITCOO:-OTF Structure

DATA: BINFILESIZE TYPE I,

FILE_NAME TYPE STRING,

FILE_PATH TYPE STRING,

FULL_PATH TYPE STRING.

BINFILESIZE = 10000000.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

DEVICE = 'PRINTER'

DIALOG = SPACE

FORM = 'ZPDF'

  • 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 = 'ZPDF'

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

*________________________________________________________________--

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.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG

  • EXPORTING

  • WINDOW_TITLE =

  • DEFAULT_EXTENSION =

  • DEFAULT_FILE_NAME =

  • WITH_ENCODING =

  • FILE_FILTER =

  • INITIAL_DIRECTORY =

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

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE = binfilesize

FILENAME = FULL_PATH

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

  • WRITE_EOL = ABAP_TRUE

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

-


The program is working so is the script. But while downloading it to system the message comes that 0bytes transfered.

I think I need to add something more in the script all i have written is this.

/E ELEM1

* sCRIPT BY vIJAY

/E ELEM2

/ &ITAB-CARRID&

/ &ITAB-CONNID&

/ &ITAB-PRICE&

Do i need to add anything more.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 21, 2007 at 12:57 PM

    See the sample code and do accordingly

    REPORT zzz_jaytest .

    • Types Declaration

    TYPES : BEGIN OF ty_pa0001,

    pernr TYPE pa0001-pernr,

    bukrs TYPE pa0001-bukrs,

    werks TYPE pa0001-werks,

    END OF ty_pa0001.

    • Internal Table Declaration

    DATA : i_pa0001 TYPE STANDARD TABLE OF ty_pa0001, "For pa0001 Details

    i_otf TYPE STANDARD TABLE OF itcoo, "For OTF data

    i_content_txt TYPE soli_tab, "Content

    i_content_bin TYPE solix_tab, "Content

    i_objhead TYPE soli_tab,

    • Work Area Declaration

    w_pa0001 TYPE ty_pa0001, "For pa0001 Details

    w_res TYPE itcpp, "SAPscript output

    "parameters

    w_otf TYPE itcoo, "For OTF

    w_pdf TYPE solisti1, "For PDF

    w_transfer_bin TYPE sx_boolean, "Content

    w_options TYPE itcpo, "SAPscript output

    "interface

    • Variable Declaration

    v_len_in TYPE so_obj_len,

    v_size TYPE i.

    • Constants Declaration

    CONSTANTS : c_x TYPE c VALUE 'X', "X

    c_locl(4) TYPE c VALUE 'LOCL', "Local Printer

    c_otf TYPE sx_format VALUE 'OTF', "OTF

    c_pdf TYPE sx_format VALUE 'PDF', "PDF

    c_printer TYPE sx_devtype VALUE 'PRINTER', "PRINTER

    c_bin TYPE char10 VALUE 'BIN', "BIN

    c_name TYPE string VALUE 'C:\ZZZ_JAYTEST.PDF',"Downloading

    "File Name

    c_form(11) TYPE c VALUE 'ZZZ_JAYTEST'. "Form Name

    START-OF-SELECTION.

    • Selecting the records from pa0001

    SELECT pernr bukrs werks FROM pa0001

    INTO TABLE i_pa0001 UP TO 10 ROWS.

    • Setting the options

    w_options-tdcopies = 1 ."Number of copies

    w_options-tdnoprev = c_x."No print preview

    w_options-tdgetotf = c_x."Return of OTF table

    w_options-tddest = c_locl."Spool: Output device

    • Opening the form

    CALL FUNCTION 'OPEN_FORM'

    EXPORTING

    form = c_form

    device = c_printer

    language = sy-langu

    OPTIONS = w_options

    IMPORTING

    RESULT = w_res.

    LOOP AT i_pa0001 INTO w_pa0001.

    • Writting into the form

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    element = 'MAIN'

    window = 'MAIN'.

    ENDLOOP.

    • Closing the form

    CALL FUNCTION 'CLOSE_FORM'

    IMPORTING

    RESULT = w_res

    TABLES

    otfdata = i_otf

    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.

    • Converting OTF data to single line

    LOOP AT i_otf INTO w_otf.

    CONCATENATE w_otf-tdprintcom w_otf-tdprintpar

    INTO w_pdf.

    APPEND w_pdf TO i_content_txt.

    ENDLOOP.

    • Converting to PDF Format

    CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'

    EXPORTING

    format_src = c_otf

    format_dst = c_pdf

    devtype = c_printer

    CHANGING

    transfer_bin = w_transfer_bin

    content_txt = i_content_txt

    content_bin = i_content_bin

    objhead = i_objhead

    len = v_len_in

    EXCEPTIONS

    err_conv_failed = 1

    OTHERS = 2.

    v_size = v_len_in.

    • Downloading the PDF File

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    bin_filesize = v_size

    filename = c_name

    filetype = c_bin

    TABLES

    data_tab = i_content_bin.

    If you r using this function module check it once....

    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.

    • Fehlerhandling

    if sy-subrc <> 0.

    *

    endif.

    or u can use the standard program RSTXPDFT4 to download the script into PDF format onto a particular location

    follow this link for sample program.

    http://searchsap.techtarget.com/tip/0,289483,sid21_gci1121833,00.html

    regards,

    srinivas

    <b>*reward for useful answers*</b>

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 21, 2007 at 12:57 PM

    hi

    Visit this link for SAMple code of SAPSCRIPT to PDF.:

    http://www.sapgenie.com/abap/pdf_creation.htm

    and check the following weblog for code samples.

    /people/sap.user72/blog/2004/11/10/bsphowto-generate-pdf-output-from-a-bsp

    chk this one

    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

    some function modules useful would be

    CONVERT_OTF

    SO_NEW_DOCUMENT_ATT_SEND_API1 to send mails with attachments

    plzz refer to this link..it will solve ur problem

    sending-a-pdf-document-as-an-attachment

    sending-the-mail-with-pdf-attachment

    Regards

    ravish

    <b>plz dont forget to reward points if helpful</b>

    Add comment
    10|10000 characters needed characters exceeded