Application Development and Automation 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: 
Read only

regarding internal table

Former Member
0 Likes
1,762

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
Read only

Former Member
0 Likes
1,731

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
Read only

Former Member
0 Likes
1,731

Hi,

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

Regards,

Srini.

Read only

0 Likes
1,731

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

Read only

Former Member
0 Likes
1,732

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

Read only

0 Likes
1,731

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

thnx

Read only

0 Likes
1,731

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.

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,731

Paste your code snippet here .

Read only

0 Likes
1,731

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

Read only

0 Likes
1,731

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

Read only

0 Likes
1,731

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

Read only

0 Likes
1,731

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.

Read only

0 Likes
1,731

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

Read only

0 Likes
1,731
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???

Read only

0 Likes
1,731

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

Read only

0 Likes
1,731

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

Read only

0 Likes
1,731

>

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

AAHHH....well spotted!

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,731

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

Read only

0 Likes
1,731

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

Read only

0 Likes
1,731

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.

Read only

Former Member
0 Likes
1,731

thanks everybody for your time....

Read only

0 Likes
1,731

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.