11-12-2010 10:51 AM
Hi All,
I am facing a problem during operation on internal table, I have some data in internal table, i simply put a loop at itab with condition using where clause comparing two of its fields. the data in where condition is exactly matching with the data in internal table but still it is not fetching ,giving sy-subrc 4. for other records it is working perfectly.
anybody have some idea ..
thanks and regards,
Deepak
Moderator message: please use more descriptive subject lines from now on.
Edited by: Thomas Zloch on Nov 12, 2010 1:07 PM
11-12-2010 11:00 AM
Hi,
Why dont you Loop at the table without where clause and compare fields using If Condition inside loop.
e.g. Loop at It_tab into wa_tab.
if wa_tab-field1 = wa_tab-field2.
... Do your Processing.
endif.
endloop.
Thanks
Nitesh
11-12-2010 10:56 AM
Hi,
Check data type of the fields. Might be data type is different for the fields.
Regards,
Srini.
11-12-2010 11:06 AM
11-12-2010 11:00 AM
Hi,
Why dont you Loop at the table without where clause and compare fields using If Condition inside loop.
e.g. Loop at It_tab into wa_tab.
if wa_tab-field1 = wa_tab-field2.
... Do your Processing.
endif.
endloop.
Thanks
Nitesh
11-12-2010 11:10 AM
HI, there are many records in itab so performance wise also we have to check, is it ok ..?
thnx
11-12-2010 11:22 AM
Hi,
If you keep IF condition inside the loop, then Performance will get
1)Decreased when your table is a SORTED TABLE with the conditions being the Key fields. As here system will search based on BINARY SEARCH.
2)Will not make much of a difference if your table is not a SORTED TABLE with the fields you are checking are non key fields. Here system will take a linear search.
Thanks & Regards,
Faheem.
11-12-2010 11:07 AM
11-12-2010 11:16 AM
HI,
LOOP AT gt_tab INTO gw_tab WHERE a = gw_itab-a and b = gw_itab-b.
IF sy-subrc = 0.
ENDIF.
ENDLOOP.
thx
11-12-2010 11:19 AM
hi,
Certainly, using if will increase number of loop passes, but you can not compare fields in where clause like you are doing.
Thanks
Nitesh
11-12-2010 11:23 AM
actually it is fetching the value but sy-subrc is 4 so i will not able to process further as i am not in touch with abap extensively for some time so may be i am missing something
thxs
11-12-2010 11:33 AM
There isn't much sense in putting the condition IF sy-subrc = 0 inside the loop, because the only way it will go inside the loop is when sy-subrc = 0, so it's a big redudancy.
11-12-2010 11:36 AM
11-12-2010 11:40 AM
LOOP AT gt_tab INTO gw_tab WHERE a = gw_itab-a and b = gw_itab-b.
This doesn't make any sense: you read an entry from the internal table using it's own work area???
11-12-2010 11:41 AM
Yes, but the sy-subrc of the loop only changes at the end of the loop, so the sy-subrc = 4 is from some other instruction you have prior to the loop.
for example :
read table itab with key field = 'A'.
Here if it doesn't find anything sy-subrc will be 4.
then you do a loop on some other table.
loop at itab2.
In here, inside the loop, sy-subrc is still 4, only when you leave the loop it will be 0.
endloop.
Edited by: Pedro Guarita on Nov 12, 2010 11:42 AM
11-12-2010 11:42 AM
I thought so to but if you look carefully it's diferent, gw_tab and gw_itab.
11-12-2010 11:45 AM
>
> I thought so to but if you look carefully it's diferent, gw_tab and gw_itab.
AAHHH....well spotted!
11-12-2010 11:47 AM
Hello,
In case of LOOP the value of SY-SUBRC =4 if the LOOP has not executed at least once otherwise it is 0. You should have referred to SAP documentation before posting.
BR,
Suhas
11-12-2010 11:48 AM
11-12-2010 11:51 AM
Don't worry about checking sy-subrc inside the loop, if it executes anything in there then it's because it found the records you were looking for. If anything you can check AFTER the loop, for some reason. Inside the loop it doesn't make much sense unless you want want to do something related to an instruction prior to the loop.
11-12-2010 11:53 AM
11-12-2010 12:11 PM
Hi,
If your query is answered then mark the thread as answered(above you can see options-Answered at the top of the thread) and close the thread.
Thanks & Regards,
Faheem.