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

Text File to PDF Conversion - Urgent

Hi,

Anybody knows how to convert a text tab limited file into PDF Format or to convert an internal table data to PDF directly...

Regards

Jiku

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 15, 2007 at 09:28 AM
    first u write Internal table to spool then u can convert the spool to pdf....see the below code.. hope it helps...
    
    
    DATA: BEGIN OF i_mara OCCURS 0,
    matnr LIKE mara-matnr.
    DATA: END OF i_mara.
    
    DATA: v_dest LIKE tsp01-rqdest,
    v_handle LIKE sy-tabix,
    v_spool_id LIKE tsp01-rqident,
    v_rc TYPE c,
    v_errmessage(100) TYPE c,
    v_text(70) TYPE c.
    
    START-OF-SELECTION.
    
    SELECT matnr FROM mara INTO TABLE i_mara.
    
    CALL FUNCTION 'RSPO_OPEN_SPOOLREQUEST'
    EXPORTING
    dest = 'LOCL'
    * LAYOUT =
    * NAME =
    * SUFFIX1 =
    * SUFFIX2 =
    * COPIES =
    * PRIO =
    * IMMEDIATE_PRINT =
    * AUTO_DELETE =
    * TITLELINE =
    * RECEIVER =
    * DIVISION =
    * AUTHORITY =
    * POSNAME =
    * ACTTIME =
    * LIFETIME = '8'
    * APPEND =
    * COVERPAGE =
    * CODEPAGE =
    * DOCTYPE =
    IMPORTING
    handle = v_handle
    spoolid = gd_spool_nr
    rc = v_rc
    errmessage = v_errmessage.
    
    LOOP AT i_mara.
    v_text = i_mara-matnr.
    CALL FUNCTION 'RSPO_WRITE_SPOOLREQUEST'
    EXPORTING
    handle = v_handle
    text = v_text
    * LENGTH =
    * CODEPAGE =
    * TRUNCATE =
    IMPORTING
    rc = v_rc
    errmessage = v_errmessage
    EXCEPTIONS
    handle_not_valid = 1
    OTHERS = 2.
    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 'RSPO_CLOSE_SPOOLREQUEST'
    EXPORTING
    handle = v_handle
    IMPORTING
    rc = v_rc
    errmessage = v_errmessage
    EXCEPTIONS
    handle_not_valid = 1
    OTHERS = 2.
    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_ABAPSPOOLJOB_2_PDF'
    EXPORTING
    src_spoolid = gd_spool_nr
    no_dialog = c_no
    dst_device = c_device
    IMPORTING
    pdf_bytecount = gd_bytecount
    TABLES
    pdf = it_pdf_output
    EXCEPTIONS
    err_no_abap_spooljob = 1
    err_no_spooljob = 2
    err_no_permission = 3
    err_conv_not_possible = 4
    err_bad_destdevice = 5
    user_cancelled = 6
    err_spoolerror = 7
    err_temseerror = 8
    err_btcjob_open_failed = 9
    err_btcjob_submit_failed = 10
    err_btcjob_close_failed = 11
    OTHERS = 12.
    CHECK sy-subrc = 0.
    
    

    If useful reward

    Vasanth

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Mir ist aufgefallen, daß in unserem SRM-System (alte Version: 4.0) schon bei den Funktionsbausteinen

      RSPO_OPEN_SPOOLREQUEST

      RSPO_WRITE_SPOOLREQUEST

      RSPO_CLOSE_SPOOLREQUEST

      in der Beschreibung steht "(Alte Schnittstelle)".

  • author's profile photo Former Member
    Former Member
    Posted on May 15, 2007 at 09:31 AM

    hi,

    Check the program <b>RSTXPDF4</b>. It converts the given spool no into PDF file.

    Create a spool from the data in internal table and call the program RSTXPDF4.

    Sample code to write to spool.

    CONSTANTS: CX_MARK(1) TYPE C VALUE 'X',       
               C_ROWS TYPE I VALUE 65,            
               C_COLS TYPE I VALUE 132,           
               C_LAY(16) TYPE C VALUE 'X_65_132'. 
    DATA: VAL(1) TYPE C.
    DATA: PRIPAR LIKE PRI_PARAMS.
    START-OF-SELECTION.
    
    PERFORM GET_PRINT_PARAM.
    NEW-PAGE PRINT ON NEW-SECTION
            PARAMETERS PRIPAR NO DIALOG.
    PERFORM PRINT_SPOOL.
    NEW-PAGE PRINT OFF.
    
    FORM PRINT_SPOOL.
      WRITE : / 'this is test spool -- test 7:30'. "<--loop "your internal table.
    ENDFORM.  
    
    
    FORM GET_PRINT_PARAM.
    CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
    *         ARCHIVE_ID             = C_CHAR_UNKNOWN
    *         ARCHIVE_INFO           = C_CHAR_UNKNOWN
    *         ARCHIVE_MODE           = C_CHAR_UNKNOWN
    *         ARCHIVE_TEXT           = C_CHAR_UNKNOWN
    *         AR_OBJECT              = C_CHAR_UNKNOWN
    *         AUTHORITY              = C_CHAR_UNKNOWN
    *         COPIES                 = C_NUM3_UNKNOWN
    *         COVER_PAGE             = C_CHAR_UNKNOWN
    *         DATA_SET               = C_CHAR_UNKNOWN
    *         DEPARTMENT             = C_CHAR_UNKNOWN
    *         DESTINATION            = C_CHAR_UNKNOWN
    *         EXPIRATION             = C_NUM1_UNKNOWN
    *         IMMEDIATELY            = C_CHAR_UNKNOWN
    *         IN_ARCHIVE_PARAMETERS  = ' '
    *         IN_PARAMETERS          = ' '
    *         LAYOUT                 = C_CHAR_UNKNOWN
    *         LINE_COUNT             = C_INT_UNKNOWN
    *         LINE_SIZE              = C_INT_UNKNOWN
    *         LIST_NAME              = C_CHAR_UNKNOWN
    *         LIST_TEXT              = C_CHAR_UNKNOWN
    *         MODE                   = ' '
    *         NEW_LIST_ID            = C_CHAR_UNKNOWN
              NO_DIALOG              = CX_MARK
    *         RECEIVER               = C_CHAR_UNKNOWN
    *         RELEASE                = C_CHAR_UNKNOWN
    *         REPORT                 = C_CHAR_UNKNOWN
    *         SAP_COVER_PAGE         = C_CHAR_UNKNOWN
    *         SAP_OBJECT             = C_CHAR_UNKNOWN
    *         TYPE                   = C_CHAR_UNKNOWN
    *    IMPORTING
    *         OUT_ARCHIVE_PARAMETERS =
              OUT_PARAMETERS         = PRIPAR
              VALID                  = VAL
         EXCEPTIONS
              ARCHIVE_INFO_NOT_FOUND = 1
              INVALID_PRINT_PARAMS   = 2
              INVALID_ARCHIVE_PARAMS = 3
              OTHERS                 = 4.
    
    * Output device
      IF PRIPAR-PDEST IS INITIAL.
         PRIPAR-PDEST = 'LOCL'.
      ENDIF.
    
    * Number of copies
      PRIPAR-PRCOP = '001'.
    
    *Name of spool request
      CONCATENATE SY-CPROG '_' SY-UNAME+0(3) INTO PRIPAR-PLIST.
    
    * Text for cover sheet
      CONCATENATE SY-TITLE SPOOLLOG INTO PRIPAR-PRTXT SEPARATED BY SPACE.
    
    * Print immediately
      PRIPAR-PRIMM = SPACE.
    
    * Delete after printing
      PRIPAR-PRREL = SPACE.
    
    * new spool request
      PRIPAR-PRNEW = CX_MARK.
    
    * Spool retention period
      IF PRIPAR-PEXPI IS INITIAL.
         PRIPAR-PEXPI = '8'.
      ENDIF.
    
    * Number of list lines
      PRIPAR-LINCT = C_ROWS.
    
    * Line size of list
      PRIPAR-LINSZ = C_COLS.
    
    * Format
      PRIPAR-PAART = C_LAY.
    
    * Selection cover sheet
      PRIPAR-PRBIG = SPACE.
    
    * SAP cover sheet
      PRIPAR-PRSAP = 'D'.
    
    * Recipient
      PRIPAR-PRREC = SY-UNAME.
    
    * Department on cover sheet
      PRIPAR-PRABT = SPACE.
    
    * Authorization
      PRIPAR-PRBER = SPACE.
    
    * Name of spool dataset
      IF PRIPAR-PRDSN IS INITIAL.
        PRIPAR-PRDSN = 'LIST1S'.
      ENDIF.
    
    * Type of spool request
      IF PRIPAR-PTYPE IS INITIAL.
         PRIPAR-PTYPE = 'TEXT'.
    *    pripar-ptype = 'OTF'.
      ENDIF.
    
    * Archiving mode
      PRIPAR-ARMOD = '1'.    "Print only
    
    * Output footer
      PRIPAR-FOOTL = SPACE.
    
    * Check sum for print and archiving parameters
     PERFORM COMPUTE_CHECKSUM USING PRIPAR CHANGING PRIPAR-PRCHK.
    ENDFORM.                    " GET_PRINT_PARAM
    
    
    *------------------------------------*
    *&      Form  COMPUTE_CHECKSUM
    *------------------------------------*
    FORM COMPUTE_CHECKSUM USING    P_BUFFER TYPE ANY
                          CHANGING P_CHECKSUM TYPE I.
      FIELD-SYMBOLS <L_FS>.
      DATA L_LENGTH TYPE I.
      P_CHECKSUM = 0.
      DESCRIBE FIELD P_BUFFER LENGTH L_LENGTH.
      SUBTRACT 4 FROM L_LENGTH.
      ASSIGN P_BUFFER(1) TO <L_FS> TYPE 'X'.
      DO L_LENGTH TIMES.
        ADD <L_FS> TO P_CHECKSUM.
        ASSIGN <L_FS>+1 TO <L_FS>.
      ENDDO.
    
    ENDFORM.                    " COMPUTE_CHECKSUM
    

    Regards

    Sailaja.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 15, 2007 at 10:59 AM

    Hi,

    Thanks for your replies...

    I'm using RSPO_OPEN_SPOOLREQUEST

    and getting an error like "There was an error opening this document. The file cannot be opened because it has no pages" and if I check the spool the pages is 0 but i could able to see the contents in the spool.

    Regards

    Jiku

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 11:11 AM

    Currently Im trying to implement the same thing. Any solutions yet?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 11, 2008 at 08:01 AM

    Hi,

    Refer to the following code:

    form F_CREATE_PDF using P_SPOOLNO

    P_DUNIX

    P_FILE

    P_DOCNUM.

    data OTF like ITCOO occurs 100 with header line.

    data CANCEL.

    data PDF like TLINE occurs 100 with header line.

    data DOCTAB like DOCS occurs 1 with header line.

    data: NUMBYTES type I,

    ARC_IDX like TOA_DARA,

    PDFSPOOLID like TSP01-RQIDENT,

    JOBNAME like TBTCJOB-JOBNAME,

    JOBCOUNT like TBTCJOB-JOBCOUNT,

    IS_OTF.

    data: CLIENT like TST01-DCLIENT,

    NAME like TST01-DNAME,

    OBJTYPE like RSTSTYPE-TYPE,

    TYPE like RSTSTYPE-TYPE.

    tables: TSP01.

    select single * from TSP01 where RQIDENT = P_SPOOLNO.

    if SY-SUBRC <> 0.

    WF_ERROR = 'X'.

    WF_MESSAGE = TEXT-006. "Spool file not generated

    exit.

    endif.

    CLIENT = TSP01-RQCLIENT.

    NAME = TSP01-RQO1NAME.

    call function 'RSTS_GET_ATTRIBUTES'

    exporting

    AUTHORITY = 'SP01'

    CLIENT = CLIENT

    NAME = NAME

    PART = 1

    importing

    TYPE = TYPE

    OBJTYPE = OBJTYPE

    exceptions

    FB_ERROR = 1

    FB_RSTS_OTHER = 2

    NO_OBJECT = 3

    NO_PERMISSION = 4.

    if OBJTYPE(3) = 'OTF'.

    IS_OTF = 'X'.

    else.

    IS_OTF = SPACE.

    endif.

    if IS_OTF = 'X'.

    call function 'CONVERT_OTFSPOOLJOB_2_PDF'

    exporting

    SRC_SPOOLID = P_SPOOLNO

    NO_DIALOG = ' '

    importing

    PDF_BYTECOUNT = NUMBYTES

    PDF_SPOOLID = PDFSPOOLID

    BTC_JOBNAME = JOBNAME

    BTC_JOBCOUNT = JOBCOUNT

    tables

    PDF = PDF

    exceptions

    ERR_NO_OTF_SPOOLJOB = 1

    ERR_NO_SPOOLJOB = 2

    ERR_NO_PERMISSION = 3

    ERR_CONV_NOT_POSSIBLE = 4

    ERR_BAD_DSTDEVICE = 5

    USER_CANCELLED = 6

    ERR_SPOOLERROR = 7

    ERR_TEMSEERROR = 8

    ERR_BTCJOB_OPEN_FAILED = 9

    ERR_BTCJOB_SUBMIT_FAILED = 10

    ERR_BTCJOB_CLOSE_FAILED = 11.

    if SY-SUBRC <> 0.

    WF_ERROR = 'X'.

    WF_MESSAGE = TEXT-023. " Error while converting spool file to PDF

    exit.

    endif.

    else.

    call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

    exporting

    SRC_SPOOLID = P_SPOOLNO

    NO_DIALOG = ' '

    importing

    PDF_BYTECOUNT = NUMBYTES

    PDF_SPOOLID = PDFSPOOLID

    BTC_JOBNAME = JOBNAME

    BTC_JOBCOUNT = JOBCOUNT

    tables

    PDF = PDF

    exceptions

    ERR_NO_ABAP_SPOOLJOB = 1

    ERR_NO_SPOOLJOB = 2

    ERR_NO_PERMISSION = 3

    ERR_CONV_NOT_POSSIBLE = 4

    ERR_BAD_DESTDEVICE = 5

    USER_CANCELLED = 6

    ERR_SPOOLERROR = 7

    ERR_TEMSEERROR = 8

    ERR_BTCJOB_OPEN_FAILED = 9

    ERR_BTCJOB_SUBMIT_FAILED = 10

    ERR_BTCJOB_CLOSE_FAILED = 11.

    if SY-SUBRC <> 0.

    WF_ERROR = 'X'.

    WF_MESSAGE = TEXT-023. " Error while converting spool file to PDF

    exit.

    endif.

    endif.

    • download PDF file ***********

    check P_DUNIX = 'X'.

    if not ( JOBNAME is initial ).

    WF_ERROR = 'X'.

    WF_MESSAGE = TEXT-023. " Error while converting spool file to PDF

    exit.

    endif.

    perform DOWNLOAD_W_EXT tables PDF

    using P_FILE

    'BIN'

    P_DOCNUM.

    endform. "f_create_pdf

    Hope this helps.

    Reward if helpful.

    Regards,

    Sipra

    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.