02-06-2009 7:29 AM
Hi,
We are displaying Master and Child level data using Hierarchical ALV. In this user wants to display HEADING before each CHILD level data getting displayed. Is it possible to do in Hierarchical ALV and how.
Thanks.
02-06-2009 7:56 AM
Hi Venu,
Prepare a header table with set of fields to be displayed in the Header and maintain an item table.
delete duplicates from the header table and then fill the field details in the IS_KEYINFO parameter in the ALV FM
For example the key fields in the header are REFNUMH and KUNUMH and the fields REFNUM and KUNUM are the item key fields.
l_r_keyinfo-header01 = 'REFNUMH'.
l_r_keyinfo-item01 = 'REFNUM'.
l_r_keyinfo-header02 = 'KUNUMH'.
l_r_keyinfo-item02 = 'KUNUM'.
and in the fieldcat for these fields update the parameter KEY with value X.
Hope this will work.
Regards,
Phani.
02-06-2009 8:23 AM
I think you can display like following,
Heading details.
aaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaa
Master1
child 1
child 2
child 3
child 4
Master2
child a
child b
child c
child d
You can't display a heading before every child.
02-06-2009 8:53 AM
Hi,
I hope using this FM 'REUSE_ALV_HIERSEQ_LIST_DISPLAY you can display only master record infront of the respective child records. You cann't display other heading for this child records.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
is_layout = it_layout
it_fieldcat = it_fieldcat
i_tabname_header = 'IT_DD02L'
i_tabname_item = 'IT_DD03L'
is_keyinfo = key
TABLES
t_outtab_header = it_dd02l
t_outtab_item = it_dd03l.
Regards,
Joan
02-06-2009 9:54 AM
Thanks for your answers.
My requirement is like below
Master Record 1: XXXXX
Emp Name Emp Add Emp Date
ChildRecord 1
ChildRecord 2
ChildRecord 3
Master Record 2: XXXXX
Emp Name Emp Add Emp Date
ChildRecord 1
ChildRecord 2
ChildRecord 3
I have to display 'Emp Name Emp Add Emp Date ' Child record HEADER for each set for corresponding MASTER entry.
Edited by: Venu Sarangadharan on Feb 6, 2009 10:55 AM
02-06-2009 10:37 AM
I had developed the code for my similar requirement. Paste the following code and execute. If the layout is fine, it can be changed as per your requirement.
&----
*& Report ZHRDACPYSAMPLE
*& developed by Saipriya
&----
*&This report is used to show the usage of Hierarchical ALV
*& and is meant for beginners
&----
report zhrdacpysample no standard page heading.
type-pools : slis.
parameters : p_begda type begda default '20000101',
p_endda type endda default sy-datum.
types :begin of itab1,
begda type begda,
endda type endda,
pernr type pernr,
names(40) ,
end of itab1.
data : line1 type itab1,
it_line1 type standard table of itab1,
line3 type itab1,
it_line3 type standard table of itab1.
types :begin of itab2 ,
pernr type pernr,
infotype(4) type n,
begda type begda,
endda type endda,
fldname(15) type c,
value(20),
end of itab2.
data : line2 type itab2,
it_line2 type standard table of itab2.
data: line4 type itab2,
itab4 type standard table of itab2.
data : l_pernr type string,
lines type i,
chk1 type c,
val1 type pernr,
val3 type begda,
val4 type endda.
data : begin of wt_infotype occurs 0,
infotype(4) type n,
infotxt(20) type c,
begda type begda,
endda type endda,
end of wt_infotype.
data : head1 like line of wt_infotype.
data: ws_fcat type slis_fieldcat_alv,
wt_fcat type slis_t_fieldcat_alv,
ws_keyinfo type slis_keyinfo_alv,
wt_sortdata type slis_t_sortinfo_alv,
ws_sortdata type slis_sortinfo_alv,
ws_layout type slis_layout_alv,
wt_events type slis_t_event,
ws_eventcat like line of wt_events.
data: gs_line type slis_listheader,
gt_list type slis_t_listheader.
***Constants for header
constants: gc_header_type1 type c value 'H',
gc_header_type2 type c value 'S'.
val3 = p_begda.
val4 = p_endda.
hard coding for itab1
line1-begda = '20000101'.
line1-endda = sy-datum.
line1-pernr = '00000001'.
line1-names = 'Mrs. Alice Mathew'.
append line1 to it_line1.
clear line1.
line1-begda = '20000101'.
line1-endda = sy-datum.
line1-pernr = '00000002'.
line1-names = 'Mr.Jones Bosco'.
append line1 to it_line1.
clear line1.
*Hard coding for itab2
line2-pernr = '00000001'.
line2-infotype = '0002'.
line2-begda = '19800101'.
line2-endda = '20080201'.
line2-fldname = 'Birthdate'.
line2-value = '19850203'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000001'.
line2-infotype = '0006'.
line2-begda = '19900101'.
line2-endda = '19980201'.
line2-fldname = 'City'.
line2-value = 'Chennai'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000001'.
line2-infotype = '0006'.
line2-begda = '19900101'.
line2-endda = '19980201'.
line2-fldname = 'Postal Code'.
line2-value = '45456565'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000001'.
line2-infotype = '0002'.
line2-begda = '20200404'.
line2-endda = '20480201'.
line2-fldname = 'NameAtBirth'.
line2-value = 'Gary'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000001'.
line2-infotype = '0002'.
line2-begda = '20200404'.
line2-endda = '20480201'.
line2-fldname = 'Birthdate'.
line2-value = '04.06.1983'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000001'.
line2-infotype = '0002'.
line2-begda = '20200404'.
line2-endda = '20480201'.
line2-fldname = 'Nationality'.
line2-value = 'Indian'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000001'.
line2-infotype = '0105'.
line2-begda = '20080201'.
line2-endda = '20280201'.
line2-fldname = 'E-mail'.
line2-value = 'trialtest.com'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000001'.
line2-infotype = '0006'.
line2-begda = '20060808'.
line2-endda = '20080404'.
line2-fldname = 'City'.
line2-value = 'London'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000002'.
line2-infotype = '0002'.
line2-begda = '19800101'.
line2-endda = '20080201'.
line2-fldname = 'Birthdate'.
line2-value = '02.05.1987'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000002'.
line2-infotype = '0006'.
line2-begda = '19900101'.
line2-endda = '19980201'.
line2-fldname = 'City'.
line2-value = 'Berlin'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000002'.
line2-infotype = '0002'.
line2-begda = '20200404'.
line2-endda = '20480201'.
line2-fldname = 'Mar.Status'.
line2-value = 'Single'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000002'.
line2-infotype = '0105'.
line2-begda = '20080201'.
line2-endda = '20280201'.
line2-fldname = 'E-mail'.
line2-value = 'pernr2test.com'.
append line2 to it_line2.
clear line2.
line2-pernr = '00000002'.
line2-infotype = '0006'.
line2-begda = '20060808'.
line2-endda = '20080404'.
line2-fldname = 'City'.
line2-value = 'London'.
append line2 to it_line2.
clear line2.
*header hard coding
head1-infotype = '0002'.
head1-infotxt = 'Personal Data'.
head1-begda = '20000101'.
head1-endda = '20080201'.
append head1 to wt_infotype.
clear head1.
head1-infotype = '0002'.
head1-infotxt = 'Personal Data'.
head1-begda = '20200404'.
head1-endda = '20480201'.
append head1 to wt_infotype.
clear head1.
head1-infotype = '0006'.
head1-infotxt = 'Addresses'.
head1-begda = '19900101'.
head1-endda = '19980201'.
append head1 to wt_infotype.
clear head1.
head1-infotype = '0105'.
head1-infotxt = 'Communication'.
head1-begda = '20080101'.
head1-endda = '20280201'.
append head1 to wt_infotype.
clear head1.
head1-infotype = '0006'.
head1-infotxt = 'Addresses'.
head1-begda = '20060808'.
head1-endda = '20080404'.
append head1 to wt_infotype.
clear head1.
if sy-subrc = 0.
sort wt_infotype by infotype begda endda.
endif.
perform key_info.
perform f_build_eventcat.
perform build_fieldcat.
perform f_sort_info.
perform f_set_layout.
*----
END-OF-SELECTION
*----
end-of-selection.
loop at it_line1 into line1 where begda = p_begda and endda = p_endda.
move-corresponding line1 to line3.
append line3 to it_line3.
endloop.
describe table it_line3 lines lines.
loop at it_line3 into line3.
write : /5 chk1 as checkbox , 10 line3-pernr, 20 line3-names.
hide line3-pernr.
endloop.
*----
*AT LINE-SELECTION
*----
at line-selection.
check sy-lsind = 1.
do lines times.
clear chk1.
read line sy-index field value chk1.
if chk1 = 'X'.
val1 = line3-pernr.
perform populate_header using val1.
loop at it_line2 into line2 where pernr = line3-pernr.
move-corresponding line2 to line4.
append line4 to itab4.
endloop.
if sy-subrc = 0.
sort itab4 by infotype begda endda.
perform display_alv.
else.
message 'Select any of the PERNR' type 'I'.
endif.
endif.
enddo.
&----
*& Form key_info
&----
text
----
form key_info .
ws_keyinfo-header01 = 'INFOTYPE'.
ws_keyinfo-item01 = 'INFOTYPE'.
ws_keyinfo-header01 = 'BEGDA'.
ws_keyinfo-item01 = 'BEGDA'.
ws_keyinfo-header01 = 'ENDDA'.
ws_keyinfo-item01 = 'ENDDA'.
endform. "key_info
&----
*& Form build_fieldcat
&----
text
----
form build_fieldcat .
clear ws_fcat.
ws_fcat-col_pos = 1.
ws_fcat-fieldname = 'INFOTYPE'.
ws_fcat-seltext_m = 'Infotype'.
ws_fcat-tabname = 'WT_INFOTYPE'.
ws_fcat-outputlen = 8.
append ws_fcat to wt_fcat.
clear ws_fcat.
ws_fcat-col_pos = 2.
ws_fcat-fieldname = 'INFOTXT'.
ws_fcat-seltext_m = 'Infotext'.
ws_fcat-tabname = 'WT_INFOTYPE'.
ws_fcat-outputlen = 20.
append ws_fcat to wt_fcat.
clear ws_fcat.
ws_fcat-col_pos = 3.
ws_fcat-fieldname = 'BEGDA'.
ws_fcat-seltext_m = 'Start Date'.
ws_fcat-tabname = 'WT_INFOTYPE'.
ws_fcat-outputlen = 20.
append ws_fcat to wt_fcat.
clear ws_fcat.
ws_fcat-col_pos = 4.
ws_fcat-fieldname = 'ENDDA'.
ws_fcat-seltext_m = 'End Date'.
ws_fcat-tabname = 'WT_INFOTYPE'.
ws_fcat-outputlen = 20.
append ws_fcat to wt_fcat.
clear ws_fcat.
ws_fcat-col_pos = 5.
ws_fcat-fieldname = 'FLDNAME'.
ws_fcat-seltext_m = 'Fieldname'.
ws_fcat-tabname = 'ITAB4'.
ws_fcat-outputlen = 20.
append ws_fcat to wt_fcat.
clear ws_fcat.
ws_fcat-col_pos = 6 .
ws_fcat-fieldname = 'VALUE'.
ws_fcat-seltext_m = 'Fieldvalue'.
ws_fcat-tabname = 'ITAB4'.
ws_fcat-outputlen = 20.
append ws_fcat to wt_fcat.
clear ws_fcat.
endform. "build_fieldcat
&----
*& Form DISPLAY_ALV
&----
text
----
form display_alv.
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
i_callback_program = sy-cprog
is_layout = ws_layout
it_fieldcat = wt_fcat
it_events = wt_events
i_tabname_header = 'WT_INFOTYPE'
i_tabname_item = 'ITAB4'
is_keyinfo = ws_keyinfo
tables
t_outtab_header = wt_infotype
t_outtab_item = itab4
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message 'Error in calling Function Module' type 'E'.
endif.
clear itab4[].
endform. " DISPLAY_ALV
&----
*& Form F_SORT_INFO
&----
text
----
form f_sort_info .
ws_sortdata-fieldname = 'BEGDA'.
ws_sortdata-tabname = 'ITAB4'.
ws_sortdata-spos = 1.
ws_sortdata-up = 'X'.
ws_sortdata-group = '*'.
append ws_sortdata to wt_sortdata.
clear ws_sortdata.
ws_sortdata-fieldname = 'ENDDA'.
ws_sortdata-tabname = 'ITAB4'.
ws_sortdata-spos = 2.
ws_sortdata-up = 'X'.
ws_sortdata-group = '*'.
append ws_sortdata to wt_sortdata.
clear ws_sortdata.
ws_sortdata-fieldname = 'FLDNAME'.
ws_sortdata-tabname = 'ITAB4'.
ws_sortdata-spos = 3.
ws_sortdata-up = 'X'.
ws_sortdata-group = '*'.
append ws_sortdata to wt_sortdata.
clear ws_sortdata.
ws_sortdata-fieldname = 'VALUE'.
ws_sortdata-tabname = 'ITAB4'.
ws_sortdata-spos = 4.
ws_sortdata-up = 'X'.
ws_sortdata-group = '*'.
append ws_sortdata to wt_sortdata.
clear ws_sortdata.
endform. " F_SORT_INFO
&----
*& Form f_build_eventcat
&----
text
----
form f_build_eventcat .
clear: wt_events.
refresh: wt_events.
clear: ws_eventcat.
ws_eventcat-name = 'TOP_OF_PAGE'.
ws_eventcat-form = 'F_HEADER'.
append ws_eventcat to wt_events.
endform. " f_build_eventcat
&----
*& Form f_set_layout
&----
text
----
form f_set_layout .
ws_layout-zebra = 'X'.
ws_layout-header_text = 'WT_INFOTYPE'.
ws_layout-item_text = 'ITAB4'.
ws_layout-coltab_fieldname = 'COLOR_FIELD'.
ws_layout-detail_popup = 'X'.
endform. " f_set_layout
&----
*& Form f_header
&----
text
----
form f_header.
***Function module for printing the header
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = gt_list.
if sy-subrc <> 0.
message text-001 type 'I'.
endif.
endform. "f_header
&----
*& Form POPULATE_HEADER
&----
text
----
form populate_header using val1 type pernr.
if val1 eq '00000001'.
val3 = 'Mathew'.
val4 = 'Alice'.
else.
val3 = 'Bosco'.
val4 = 'Jones'.
endif.
clear: gs_line, gt_list.
gs_line-typ = gc_header_type1.
MOVE 'BASIC DATA' TO gs_line-info.
APPEND gs_line TO gt_list.
CLEAR gs_line.
gs_line-typ = gc_header_type2.
concatenate 'Personnel no(SAP Core System) :' val1 into gs_line-info.
append gs_line to gt_list.
gs_line-typ = gc_header_type2.
concatenate 'Personnel no(SAP Payroll System) :' val1 into gs_line-info.
append gs_line to gt_list.
gs_line-typ = gc_header_type2.
concatenate 'Last Name :' val3 into gs_line-info.
append gs_line to gt_list.
gs_line-typ = gc_header_type2.
concatenate 'First Name :' val4 into gs_line-info.
append gs_line to gt_list.
gs_line-typ = gc_header_type2.
concatenate 'CHANGED BY :' sy-uname into gs_line-info.
append gs_line to gt_list.
gs_line-typ = gc_header_type2.
concatenate 'PRINTED AT :' sy-uzeit into gs_line-info.
append gs_line to gt_list.
endform. " POPULATE_HEADER