Write ABAP program for SAP S/4HANA based on the SQL query below to produce ALV report. Start and end of report period and threshold of items number should be date parameters on a selection screen. Use CL_SALV_TABLE class for output.
SELECT VBRP.VBELN, COUNT(distinct POSNR) as ItemCount FROM VBRP JOIN VBRK ON VBRP.VBELN = VBRK.VBELN WHERE FKDAT between 20220101 and 202221231 GROUP BY VBRP.VBELN HAVING COUNT(distinct POSNR) > 10 ORDER BY 2 DESCENDING
Below is an example of an ABAP program tailored for SAP S/4HANA that selects records based on the specified SQL query, including input parameters for the report period and item number threshold on the selection screen, and displays the output in an ALV report using the CL_SALV_TABLE
class.
Please adapt the program to meet your specific system and requirements as this is a generic template.
REPORT zsales_alv_report. PARAMETERS: p_start TYPE sy-datum DEFAULT '20220101' OBLIGATORY, p_end TYPE sy-datum DEFAULT '20221231' OBLIGATORY, p_thrsh TYPE i DEFAULT 10 OBLIGATORY. TYPES: BEGIN OF ty_vbrp, vbeln TYPE vbeln_va, itemcount TYPE i, END OF ty_vbrp. DATA: it_vbrp TYPE TABLE OF ty_vbrp, wa_vbrp TYPE ty_vbrp, go_alv TYPE REF TO cl_salv_table. START-OF-SELECTION. SELECT vbrp~vbeln, COUNT( DISTINCT posnr ) AS itemcount FROM vbrp INNER JOIN vbrk ON vbrp~vbeln = vbrk~vbeln WHERE vbrk~fkdat BETWEEN @p_start AND @p_end GROUP BY vbrp~vbeln HAVING COUNT( DISTINCT posnr ) > @p_thrsh ORDER BY itemcount DESCENDING INTO TABLE @it_vbrp. IF it_vbrp IS NOT INITIAL. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = go_alv CHANGING t_table = it_vbrp ). go_alv->display( ). CATCH cx_salv_msg INTO DATA(lx_msg). MESSAGE lx_msg TYPE 'I' DISPLAY LIKE 'E'. ENDTRY. ELSE. MESSAGE 'No data found for the selection criteria.' TYPE 'I'. ENDIF.
Remember to ensure that the provided date format in the default values matches what the user expects according to the locale. In the SAP system, the date format may vary based on the user's locale setting.
Additionally, ensure that the data types used above (vbeln_va
, sy-datum
, etc.) match the data types found in your system as these are common data types found in standard SAP ERP environments.
This program should be created using transaction SE38, SE80, or any other ABAP IDE like Eclipse with ADT installed. Once the program is created and saved in a package, it can be executed to generate an ALV report based on the given criteria.
google.com
erproof.com
sastrageek.com