Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Author: Nagaraj Kalbavi
Submitted: 11/07/2008

Description: This program will generate the PDF form from ABAP List Output. I have used the format X_90_120 for generating PDF form from List Output. You can do this setting by changing the properties of printer after clicking the PDF generation button in the List output.

*&---------------------------------------------------------------------
*& Report  Z_CREATE_PDF_ABAPLIST
*&---------------------------------------------------------------------
*& Description: Simple Program to generate PDF from ABAP List Output
*&---------------------------------------------------------------------
REPORT  z_create_pdf_abaplist NO STANDARD PAGE HEADING.
* 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
        TABLES
          selection_table = i_rsparams.
      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 z_create_pdf_abaplist 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.
  ENDCASE.
*&---------------------------------------------------------------------*
*&      Form  GET_MARA
*&---------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
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