SIMPLE ALV WITH LIST HEADER AND LAYOUT AS OPTIMISED
*&---------------------------------------------------------------------*
*& Report ZALVWITHHEADER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZALVWITHHEADER.
TYPE-POOLS : SLIS.
TABLES: scarr.
**************
TYPES: BEGIN OF TY_SCAR,
CARRID TYPE SCARR-CARRID,
CARRNAME TYPE SCARR-CARRNAME,
CURRCODE TYPE SCARR-CURRCODE,
END OF TY_SCAR.
*DECLARING THE INTERNAL TABLE AND WORK AREA
DATA : IT_SCARR TYPE TABLE OF TY_SCAR,
WA_SCARR TYPE TY_SCAR.
*NOW DECLARING INTERNAL TABLE FOR FIELD CATLOG
DATA: IT_FCAT TYPE slis_t_fieldcat_alv,
WA_FCAT TYPE slis_fieldcat_alv.
**NOW DECLARE FOR LAYOUT
DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
*NOW DECLARING INTERNAL TABLE AND WORK ARE FOR HEADER TABLE
DATA : IT_HEAD TYPE SLIS_T_LISTHEADER,
WA_HEAD TYPE SLIS_LISTHEADER.
**********************************************************
SELECT-OPTIONS: s_carrid FOR scarr-carrid.
********************************************************
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM CR_FIELDCAT.
PERFORM CRE_HEADER.
PERFORM CRE_LAYOUT.
PERFORM DISPLAY_ALV.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
IF S_carrid is NOT INITIAL.
SELECT CARRID
CARRNAME
CURRCODE
FROM SCARR INTO TABLE IT_SCARR WHERE CARRID IN S_CARRID.
ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form CR_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CR_FIELDCAT .
IF IT_SCARR IS NOT INITIAL.
****CREATING A FIELDCATLOG **************
WA_FCAT-COL_POS = '1'.
WA_FCAT-FIELDNAME = 'CARRID' .
WA_FCAT-TABNAME = 'IT_SCARR'.
WA_FCAT-SELTEXT_M = 'AIRLINE CODE'.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '2'.
WA_FCAT-FIELDNAME = 'CARRNAME'.
WA_FCAT-TABNAME = 'IT_SCARR'.
WA_FCAT-SELTEXT_M = 'AIRLINE NAME'.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '3'.
WA_FCAT-FIELDNAME = 'CARRCODE'.
WA_FCAT-TABNAME = 'IT_SCARR'.
WA_FCAT-SELTEXT_M = 'LOCAL CURRENCY'.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT.
ENDIF.
ENDFORM. " CR_FIELDCAT
*&---------------------------------------------------------------------*
*& Form CRE_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CRE_HEADER .
WA_HEAD-TYP = 'H'.
WA_HEAD-INFO = 'ARLINE DETAILS'.
APPEND WA_HEAD TO IT_HEAD.
CLEAR WA_HEAD .
WA_HEAD-TYP = 'S'.
WA_HEAD-INFO = 'ALV REPORT'.
APPEND WA_HEAD TO IT_HEAD.
CLEAR WA_HEAD.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_HEAD
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM. " CRE_HEADER
*&---------------------------------------------------------------------*
*& Form CRE_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CRE_LAYOUT .
WA_LAYOUT-ZEBRA = 'X'.
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ENDFORM. " CRE_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_ALV .
IF IT_FCAT IS NOT INITIAL .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = 'SY-REPID'
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = 'IT_HEAD'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_SCARR
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDFORM. " DISPLAY_ALV