09-06-2008 3:10 AM
how do I find if an string is contained in an internal table field. Please could you give me just an small example
Thx
09-06-2008 5:31 AM
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.
09-06-2008 5:31 AM
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.
09-06-2008 6:18 AM
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
09-06-2008 6:21 AM
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.