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: 

what is the difference between the blocked alvs and hirarchical alvs

Former Member
0 Kudos

hi,

what is the difference between the blocked alvs and hirarchical alvs

could u plz explain

4 REPLIES 4

Former Member
0 Kudos

Hi Rajesh,

Block ALV are used to append different layouts one after another.

Heirarchical ALV are used to display the header and item data in a single layout.

Example for Hierarchical ALV:

http://www.geocities.com/mpioud/Z_ALV_HIERSEQ_LIST.html

Example for Blocked ALV:

http://www.sap-basis-abap.com/abap/sample-program-on-block-lists.htm

U can check this link

http://www.erpgenie.com/sapgenie/docs/Using%20ALV.pdf

<b>Reward Points if this helps,</b>

Satish

Former Member
0 Kudos

Dear Rajeshreddy,

I have explained the difference between Blocked ALV and Hierarchical ALV using examples. Hope you find it useful.

>BLOCKED ALV

>>In this case more than one independent block is displayed in the output. This is generally used when we need to display data from two internal tables in the same list where the structure of the table is different.

>>For eg:

TYPE-POOLS : slis.

TABLES : mara,

makt.

SELECT-OPTIONS : mat FOR mara-matnr.

DATA : BEGIN OF itab OCCURS 0,

matnr LIKE mara-matnr,

maktx LIKE makt-maktx,

matkl LIKE mara-matkl,

mtart LIKE mara-mtart,

END OF itab.

DATA : BEGIN OF itab1 OCCURS 0,

mtart LIKE mara-mtart,

count TYPE i,

END OF itab1.

DATA : BEGIN OF itab1_col OCCURS 0,

mtart LIKE mara-mtart,

count TYPE i,

END OF itab1_col.

DATA : t_fcat1 TYPE slis_t_fieldcat_alv,

t_fcat2 TYPE slis_t_fieldcat_alv,

wa_fcat TYPE slis_fieldcat_alv,

t_eve TYPE slis_t_event,

wa_eve TYPE slis_alv_event,

t_layout TYPE slis_layout_alv.

DATA : v_repid LIKE sy-repid,

t_mat LIKE mara-matnr.

DEFINE create_fcat.

clear wa_fcat.

wa_fcat-fieldname = &1.

wa_fcat-seltext_l = &2.

wa_fcat-outputlen = &3.

append wa_fcat to t_fcat1.

END-OF-DEFINITION.

START-OF-SELECTION.

PERFORM get_data.

PERFORM dis_data.

&----


*& Form get_data

&----


text

-


FORM get_data.

SELECT amatnr bmaktx amtart amatkl INTO CORRESPONDING FIELDS OF TABLE itab

FROM mara AS a INNER JOIN makt AS b ON

amatnr = bmatnr

WHERE a~matnr IN mat.

LOOP AT itab.

itab1-mtart = itab-mtart.

itab1-count = 1.

APPEND itab1.

ENDLOOP.

SORT itab1 BY mtart.

LOOP AT itab1.

MOVE-CORRESPONDING itab1 TO itab1_col.

COLLECT itab1_col.

ENDLOOP.

ENDFORM. "get_data

&----


*& Form dis_data

&----


text

-


FORM dis_data.

v_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

i_callback_program = v_repid.

REFRESH t_fcat1.

CLEAR t_fcat1.

REFRESH t_eve.

wa_eve-name = 'TOP_OF_PAGE'.

wa_eve-form = 'TOP_OF_PAGE1'.

APPEND wa_eve TO t_eve.

create_fcat:

'MATNR' 'Material' '10',

'MAKTX' 'Material Description' '40',

'MTART' 'Type' '10',

'MATKL' 'Group' '10'.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

is_layout = t_layout

it_fieldcat = t_fcat1

i_tabname = 'ITAB'

it_events = t_eve

TABLES

t_outtab = itab.

REFRESH t_fcat1.

CLEAR t_fcat1.

REFRESH t_eve.

wa_eve-name = 'TOP_OF_PAGE'.

wa_eve-form = 'TOP_OF_PAGE2'.

APPEND wa_eve TO t_eve.

create_fcat:

'MTART' 'Type' '10',

'COUNT' 'Total' '5'.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

is_layout = t_layout

it_fieldcat = t_fcat1

i_tabname = 'ITAB1_COL'

it_events = t_eve

TABLES

t_outtab = itab1_col.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.

ENDFORM. "dis_data

&----


*& Form top_of_page1

&----


text

-


FORM top_of_page1.

FORMAT COLOR COL_POSITIVE.

WRITE:/ 'First Block'.

FORMAT COLOR OFF.

ENDFORM. "top_of_page

&----


*& Form top_of_page2

&----


text

-


FORM top_of_page2.

FORMAT COLOR COL_NEGATIVE.

WRITE /5 'Second Block'.

FORMAT COLOR OFF.

ENDFORM. "top_of_page

>*********************************************************************

>HIERARCHICAL ALV:

>> Heirarchical ALV are used to display the header and item data in a single layout. i.e., we are displaying data like TREE

>>>Header data at top level

>>> Item data at next level

>>> Subitem data at child level...

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

&----


*& Form top_of_page

&----


text

-


FORM top_of_page.

CLEAR st_line.

st_line-typ = 'H'.

st_line-info = 'Dhwani Shah'.

APPEND st_line TO t_listhead.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_listhead

I_LOGO =

I_END_OF_LIST_GRID =

I_ALV_FORM =

.

ENDFORM. "top_of_page

Best Regards,

Rajesh

Please reward points if found helpful.

Former Member
0 Kudos

Blocked ALVs: Can display multiple list outputs. I.e we can combine more than one report output.

Hierarchical ALVs: Based on the Header level Item leve is displayed.

- S

Former Member
0 Kudos

Hi,

Blocked ALV:This is used to display multiple lists continuosly.

e.g.

'Material' 'Material Description' 'Plant'

000001 Test Material 1000

000002 Raw Material 2000

'Material Doc. No.' 'Quantity' 'Date'

000011 22 21/06/2007

000012 23 23/07/2007

000021 500 01/10/2006

000022 100 10/10/2007

Hierarchical ALV:

Hierarchical sequential alv report means displaying the OUTPUT in the TREE format. Means it display the basic info in first line and its detail info in following line.

e.g.

'Material' 'Material Description' 'Plant'

'Material Doc. No.' 'Quantity' 'Date'

000001 Test Material 1000

000011 22 21/06/2007

000012 23 23/07/2007

000002 Raw Material 2000

000021 500 01/10/2006

000022 100 10/10/2007

If u need any example programs,then i well give u.

reward points if it is useful

thank you

chandu