2007 Jul 06 8:55 PM
Hi, I work on SAP BW and need guidance on the functionality from the below code:
l_s_datapak_line[] = datapak[].
l_s_datapak[] = datapak[].
sort l_s_datapak_line by pernr endda descending.
loop at l_s_datapak.
read table l_s_datapak_line with key pernr = l_s_datapak-pernr
endda = '99991231'.
if sy-subrc = 0.
pernr = l_s_datapak_line-pernr.
curr_compcode = l_s_datapak_line-bukrs.
curr_job = l_s_datapak_line-stell.
curr_mastcctr = l_s_datapak_line-kostl.
curr_orgunit = l_s_datapak_line-orgeh.
curr_persarea = l_s_datapak_line-werks.
curr_perssubarea = l_s_datapak_line-BTRTL.
curr_position = l_s_datapak_line-plans.
curr_chief = l_s_datapak_line-zzchiefpernr.
curr_supervisor = l_s_datapak_line-zzsupervisor.
modify i_curr index i_index.
exit.
endif.
endloop.
In the above code, I want the loop to run only once for each pernr. If there are 10 records in l_s_datapak with pernr = 100, then the loop would run 100 times although there would be only one record in l_s_datapak_line with endda = '99991231'. I want the loop to run only once , assign the values and then l_s_datapak-pernr should become 101. How do I do it?
Any help is highly appreciated and thanks for the help in advance.
2007 Jul 06 9:32 PM
I am not sure I understood the requirement here. Both l_s_datapak_line and l_s_datapak have the same records (since both are filled from datapak). If the purpose is to get the current employee record out of datapak, why don't you simply do this.
l_s_datapak[] = datapak[].
SORT l_s_datapak BY pernr endda DESCENDING.
DELETE ADJACENT DUPLICATES FROM l_s_datapak COMPARING pernr.
*-- Now l_s_datapak has only unique pernr records with only the record that has
the greatest end date. But we are interested only in those PERNR records that
have an end date of '99991231'.
LOOP AT l_s_datapak WHERE endda = '99991231'.
pernr = l_s_datapak-pernr.
curr_compcode = l_s_datapak-bukrs.
curr_job = l_s_datapak-stell.
curr_mastcctr = l_s_datapak-kostl.
curr_orgunit = l_s_datapak-orgeh.
curr_persarea = l_s_datapak-werks.
curr_perssubarea = l_s_datapak-BTRTL.
curr_position = l_s_datapak-plans.
curr_chief = l_s_datapak-zzchiefpernr.
curr_supervisor = l_s_datapak-zzsupervisor.
modify i_curr index i_index.
ENDLOOP.
Message was edited by:
Srinivas Adavi
Hi, I work on SAP BW and need guidance on the functionality from the below code:
l_s_datapak_line[] = datapak[].
l_s_datapak[] = datapak[].
sort l_s_datapak_line by pernr endda descending.
loop at l_s_datapak.
read table l_s_datapak_line with key pernr = l_s_datapak-pernr
endda = '99991231'.
if sy-subrc = 0.
pernr = l_s_datapak_line-pernr.
curr_compcode = l_s_datapak_line-bukrs.
curr_job = l_s_datapak_line-stell.
curr_mastcctr = l_s_datapak_line-kostl.
curr_orgunit = l_s_datapak_line-orgeh.
curr_persarea = l_s_datapak_line-werks.
curr_perssubarea = l_s_datapak_line-BTRTL.
curr_position = l_s_datapak_line-plans.
curr_chief = l_s_datapak_line-zzchiefpernr.
curr_supervisor = l_s_datapak_line-zzsupervisor.
modify i_curr index i_index.
exit.
endif.
endloop.
In the above code, I want the loop to run only once for each pernr. If there are 10 records in l_s_datapak with pernr = 100, then the loop would run 100 times although there would be only one record in l_s_datapak_line with endda = '99991231'. I want the loop to run only once , assign the values and then l_s_datapak-pernr should become 101. How do I do it?
Any help is highly appreciated and thanks for the help in advance.
2007 Jul 06 9:08 PM
You can do something like this...
LOOP AT T_NPEDI ASSIGNING <NPEDI>.
IF W_NPEDI NE <NPEDI>-NPEDI.
W_NPEDI = <NPEDI>-NPEDI.
ELSE.
CONTINUE.
ENDIF.
*Do logic....
ENDLOOP.
Greetings,
Blag.
2007 Jul 06 9:22 PM
Hi Alvaro, thanks for the prompt response. however i am at the basic level of abap and could not understand much of the field symbol logic that you have posted. could you please write the same using the table names that I have given.
Thanks
2007 Jul 06 9:26 PM
Sure -:)
l_s_datapak_line[] = datapak[].
l_s_datapak[] = datapak[].
sort l_s_datapak_line by pernr endda descending.
loop at l_s_datapak.
*----ADD THIS LOGIC----*
if w_pernr ne l_s_datapak-pernr.
w_pernr = l_s_datapak-pernr.
else.
continue.
endif.
*----ADD THIS LOGIC----*
read table l_s_datapak_line with key pernr = l_s_datapak-pernr
endda = '99991231'.
if sy-subrc = 0.
pernr = l_s_datapak_line-pernr.
curr_compcode = l_s_datapak_line-bukrs.
curr_job = l_s_datapak_line-stell.
curr_mastcctr = l_s_datapak_line-kostl.
curr_orgunit = l_s_datapak_line-orgeh.
curr_persarea = l_s_datapak_line-werks.
curr_perssubarea = l_s_datapak_line-BTRTL.
curr_position = l_s_datapak_line-plans.
curr_chief = l_s_datapak_line-zzchiefpernr.
curr_supervisor = l_s_datapak_line-zzsupervisor.
modify i_curr index i_index.
* exit.
endif.
endloop.
Done -;)
Greetings,
Blag.
2007 Jul 06 9:22 PM
Hi,
Use Control Break statements i.e. AT NEW....ENDAT as shown below.
l_s_datapak_line[] = datapak[].
l_s_datapak[] = datapak[].
sort l_s_datapak_line by pernr endda descending.
loop at l_s_datapak.
<b>AT NEW pernr.</b>
read table l_s_datapak_line with key pernr = l_s_datapak-pernr
endda = '99991231'.
if sy-subrc = 0.
pernr = l_s_datapak_line-pernr.
curr_compcode = l_s_datapak_line-bukrs.
curr_job = l_s_datapak_line-stell.
curr_mastcctr = l_s_datapak_line-kostl.
curr_orgunit = l_s_datapak_line-orgeh.
curr_persarea = l_s_datapak_line-werks.
curr_perssubarea = l_s_datapak_line-BTRTL.
curr_position = l_s_datapak_line-plans.
curr_chief = l_s_datapak_line-zzchiefpernr.
curr_supervisor = l_s_datapak_line-zzsupervisor.
modify i_curr index i_index.
exit.
endif.
<b>ENDAT.</b>
endloop.
Reward points if the answer is helpful.
Regards,
Mukul
2007 Jul 06 9:32 PM
I am not sure I understood the requirement here. Both l_s_datapak_line and l_s_datapak have the same records (since both are filled from datapak). If the purpose is to get the current employee record out of datapak, why don't you simply do this.
l_s_datapak[] = datapak[].
SORT l_s_datapak BY pernr endda DESCENDING.
DELETE ADJACENT DUPLICATES FROM l_s_datapak COMPARING pernr.
*-- Now l_s_datapak has only unique pernr records with only the record that has
the greatest end date. But we are interested only in those PERNR records that
have an end date of '99991231'.
LOOP AT l_s_datapak WHERE endda = '99991231'.
pernr = l_s_datapak-pernr.
curr_compcode = l_s_datapak-bukrs.
curr_job = l_s_datapak-stell.
curr_mastcctr = l_s_datapak-kostl.
curr_orgunit = l_s_datapak-orgeh.
curr_persarea = l_s_datapak-werks.
curr_perssubarea = l_s_datapak-BTRTL.
curr_position = l_s_datapak-plans.
curr_chief = l_s_datapak-zzchiefpernr.
curr_supervisor = l_s_datapak-zzsupervisor.
modify i_curr index i_index.
ENDLOOP.
Message was edited by:
Srinivas Adavi
2007 Jul 06 10:22 PM
Hi Srinivas, thanks a lot, my issue is almost resolved. I am not able to test it as the system is down, but looking at the code i am sure that it will work. thanks !!
Points awarded too !!!
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |