05-24-2007 5:06 AM
please tell me the difference between:
displaying table entries using loop in base table then loop in next table :
LOOP AT IKNA1.
LOOP AT IKNVP WHERE KUNNR = IKNA1-KUNNR.
Code....
endloop.
endloop.
and
displaying table entries using loop in base table then read in next table :
LOOP AT IKNA1.
READ TABLE IKNVP WITH KEY KUNNR = IKNA1-KUNNR.
Code.....
Endloop.
05-24-2007 5:22 AM
guys prob is still not answered
i am gettin multiple entries in case of read NOT loop and these are not different entries but they are previous repeated entry may be wen we get an entry in main table which is not in secondary table then entries in second tables shows some <b>repeated</b> entries
05-24-2007 5:08 AM
LOOP AT IKNA1.
LOOP AT IKNVP WHERE KUNNR = IKNA1-KUNNR.
Code....
endloop.
endloop.
This can get multiple records from IKNVP,if there are multiple records satisfying where condition.
LOOP AT IKNA1.
READ TABLE IKNVP WITH KEY KUNNR = IKNA1-KUNNR.
Code.....
Endloop.
This can get only single record.
If there are multiple records with the same KEY then the first record which satisfied the WITH KEY condition will be fetched.
Both return sy-subrc = 4 if no records are found with specified condition.
05-24-2007 5:09 AM
Both are same and performance of point of view we use read table in Loop .
Loop means - we can read multiple data from internal table..
Read table meand - we can read one record from internal table.
05-24-2007 5:10 AM
05-24-2007 5:12 AM
Redundant in what sense?
READ statement will fetch the matching KUNNR record into header line of IKNVP.
05-24-2007 5:10 AM
LOOP AT IKNA1.
LOOP AT IKNVP WHERE KUNNR = IKNA1-KUNNR.
Code....
endloop.
endloop.
This code fetches the multiple entires from the table IKNVP which statisfy the condtions .
LOOP AT IKNA1.
READ TABLE IKNVP WITH KEY KUNNR = IKNA1-KUNNR.
Code.....
Endloop.
This code fetches the single entry from the table IKNVP which statisfy the condtions .
This second method is more efficient compare to first one .
05-24-2007 5:11 AM
Hi
The second method is advisable.Because insted of looking line-by-line in the second internal table, According to the key you have give in The READ TABLE it will do a search and this will save a lot of time..Put a break-point here and goto debugg mode you can see what is happening....Looping through the internal table is always will take a longer time that that of READ table,,...
Reward ALL helpfull Answers........
05-24-2007 5:12 AM
hi karan,
in first case we use move corresponding for moving whole data to the final output table but in second case data move by key and line by line.
in first case we use sy-tabix for tracking the index. while in second case we use key as keyword.
thanks and regards
vijay dwivedi
rewards if answer is helpful to you
05-24-2007 5:13 AM
LOOP AT IKNA1.
LOOP AT IKNVP WHERE KUNNR = IKNA1-KUNNR.
Code....
endloop.
endloop.
<b>above will fetches multiple records from IKNVP</b>
LOOP AT IKNA1.
READ TABLE IKNVP WITH KEY KUNNR = IKNA1-KUNNR.
Code.....
Endloop.
<b>It fetches single record from IKNVP
Depending on your requirement you should use accordingly.
If you want to fetch one record from second internal table then read statment will me useful. (performance wise)</b>
Reward to all useful answers.
Regards,
SaiRam
05-24-2007 5:13 AM
doono sy-tabix for second table becomes 0 then again to original value
i mean wen entry of first table is not found in second the previous entry of second tables is displayed again
05-24-2007 5:20 AM
Use sy-subrc check after READ statement before writing any other logic.
Loop..
READ..
if sy-subrc = 0.
..code..
endif.
Endloop.
The reason why the previous record is displayed is because if it doesnt find any record in the other table, it will not clear the header line and hence it will contain values of the last record.
05-24-2007 5:16 AM
1)
LOOP AT IKNA1.
LOOP AT IKNVP WHERE KUNNR = IKNA1-KUNNR.
Code....
endloop.
endloop.
here, u are using a loop inside a loop.
in the second loop, every entry of IKNVP is selected where KUNNR = IKNA1-KUNNR.
2)
LOOP AT IKNA1.
READ TABLE IKNVP WITH KEY KUNNR = IKNA1-KUNNR.
Code.....
Endloop.
here, there is only one loop.
the READ statement selects the first entry of IKNVP where KUNNR = IKNA1-KUNNR.
for example, the IKNVP table may contain more than more entries of the same value of KUNNR, but only the first one is selected.
please let me know if ur doubt still exists.
thanks,
viji.
05-24-2007 5:17 AM
In the first case( loop and loop), For 1 IKNA1 record, you are trying to fetch all those records in IKNVP which satisfy the condition IKNA1-Kunnr - IKNVP-kunnr.
In the second case , You are trying to read the first record from IKNVP that satisfies the condition IKNA1-Kunnr - IKNVP-kunnr for each reecord of IKNA1.
For example, lets say you are trying to build an internal table TEST in the CODE section of the loop endloop.
let the records of IKNA1 be
KUNNR(field name)
1
2
Let the records of IKNVP be
Example field(fieldname) KUNNR
A 1
B 1
C 2
Then if you consider the first case ie (Loop-loop-endloop-endloop),then the records in TEST(let it contain 2 field example field and kunnr) would be
Kunnr Example field
1 A
1 B
2 C
if you had used READ inside LOOP then TEST table will have
Kunnr Example field
1 A
2 C
Hope this helps You.
05-24-2007 5:22 AM
guys prob is still not answered
i am gettin multiple entries in case of read NOT loop and these are not different entries but they are previous repeated entry may be wen we get an entry in main table which is not in secondary table then entries in second tables shows some <b>repeated</b> entries
05-24-2007 5:25 AM
Hey did you try as per my earlier reply?
Can you please paste your code here?
05-24-2007 5:27 AM
thanks a lot Darshil Shah
u answered my prob thanx a lot dude i got rite entries now
thanx to alllll