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

Searching an internal table

Former Member
0 Likes
4,398

Hi,

I have an internal table, t_jstat, that contains a list of active statuses for an object.

I am using the SEARCH command to check if a status is active for that object, e.g.

SEARCH t_jstat FOR 'I0001'.
IF sy-subrc EQ 0.....

It works well.

Is it possible for the search to include a number of parameters, like

SEARCH t_jstat FOR 'I0004' OR 'I0090' OR 'E0005' OR...

I know this syntax doesn't work, but is there something similar that will?

1 ACCEPTED SOLUTION
Read only

kostas_tsioubris
Contributor
0 Likes
1,598

Hi,

you can use loop statement.

loop at t_jstat where fieldname = 'I0001' or fieldname = 'I0004' ....

endloop.

Kostas

Hi,

I have an internal table, t_jstat, that contains a list of active statuses for an object.

I am using the SEARCH command to check if a status is active for that object, e.g.

SEARCH t_jstat FOR 'I0001'.
IF sy-subrc EQ 0.....

It works well.

Is it possible for the search to include a number of parameters, like

SEARCH t_jstat FOR 'I0004' OR 'I0090' OR 'E0005' OR...

I know this syntax doesn't work, but is there something similar that will?

4 REPLIES 4
Read only

kostas_tsioubris
Contributor
0 Likes
1,599

Hi,

you can use loop statement.

loop at t_jstat where fieldname = 'I0001' or fieldname = 'I0004' ....

endloop.

Kostas

Read only

Former Member
0 Likes
1,598

Hi Stuart

These are the options that we have in searching in Internal Table

<b>To find a character string in a line of an index table, use the following statement:</b>

SEARCH <itab> FOR <str> <options>.

The statement searches the internal table <itab> for the character string <str>. If the search is successful, SY-SUBRC is set to 0, and SY-TABIX is set to the index of the table line in which the string was found. SY-FDPOS contains the offset position of the string in the table line. Otherwise, SY-SUBRC is set to 4.

In a Unicode system, the line type of the internal table must have a character type. In a non-Unicode system, the line can also contain numeric or hexadecimal components.

The statement treats all table lines as type C fields, regardless of their actual line type. There is no conversion. The search string <str> can have the same form as for a normal string search in a field.

<b>The different options (<options>) for the search in an internal table are:</b>

<b>ABBREVIATED</b>

Searches table <itab> for a word containing the string in <str>. The characters can be separated by other characters. The first letter of the word and the string <str> must be the same.

<b>STARTING AT <lin1></b>

Searches table <itab> for <str>, starting at line <lin 1 >.<lin 1 > can be a variable.

<b>

ENDING AT <lin2></b>

Searches table <itab> for <str> up to line <lin 2 >.<lin 2 > can be a variable.

<b>AND MARK</b>

If the search string is found, all the characters in the search string (and all the characters in between when using ABBREVIATED) are converted to upper case.

This statement only works with index tables. There is no corresponding statement for hashed tables.



REPORT demo_int_tables_search_index.

DATA: BEGIN OF line,
        index(4) TYPE c,
        text(8) TYPE c,
      END OF line.

DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY index.

DATA num(2) TYPE n.

DO 10 TIMES.
  line-index = sy-index.
  num = sy-index.
  CONCATENATE 'string' num INTO line-text.
  APPEND line TO itab.
ENDDO.

SEARCH itab FOR 'string05' AND MARK.

WRITE: / '''string05'' found at line', (1) sy-tabix,
         'with offset', (1) sy-fdpos.

SKIP.

READ TABLE itab INTO line INDEX sy-tabix.
WRITE: / line-index, line-text.

<b>The output is:</b>

<b>'string05' found at line 5 with offset 4

5 STRING05

</b>

The offset of the string found in the table is determined by the width of the first table column, which has type I and length 4. The option AND MARK changes the table contents in the corresponding line.

Regards Rk

Read only

Former Member
0 Likes
1,598

Hi,

Loop at T_JSTAT where <fnam> = 'I0004'

or <Fnam> = 'I0090'....

EndLoop.

If Sy-subrc EQ = 0.

EndIf.

Read only

Former Member
0 Likes
1,598

Hi,

The search will not work for multiple..

You can Use READ statement and solve your neccesary..

READ table t_jstat into wa_jstat wiht key status = '<active> or what ever..

reward if useful .

regards,

nazeer