Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

regarding internal table

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

20 REPLIES 20

Former Member
0 Kudos

Hi,

Check data type of the fields. Might be data type is different for the fields.

Regards,

Srini.

0 Kudos

Hi, as i mentioned that for other records its working perfectly

Former Member
0 Kudos

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

0 Kudos

HI, there are many records in itab so performance wise also we have to check, is it ok ..?

thnx

0 Kudos

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.

Sandeep_Kumar
Advisor
Advisor
0 Kudos

Paste your code snippet here .

0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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.

0 Kudos

HI, it is going inside the loop but sy-subrc = 4 ..

0 Kudos
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???

0 Kudos

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

0 Kudos

I thought so to but if you look carefully it's diferent, gw_tab and gw_itab.

0 Kudos

>

> I thought so to but if you look carefully it's diferent, gw_tab and gw_itab.

AAHHH....well spotted!

0 Kudos

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

0 Kudos

so i think i should remove sy-subrc ...

0 Kudos

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.

Former Member
0 Kudos

thanks everybody for your time....

0 Kudos

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.