Hi Barnabas,
I have written a program that will fill a table with pernr, date type and date taking values from pa0041. You can modify the program to suit your need.
REPORT ZTEST_HR.
tables pa0041.
types : beginof it_type,
pernr type pernr,
dar like pa0041-dar01,
dat like pa0041-dat01,
endof it_type.
data : i_pa0041 typeTABLEOF pa0041,
wa_pa0041 likeLINEOF i_pa0041,
it_tab typeTABLEOF it_type,
wa_tab likelineof it_tab.
DATA: tb_struct TYPEREFTO cl_abap_structdescr,
tb_comp TYPE abap_component_tab.
data : wa_field1(20), wa_field2(20).
FIELD-SYMBOLS : <fs>,<fs1> ,<fs2>,<fs_components>.
select-OPTIONS : s_pernr for pa0041-pernr.
START-OF-SELECTION.
* Get the structure of pa0041
tb_struct ?=
cl_abap_typedescr=>describe_by_data( wa_pa0041 ).
select * from pa0041 intotable i_pa0041 where pernr in s_pernr.
loopat i_pa0041 into wa_pa0041.
* Loop through each field in pa0041.
LOOPAT tb_struct->components ASSIGNING<fs_components>.
assigncomponent'NAME'ofSTRUCTURE<fs_components> to<fs>.
wa_field1 = <fs>.
* When the field is a 'DAR' field, take the corresponding 'DAT' field and append to the table for that pernr.
if wa_field1 CS'DAR'.
ASSIGNCOMPONENT wa_field1 ofSTRUCTURE wa_pa0041 to<fs1>.
ifnot<fs1> isinitial.
concatenate'DAT' wa_field1+3(2) into wa_field2.
condense wa_field2.
ASSIGNCOMPONENT wa_field2 ofSTRUCTURE wa_pa0041 to<fs2>.
wa_tab-pernr = wa_pa0041-pernr.
wa_tab-dar = <fs1>.
wa_tab-dat = <fs2>.
append wa_tab to it_tab.
clear wa_tab.
endif.
endif.
UNASSIGN : <fs1> , <fs2>, <fs>.
ENDLOOP.
ENDLOOP.
In the example you have given, the condition would be as follows.
if<fs1> = 'Z1'.
concatenate'DAT' wa_field1+3(2) into wa_field2.
condense wa_field2.
ASSIGNCOMPONENT wa_field2 ofSTRUCTURE wa_pa0041 to<fs2>.
wa_tab-pernr = wa_pa0041-pernr.
wa_tab-dar = <fs1>.
wa_tab-dat = <fs2>.
append wa_tab to it_tab.
clear wa_tab.
endif.
endif.