Example of A Simple ABAP ALV Grid Report: SAP List Viewer
Example of A Simple ABAP ALV Grid Report: SAP List Viewer
com/ ©
https://www.youtube.com/@s4hclubforyou ©
The ABAP List Viewer (ALV) is a set of application programming interfaces (APIs; function
modules or classes) for displaying data in a tabular or hierarchical format and built-in options
for visual presentation and event processing.
ALV is originally short for ABAP List Viewer, but the current term found in SAP documentation
is SAP List Viewer. This is of little importance, though: in everyday practice, it’s simply referred
to as ALV, not by any longer name.
To users, ALV offers a friendly interface with a toolbar that allows each user to adjust the
presented layout to their preferences and sort or filter data easily. Many standard SAP reports
use ALV and it has become a popular tool when building custom ABAP reports due to its
flexibility, ease of implementation, and variety of features.
MANDATORY
https://www.youtube.com/@s4hclubforyou ©
*ALV
TYPE-POOLS : SLIS.
*SAP ALV
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = lt_filout.
gr_table->set_screen_status(
pfstatus = 'STANDARD_GRID'
report = sy-repid
set_functions = gr_table->c_functions_all ).
* Set up selections.
gr_selections = gr_table->get_selections( ).
gr_selections->set_selection_mode( 1 ). "Single
TRY.
l_columns = gr_table->get_columns( ).
l_columns->set_optimize( 'X' ).
CATCH cx_salv_not_found INTO not_found.
" error handling
ENDTRY.
https://www.youtube.com/@s4hclubforyou ©
* Display
gr_table->display( ).
SE38
REPORT zfid_rep_cdsd_item_sub_syn.
*&---------------------------------------------------------------------*
*& Report ZFID_REP_CDSD_ITEM_sub *
*----------------------------------------------------------------------*
https://www.youtube.com/@s4hclubforyou ©
* *
*----------------------------------------------------------------------*
* Modifications : *
* *
* Auteur Date Description Flag *
*----------------------------------------------------------------------*
************************************************************************
* Déclaration de données
************************************************************************
INCLUDE ZFID_REP_CDSD_ITEM_SUB_SYN_TOP.
INCLUDE ZFID_REP_CDSD_ITEM_SUB_SYN_SCR.
INCLUDE ZFID_REP_CDSD_ITEM_SUB_SYN_F01.
************************************************************************
* INITIALIZATION
************************************************************************
INITIALIZATION.
PERFORM f000_init.
***********************************************************************
* AT SELECTION SCREEN
***********************************************************************
AT SELECTION-SCREEN.
************************************************************************
* AT SELECTION SCREEN ON Value-Request
************************************************************************
*at selection-screen on value-request for
************************************************************************
*START-OF-SELECTION
************************************************************************
START-OF-SELECTION.
*************************************************************************
*END-OF-SELECTION
*************************************************************************
END-OF-SELECTION.
https://www.youtube.com/@s4hclubforyou ©
*SAP ALV
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = lt_filout.
gr_table->set_screen_status(
pfstatus = 'STANDARD_GRID'
report = sy-repid
set_functions = gr_table->c_functions_all ).
* Set up selections.
gr_selections = gr_table->get_selections( ).
gr_selections->set_selection_mode( 1 ). "Single
TRY.
l_columns = gr_table->get_columns( ).
l_columns->set_optimize( 'X' ).
CATCH cx_salv_not_found INTO not_found.
" error handling
ENDTRY.
* Display
gr_table->display( ).
TOP
INCLUDE ZFID_REP_CDSD_ITEM_SUB_SYN_TOP.
*&---------------------------------------------------------------------*
*& Include ZFID_REP_CDSD_ITEM_COND_TOP
*&---------------------------------------------------------------------*
*types:
https://www.youtube.com/@s4hclubforyou ©
* Aktueller Tabellenstand
DATA: BEGIN OF XFPLT OCCURS 2.
INCLUDE STRUCTURE FPLTVB.
DATA: END OF XFPLT.
https://www.youtube.com/@s4hclubforyou ©
* Aktueller Tabellenstand
DATA: BEGIN OF XFPLA OCCURS 10.
INCLUDE STRUCTURE FPLAVB.
DATA: END OF XFPLA.
* Aktueller Tabellenstand
DATA: BEGIN OF XFPLA_REC OCCURS 10.
INCLUDE STRUCTURE FPLAVB.
DATA: END OF XFPLA_REC.
* Aktueller Tabellenstand
DATA: BEGIN OF XFPLT_REC OCCURS 2.
INCLUDE STRUCTURE FPLTVB.
DATA: END OF XFPLT_REC.
*ALV
TYPE-POOLS : SLIS.
https://www.youtube.com/@s4hclubforyou ©
SCREEN
INCLUDE ZFID_REP_CDSD_ITEM_SUB_SYN_SCR.
*&---------------------------------------------------------------------*
*& Include ZFID_REP_CDSD_ITEM_COND_SCR
*&---------------------------------------------------------------------*
https://www.youtube.com/@s4hclubforyou ©
SELECTION
INCLUDE ZFID_REP_CDSD_ITEM_SUB_SYN_F01.
*&---------------------------------------------------------------------*
*& Include ZFID_REP_CDSD_ITEM_COND_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form F_SELECTION
*&---------------------------------------------------------------------*
FORM F_SELECTION .
CLEAR LT_CMD[].
SELECT A~AUART, A~VKORG, A~VTWEG, A~SPART, A~VBELN,
B~MATNR, B~POSNR, B~PSTYV, B~PRODH,
D~ENDAT, D~BEDAT, D~FPLNR, D~LODAT, D~TNDAT
FROM ( ( VBAK AS A
INNER JOIN VBAP AS B ON B~VBELN = A~VBELN )
INNER JOIN V_VBUP_CDS AS C ON C~VBELN = A~VBELN
AND C~POSNR = B~POSNR
INNER JOIN FPLA AS D ON D~FPLNR = B~FPLNR_ANA )
INTO CORRESPONDING FIELDS OF TABLE @LT_CMD
WHERE C~FKSAA <> 'C'
AND A~VBELN IN @S_VBELN
AND A~AUART IN @S_AUART
AND B~MATNR IN @S_MATNR
AND B~PSTYV IN @S_PSTYV
https://www.youtube.com/@s4hclubforyou ©
CLEAR LT_VBFA[].
SELECT * FROM VBFA
INTO CORRESPONDING FIELDS OF TABLE @LT_VBFA
FOR ALL ENTRIES IN @LT_CMD
WHERE VBELV = @LT_CMD-VBELN.
CHECK SY-SUBRC = 0.
CLEAR LS_VBFA.
LOOP AT LT_VBFA INTO LS_VBFA.
AT NEW VBELN.
ENDAT.
ENDLOOP.
CLEAR LT_VBAP_REC[].
SELECT VBELN, POSNR, FPLNR_ANA
FROM VBAP INTO CORRESPONDING FIELDS OF TABLE @LT_VBAP_REC
FOR ALL ENTRIES IN @LT_DOCFLOW
WHERE VBELN = @LT_DOCFLOW-VBELN.
CHECK SY-SUBRC = 0.
https://www.youtube.com/@s4hclubforyou ©
CHECK SY-SUBRC = 0.
LS_FILOUT-AUART = LS_CMD-AUART.
LS_FILOUT-VKORG = LS_CMD-VKORG.
LS_FILOUT-VTWEG = LS_CMD-VTWEG.
LS_FILOUT-SPART = LS_CMD-SPART.
LS_FILOUT-VBELN = LS_CMD-VBELN.
LS_FILOUT-POSNR = LS_CMD-POSNR.
LS_FILOUT-MATNR = LS_CMD-MATNR.
LS_FILOUT-PSTYV = LS_CMD-PSTYV.
LS_FILOUT-PRODH = LS_CMD-PRODH.
LS_FILOUT-FPLNR = LS_CMD-FPLNR.
LS_FILOUT-BEDAT = LS_CMD-BEDAT.
LS_FILOUT-ENDAT = LS_CMD-ENDAT.
LS_FILOUT-LODAT = LS_CMD-LODAT.
LS_FILOUT-TNDAT = LS_CMD-TNDAT.
LS_FILOUT-VBELN2 = LS_DOCFLOW-VBELN.
LS_FILOUT-POSNR2 = LS_DOCFLOW-POSNN.
CLEAR LS_VBAP_REC.
READ TABLE LT_VBAP_REC INTO LS_VBAP_REC WITH KEY VBELN = LS_FILOUT-VBELN2
POSNR = LS_FILOUT-POSNR2.
CHECK SY-SUBRC = 0.
LS_FILOUT-FPLNR2 = LS_VBAP_REC-FPLNR_ANA.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form F_BUILD
*&---------------------------------------------------------------------*
FORM F_BUILD .
CLEAR LS_FILOUT.
LOOP AT LT_FILOUT INTO LS_FILOUT.
https://www.youtube.com/@s4hclubforyou ©
CHECK SY-SUBRC = 0.
CHECK SY-SUBRC = 0.
CLEAR LS_FPLA.
LOOP AT YFPLA INTO LS_FPLA.
CLEAR LS_FPLA_REC-LODAT.
CLEAR LS_FPLA_REC-TNDAT.
**No dates until SO1, No End date SO1 and dates from SO1
IF LS_FPLA-TNDAT(4) IS INITIAL AND LS_FPLA-ENDAT(4) IS INITIAL AND NOT LS_FPLA-LODAT(4) IS
INITIAL.
*start date SO2 = dates from SO1 + 1 DY + 1 YR
LS_FPLA_REC-BEDAT = LS_FPLA-LODAT + 1.
LS_FPLA_REC-BEDAT(4) = LS_FPLA-LODAT(4) + 1.
ENDIF.
**No dates until SO1, No End date SO1 and no dates from SO1
IF LS_FPLA-TNDAT(4) IS INITIAL AND LS_FPLA-ENDAT(4) IS INITIAL AND LS_FPLA-LODAT(4) IS
INITIAL.
*start date SO2 = start date SO1 + 1 YR
LS_FPLA_REC-BEDAT = LS_FPLA-BEDAT.
LS_FPLA_REC-BEDAT(4) = LS_FPLA-BEDAT(4) + 1.
ENDIF.
https://www.youtube.com/@s4hclubforyou ©
LS_FILOUT-BEDAT2 = LS_FPLA_REC-BEDAT.
LS_FILOUT-ENDAT2 = LS_FPLA_REC-ENDAT.
MODIFY LT_FILOUT FROM LS_FILOUT.
ENDIF.
ENDLOOP.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form F000_INIT
*&---------------------------------------------------------------------*
https://www.youtube.com/@s4hclubforyou ©
FORM F000_INIT .
ENDFORM.
Result
SA38
https://www.youtube.com/@s4hclubforyou ©
https://www.youtube.com/@s4hclubforyou ©
Issue
SE41
https://www.youtube.com/@s4hclubforyou ©
GR_TABLE->SET_SCREEN_STATUS(
PFSTATUS = 'STANDARD_GRID'
REPORT = SY-REPID
SET_FUNCTIONS = GR_TABLE->C_FUNCTIONS_ALL )
https://www.youtube.com/@s4hclubforyou ©
https://www.youtube.com/@s4hclubforyou ©
https://www.youtube.com/@s4hclubforyou ©
Result
https://www.youtube.com/@s4hclubforyou ©
https://www.youtube.com/@s4hclubforyou ©