You are on page 1of 10

Step 1: Go to SE41.

Write the name of PF-STATUS in “Status” and the name of the program where you will enter the status in
“Program”. Click on Create or click on the “Copy Status” button above. In this case, I am using the “Copy Status” button.

Step 2: A pop-up will open, asking from which status we want to copy and to which status.
Provide the program name and Status name as follows and click on the copy button.

Macbook Air APPLE Cinzento ...


OS Big Sur

Ad Worten PT Go !

Step 3: Another pop-up will open, just click the copy button.


Step 4: An “Maintain Status” Interface will open will all the System generated menu icons copied. Now click on Application Toolbar
expand button and enter the name of the icon as shown below.

Step 5: Double click on it, and a pop-up will open click on the Static Text radio button and click on the tick button.

Step 6: Another pop-up will appear, Provide the Icon name of your choice, choose an icon from the Icon Name field, and provide some
info in the Info text field about the icon. Now provide info as shown below.

Step 7: Now Provide a shortcut key to access that icon on your report.

Step 8: Click the save button and activate it.

Step 9: Now Go to SE38 Tcode. Type the program name and choose Source Code from Subjects and Click on Create button.

Step 10: Enter Title & select ‘Executable Program’ type in Attributes and then click on save.


Step 11: Now enter the Package name in the ‘Package’ Attribute and click on the button.

Step 12: Select the TR and click on it.

Now ABAP Editor will open, here write the code given below for the report.

REPORT zalvexample9.
*Table Declaration.
TABLES : vbak, vbap.
*Type-Pools
TYPE-POOLS: slis.

*Type Declaration

TYPES: BEGIN OF ty_vbak,

vbeln TYPE vbak-vbeln,


erdat TYPE vbak-erdat,
ernam TYPE vbak-ernam,
auart TYPE vbak-auart,
vkorg TYPE vbak-vkorg,
vtweg TYPE vbak-vtweg,
spart TYPE vbak-spart,
vkgrp TYPE vbak-vkgrp,
kunnr TYPE vbak-kunnr,

END OF ty_vbak,

BEGIN OF ty_vbap,

vbeln TYPE vbap-vbeln,


posnr TYPE vbap-posnr, 
matnr TYPE vbap-matnr,
SELECT-OPTIONS : so_vbeln FOR vbap-vbeln.

SELECTION-SCREEN END OF BLOCK b1.

*Data Fetching From Table VBAK

SELECT vbeln
erdat
ernam
auart
vkorg
vtweg
spart
vkgrp
kunnr
FROM vbak INTO TABLE gt_vbak
WHERE vbeln IN so_vbeln.

SORT gt_vbak BY vbeln.

SELECT vbeln
posnr
matnr
matkl
arktx
netwr
waerk
klmeng
vrkme
FROM vbap INTO TABLE gt_vbap FOR ALL ENTRIES IN gt_vbak
WHERE vbeln = gt_vbak-vbeln.

SORT gt_vbap BY vbeln.

LOOP AT gt_vbap INTO wa_vbap.

wa_all-vbeln = wa_vbap-vbeln.
wa_all-posnr = wa_vbap-posnr.
wa_all-matnr = wa_vbap-matnr.
wa_all-matkl = wa_vbap-matkl.
wa_all-arktx = wa_vbap-arktx.
wa_all-netwr = wa_vbap-netwr.
wa_all-waerk = wa_vbap-waerk.
wa_all-klmeng = wa_vbap-klmeng.
wa_all-vrkme = wa_vbap-vrkme.

READ TABLE gt_vbak INTO wa_vbak WITH KEY vbeln = wa_vbap-vbeln.

IF sy-subrc = 0.

wa_all-erdat = wa_vbak-erdat.
wa_all-ernam = wa_vbak-ernam.
wa_all-auart = wa_vbak-auart.
wa_all-vkorg = wa_vbak-vkorg.
wa_all-vtweg = wa_vbak-vtweg.
wa_all-spart = wa_vbak-spart. 
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 15.
wa_fcat-fieldname = ‘WAERK’.
wa_fcat-seltext_m = ‘CURRENCY’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 16.
wa_fcat-fieldname = ‘KLMENG’.
wa_fcat-seltext_m = ‘QUANTITY’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-col_pos = 17.
wa_fcat-fieldname = ‘VRKME’.
wa_fcat-seltext_m = ‘SALES UNIT’.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

*LAYOUT

gt_layout-colwidth_optimize = ‘X’.
gt_layout-edit = ‘X’.

*Displaying ALV Grid

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’


EXPORTING

i_callback_program = sy-repid
i_callback_pf_status_set = ‘PF_STATUS’
i_callback_user_command = ‘USER_COMMAND’
is_layout = gt_layout
it_fieldcat = gt_fcat

TABLES
          t_outtab = gt_all
* EXCEPTIONS
*        PROGRAM_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

*Creating PF-STATUS

FORM pf_status USING rt_extab TYPE slis_t_extab.


SET PF-STATUS ‘STANDARD_STATUS’.
ENDFORM.

*Creating User Command

FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. 


       CASE r_ucomm.
              WHEN ‘EPDF’. “function code for export which we created in MENU

TYPES : BEGIN OF ty_tsp01,


                rqident TYPE tsp01-rqident, “spool-number
                rq2name TYPE tsp01-rq2name, “spool request: SUFFIX 2
                rqcretime TYPE tsp01-rqcretime, “User name
END OF ty_tsp01.

DATA : lv_jobcnt TYPE tbtcjob-jobcount, “job number


              lv_jobname TYPE tbtcjob-jobname. “job name
DATA : lv_len TYPE i,
              ls_param TYPE rsparams, “selection work area
              ls_tsp01 TYPE ty_tsp01, “Spool Requests Work Area
              lt_tsp01 TYPE STANDARD TABLE OF ty_tsp01, “Spool Requests Internal table
              lt_param TYPE rsparams_tt. “Selection table

“DERIVE JOB COUNTER

lv_jobname = ‘ZALV2PDF’. “BACKGROUND JOB NAME


CALL FUNCTION ‘JOB_OPEN’ “open a job
EXPORTING
       jobname = lv_jobname
IMPORTING
       jobcount = lv_jobcnt
EXCEPTIONS
       cant_create_job = 1
       invalid_job_data = 2
       jobname_missing = 3
OTHERS = 4.

IF sy-subrc = 0.
       DATA : lv_rqdest TYPE tsp01-rqdest VALUE ‘LP01’,
       lv_linsz TYPE sylinsz VALUE ‘9999999’.

SUBMIT (sy-repid) “submit the same program


TO SAP-SPOOL DESTINATION lv_rqdest
LINE-SIZE lv_linsz
IMMEDIATELY ‘X’
KEEP IN SPOOL ‘X’
USER sy-uname VIA JOB lv_jobname NUMBER lv_jobcnt
WITHOUT SPOOL DYNPRO
WITH SELECTION-TABLE lt_param
AND RETURN.

CALL FUNCTION ‘JOB_CLOSE’ “job close


EXPORTING
      jobcount = lv_jobcnt
      jobname = lv_jobname
      strtimmed = ‘X’
EXCEPTIONS
      cant_start_immediate = 1
      invalid_startdate = 2
      jobname_missing = 3
      job_close_failed = 4
      job_nosteps = 5

     job_notex = 6
     lock_failed = 7
     invalid_target = 8
OTHERS = 9.

IF sy-subrc <> 0.
        RAISE job_cannot_be_closed. ” Raise exception
ENDIF.
ELSE.
        RAISE job_cannot_be_submitted.
ENDIF.

*********** Confirm job status if finished


DATA: lv_job TYPE tbtcv-fin. “Job status
DO 120 TIMES.
CALL FUNCTION ‘BDL_READ_JOB_STATUS’ “get job status
EXPORTING
      jobname = lv_jobname
      jobnumber = lv_jobcnt
IMPORTING
      jobstatus = lv_job
EXCEPTIONS
      job_not_found = 1
OTHERS = 2.

IF lv_job NE ‘F’. “job finished


   WAIT UP TO 1 SECONDS.
   CONTINUE.
ELSE.
EXIT.
ENDIF.
ENDDO.

*Calculate report name in Spool table


DATA: lv_rq2name TYPE tsp01-rq2name. “Spool request
DATA: lv_tmp(14) TYPE c, “temp
             lv_string TYPE string, “store program name
             lv_temp TYPE tsp01-rq2name, “Spool request
             lv_spool TYPE tsp01-rqident. “spool number

IF lv_job EQ ‘F’. “job finished


lv_len = strlen( sy-repid ) .
IF lv_len >= 9 .
     CONCATENATE sy-repid+0(9)
     sy-uname+0(3) INTO lv_rq2name .
ELSE.
     lv_len = 9 – lv_len.
     DO lv_len TIMES .
     CONCATENATE lv_temp ‘_’ INTO lv_temp .
ENDDO.
    CONCATENATE sy-repid lv_temp
    sy-uname INTO lv_rq2name .
ENDIF.

*Get spool request from SPOOL table TSP01


SELECT rqident rq2name rqcretime 
FROM tsp01
INTO TABLE lt_tsp01
WHERE rq2name = lv_rq2name
AND rqowner = sy-uname .

*sort table to find latest spool no


SORT lt_tsp01 BY rqcretime DESCENDING .

*Read table to find latest spool no


READ TABLE lt_tsp01 INTO ls_tsp01 INDEX 1.

*Get user desktop


CALL METHOD cl_gui_frontend_services=>get_desktop_directory
CHANGING
       desktop_directory = lv_string
EXCEPTIONS
       cntl_error = 1
       error_no_gui = 2
       not_supported_by_gui = 3
OTHERS = 4.
 

IF sy-subrc <> 0.
*   Implement suitable error handling here
     lv_string = sy-repid.
ENDIF.

CALL METHOD cl_gui_cfw=>update_view.


CONCATENATE lv_string text-001 INTO lv_string.

*Prepare selection table for PDF download


ls_param-selname = ‘SPOOLNO’.
ls_param-sign = ‘I’.
ls_param-option = ‘EQ’.
ls_param-low = ls_tsp01-rqident.
ls_param-high = ‘ ‘.
APPEND ls_param TO lt_param.

ls_param-selname = ‘P_FILE’.
ls_param-sign = ‘I’.
ls_param-option = ‘EQ’.
ls_param-low = lv_string.
ls_param-high = ‘ ‘.
APPEND ls_param TO lt_param.

* Submit to PDF converted and download


SUBMIT rstxpdft4 WITH SELECTION-TABLE lt_param
AND RETURN.
IF sy-subrc <> 0.

   MESSAGE ‘PDF convert not possible’ TYPE ‘I’.


ENDIF.
ELSE.
MESSAGE ‘PDF Can not be downloaded, you have selected huge data. Reduce data and try again’ TYPE ‘I’.
ENDIF.
ENDCASE.

ENDFORM.
OUTPUT

Let’s check the output.

Step 1: Press F8

Step 2: Again press F8 to execute the Report & Click on the below-marked Icon.

Step 3: Save the file & the file will be downloaded.

You might also like