Application Development and Automation 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: 
Read only

Find a variable length string between two strings

Former Member
0 Likes
2,422

HI Experts,

I have a requirement where i have to fetch a sub-string of variable length between two substring in a string.

I have a string like this:

<MOABETR>amount</MOABETR>.

i need to fetch value of amount and length of amount can vary. Is there any way to do that?

IF i search for occurrence of <MOABETR> and get the offset and i add the length of it to that offset and start fetching value from there, i wouldn't be sure; how many characters to fetch because length of amount varies.

Thanks,

Dheeraj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,460

As the tags are XML alike, you could try this:

Execute function module SCMS_STRING_TO_XSTRING with importing parameter TEXT = <MOABETR>amount</MOABETR>.

The restult will be in the exporting parameter buffer.

execute function module SMUM_XML_PARSE and use the buffer as input for XML_INPUT.

the table XML_TABLE will have what you need 🙂

4 REPLIES 4
Read only

Former Member
0 Likes
1,461

As the tags are XML alike, you could try this:

Execute function module SCMS_STRING_TO_XSTRING with importing parameter TEXT = <MOABETR>amount</MOABETR>.

The restult will be in the exporting parameter buffer.

execute function module SMUM_XML_PARSE and use the buffer as input for XML_INPUT.

the table XML_TABLE will have what you need 🙂

Read only

ThomasKruegl
Participant
0 Likes
1,460

You could search for occurrence of </MOABETR> too, and then combine the values to get the correct start and length.

kind regards,

Thomas

Read only

pranay570708
Active Contributor
0 Likes
1,460

Hi,

Check this example:

DATA: L_STRING TYPE STRING VALUE '<MOABETR>1234567890</MOABETR>',

       L_OUT    TYPE STRING,

       L_LEN    TYPE I.

REPLACE ALL OCCURRENCES OF REGEX '[A-Z]' IN L_STRING WITH SPACE .

L_LEN = STRLEN( L_STRING ) - 5.

L_OUT = L_STRING+2(L_LEN).

WRITE: L_out.

Read only

Former Member
0 Likes
1,460

Hello All,

Thanks for your response but that string could be repeated as well. Glenn's answer seems best.