SAP ABAP - Simple Program to generate PDF from ABAP List Output.
This is a sample report program to generate PDF File From ABAP List Output.
REPORT zjal_list_to_pdf 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 get_mara.
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.
call function 'GET_PRINT_PARAMETERS'
exporting
destination = 'LP01'
layout = 'X_65_132'
line_count = 65
line_size = 132
no_dialog = 'X'
importing
out_parameters = l_params
valid = l_valid
exceptions
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
others = 4.
* INTERNAL TABLE FOR SELECTION SCREEN
DATA: BEGIN OF i_rsparams OCCURS 0.
INCLUDE STRUCTURE rsparams.
DATA: END OF i_rsparams.
* STORE CURRENT 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 zjal_list_to_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.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form GET_MARA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------*
FORM get_mara .
CLEAR : ts_mara.
REFRESH: ts_mara.
* SELECT MATERIALS BASED ON SELECTION SCREEN
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
REPORT zjal_list_to_pdf 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 get_mara.
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.
call function 'GET_PRINT_PARAMETERS'
exporting
destination = 'LP01'
layout = 'X_65_132'
line_count = 65
line_size = 132
no_dialog = 'X'
importing
out_parameters = l_params
valid = l_valid
exceptions
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
others = 4.
* INTERNAL TABLE FOR SELECTION SCREEN
DATA: BEGIN OF i_rsparams OCCURS 0.
INCLUDE STRUCTURE rsparams.
DATA: END OF i_rsparams.
* STORE CURRENT 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 zjal_list_to_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.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form GET_MARA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------*
FORM get_mara .
CLEAR : ts_mara.
REFRESH: ts_mara.
* SELECT MATERIALS BASED ON SELECTION SCREEN
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
MORE PROGRAMS ON REPORT PROGRAMMING:
- Uploading Large Data From Excel Sheet To Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE
- Send an excel sheet to the concerned person in an email format via SAP System.
- Upload the financial documents from a legacy system (excel file) into SAP using transaction code FB01.
- Upload Excel Sheet Data Into Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE.
- Uploading Large Data From Excel Sheet To Internal Table Using FM ALSM_EXCEL_TO_INTERNAL_TABLE
- ...Back To Index On Report Programming.
Your suggestions and comments are welcome in this section.
Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.