Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

String manipulation

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

Former Member
replied

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question