&———————————————————————*
*& Report Z01_DEMO_ALV_FIELDCATALOG
*&
*&———————————————————————*
*& Programmer: Vy Khang Ly
*& SAP FREE ABAP TUTORIALS
*& http://sapforbeginner.com
*&———————————————————————*
REPORT Z01_DEMO_ALV_FIELDCATALOG.
TYPE-POOLS: slis. ” SLIS contains all the ALV data types
*&———————————————————————*
*& Data Declaration
*&———————————————————————*
DATA: lt_sflight TYPE TABLE OF sflight.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv.
DATA: g_repid TYPE sy-repid.
*&———————————————————————*
*& START-OF-SELECTION
*&———————————————————————*
START-OF-SELECTION.
g_repid = sy-repid.
*&—– Fetch data from the database —–*
SELECT *
FROM sflight
INTO TABLE lt_sflight.
*&—– Field Catalog —–*
ls_fieldcat-fieldname = ‘CARRID’. “Fieldname in the data table
ls_fieldcat-seltext_m = ‘Airline’. “Column description in the output
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat-fieldname = ‘CONNID’.
ls_fieldcat-seltext_m = ‘FLight Number’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat-fieldname = ‘FLDATE’.
ls_fieldcat-seltext_m = ‘FLight Date’.
APPEND ls_fieldcat TO lt_fieldcat.
*Calculating total of bookings.
ls_fieldcat-fieldname = ‘PAYMENTSUM’.
ls_fieldcat-seltext_m = ‘Total of current bookings’.
ls_fieldcat-do_sum = ‘X’.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat-fieldname = ‘CURRENCY’.
ls_fieldcat-seltext_m = ‘Currency’.
APPEND ls_fieldcat TO lt_fieldcat.
*Build a sort catalog to generating sub-total
ls_sort-spos = 1.
ls_sort-fieldname = ‘FLDATE’.
ls_sort-up = ‘X’.
ls_sort-subtot = ‘X’.
APPEND ls_sort TO lt_sort.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
it_fieldcat = lt_fieldcat
it_sort = lt_sort
TABLES
t_outtab = lt_sflight.
Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP S/4 HANA Logistics Team Lead
Contact : serkurumsal@yandex.com
Social Plugin