2016 Jun 03 3:35 PM
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
2016 Jun 03 3:53 PM
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 🙂
2016 Jun 03 3:53 PM
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 🙂
2016 Jun 06 9:58 AM
You could search for occurrence of </MOABETR> too, and then combine the values to get the correct start and length.
kind regards,
Thomas
2016 Jun 06 10:13 AM
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.
2016 Jun 06 10:20 AM
Hello All,
Thanks for your response but that string could be repeated as well. Glenn's answer seems best.