Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

alvs

Former Member
0 Kudos

what is the main purpose of using Hierarchical ALVs.Can anyone send code for it.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

it is using to prepare list in hierarchical manner.

Main Info in first line than detail info of that in following lines.

Here is code....

TYPE-POOLS : slis.

TABLES : mseg.

DATA : BEGIN OF itab_head OCCURS 0,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

END OF itab_head.

DATA : BEGIN OF itab_item OCCURS 0,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

mblnr LIKE mseg-mblnr,

menge LIKE mseg-menge,

END OF itab_item.

DATA : t_fcat TYPE slis_t_fieldcat_alv,

key_info TYPE slis_keyinfo_alv,

t_eve TYPE slis_t_event,

gt_subtot TYPE slis_t_sortinfo_alv,

subtot LIKE LINE OF gt_subtot,

t_listhead TYPE slis_t_listheader,

st_line TYPE slis_listheader.

DATA : t_mtdoc LIKE mseg-mblnr.

SELECT-OPTIONS : mat FOR mseg-matnr.

INITIALIZATION.

PERFORM build_cat USING t_fcat.

PERFORM build_eve.

START-OF-SELECTION.

PERFORM get_data.

PERFORM dis_data.

&----


*& Form build_cat

&----


  • text

----


  • -->TEMP_FCAT text

----


FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.

DATA : wa_fcat TYPE slis_fieldcat_alv.

wa_fcat-tabname = 'ITAB_HEAD'.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-seltext_m = 'Material'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB_HEAD'.

wa_fcat-fieldname = 'WERKS'.

wa_fcat-seltext_m = 'Plant'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB_ITEM'.

wa_fcat-fieldname = 'MBLNR'.

wa_fcat-seltext_m = 'Material Doc.'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB_ITEM'.

wa_fcat-fieldname = 'MENGE'.

wa_fcat-seltext_m = 'Quantity'.

  • wa_fcat-do_sum = 'Y'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

  • subtot-spos = 1.

  • subtot-fieldname = 'MATNR'.

  • subtot-tabname = 'ITAB_HEAD'.

  • subtot-up = 'X'.

  • subtot-group = 'X'.

  • subtot-subtot = 'X'.

  • subtot-expa = 'X'.

  • APPEND subtot TO gt_subtot.

ENDFORM. "build_cat

&----


*& Form build_eve

&----


  • text

----


FORM build_eve.

DATA : wa_eve TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = t_eve

  • EXCEPTIONS

  • LIST_TYPE_WRONG = 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.

  • READ TABLE t_eve INTO wa_eve WITH KEY name = 'TOP_OF_PAGE'.

  • IF sy-subrc = 0.

  • wa_eve-form = 'TOP_OF_PAGE'.

  • MODIFY t_eve FROM wa_eve INDEX sy-tabix.

  • ENDIF.

*

ENDFORM. "build_eve

&----


*& Form get_data

&----


  • text

----


FORM get_data.

SELECT matnr werks mblnr menge FROM mseg INTO CORRESPONDING FIELDS OF TABLE itab_item

WHERE matnr IN mat.

ENDFORM. "get_data

&----


*& Form dis_data

&----


  • text

----


FORM dis_data.

key_info-header01 = 'MATNR'.

key_info-item01 = 'MATNR'.

key_info-header02 = 'WERKS'.

key_info-item02 = 'WERKS'.

REFRESH itab_head.

LOOP AT itab_item.

ON CHANGE OF itab_item-matnr OR itab_item-werks.

MOVE-CORRESPONDING itab_item TO itab_head.

APPEND itab_head.

ENDON.

ENDLOOP.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_callback_program = 'ZHEIRALV_PRDS'

  • i_callback_user_command = 'USER_COMMAND'

it_fieldcat = t_fcat

it_sort = gt_subtot

it_events = t_eve[]

i_tabname_header = 'ITAB_HEAD'

i_tabname_item = 'ITAB_ITEM'

is_keyinfo = key_info

TABLES

t_outtab_header = itab_head

t_outtab_item = itab_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. "dis_data

1 REPLY 1

Former Member
0 Kudos

hi,

it is using to prepare list in hierarchical manner.

Main Info in first line than detail info of that in following lines.

Here is code....

TYPE-POOLS : slis.

TABLES : mseg.

DATA : BEGIN OF itab_head OCCURS 0,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

END OF itab_head.

DATA : BEGIN OF itab_item OCCURS 0,

matnr LIKE mseg-matnr,

werks LIKE mseg-werks,

mblnr LIKE mseg-mblnr,

menge LIKE mseg-menge,

END OF itab_item.

DATA : t_fcat TYPE slis_t_fieldcat_alv,

key_info TYPE slis_keyinfo_alv,

t_eve TYPE slis_t_event,

gt_subtot TYPE slis_t_sortinfo_alv,

subtot LIKE LINE OF gt_subtot,

t_listhead TYPE slis_t_listheader,

st_line TYPE slis_listheader.

DATA : t_mtdoc LIKE mseg-mblnr.

SELECT-OPTIONS : mat FOR mseg-matnr.

INITIALIZATION.

PERFORM build_cat USING t_fcat.

PERFORM build_eve.

START-OF-SELECTION.

PERFORM get_data.

PERFORM dis_data.

&----


*& Form build_cat

&----


  • text

----


  • -->TEMP_FCAT text

----


FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.

DATA : wa_fcat TYPE slis_fieldcat_alv.

wa_fcat-tabname = 'ITAB_HEAD'.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-seltext_m = 'Material'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB_HEAD'.

wa_fcat-fieldname = 'WERKS'.

wa_fcat-seltext_m = 'Plant'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB_ITEM'.

wa_fcat-fieldname = 'MBLNR'.

wa_fcat-seltext_m = 'Material Doc.'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

wa_fcat-tabname = 'ITAB_ITEM'.

wa_fcat-fieldname = 'MENGE'.

wa_fcat-seltext_m = 'Quantity'.

  • wa_fcat-do_sum = 'Y'.

APPEND wa_fcat TO temp_fcat.

CLEAR wa_fcat.

  • subtot-spos = 1.

  • subtot-fieldname = 'MATNR'.

  • subtot-tabname = 'ITAB_HEAD'.

  • subtot-up = 'X'.

  • subtot-group = 'X'.

  • subtot-subtot = 'X'.

  • subtot-expa = 'X'.

  • APPEND subtot TO gt_subtot.

ENDFORM. "build_cat

&----


*& Form build_eve

&----


  • text

----


FORM build_eve.

DATA : wa_eve TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = t_eve

  • EXCEPTIONS

  • LIST_TYPE_WRONG = 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.

  • READ TABLE t_eve INTO wa_eve WITH KEY name = 'TOP_OF_PAGE'.

  • IF sy-subrc = 0.

  • wa_eve-form = 'TOP_OF_PAGE'.

  • MODIFY t_eve FROM wa_eve INDEX sy-tabix.

  • ENDIF.

*

ENDFORM. "build_eve

&----


*& Form get_data

&----


  • text

----


FORM get_data.

SELECT matnr werks mblnr menge FROM mseg INTO CORRESPONDING FIELDS OF TABLE itab_item

WHERE matnr IN mat.

ENDFORM. "get_data

&----


*& Form dis_data

&----


  • text

----


FORM dis_data.

key_info-header01 = 'MATNR'.

key_info-item01 = 'MATNR'.

key_info-header02 = 'WERKS'.

key_info-item02 = 'WERKS'.

REFRESH itab_head.

LOOP AT itab_item.

ON CHANGE OF itab_item-matnr OR itab_item-werks.

MOVE-CORRESPONDING itab_item TO itab_head.

APPEND itab_head.

ENDON.

ENDLOOP.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_callback_program = 'ZHEIRALV_PRDS'

  • i_callback_user_command = 'USER_COMMAND'

it_fieldcat = t_fcat

it_sort = gt_subtot

it_events = t_eve[]

i_tabname_header = 'ITAB_HEAD'

i_tabname_item = 'ITAB_ITEM'

is_keyinfo = key_info

TABLES

t_outtab_header = itab_head

t_outtab_item = itab_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. "dis_data