‎2010 Jun 22 6:10 PM
Hello expert,
I have an internal table contains strings. I have to delete the entry that contains some pattern. For example:
*ABC delete the entry that starts with ABC
*ABC* delete the entry that contains ABC
ABC* delete the entry that ends with ABC
Can someone tell me how I can manipulate the string. Are there any methods or functions to find the pattern in a String?
Thanks,
AS
‎2010 Jun 22 7:33 PM
I guess I didn't explain well.
Assume I have two internal tables as follow: The value in Table 1 is unknown (dynamic)
>Table 1: Table 2:
>ABCDE *ABC delete the entry if the string in Table 1 starts with ABC
>GFABCDE FA delete the entry if the string in Table 1 contains FA
>FGDEAED ED* delete the entry if the string in Table 1 ends with ED
I have to find if the string in Table 1 contains * first, I then have to hold pattern such as ABC, FA, and or ED from Table 2,
Finaly I have to find if the pattern is in the beginning of the string, middle of the string, or end of the string.
Thanks,
AS
Please do not use code tags to format text.
Edited by: Rob Burbank on Jun 22, 2010 2:35 PM
‎2010 Jun 22 6:16 PM
This looks pretty basic to me. Have you pressed F1 on DELETE??
Rob
‎2010 Jun 22 6:28 PM
you can write like
delete str WHERE name CP 'ABC*'.
delete str WHERE name CP 'ABC'.
delete str WHERE name CP '*ABC'.
Thanks
Bala Duvvuri
Edited by: Bala Duvvuri on Jun 22, 2010 11:29 AM
Edited by: Bala Duvvuri on Jun 22, 2010 11:30 AM
‎2010 Jun 22 7:33 PM
I guess I didn't explain well.
Assume I have two internal tables as follow: The value in Table 1 is unknown (dynamic)
>Table 1: Table 2:
>ABCDE *ABC delete the entry if the string in Table 1 starts with ABC
>GFABCDE FA delete the entry if the string in Table 1 contains FA
>FGDEAED ED* delete the entry if the string in Table 1 ends with ED
I have to find if the string in Table 1 contains * first, I then have to hold pattern such as ABC, FA, and or ED from Table 2,
Finaly I have to find if the pattern is in the beginning of the string, middle of the string, or end of the string.
Thanks,
AS
Please do not use code tags to format text.
Edited by: Rob Burbank on Jun 22, 2010 2:35 PM
‎2010 Jun 22 7:39 PM
It sounds like you use table 2 to create a range table of the patterns you want to delete.
Rob
‎2010 Jun 22 9:04 PM
Yes. it is easier to use a range table.
I found a class CL_ABAP_MATCHER that contains lots of methods. I wonder if anyone used them before.
Can someone give me some suggestion.
Thanks,
AS
‎2010 Jun 23 5:18 PM
you can also use CS in if condition and check...CS means COntains String...
try with CS...
ex:
if wa_int CS 'ABC'
Edited by: poo_m_s on Jun 23, 2010 6:20 PM
‎2010 Jun 23 7:03 PM
data: begin of itab OCCURS 0,
s1 type string,
END OF itab.
itab-s1 = 'asdjyaskdasdhjakjABC'.
APPEND itab.
itab-s1 = 'asdjyaskdasdhjakjABCasd'.
APPEND itab.
itab-s1 = 'ABCdfghjkdskfsdf'.
APPEND itab.
DELETE itab WHERE s1 NP 'ABC*'. " deletes entry other than starting with ABC
"DELETE itab WHERE s1 NP '*ABC'. ===>deletes entry other than ending with ABC
"DELETE itab WHERE s1 NP '+*ABC*+'. " deletes entry with ABC in middle
LOOP AT itab .
WRITE :/ itab-s1.
ENDLOOP.try this
‎2010 Jun 23 7:18 PM
anna.. do this
data : s1 type range of itab1-field1,
s2 like line of s1..
s2-sign = 'I'.
s2-option = CP.
loop at the table2 into is2.
if is2-field1 CA '*'.
s2-low = is2-field1.
else.
concatenate '*' is2-field1 '*' into s2-low.
endif.
append s2 to s1.
endloop.this is jsut an example how to create the range table... but i dont think this will help you much.... you need line by line matching..
so.. do this for your purpose.
loop at tabl1 into is1.
read table itab2 into is2 index sy-tabix.
if sy-subrc = 0.
if is2-f1 NA '*'. "means there are no *s so you have to provide the two *s
concatenate '*' is2-f1 '*' into is2-f1.
endif.
if is1-f1 CP is2-f1.
delete TAB1. "current line will be deleted.
endif.
endif.
endloop.this will check line by line from itab1 with itab2
‎2010 Jun 24 5:52 AM
I think you have a misunderstanding of the sap patterns...ABC* means a string starts with ABC. FA means FA is somehwere in the string. *ED means the string ends in ED.
data: t1 type table of string with header line.
data: t2 type table of string with header line.
data e1 type string. data e2 type string.
e1 = 'ABCDE'. append e1 to t1.
e2 = 'ABC*'. append e2 to t2.
if e1 cp e2. write:/ e1,'cp',e2. endif.
e1 = 'GFABCDE'. append e1 to t1.
e2 = 'FA'. append e2 to t2.
if e1 cp e2. write:/ e1,'cp',e2. endif.
e1 = 'FGDEAED'. append e1 to t1.
e2 = '*ED'. append e2 to t2.
if e1 cp e2. write:/ e1,'cp',e2. endif.
skip 1.
write:/ 'T1-before-deletes:'.
loop at t1. write:/ t1. endloop.
loop at t2.
skip 1.
delete t1 where table_line cp t2.
write:/ 'after-try-to-delete',t2.
loop at t1. write:/ t1. endloop.
endloop.
‎2010 Jun 29 8:46 PM
Hello, Thanks for all your help.
I finally created a dynamic range table to solve my problem and it works well. Here is the code.
* ALV - Field catalog data
DATA: l_fc TYPE lvc_s_fcat,
ltab_fc TYPE lvc_t_fcat,
r_fld_desc TYPE REF TO cl_abap_elemdescr.
* dy_range_table TYPE REF TO data.
* Get the field description
r_fld_desc ?= cl_abap_typedescr=>describe_by_data( field ).
* Create a field catalogue of ALV for dynamic ranges table
REFRESH ltab_fc.
CLEAR l_fc.
l_fc-fieldname = 'SIGN'.
l_fc-datatype = 'C'.
l_fc-inttype = 'C'.
l_fc-intlen = '1'.
APPEND l_fc TO ltab_fc.
CLEAR l_fc.
l_fc-fieldname = 'OPTION'.
l_fc-datatype = 'C'.
l_fc-inttype = 'C'.
l_fc-intlen = '2'.
APPEND l_fc TO ltab_fc.
CLEAR l_fc.
l_fc-fieldname = 'LOW'.
l_fc-datatype = r_fld_desc->type_kind.
l_fc-inttype = r_fld_desc->type_kind.
l_fc-intlen = r_fld_desc->length.
l_fc-decimals = r_fld_desc->decimals.
APPEND l_fc TO ltab_fc.
CLEAR l_fc.
l_fc-fieldname = 'HIGH'.
l_fc-datatype = r_fld_desc->type_kind.
l_fc-inttype = r_fld_desc->type_kind.
l_fc-intlen = r_fld_desc->length.
l_fc-decimals = r_fld_desc->decimals.
APPEND l_fc TO ltab_fc.
* call static method to create the dynamic range table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ltab_fc
IMPORTING
ep_table = dy_range_table.
Edited by: Anna Smith on Jun 29, 2010 9:48 PM