Application Development 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: 

Extracting OCMT & CHGS subfields from a Note to Payee field in SAP ABAP

former_member721373
Participant
0 Kudos

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. 🙂

1 ACCEPTED SOLUTION

joltdx
Active Contributor
0 Kudos

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...

3 REPLIES 3

joltdx
Active Contributor
0 Kudos

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...

0 Kudos

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!

joltdx
Active Contributor
0 Kudos

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...