‎2013 Jul 15 1:11 PM
Hi, i used 7 tables in a report using alv grid display....
my loop condition failed to retrieve all data from those tables....
is this my loop wright or wrong..???? plz help me in a wright ans....
LOOP AT it_ekko into wa_ekko.
LOOP AT it_ekpo into wa_ekpo WHERE ebeln = wa_ekko-ebeln.
READ TABLE it_lfa1 INTO wa_lfa1 with KEY lifnr = wa_ekko-lifnr
land1 = wa_lfa1-land1
name1 = wa_lfa1-name1.
READ TABLE it_t005t INTO wa_t005t with KEY land1 = wa_lfa1-land1
landx = wa_t005t-landx.
READ TABLE it_tvzbt INTO wa_tvzbt with KEY zterm = wa_ekko-zterm
vtext = wa_tvzbt-vtext.
READ TABLE it_eket INTO wa_eket with KEY ebeln = so_ebeln
eindt = wa_eket-eindt.
READ TABLE it_esuh INTO wa_esuh with KEY packno = wa_ekpo-packno
commitment = wa_esuh-commitment.
Regards,
ManiGandan
‎2013 Jul 16 7:28 AM
Hi all,
Solved the issue, Got the solution.
The loop condition is,
*
LOOP AT it_ekko into wa_ekko.
LOOP AT it_ekpo into wa_ekpo WHERE ebeln = wa_ekko-ebeln.
READ TABLE it_lfa1 INTO wa_lfa1 with KEY lifnr = wa_ekko-lifnr.
loop at it_t005t INTO wa_t005t WHERE land1 = wa_lfa1-land1.
READ TABLE it_tvzbt INTO wa_tvzbt with KEY zterm = wa_ekko-zterm.
READ TABLE it_eket INTO wa_eket with KEY ebeln = so_ebeln.
READ TABLE it_esuh INTO wa_esuh with KEY packno = wa_ekpo-packno.
wa_final-ebeln = wa_ekko-ebeln.
wa_final-bukrs = wa_ekko-bukrs.
wa_final-bsart = wa_ekko-bsart.
wa_final-aedat = wa_ekko-aedat.
wa_final-lifnr = wa_ekko-lifnr.
wa_final-zterm = wa_ekko-zterm.
wa_final-matnr = wa_ekpo-matnr.
wa_final-werks = wa_ekpo-werks.
wa_final-packno = wa_ekpo-packno.
WA_FINAL-NETPR = WA_EKPO-NETPR.
wa_final-land1 = wa_lfa1-land1.
wa_final-name1 = wa_lfa1-name1.
wa_final-landx = wa_t005t-landx.
wa_final-vtext = wa_tvzbt-vtext.
wa_final-eindt = wa_eket-eindt.
wa_final-commitment = wa_esuh-commitment.
APPEND wa_final to it_final.
ENDLOOP.
ENDLOOP.
ENDLOOP.
Working fine...
Warm Regards,
ManiGandan G.
‎2013 Jul 15 5:36 PM
Hi ManiGandan,
1.first check the internal tables from which you are reading records contains some records or not?
2. use sy-subrc system field to check where you are not able to fetch records after checking you can remove those conditions if you want to.
example:
LOOP AT it_ekko into wa_ekko.
LOOP AT it_ekpo into wa_ekpo WHERE ebeln = wa_ekko-ebeln.
if sy-subrc = 0.
READ TABLE it_lfa1 INTO wa_lfa1 with KEY lifnr = wa_ekko-lifnr
land1 = wa_lfa1-land1
name1 = wa_lfa1-name1.
if sy-subrc = 0.
READ TABLE it_t005t INTO wa_t005t with KEY land1 = wa_lfa1-land1
landx = wa_t005t-landx.
if sy-subrc = 0.
READ TABLE it_tvzbt INTO wa_tvzbt with KEY zterm = wa_ekko-zterm
vtext = wa_tvzbt-vtext.
if sy-subrc = 0.
READ TABLE it_eket INTO wa_eket with KEY ebeln = so_ebeln
eindt = wa_eket-eindt.
if sy-subrc = 0.
READ TABLE it_esuh INTO wa_esuh with KEY packno = wa_ekpo-packno
commitment = wa_esuh-commitment.
endif.
endif.
endif.
endif.
endif.
‎2013 Jul 15 6:41 PM
we dont know what the requirement is, still i see some issues in the above loop.
1) you have a loop inside a loop.. if possible avoid it.
2) you are reading it_lfa1 with key from ekko table + lfa1 again... how can you do that..your read statement should be based on ekko or ekpo..
3)since first read statement fails, it will fail read for t005 too..
thanks
Sam
‎2013 Jul 15 7:23 PM
Hi ManiGandan,
I think there is somthing wrong in your code.
First declare an internal table containing all the fields required for passing to the ALV display.
types: begin of out_type,
ebeln like ekko-ebeln,
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
land1 like lfa1-land1,
landx like t005t-landx,
zterm like ekko-zterm,
vtext like tvzbt-vtext,
eindt like eket-eindt,
packno like ekpo-packno,
commitment like esuh-commitment,
*Add any other field that is required.
end of out_type.
Data :itab like table of out_type,
Wa_itab like line of itab.
*Read data into internal tables It_ekko, it_ekpo, it_lfa1, it_t005t, it_tzvbt, it_eket, it_esuh from the corresponding database tables with required selection criteria.
For that use the select statements select * from ekko into table it_ekko where <condition>.
Similarly for all other tables.
Select * from ekpo into table it_ekpo for all entries in it_ekko where ebeln = it_ekko-ebeln.
Select * from lfai into table it_lfa1 for all entries in it_ekko where lifnr = it_ekko-lifnr.
Select * from t005t into table it_t005t for all entries in it_lfa1 where land1 = it_lfa1-land1.
Select * from tvzbt into tablt it_tvzbt for all entries in it_ekko where zterm = it_ekko-zterm.
Select * from eket into table it_eket for all entires in it_ekko where ebeln = it_ekko-ebeln.
Select * from esuh into table it_esuh for all entries in it_ekpo where packno = .it_ekpo-packno
Now coming to your loop statements, the conditions for read statemntare not exactly right.
LOOP AT it_ekko into wa_ekko.
LOOP AT it_ekpo into wa_ekpo WHERE ebeln = wa_ekko-ebeln.
wa_itab-ebeln = ekko-ebeln.
Wa_itab-lifnr = ekko-lifnr.
" The main mistake in read statement is that you cannot use wa_lfa1 in your condition since the values will be in that only after the read statement. So also for all the other read statements.
READ TABLE it_lfa1 INTO wa_lfa1 with KEY lifnr = wa_ekko-lifnr.
Wa_itab name1 = wa_lfa1-name1.
READ TABLE it_t005t INTO wa_t005t with KEY land1 = spras = sy-langu wa_lfa1-land1 .
Wa_itba- landx = wa_t005t-landx.
READ TABLE it_tvzbt INTO wa_tvzbt with KEY spras = sy-langu zterm = wa_ekko-zterm.
wa_itab-zterm = wa_ekko-zterm.
wa_itab-vtext = wa_tvzbt-vtext.
READ TABLE it_eket INTO wa_eket with KEY ebeln = wa_ekko-ebeln and ebelp = wa_ekko-ebelp.
wa_itab-eindt = wa_eket-eindt.
READ TABLE it_esuh INTO wa_esuh with KEY packno = wa_ekpo-packno.
wa_itab- wa_ekpo-packno.
wa_itab- commitment = wa_esuh-commitment.
append wa_itab into itab.
clear : wa_itab, wa_ekko, wa_ekpo, wa_t005t,wa_tvzbt, wa_eket, wa_esuh, wa_lfa1.
Endloop.
Endloop.
Now the table itab will contain the required data to be passed to ALV display.
‎2013 Jul 16 9:04 AM
For the above example, we can use field symbol instead of work area. It will improve the performance.
‎2013 Jul 15 7:43 PM
Dear Mani,
You cannot Put a work area Field in Equality Condition in which ( work area ) you are reading the the values from Internal Table.
You have to use the values from Previously Read Internal Table in the equality condition.
to help you with Code :
LOOP AT it_ekko into wa_ekko.
read table it_ekpo into wa_ekpo with key vbeln = wa_ekko-vbeln. ## CORRECT
**Your processing here
Read table it_ekpo into WA_EKPO with key vbeln = WA_EKPO-vbeln ## INCORRECT
ENDLOOP.
‎2013 Jul 16 7:28 AM
Hi all,
Solved the issue, Got the solution.
The loop condition is,
*
LOOP AT it_ekko into wa_ekko.
LOOP AT it_ekpo into wa_ekpo WHERE ebeln = wa_ekko-ebeln.
READ TABLE it_lfa1 INTO wa_lfa1 with KEY lifnr = wa_ekko-lifnr.
loop at it_t005t INTO wa_t005t WHERE land1 = wa_lfa1-land1.
READ TABLE it_tvzbt INTO wa_tvzbt with KEY zterm = wa_ekko-zterm.
READ TABLE it_eket INTO wa_eket with KEY ebeln = so_ebeln.
READ TABLE it_esuh INTO wa_esuh with KEY packno = wa_ekpo-packno.
wa_final-ebeln = wa_ekko-ebeln.
wa_final-bukrs = wa_ekko-bukrs.
wa_final-bsart = wa_ekko-bsart.
wa_final-aedat = wa_ekko-aedat.
wa_final-lifnr = wa_ekko-lifnr.
wa_final-zterm = wa_ekko-zterm.
wa_final-matnr = wa_ekpo-matnr.
wa_final-werks = wa_ekpo-werks.
wa_final-packno = wa_ekpo-packno.
WA_FINAL-NETPR = WA_EKPO-NETPR.
wa_final-land1 = wa_lfa1-land1.
wa_final-name1 = wa_lfa1-name1.
wa_final-landx = wa_t005t-landx.
wa_final-vtext = wa_tvzbt-vtext.
wa_final-eindt = wa_eket-eindt.
wa_final-commitment = wa_esuh-commitment.
APPEND wa_final to it_final.
ENDLOOP.
ENDLOOP.
ENDLOOP.
Working fine...
Warm Regards,
ManiGandan G.
‎2013 Jul 16 8:20 AM
Dear Mani,
Please have a look into the below code ,
DATA : LV_INDEX(4) TYPE C.
SORT IT_EKKO BY EBELN DESCENDING.
SORT IT_EKPO BY EBELN EBELP DESCENDING.
LOOP AT it_ekko into wa_ekko.
READ TABLE IT_EKPO INTO WA_EKPO WITH KEY EBELN = WA_EKKO-EBELN BINARY SEARCH.
IF SY-SUBRC EQ 0.
LV_INDEX = SY-TABIX.
LOOP AT it_ekpo into wa_ekpo FROM LV_INDEX.
IF WA_EKKO-EBELN EQ WA_EKPO-EBELN.
READ TABLE it_lfa1 INTO wa_lfa1 with KEY lifnr = wa_ekko-lifnr.
IF SY-SUBRC EQ 0.
" FILL REQUIRED FEILDS
ENDIF.
READ TABLE it_t005t INTO wa_t005t with KEY land1 = wa_lfa1-land1.
IF SY-SUBRC EQ 0.
" FILL REQUIRED FEILDS
ENDIF.
READ TABLE it_tvzbt INTO wa_tvzbt with KEY zterm = wa_ekko-zterm.
IF SY-SUBRC EQ 0.
" FILL REQUIRED FEILDS
ENDIF.
READ TABLE it_eket INTO wa_eket with KEY ebeln = so_ebeln.
" FILL REQUIRED FEILDS
IF SY-SUBRC EQ 0.
ENDIF.
READ TABLE it_esuh INTO wa_esuh with KEY packno = wa_ekpo-packno.
IF SY-SUBRC EQ 0.
" FILL REQUIRED FEILDS
ENDIF.
ELSE.
EXIT.
ENDIF.
CLEAR : WA_EKPO ,WA_LFA1,WA_ESUH, WA_EKET,WA_TVZBT,WA_T005T.
ENDLOOP.
ENDIF.
CLEAR : WA_EKPO, WA_EKKO.
ENDLOOP .
after looking to your code i found there were some bugs,
Do not use the same work area in "with key" conditions of Read statements ,
READ TABLE it_lfa1 INTO wa_lfa1 with KEY lifnr = wa_ekko-lifnr
land1 = wa_lfa1-land1
name1 = wa_lfa1-name1. " wrong way
READ TABLE it_lfa1 INTO wa_lfa1 with KEY lifnr = wa_ekko-lifnr.
and try to avoid the loop inside the loop statements , use parallel cursor technique.
For any further issues please let me know
Regards,
Pavan Kumar