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.
Showing results for 
Search instead for 
Did you mean: 

Looping through an internal table

0 Kudos

I wrote the following piece of code:

<b> LOOP AT gt_rpm_project INTO ls_rpm_project

WHERE guid = ls_cgpl_project-guid

AND category = p_categ

AND subcategory IN p_subct.



gt_rpm_project is an internal table and

p_subct is a select option in the selection screen.this code gives an error mentioning <b>IN cannot be used</b>. Since it is a select -option i cannot use '=' or'between'(as p_subct apart from having a range can also have individual entries.)

Please advice how to go about this.

Thanks in advance!!



Former Member
0 Kudos

Because you are using a select option, I believe you would be having a database access before this query.

Why don't you filter the entries based on the select options that time itself. You wouldn't have to include a IN claus at all then.



0 Kudos

you can also try

subcategory > selectoption-low AND subcategory < selectoption-high.


Active Contributor
0 Kudos

should not be a problem. you should be able to use it. can you give us the exact error message?

to simulate your case i tried the following code and there was no syntax error.

data: itab type standard table of csks .

data: wa like line of itab .

select-options: p_dt for sy-datum .

loop at itab into wa where kokrs = '9999' and datab in p_dt .

endloop .



Former Member
0 Kudos

The simplest way would be to remove the subcategory field from the where condition and write an IF condition inside the Loop . IF SY-SUBRC = 0 then move the values from the internal table gt_rpm_project into ls_rpm_project.

LOOP AT gt_rpm_project

WHERE guid = ls_cgpl_project-guid

AND category = p_categ.

IF gt_rpm_project-subcategory IN p_subct.

ls_rpm_project = gt_rpm_project.

append ls_rpm_project.



Former Member
0 Kudos


Could u please let us know what is the exact error message, because the code u have posted looks perfectly alright to me, only possiblity would be that p_subct is not declared as select option which u have mentioned it has been declared, can u post the complete code with the variables declaration..

0 Kudos

the only reason that I can see to your erro is, Your field p_subct is a parameter, and not a select-options.

Or it's anything different from a value range.

Alexandre Nogueira.

Former Member
0 Kudos

This works OK:

REPORT ztest.

DATA: BEGIN OF gt_rpm_project OCCURS 0,
      END   OF gt_rpm_project,

      BEGIN OF ls_rpm_project.
        INCLUDE STRUCTURE gt_rpm_project.
DATA: END   OF ls_rpm_project,
      ls_cgpl_project LIKE ls_rpm_project.

DATA: p_categ.
RANGES p_subct FOR gt_rpm_project-subcategory.

LOOP AT gt_rpm_project INTO ls_rpm_project
  WHERE guid         = ls_cgpl_project-guid
  AND   category     = p_categ
  AND   subcategory IN p_subct.

What version are you on?