ALV USING LAYOUT WORKAREA:
Some of the fields in layout WA: -
1.Colwidth_optimize ( Compress the displayed field )
2.Zebra ( Stripped pattern )
3.Info_fieldname ( colour field ) .
Note: - In slis we have one type I.e. slis_layout_alv which contains all the fields related to layout work area. So we simply declare our layout work area by referring above type.
*&---------------------------------------------------------------------*
*& Report ZR_ALV_LAYOUT_WORKAREA
*&
*&---------------------------------------------------------------------*
REPORT ZR_ALV_LAYOUT_WORKAREA.
TYPE-POOLS : SLIS .
*DATA DECLARAATIONS
DATA : I_MARA TYPE TABLE OF MARA .
DATA : WA_MARA TYPE MARA .
*ALV DECLARATIONS
DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT TYPE SLIS_FIELDCAT_ALV .
DATA : V_POS TYPE I .
DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV .
PARAMETERS : P_MTART TYPE MARA-MTART.
START-OF-SELECTION .
PERFORM GET_DATA .
PERFORM CREATE_FCAT .
PERFORM CREATE_LAYOUT.
PERFORM DISPLAY_DATA .END-OF-SELECTION .
\
FORM GET_DATA .
SELECT * FROM MARA
INTO TABLE I_MARA
UP TO 100 ROWS WHERE MTART = P_MTART .
ENDFORM. " GET_DATA
FORM DISPLAY_DATA .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = I_FCAT
TABLES
T_OUTTAB = I_MARA.
ENDFORM. " DISPLAY_DATA
FORM DISPLAY_DATA_LIST .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'MARA'
TABLES
T_OUTTAB = I_MARA.
IF SY-SUBRC NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_DATA_LIST
FORM CREATE_FCAT .
V_POS = 1 .
WA_FCAT-COL_POS = V_POS.
WA_FCAT-FIELDNAME = 'MATNR' .
WA_FCAT-SELTEXT_M = 'Material.NO' .
WA_FCAT-HOTSPOT = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS + 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MTART' .
WA_FCAT-SELTEXT_M = 'Material.Type' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS + 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MBRSH' .
WA_FCAT-SELTEXT_M = 'Ind.Sector' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS + 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MATKL' .
WA_FCAT-SELTEXT_M = 'Mat.Grp' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS + 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MEINS' .
WA_FCAT-SELTEXT_M = 'Units' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .ENDFORM. " CREATE_FCAT
FORM CREATE_LAYOUT .
WA_LAYOUT-ZEBRA = 'X' .
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X' .
WA_LAYOUT-EDIT = 'X' .
WA_LAYOUT-NO_VLINE = 'X' .
WA_LAYOUT-NO_HLINE = 'X' .
ENDFORM. " CREATE_LAYOUT
OUTPUT:
Some of the fields in layout WA: -
1.Colwidth_optimize ( Compress the displayed field )
2.Zebra ( Stripped pattern )
3.Info_fieldname ( colour field ) .
Note: - In slis we have one type I.e. slis_layout_alv which contains all the fields related to layout work area. So we simply declare our layout work area by referring above type.
*&---------------------------------------------------------------------*
*& Report ZR_ALV_LAYOUT_WORKAREA
*&
*&---------------------------------------------------------------------*
REPORT ZR_ALV_LAYOUT_WORKAREA.
TYPE-POOLS : SLIS .
*DATA DECLARAATIONS
DATA : I_MARA TYPE TABLE OF MARA .
DATA : WA_MARA TYPE MARA .
*ALV DECLARATIONS
DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT TYPE SLIS_FIELDCAT_ALV .
DATA : V_POS TYPE I .
DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV .
PARAMETERS : P_MTART TYPE MARA-MTART.
START-OF-SELECTION .
PERFORM GET_DATA .
PERFORM CREATE_FCAT .
PERFORM CREATE_LAYOUT.
PERFORM DISPLAY_DATA .END-OF-SELECTION .
\
FORM GET_DATA .
SELECT * FROM MARA
INTO TABLE I_MARA
UP TO 100 ROWS WHERE MTART = P_MTART .
ENDFORM. " GET_DATA
FORM DISPLAY_DATA .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = I_FCAT
TABLES
T_OUTTAB = I_MARA.
ENDFORM. " DISPLAY_DATA
FORM DISPLAY_DATA_LIST .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'MARA'
TABLES
T_OUTTAB = I_MARA.
IF SY-SUBRC NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_DATA_LIST
FORM CREATE_FCAT .
V_POS = 1 .
WA_FCAT-COL_POS = V_POS.
WA_FCAT-FIELDNAME = 'MATNR' .
WA_FCAT-SELTEXT_M = 'Material.NO' .
WA_FCAT-HOTSPOT = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS + 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MTART' .
WA_FCAT-SELTEXT_M = 'Material.Type' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS + 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MBRSH' .
WA_FCAT-SELTEXT_M = 'Ind.Sector' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS + 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MATKL' .
WA_FCAT-SELTEXT_M = 'Mat.Grp' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .
V_POS = V_POS + 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MEINS' .
WA_FCAT-SELTEXT_M = 'Units' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .ENDFORM. " CREATE_FCAT
FORM CREATE_LAYOUT .
WA_LAYOUT-ZEBRA = 'X' .
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X' .
WA_LAYOUT-EDIT = 'X' .
WA_LAYOUT-NO_VLINE = 'X' .
WA_LAYOUT-NO_HLINE = 'X' .
ENDFORM. " CREATE_LAYOUT
OUTPUT: