REPORT Z03_ALV_01.
TYPE-POOLs:slis.
TYPES:BEGIN OF TY_ITEM,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
AEDAT TYPE EKPO-AEDAT,
MATNR TYPE EKPO-MATNR,
WERKS TYPE EKPO-WERKS,
LGORT TYPE EKPO-LGORT,
MEINS TYPE EKPO-MEINS,
NETWR TYPE EKPO-NETWR,
END OF TY_ITEM,
BEGIN OF TY_HEADER,
EBELN TYPE EKKO-EBELN,
BUKRS TYPE EKKO-BUKRS,
END OF TY_HEADER.
DATA: LS_HEAD TYPE TY_HEADER,
LT_HEAD TYPE TABLE OF TY_HEADER,
LS_ITEM TYPE TY_ITEM,
LT_ITEM TYPE TABLE OF TY_ITEM,
LT_SORT TYPE SLIS_T_SORTINFO_ALV, " Field catlog for at new..
LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
INITIALIZATION.
PERFORM field.
PERFORM s_up USING lT_SORT.
SELECT-OPTIONS: S_EBELN FOR LS_HEAD-EBELN,
S_BUKRS FOR LS_HEAD-BUKRS.
START-OF-SELECTION.
SELECT EBELN BUKRS FROM EKKO
INTO TABLE LT_HEAD WHERE EBELN IN S_EBELN AND BUKRS IN S_BUKRS.
IF LT_HEAD IS INITIAL.
MESSAGE 'EMPTY' TYPE 'S'.
ENDIF.
SELECT EBELN
EBELP
AEDAT
MATNR
WERKS
LGORT
MEINS
NETWR FROM EKPO INTO TABLE LT_ITEM FOR ALL ENTRIES IN LT_HEAD
WHERE EBELN = LT_HEAD-EBELN.
end-OF-SELECTION.
PERFORM alv_build.
*&---------------------------------------------------------------------*
*& Form FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FIELD .
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'EBELN'.
LS_FIELDCAT-REF_TABNAME = 'EKKO'.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-EMPHASIZE = 'X'.
LS_FIELDCAT-COL_POS = 0.
APPEND LS_FIELDCAT TO Lt_FIELDCAT.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'EBELP'.
LS_FIELDCAT-REF_TABNAME = 'EKPO'.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-EMPHASIZE = 'X'.
LS_FIELDCAT-COL_POS = 1.
APPEND LS_FIELDCAT TO Lt_FIELDCAT.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'AEDAT'.
LS_FIELDCAT-REF_TABNAME = 'EKPO'.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-EMPHASIZE = 'X'.
LS_FIELDCAT-COL_POS = 2.
APPEND LS_FIELDCAT TO Lt_FIELDCAT.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'MATNR'.
LS_FIELDCAT-REF_TABNAME = 'EKPO'.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-EMPHASIZE = 'X'.
LS_FIELDCAT-COL_POS = 3.
APPEND LS_FIELDCAT TO Lt_FIELDCAT.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'WERKS'.
LS_FIELDCAT-REF_TABNAME = 'EKPO'.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-COL_POS = 4.
APPEND LS_FIELDCAT TO Lt_FIELDCAT.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'LGORT'.
LS_FIELDCAT-REF_TABNAME = 'EKPO'.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-EMPHASIZE = 'X'.
LS_FIELDCAT-COL_POS = 5.
APPEND LS_FIELDCAT TO Lt_FIELDCAT.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'MEINS'.
LS_FIELDCAT-REF_TABNAME = 'EKPO'.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-EMPHASIZE = 'X'.
LS_FIELDCAT-COL_POS = 6.
APPEND LS_FIELDCAT TO Lt_FIELDCAT.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'NETWR'.
LS_FIELDCAT-REF_TABNAME = 'EKPO'.
LS_FIELDCAT-OUTPUTLEN = 10.
LS_FIELDCAT-EMPHASIZE = 'X'.
LS_FIELDCAT-COL_POS = 7.
APPEND LS_FIELDCAT TO Lt_FIELDCAT.
CLEAR LS_FIELDCAT.
ENDFORM. " FIELD
*&---------------------------------------------------------------------*
*& Form S_UP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_SORT text
*----------------------------------------------------------------------*
FORM S_UP USING LT_SORT . "Apply the concept here
DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.
CLEAR LS_SORT.
LS_SORT-FIELDNAME = 'EBELN'.
LS_SORT-SPOS = 0.
LS_SORT-UP = 'X'.
* ls_sort-subtot = 'X'.
APPEND LS_SORT TO LT_SORT.
ENDFORM. " S_UP
*&---------------------------------------------------------------------*
*& Form ALV_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ALV_BUILD .
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 = ' '
* 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 =
IT_FIELDCAT = Lt_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = lt_SORT "Apply the fieldcatlog table
* 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 = LT_ITEM
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " ALV_BUILD