02-12-2008 1:16 PM
the problem is for every record its displaying the same GL ACC(saknr) no.. it should be differ for every record.. while debugging i am able to get the different values...but in the final result its not... please help me out....
and please write the code using read statement....
START-OF-SELECTION.
SELECT mblnr mjahr budat
FROM mkpf
INTO CORRESPONDING FIELDS OF
TABLE itab_mkpf
WHERE budat IN s_budat.
SELECT bukrs mblnr zeile
bwtar matnr gsber
werks menge meins dmbtr
FROM mseg
INTO CORRESPONDING FIELDS OF
TABLE itab_mseg
FOR ALL ENTRIES IN
itab_mkpf WHERE bukrs EQ p_bukrs
AND mblnr EQ itab_mkpf-mblnr
AND gsber IN p_gsber
AND bwtar IN s_bwtar
AND mjahr EQ itab_mkpf-mjahr.
SELECT bukrs saknr
FROM skb1
INTO corresponding fieldS of
table itab_skb1 WHERE bukrs EQ p_bukrs.
SELECT matnr maktx
FROM makt INTO
TABLE itab_makt
FOR ALL ENTRIES IN itab_mseg
WHERE matnr EQ itab_mseg-matnr.
LOOP AT itab_mkpf.
LOOP AT itab_mseg WHERE mblnr EQ itab_mkpf-mblnr.
MOVE-CORRESPONDING itab_mseg TO itab_final.
**************
LOOP AT itab_skb1 WHERE bukrs EQ itab_mseg-bukrs.
MOVE-CORRESPONDING itab_skb1 TO itab_final.
*******************
LOOP AT itab_makt WHERE matnr EQ itab_mseg-matnr.
MOVE-CORRESPONDING itab_makt TO itab_final.
APPEND itab_final.
CLEAR itab_final.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
all the table are with header line...
if i move the data to main table the value of gl account field SAKNR is same for all the records...
here i need to get different value for saknr for different records and also this is the performance issue please give me the solution for this ......
thanks
regards
babu
Edited by: Aeda N on Feb 12, 2008 2:22 PM
Edited by: Aeda N on Feb 12, 2008 2:26 PM
02-12-2008 1:24 PM
Hi,
Why are you using loops within the loops? thats why you get the performance issues. You have to read the tables then assign each feild then append to the final table. It will solve your problem.
Thanks
Sarada
02-12-2008 2:12 PM
Hi,
create one more internal table same as itab_final and do this code.
clear itab_mkpf.
LOOP AT itab_mkpf.
read table itab_mseg with key mblnr = itab_mkpf-mblnr.
if sy-subrc eq 0.
MOVE-CORRESPONDING itab_mseg TO itab_table.
append itab_table.
clear itab_table.
endif.
endloop.
clear itab_table.
loop at itab_table.
read table itab_skb1 with key bukrs = itab_table-bukrs.
if sy-subrc eq 0.
MOVE-CORRESPONDING itab_skb1 TO itab_final.
append itab_final.
clear itab_final.
endif.
*******************
read table itab_makt With key matnr = itab_table-matnr.
if sy-subrc eq 0.
MOVE-CORRESPONDING itab_makt TO itab_final.
append itab_final.
clear itab_final.
endif.
ENDLOOP.
i hope it may work for u.
regards,
ravi shankar reddy
02-12-2008 3:15 PM
You will not get much benefit from using the READ statement unless you add the BINARY SEARCH option to it or use hashed or sorted tables.
Please see:
[The Performance of Nested Loops|/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops]
Rob
02-13-2008 2:40 AM
Nested loops is always a performance issue. use the parallel cursor in such a case. look at the link below:
http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm
02-13-2008 3:07 AM
Hi babu,
You need not to write the loops that many times when you have only single record in each tables. you just read the tables by looping the Item tables. and also define all the fields in the proper order (Refer D/B tables), so that you can avoid ' INTO CORRESPONDING FIELDS OF ' in Select statements.this is also makes some sense in performance.
START-OF-SELECTION.
SELECT mblnr mjahr budat
FROM mkpf
INTO TABLE itab_mkpf
WHERE budat IN s_budat.
if sy-subrc eq 0.
sort itab_mkpf by mblnr.
endif.
Note: in the below table add SAKTO field also.
SELECT bukrs mblnr zeile
bwtar matnr gsber
werks menge meins dmbtr
FROM mseg
INTO TABLE itab_mseg
FOR ALL ENTRIES IN
itab_mkpf WHERE bukrs EQ p_bukrs
AND mblnr EQ itab_mkpf-mblnr
AND gsber IN p_gsber
AND bwtar IN s_bwtar
AND mjahr EQ itab_mkpf-mjahr.
if sy-subrc eq 0.
sort itab_mseg by mblnr.
endif.
SELECT bukrs saknr
FROM skb1
INTO table itab_skb1
WHERE bukrs EQ p_bukrs.
if sy-subrc eq 0.
sort itab_skb1 by saknr.
endif.
SELECT matnr maktx
FROM makt INTO
TABLE itab_makt
FOR ALL ENTRIES IN itab_mseg
WHERE matnr EQ itab_mseg-matnr.
if sy-subrc eq 0.
sort itab_makt by matnr.
endif.
LOOP AT itab_mkpf.
Read table itab_mseg with key mblnr = itab_mkpf-mblnr binary search.
if sy-subrc = 0.
MOVE-CORRESPONDING itab_mseg TO itab_final.
Read table itab_skb1 with key saknr = itab_mseg-mblnr
bukrs = itab_mkpf-SAKTO
binary search.
if sy-subrc eq 0.
MOVE-CORRESPONDING itab_skb1 TO itab_final.
Read table itab_makt with key matnr = itab_mkpf-matnr binary search.
MOVE-CORRESPONDING itab_makt TO itab_final.
endif.
endif.
endif.
APPEND itab_final.
CLEAR itab_final.
ENDLOOP.
if itab_final[] is not initial.
sort itab_final by mblnr.
endif.
Dont forget to Reward, if my solution is solved your problem.
Thanks,
Murali.