‎2018 Dec 12 6:17 AM
Hello.
For example, I have a string
my string = 'morning day evening day hello age day morning'
I need to write words that occurs more than 1 time. So for this example answer is:
morning, day
How can I solve this in abap?
Firstly I split string into table.
DATA itab TYPE TABLE OF string.
SPLIT my_string AT SPACE INTO itab.
So I have table itab with my words.
Now I need to select rows that dont repeat.
In SQL its easy to use
select * from itab groupby field_name having count(*) > 1
But how can I do that in ABAP?
‎2018 Dec 12 6:50 AM
you can loop at group by and get the size of group, if it > 1 then it duplicate text.
‎2018 Dec 12 8:24 AM
‎2018 Dec 12 10:12 AM
Check the abap docu: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abaploop_at_group.htm
‎2018 Dec 13 12:06 AM
look at demo package in sap or simply F1 help on statement LOOP AT GROUP.
‎2018 Dec 12 8:41 AM
itab1[] = itab[].
Loop at itab assigning <fs_data>.
Read table itab1 assigning <fs_data1> with key table line eq <fs_data>.
if ( sy-subrc eq 0 ).
write :/ <fs_data1>.
endif.
Endloop.
‎2018 Dec 12 12:25 PM
You know that's the link to this question... Not massively helpful, I feel.
‎2018 Dec 12 4:04 PM
‎2018 Dec 21 8:38 AM
Hi,
I prefer to use alternative internal table to store the count.
very simple is:
data MY_STRING type STRING value 'morning day evening day hello age day morning'.
data ITAB type table of STRING.
data: begin of ITAB2 occurs 0,
WORDS type STRING,
COUNT type INT4,
end of ITAB2.
refresh ITAB.
split MY_STRING at SPACE into table ITAB.
"Counting duplicated words
refresh itab2.
loop at ITAB into data(LS_ITAB).
clear itab2.
ITAB2-WORDS = LS_ITAB.
ITAB2-COUNT = 1.
collect ITAB2.
endloop.
"Read or loop with itab2 with condition
loop at ITAB2 where COUNT > 1.
write: / ITAB2-WORDS, ITAB2-COUNT.
endloop.
Regards,
Nam
‎2018 Dec 21 11:05 AM
‎2018 Dec 24 2:12 AM