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: 

reading an internal table

Former Member
0 Kudos

Hi

I want to read the data from a itab where a particular field can have one of the three values.

something like this:

Read itab with table key flag = X and ( number = 26 or number = 27 or number = 28. ).

I used select options but it didn’t work… give me the syntax to so that I can read the table with the above condition

regards,

Ganesh

1 ACCEPTED SOLUTION

Former Member
0 Kudos

or condition cannot be used with read table. Use loop at with condition.

Hope this helps..

Thanks,

Vamshi Tallada

6 REPLIES 6

Former Member
0 Kudos

or condition cannot be used with read table. Use loop at with condition.

Hope this helps..

Thanks,

Vamshi Tallada

0 Kudos

hi vamshi,

I know that we cant use OR or anyother key words.

i just want to know whether there is a record satisfying the conidition. i am already in a inner loop and if i use another then it may create performance issues. if u have any suggestions let me know.

former_member186741
Active Contributor
0 Kudos

you can use the where clause of the loop and exit after one entry has been found:

loop at tab where matnr = 'a' or mandt = '300'.

exit.

endloop.

if sy-subrc = 0.

*entry found

else.

*entry not found

endif.

For your example:

loop at itab where flag = 'X' and ( number = 26 or number = 27 or number = 28 ).

exit.

endloop.

Former Member
0 Kudos

Hi,

I think don't use Loop Where, 'coz it may create performance issues.

You can try use Binary Search, like :

Sort ITAB By FLAG NUMBER.

Read Table Itab Binary Search With Key FLAG = X and NUMBER = 26.

Loop above process for Number = 27 and 28.

Thanks,

Former Member
0 Kudos

I would sort the table by flag and number. Then:


read table itab
  with key flag = 'X'
  binary search.

If sy-subrc = 0, check to see if number is 26, 27 or 28.

If it's not, and number is less than 29, do an indexed read:


wk_index = sy-tabix + 1.
read table itab index wk_index.

If sy-subrc = 0 check that flag is still X and the number is 26, 27 or 28. Do the above while number is less than 29.

Rob

Former Member
0 Kudos

Hi Ganesh,

You cannot depend on flag field to retrive your validated values 26,27,28 , better you can read thrice with binary search for 26,27,28 and check for flag.

You are saying already you have innerloops , please let me know the clear req.

<i>Reward Points If It Helps YOU.</i>

Regards,

Raghav