Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

how to generate a PDF file directly of current report program?

hi,

i have to generate PDF file directly of current executing report program.

for eg:

DATA: BUTTONS LIKE SY-UCOMM,
      SAVE_OK LIKE BUTTONS,
      OUTPUT(10) TYPE C.

set pf-status 'M100'.

WRITE: 'HELLO'.

now in ouput in menubar there is button PDF file.

when ever i clicked PDF button in output of this report, then the output of this report has to be convert as PDF file and storing into local disk.

I know how to convert to PDF from spool request. But here i have to genrate PDF directly from the current report itself...

Any helps...

Regards,

Shankar.

Tags:
replied

Below is the report code for report output in PDF

Create the PF-Status with one button and give code as 'PDF'.

After running this report it will ask you to save one file.

So save that file as PDF .

*&---------------------------------------------------------------------*
*& Report  ZNA_REPORT_PDF
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZNA_REPORT_PDF NO STANDARD PAGE HEADING.

*&---------------------------------------------------------------------

*&---------------------------------------------------------------------
*& Description: Simple Program to generate PDF from ABAP List Output
*&---------------------------------------------------------------------
*    * PF-status containing a PDF button in the report Output to generate
*    * PDF form

SET PF-STATUS 'Z_PDF'.
*----------------------------------------------------------------------
*Table Declarations
*----------------------------------------------------------------------
TABLES: MARA, MARC, MAKT.
*---------------------------------------------------------------------
*    * INTERNAL TABLE DECLARATIONS
*----------------------------------------------------------------------
DATA: BEGIN OF TS_MARA OCCURS 0,
         MATNR LIKE MARA-MATNR,
         MTART LIKE MARA-MTART,
         MATKL LIKE MARA-MATKL,
         LVORM LIKE MARA-LVORM,
         WERKS LIKE MARC-WERKS,
         MAKTX LIKE MAKT-MAKTX,
       END   OF TS_MARA.

*----------------------------------------------------------------------
*    * SELECTION SCREEN PARAMETERS
*----------------------------------------------------------------------

SELECTION-SCREEN BEGIN OF BLOCK B1.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR OBLIGATORY,
                S_WERKS FOR MARC-WERKS OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.

*----------------------------------------------------------------------

TOP-OF-PAGE.

*----------------------------------------------------------------------

  WRITE: 40 'Generating PDF from List Output' COLOR 1 INTENSIFIED ON.

  SKIP 1.

  WRITE: /1 'Date        :',  SY-DATUM,

         /1 'User ID     :',  SY-UNAME,

         /1(112) SY-ULINE.

*----------------------------------------------------------------------

START-OF-SELECTION.

*----------------------------------------------------------------------

*    * PERFORM FOR BASIC SELECTION

  PERFORM GET_MARA.

* * PERFORM TO DISPLAY DATA

  PERFORM DISPLAY_MARA.

*----------------------------------------------------------------------------------

AT USER-COMMAND.

*----------------------------------------------------------------------------------

*    * USER COMMAND TO GENERATE PDF FORM

AT USER-COMMAND.

  CASE SY-UCOMM.

    WHEN 'PDF'.

      DATA: L_PARAMS TYPE PRI_PARAMS,

              L_VALID TYPE STRING,

              W_SPOOL_NR LIKE TSP01-RQIDENT.

*     * TO GET PRINT PARAMETERS

      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        IMPORTING
          OUT_PARAMETERS = L_PARAMS
          VALID          = L_VALID.

*    IF SY-SUBRC  0.

*    ENDIF.

*     * INTERNAL TABLE FOR SELECTION SCREEN

      DATA: BEGIN OF I_RSPARAMS OCCURS 0.

              INCLUDE STRUCTURE RSPARAMS.

      DATA: END OF I_RSPARAMS.

*     * STORE THE CURRENT SELECTION SCREEN DETAILS

      CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'

        EXPORTING

          CURR_REPORT           = SY-REPID

*     * IMPORTING

*   SP                    =

        TABLES

          SELECTION_TABLE       = I_RSPARAMS

*     * EXCEPTIONS

*   NOT_FOUND             = 1

*   NO_REPORT             = 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.

*       * SUBMIT TO GET THE SPOOL NUMBER

      SUBMIT ZNA_REPORT_PDF WITH SELECTION-TABLE I_RSPARAMS

                                   TO SAP-SPOOL

                                   SPOOL PARAMETERS L_PARAMS

                                   WITHOUT SPOOL DYNPRO

                                   AND RETURN.

*       * SELECT THE RECENTLY CREATED SPOOL

      SELECT MAX( RQIDENT ) INTO W_SPOOL_NR FROM TSP01

                                 WHERE RQCLIENT = SY-MANDT

                                 AND   RQOWNER  = SY-UNAME.

*REPORT TO GENERATE SPOOL NUMBER FOR PDF CONVERT

      SUBMIT RSTXPDF5 WITH SPOOLNO  = W_SPOOL_NR

                      WITH DSTDEVIC = 'LOCL' AND RETURN .

      IF SY-SUBRC EQ 0.

        CLEAR W_SPOOL_NR.

*         * SELECT THE RECENTLY CREATED SPOOL FOR PDF

        SELECT MAX( RQIDENT ) INTO W_SPOOL_NR FROM TSP01

                                   WHERE RQCLIENT = SY-MANDT

                                   AND   RQOWNER  = SY-UNAME.

*REPORT TO DOWNLOAD PDF SPOOL TO GUI

        SUBMIT RSTXPDFT5 WITH SPOOLID = W_SPOOL_NR

                         AND RETURN.

      ENDIF.

    WHEN 'BACK'.
      LEAVE PROGRAM.

  ENDCASE.
*  &---------------------------------------------------------------------

*&      Form  GET_MARA

*  &---------------------------------------------------------------------

*       text

*  ----------------------------------------------------------------------

*  -->  p1        text

*  <--  p2        text

*  ----------------------------------------------------------------------

FORM GET_MARA .

  CLEAR  : TS_MARA.

  REFRESH: TS_MARA.

*   * TO SELECT MATERIALS BASED ON SELECTION CRITERIA

  SELECT A~MATNR A~MTART A~MATKL A~LVORM B~WERKS INTO CORRESPONDING

                            FIELDS OF TABLE TS_MARA FROM MARA AS A

                            INNER JOIN MARC AS B ON A~MATNR EQ B~MATNR

                            WHERE A~MATNR IN S_MATNR

                            AND   B~WERKS IN S_WERKS.

  LOOP AT TS_MARA.

    SELECT SINGLE * FROM MAKT WHERE MATNR EQ TS_MARA-MATNR

                              AND   SPRAS EQ SY-LANGU.

    MOVE MAKT-MAKTX TO TS_MARA-MAKTX.

    MODIFY TS_MARA INDEX SY-TABIX.

  ENDLOOP.

ENDFORM.                    " GET_MARA

*&---------------------------------------------------------------------

*&      Form  DISPLAY_MARA

*&---------------------------------------------------------------------

*       text

*----------------------------------------------------------------------

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------

FORM DISPLAY_MARA .

  CLEAR  : TS_MARA.

  WRITE: /1   '|', 2(18)  'Material Number' COLOR 7,

           21  '|', 22(5)  'Plant          ' COLOR 7,

           28  '|', 29(13) 'Material Type  ' COLOR 7,

           42  '|', 43(14) 'Material Group ' COLOR 7,

           57  '|', 58(13) 'Deletion Flag  ' COLOR 7,

           71  '|', 72(40) 'Description    ' COLOR 7,

           112 '|'.

  WRITE: /1(112) SY-ULINE.

  LOOP AT TS_MARA.

    WRITE: /1   '|', 2(18)   TS_MARA-MATNR,

            21  '|', 22(5)   TS_MARA-WERKS,

            28  '|', 29(13)  TS_MARA-MTART,

            42  '|', 43(14)  TS_MARA-MATKL,

            57  '|', 58(13)  TS_MARA-LVORM,

            71  '|', 72(40)  TS_MARA-MAKTX,

            112 '|'.

    WRITE: /1(112) SY-ULINE.

  ENDLOOP.

ENDFORM.                    " DISPLAY_MARA

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question