Hierarchical Sequential ALV-02

light111Hierarchical ALV on sales order header and item records

 

 

 

The previous post Hierarchical Sequential ALV-01 shows how to make a hierarchical sequential alv on flight data model. This post shows how to display sales order header and item data in hierarchical way.


Code Snippet:


” HIRARCHICAL-SEQUENTIAL ALV
TYPES: BEGIN OF ty_hdr,
                   expand.
                  INCLUDE STRUCTURE vbak.
TYPES: END OF ty_hdr.

DATA: lt_hdr TYPE TABLE OF ty_hdr.
DATA: lt_itm TYPE TABLE OF vbap.
DATA: ls_keyinfo TYPE slis_keyinfo_alv.
DATA: ls_layout TYPE slis_layout_alv.
DATA: lt_fcat TYPE slis_t_fieldcat_alv.
START-OF-SELECTION.
PERFORM data_read.
PERFORM build_layout.
PERFORM build_key.
PERFORM build_fcat.        

PERFORM display_hsalv.
&———————————————————————
& Form DATA_READ
&———————————————————————
FORM data_read .
SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE lt_hdr UP TO 10 ROWS
WHERE kunnr = ‘0000491000’.
CHECK lt_hdr IS NOT INITIAL.
SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE lt_itm
FOR ALL ENTRIES IN lt_hdr WHERE vbeln = lt_hdr-vbeln.
ENDFORM. ” DATA_READ
&———————————————————————
& Form BUILD_LAUOUT
&———————————————————————
FORM build_layout .
ls_layout-expand_fieldname = ‘EXPAND’.
ls_layout-colwidth_optimize = abap_true.
ENDFORM. ” BUILD_LAUOUT
&———————————————————————
& Form BUILD_FCAT
&———————————————————————*
FORM build_fcat .
DATA: ls_fcat LIKE LINE OF lt_fcat.
” header field
ls_fcat-col_pos = ‘1’.
ls_fcat-fieldname = ‘VBELN’.
ls_fcat-tabname = ‘LT_HDR’.
ls_fcat-seltext_m = ‘Document Number’.
ls_fcat-key = abap_true.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.

” header field
ls_fcat-col_pos = ‘2’.
ls_fcat-fieldname = ‘KUNNR’.
ls_fcat-tabname = ‘LT_HDR’.
ls_fcat-seltext_m = ‘Customer Number’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.

” header field
ls_fcat-col_pos = ‘3’.
ls_fcat-fieldname = ‘NETWR’.
ls_fcat-tabname = ‘LT_HDR’.
ls_fcat-seltext_m = ‘Net Amount’.
ls_fcat-emphasize = ‘C600’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.

” header field
ls_fcat-col_pos = ‘4’.
ls_fcat-fieldname = ‘WAERK’.
ls_fcat-tabname = ‘LT_HDR’.
ls_fcat-seltext_m = ‘Curreny’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.

” item field
ls_fcat-col_pos = ‘5’.
ls_fcat-fieldname = ‘POSNR’.
ls_fcat-tabname = ‘LT_ITM’.
ls_fcat-seltext_m = ‘Item Number’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.

” item field
ls_fcat-col_pos = ‘6’.
ls_fcat-fieldname = ‘MATNR’.
ls_fcat-tabname = ‘LT_ITM’.
ls_fcat-seltext_m = ‘Material Number’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.

” item field
ls_fcat-col_pos = ‘7’.
ls_fcat-fieldname = ‘NETWR’.
ls_fcat-tabname = ‘LT_ITM’.
ls_fcat-seltext_m = ‘Net Item Amount’.
ls_fcat-emphasize = ‘C610’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.

” item field
ls_fcat-col_pos = ‘8’.
ls_fcat-fieldname = ‘WAERK’.
ls_fcat-tabname = ‘LT_ITM’.
ls_fcat-seltext_m = ‘Curreny’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.

ENDFORM. ” BUILD_FCAT
&———————————————————————
& Form BUILD_KEY
&———————————————————————*
FORM build_key .
ls_keyinfo-header01 = ‘VBELN’.
ls_keyinfo-item01 = ‘VBELN’.
ENDFORM. ” BUILD_KEY

 

&———————————————————————
& Form DISPLAY_HSALV
&———————————————————————
FORM display_hsalv .
CALL FUNCTION ‘REUSE_ALV_HIERSEQ_LIST_DISPLAY’
EXPORTING
I_INTERFACE_CHECK = ‘ ‘
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ‘ ‘
* I_CALLBACK_USER_COMMAND = ‘ ‘
is_layout = ls_layout
it_fieldcat = lt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_DEFAULT = ‘X’
* I_SAVE = ‘ ‘
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
i_tabname_header = ‘LT_HDR’
i_tabname_item = ‘LT_ITM’
* I_STRUCTURE_NAME_HEADER =
* I_STRUCTURE_NAME_ITEM =
is_keyinfo = ls_keyinfo
* IS_PRINT =
* IS_REPREP_ID =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
* IR_SALV_HIERSEQ_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab_header = lt_hdr
t_outtab_item = lt_itm
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. ” DISPLAY_HSALV


Program Output: Click on the ‘+’ button to expand each row to see its items.

34

5


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s