2021 Jan 23 2:51 PM
Hello Everyone,
My requirement is to extract the OCMT and CHGS subfields from a Note to Payee field. I need help with just the text parsing for various scenarios.
Example:
Input- '1811291129CR55589,95NTRF3825-0061490955//97271/009/OCMT/EUR55600,//CHGS/EUR10,05/'
Output should be-
lv_ocmt =EUR55600
lv_chgs =EUR10,05
I can refine it further. I just need help with the text parsing part.
Scenario: 1-The above input can have multiple CHGS.
2- position of OCMT and CHGS can be reverse or arbitrary.
so in both the scenarios, our output shouldn't be affected.
E.g.
'1811291129CR55589,95NTRF3820061490955//97271/009/OCMT/EUR55600,//CHGS/EUR10,05//CHGS/EUR10,05/'
Can you please help me this.
Thanks in advance. 🙂
2021 Jan 23 3:18 PM
Hi!
You can use regular expressions for this if the input data is not really structured...
DATA input TYPE string.
DATA ocmt TYPE string.
DATA chgs TYPE string.
input = '1811291129CR55589,95NTRF3825-0061490955//97271/009/OCMT/EUR55600,//CHGS/EUR10,05/'.
FIND FIRST OCCURRENCE OF REGEX 'OCMT\/([^\/]*)\/' IN input SUBMATCHES ocmt.
FIND FIRST OCCURRENCE OF REGEX 'CHGS\/([^\/]*)\/' IN input SUBMATCHES chgs.
This will put EUR55600, into ocmt and EUR10,05 into chgs.
Note the comma at the end of the ocmt there. Do you not want that or do you only want it if there are numbers after it? It's a bit more tricky...
To find how regex works i recommend the external site regex101.com. Paste the regular expression to test in the regular expression box and your different input texts in the Test string box. To the right, there is an explanation on what happes. And there is also reference on how to change things and write regex...
2021 Jan 23 3:18 PM
Hi!
You can use regular expressions for this if the input data is not really structured...
DATA input TYPE string.
DATA ocmt TYPE string.
DATA chgs TYPE string.
input = '1811291129CR55589,95NTRF3825-0061490955//97271/009/OCMT/EUR55600,//CHGS/EUR10,05/'.
FIND FIRST OCCURRENCE OF REGEX 'OCMT\/([^\/]*)\/' IN input SUBMATCHES ocmt.
FIND FIRST OCCURRENCE OF REGEX 'CHGS\/([^\/]*)\/' IN input SUBMATCHES chgs.
This will put EUR55600, into ocmt and EUR10,05 into chgs.
Note the comma at the end of the ocmt there. Do you not want that or do you only want it if there are numbers after it? It's a bit more tricky...
To find how regex works i recommend the external site regex101.com. Paste the regular expression to test in the regular expression box and your different input texts in the Test string box. To the right, there is an explanation on what happes. And there is also reference on how to change things and write regex...
2021 Jan 25 8:50 AM
Hi
Thank you so much for the quick response.
It is giving me OCMT and CHGS.
But I have to handle the scenario where we can have Multiple CHGS as well. How can we handle it?
Thanks a lot in advance!
2021 Jan 25 9:17 AM
Great! Slight adjustment to make the results go in a table of a certain type instead.
FIND ALL OCCURRENCES OF REGEX 'CHGS\/([^\/]*)\/' IN input RESULTS results.
Here is some documentation and example, with the table type specified as well...