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: 

how do I find if an string is contained in an internal table field

Former Member
0 Kudos

how do I find if an string is contained in an internal table field. Please could you give me just an small example

Thx

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Keyword is CS.

DATA : Begin of gt_itab occurs 0,

roll(2) type n,

string(20) type c,

end of gt_itab.

gt_itab-roll = '01'.

gt_itab-string = 'KARTHIK INDIA'.

append gt_itab.

gt_itab-roll = '02'.

gt_itab-string = 'KARTHIK USA'.

append gt_itab.

gt_itab-roll = '03'.

gt_itab-string = 'ARUN INDIA'.

append gt_itab.

gt_itab-roll = '04'.

gt_itab-string = ' KALAM IND'.

append gt_itab.

gt_itab-roll = '01'.

gt_itab-string = 'BUSH USA'.

append gt_itab.

write 'Roll no '.

Loop at gt_itab.

  • Here we are checking whether the itab string contains

  • INDIA are not.

IF gt_itab-string CS 'INDIA' .

write : / gt_itab-roll.

endif.

endloop.

Done.

3 REPLIES 3

Former Member
0 Kudos

Keyword is CS.

DATA : Begin of gt_itab occurs 0,

roll(2) type n,

string(20) type c,

end of gt_itab.

gt_itab-roll = '01'.

gt_itab-string = 'KARTHIK INDIA'.

append gt_itab.

gt_itab-roll = '02'.

gt_itab-string = 'KARTHIK USA'.

append gt_itab.

gt_itab-roll = '03'.

gt_itab-string = 'ARUN INDIA'.

append gt_itab.

gt_itab-roll = '04'.

gt_itab-string = ' KALAM IND'.

append gt_itab.

gt_itab-roll = '01'.

gt_itab-string = 'BUSH USA'.

append gt_itab.

write 'Roll no '.

Loop at gt_itab.

  • Here we are checking whether the itab string contains

  • INDIA are not.

IF gt_itab-string CS 'INDIA' .

write : / gt_itab-roll.

endif.

endloop.

Done.

0 Kudos

Hi ,

You can simplify the above Loop as follows;

  • Here we are checking whether the itab string contains

  • INDIA are not.

Loop at gt_itab where string CS 'INDIA'.

  • Write logic for strings containing the search string.

endloop.

Regards

Karthik D

former_member188685
Active Contributor
0 Kudos

using FIND you can do this..

REPORT  ZTEST_FIND.

DATA: itab    TYPE TABLE OF string,
      results TYPE match_result_tab,
      wa_results like line of results.

 append 'FIRST' to itab.
 append 'SECOND' to itab.
 append 'THIRD' to itab.
 append 'FOURTH' to itab.


FIND ALL OCCURRENCES OF 'SECOND'
  IN TABLE itab
  RESPECTING CASE
  RESULTS results.

 break-point.

 loop at results into wa_results.
  write:/ wa_results-line.
 endloop.