- SAP ABAP Reports
- Report Types and Events
- Message Class
- Example of Classical Report
- Example of Interactive Report
- Example of ALV Report
- Example of Blocked ALV Report
- Example of Hierarchical Report
- Module Pool Programming
- Screen Painter Components
- Events in Flow Logic Editor
- Screen Elements and Creation Steps
- Working with Validations
- Database Operations
- OO Programming in ABAP
- Types of Programming Structure
- Key Features of OO Programming
- Classes and Objects
- Types of Visibility Section
- Class Defination and Implementation
- Object Creation for Class
- Method Declaration and Implementation
- Types of Component Class
- Global Class and implement GLOBAL methods
- OOP's ALV
- OOP's BDC
24REPORT1608 – Example of ALV Report
*&———————————————————————*
*& Report ZNEWALV_REPORT
*&———————————————————————*
*&
*&———————————————————————*
REPORT ZNEWALV_REPORT.
TYPES : BEGIN OF GTY_VBAK,
VBELN TYPE VBAK-VBELN,
ERNAM TYPE VBAK-ERNAM,
AUDAT TYPE VBAK-AUDAT,
GSBER TYPE VBAK-GSBER,
VSBED TYPE VBAK-VSBED,
KNUMV TYPE VBAK-KNUMV,
END OF GTY_VBAK.
DATA : GT_VBAK TYPE STANDARD TABLE OF GTY_VBAK,
GS_VBAK TYPE GTY_VBAK.
TYPES : BEGIN OF GTY_VBAP,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATWA TYPE VBAP-MATWA,
MATKL TYPE VBAP-MATKL,
NETWR TYPE VBAP-NETWR,
ARKTX TYPE VBAP-ARKTX,
PSTYV TYPE VBAP-PSTYV,
GEWEI TYPE VBAP-GEWEI,
END OF GTY_VBAP.
DATA : GT_VBAP TYPE STANDARD TABLE OF GTY_VBAP,
GS_VBAP TYPE GTY_VBAP.
TYPES : BEGIN OF GTY_FINAL,
VBELN TYPE VBAK-VBELN,
ERNAM TYPE VBAK-ERNAM,
AUDAT TYPE VBAK-AUDAT,
GSBER TYPE VBAK-GSBER,
VSBED TYPE VBAK-VSBED,
POSNR TYPE VBAP-POSNR,
MATWA TYPE VBAP-MATWA,
MATKL TYPE VBAP-MATKL,
ARKTX TYPE VBAP-ARKTX,
PSTYV TYPE VBAP-PSTYV,
GEWEI TYPE VBAP-GEWEI,
VAR TYPE CHAR2,
NETWR TYPE VBAP-NETWR,
END OF GTY_FINAL.
DATA : GT_FINAL TYPE STANDARD TABLE OF GTY_FINAL,
GS_FINAL TYPE GTY_FINAL.
*&———————————————————————*
*& ALV DECLRATIONS *
*&———————————————————————*
DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT TYPE SLIS_FIELDCAT_ALV,
LAYOUT TYPE TABLE OF SLIS_LAYOUT_ALV WITH HEADER LINE,
WA_SORT TYPE SLIS_SORTINFO_ALV,
IT_SORT TYPE SLIS_T_SORTINFO_ALV,
WA_HEADER TYPE SLIS_LISTHEADER,
IT_HEADER TYPE SLIS_T_LISTHEADER.
data : LV_VAR TYPE char2.
SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_VBELN TYPE VBAK-VBELN OBLIGATORY.
SELECTION-SCREEN:END OF BLOCK b1.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM FIELDCATLOG.
PERFORM DISPLAY_DATA.
*&———————————————————————*
*& Form GET_DATA
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM GET_DATA .
SELECT VBELN
ERNAM
AUDAT
GSBER
VSBED
KNUMV
FROM VBAK INTO TABLE GT_VBAK
WHERE VBELN EQ P_VBELN.
IF GT_VBAK IS NOT INITIAL.
SELECT VBELN
POSNR
MATWA
MATKL
NETWR
ARKTX
PSTYV
GEWEI
FROM VBAP INTO TABLE GT_VBAP
FOR ALL ENTRIES IN GT_VBAK
WHERE VBELN = GT_VBAK-VBELN.
ENDIF.
SORT GT_VBAP BY VBELN POSNR.
LOOP AT GT_VBAP INTO GS_VBAP.
GS_FINAL-VBELN = GS_VBAP-VBELN.
GS_FINAL-MATWA = GS_VBAP-MATWA.
GS_FINAL-MATKL = GS_VBAP-MATKL.
GS_FINAL-NETWR = GS_VBAP-NETWR.
GS_FINAL-POSNR = GS_VBAP-POSNR.
GS_FINAL-ARKTX = GS_VBAP-ARKTX.
GS_FINAL-PSTYV = GS_VBAP-PSTYV.
GS_FINAL-GEWEI = GS_VBAP-GEWEI.
READ TABLE GT_VBAK INTO GS_VBAK WITH KEY VBELN = GS_VBAP-VBELN BINARY SEARCH.
IF SY-SUBRC = 0.
GS_FINAL-AUDAT = GS_VBAK-AUDAT.
GS_FINAL-GSBER = GS_VBAK-GSBER.
GS_FINAL-ERNAM = GS_VBAK-ERNAM.
ENDIF.
LV_VAR = LV_VAR + 1.
MOVE LV_VAR TO GS_FINAL-VAR.
APPEND GS_FINAL TO GT_FINAL.
CLEAR : GS_FINAL.
ENDLOOP.
ENDFORM.
*&———————————————————————*
*& Form FIELDCATLOG
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM FIELDCATLOG .
WA_FCAT-COL_POS = ‘1’.
WA_FCAT-FIELDNAME = ‘VAR’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Sr No’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘2’.
WA_FCAT-FIELDNAME = ‘VBELN’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Sales Document’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘3’.
WA_FCAT-FIELDNAME = ‘ERNAM’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Name of person’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘4’.
WA_FCAT-FIELDNAME = ‘AUDAT’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Date’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘5’.
WA_FCAT-FIELDNAME = ‘NETWR’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Net Value’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘6’.
WA_FCAT-FIELDNAME = ‘KNUMV’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Number of the Document Condition’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘7’.
WA_FCAT-FIELDNAME = ‘POSNR’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Sales Document Item’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘8’.
WA_FCAT-FIELDNAME = ‘MATWA’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Material Entered’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘9’.
WA_FCAT-FIELDNAME = ‘MATKL’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Material Group’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ’10’.
WA_FCAT-FIELDNAME = ‘ARKTX’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Short text for sales order item’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ’11’.
WA_FCAT-FIELDNAME = ‘PSTYV’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Sales Document Item Category’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ’12’.
WA_FCAT-FIELDNAME = ‘GEWEI’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Unit of Weight’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
ENDFORM.
*&———————————————————————*
*& Form DISPLAY_DATA
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM DISPLAY_DATA .
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_USER_COMMAND = ‘USER_COMMAND’
* I_CALLBACK_TOP_OF_PAGE = ‘SUB_TOP_OF_PAGE’
* I_GRID_TITLE =
IS_LAYOUT = LAYOUT
IT_FIELDCAT = IT_FCAT
I_DEFAULT = ‘X’
I_SAVE = ‘A’
IT_SORT = IT_SORT
TABLES
T_OUTTAB = GT_FINAL “Final Internal table
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
ENDFORM.
Output:
Author : Aniket Pawar, 9373518385
24REPORT1608 – Example of ALV Report
*&———————————————————————*
*& Report ZNEWALV_REPORT
*&———————————————————————*
*&
*&———————————————————————*
REPORT ZNEWALV_REPORT.
TYPES : BEGIN OF GTY_VBAK,
VBELN TYPE VBAK-VBELN,
ERNAM TYPE VBAK-ERNAM,
AUDAT TYPE VBAK-AUDAT,
GSBER TYPE VBAK-GSBER,
VSBED TYPE VBAK-VSBED,
KNUMV TYPE VBAK-KNUMV,
END OF GTY_VBAK.
DATA : GT_VBAK TYPE STANDARD TABLE OF GTY_VBAK,
GS_VBAK TYPE GTY_VBAK.
TYPES : BEGIN OF GTY_VBAP,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATWA TYPE VBAP-MATWA,
MATKL TYPE VBAP-MATKL,
NETWR TYPE VBAP-NETWR,
ARKTX TYPE VBAP-ARKTX,
PSTYV TYPE VBAP-PSTYV,
GEWEI TYPE VBAP-GEWEI,
END OF GTY_VBAP.
DATA : GT_VBAP TYPE STANDARD TABLE OF GTY_VBAP,
GS_VBAP TYPE GTY_VBAP.
TYPES : BEGIN OF GTY_FINAL,
VBELN TYPE VBAK-VBELN,
ERNAM TYPE VBAK-ERNAM,
AUDAT TYPE VBAK-AUDAT,
GSBER TYPE VBAK-GSBER,
VSBED TYPE VBAK-VSBED,
POSNR TYPE VBAP-POSNR,
MATWA TYPE VBAP-MATWA,
MATKL TYPE VBAP-MATKL,
ARKTX TYPE VBAP-ARKTX,
PSTYV TYPE VBAP-PSTYV,
GEWEI TYPE VBAP-GEWEI,
VAR TYPE CHAR2,
NETWR TYPE VBAP-NETWR,
END OF GTY_FINAL.
DATA : GT_FINAL TYPE STANDARD TABLE OF GTY_FINAL,
GS_FINAL TYPE GTY_FINAL.
*&———————————————————————*
*& ALV DECLRATIONS *
*&———————————————————————*
DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT TYPE SLIS_FIELDCAT_ALV,
LAYOUT TYPE TABLE OF SLIS_LAYOUT_ALV WITH HEADER LINE,
WA_SORT TYPE SLIS_SORTINFO_ALV,
IT_SORT TYPE SLIS_T_SORTINFO_ALV,
WA_HEADER TYPE SLIS_LISTHEADER,
IT_HEADER TYPE SLIS_T_LISTHEADER.
data : LV_VAR TYPE char2.
SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_VBELN TYPE VBAK-VBELN OBLIGATORY.
SELECTION-SCREEN:END OF BLOCK b1.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM FIELDCATLOG.
PERFORM DISPLAY_DATA.
*&———————————————————————*
*& Form GET_DATA
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM GET_DATA .
SELECT VBELN
ERNAM
AUDAT
GSBER
VSBED
KNUMV
FROM VBAK INTO TABLE GT_VBAK
WHERE VBELN EQ P_VBELN.
IF GT_VBAK IS NOT INITIAL.
SELECT VBELN
POSNR
MATWA
MATKL
NETWR
ARKTX
PSTYV
GEWEI
FROM VBAP INTO TABLE GT_VBAP
FOR ALL ENTRIES IN GT_VBAK
WHERE VBELN = GT_VBAK-VBELN.
ENDIF.
SORT GT_VBAP BY VBELN POSNR.
LOOP AT GT_VBAP INTO GS_VBAP.
GS_FINAL-VBELN = GS_VBAP-VBELN.
GS_FINAL-MATWA = GS_VBAP-MATWA.
GS_FINAL-MATKL = GS_VBAP-MATKL.
GS_FINAL-NETWR = GS_VBAP-NETWR.
GS_FINAL-POSNR = GS_VBAP-POSNR.
GS_FINAL-ARKTX = GS_VBAP-ARKTX.
GS_FINAL-PSTYV = GS_VBAP-PSTYV.
GS_FINAL-GEWEI = GS_VBAP-GEWEI.
READ TABLE GT_VBAK INTO GS_VBAK WITH KEY VBELN = GS_VBAP-VBELN BINARY SEARCH.
IF SY-SUBRC = 0.
GS_FINAL-AUDAT = GS_VBAK-AUDAT.
GS_FINAL-GSBER = GS_VBAK-GSBER.
GS_FINAL-ERNAM = GS_VBAK-ERNAM.
ENDIF.
LV_VAR = LV_VAR + 1.
MOVE LV_VAR TO GS_FINAL-VAR.
APPEND GS_FINAL TO GT_FINAL.
CLEAR : GS_FINAL.
ENDLOOP.
ENDFORM.
*&———————————————————————*
*& Form FIELDCATLOG
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM FIELDCATLOG .
WA_FCAT-COL_POS = ‘1’.
WA_FCAT-FIELDNAME = ‘VAR’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Sr No’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘2’.
WA_FCAT-FIELDNAME = ‘VBELN’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Sales Document’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘3’.
WA_FCAT-FIELDNAME = ‘ERNAM’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Name of person’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘4’.
WA_FCAT-FIELDNAME = ‘AUDAT’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Date’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘5’.
WA_FCAT-FIELDNAME = ‘NETWR’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Net Value’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘6’.
WA_FCAT-FIELDNAME = ‘KNUMV’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Number of the Document Condition’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘7’.
WA_FCAT-FIELDNAME = ‘POSNR’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Sales Document Item’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘8’.
WA_FCAT-FIELDNAME = ‘MATWA’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Material Entered’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ‘9’.
WA_FCAT-FIELDNAME = ‘MATKL’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Material Group’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ’10’.
WA_FCAT-FIELDNAME = ‘ARKTX’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Short text for sales order item’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ’11’.
WA_FCAT-FIELDNAME = ‘PSTYV’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Sales Document Item Category’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
WA_FCAT-COL_POS = ’12’.
WA_FCAT-FIELDNAME = ‘GEWEI’.
WA_FCAT-TABNAME = ‘IT_FINAL’.
WA_FCAT-SELTEXT_M = ‘Unit of Weight’.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_fcat.
ENDFORM.
*&———————————————————————*
*& Form DISPLAY_DATA
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM DISPLAY_DATA .
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_USER_COMMAND = ‘USER_COMMAND’
* I_CALLBACK_TOP_OF_PAGE = ‘SUB_TOP_OF_PAGE’
* I_GRID_TITLE =
IS_LAYOUT = LAYOUT
IT_FIELDCAT = IT_FCAT
I_DEFAULT = ‘X’
I_SAVE = ‘A’
IT_SORT = IT_SORT
TABLES
T_OUTTAB = GT_FINAL “Final Internal table
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
ENDFORM.
Output:
Author : Aniket Pawar, 9373518385