2015 Dec 02 3:28 PM
Hi all,
Here is an example of what I have and what I am trying to do.
NOTE_STRING = '1684609022FFYOUR REF=000000428REC FROM=WELLS FARGO BANK FED ID=1210002'
I need to split this value into,
'1684609022FF'
'YOUR REF=000000428REC'
'REC FROM=WELLS FARGO BANK'
'FED ID=1210002' and write it to a Report.
The decision on where to split the string comes from a table(ZTFI_BAI_TEXTS) where the values are stored as(field name = BAITEXT) ,
'YOUR REF='
'REC FROM='
'FED ID='.
Thank You,
Anjana
2015 Dec 02 4:19 PM
Use SPLIT similar like below
ostr = '1684609022FFYOUR REF=000000428REC FROM=WELLS FARGO BANK FED ID=1210002'.
str_tmp = ostr.
SPLIT str_tmp AT 'YOUR REF=' INTO str1 str_tmp.
SPLIT str_tmp AT 'REC FROM=' INTO str2 str_tmp.
CONCATENATE 'YOUR REF=' str2 INTO str2.
...
2015 Dec 02 3:49 PM
2015 Dec 02 4:12 PM
Hi,
sub1 = NOTE_STRING+0(12). =>>> this code only if first part is a constant.
SEARCH NOTE_STRING FOR 'REF='. =>>>> in this case is a hardcode, but you can use ZTFI_BAI_TEXTS-BAITEXT in a loop.
SPLIT sub3 AT ' ' INTO sub2 sub3.
THis is an example:
DATA: NOTE_STRING type CHAR255 value '1684609022FFYOUR REF=000000428REC FROM=WELLS FARGO BANK FED ID=1210002'.
DATA: sub1 type CHAR255.
DATA: sub2 type CHAR255.
DATA: sub3 TYPE CHAR255.
DATA zlv_offset type sy-index.
DATA: lenght TYPE sy-index.
sub1 = NOTE_STRING+0(12).
WRITE NOTE_STRING.
WRITE sub1.
SEARCH NOTE_STRING FOR 'REF='.
*Split every field
CALL FUNCTION 'STRING_SPLIT_AT_POSITION'
EXPORTING
string = NOTE_STRING
pos = sy-fdpos
* LANGU = SY-LANGU
IMPORTING
STRING1 = sub2
STRING2 = sub3
* POS_NEW =
EXCEPTIONS
STRING1_TOO_SMALL = 1
STRING2_TOO_SMALL = 2
POS_NOT_VALID = 3
OTHERS = 4.
lenght = STRLEN( sub3 ).
*Split only the value
SPLIT sub3+4(lenght) AT ' ' INTO sub2 sub3.
WRITE sub2.
Regards,
Enric
2015 Dec 02 4:19 PM
Use SPLIT similar like below
ostr = '1684609022FFYOUR REF=000000428REC FROM=WELLS FARGO BANK FED ID=1210002'.
str_tmp = ostr.
SPLIT str_tmp AT 'YOUR REF=' INTO str1 str_tmp.
SPLIT str_tmp AT 'REC FROM=' INTO str2 str_tmp.
CONCATENATE 'YOUR REF=' str2 INTO str2.
...
2015 Dec 02 7:54 PM
A find with a regex would fit here good.
Data: lv_code TYPE STRING,
lv_ref TYPE STRING,
lv_from TYPE STRING,
lv_fed_id TYPE STRING.
FIND REGEX '^(.*)(YOUR\sREF=.*)(REC\sFROM=.*)(FED\sID=.*)$'
IN '1684609022FFYOUR REF=000000428REC FROM=WELLS FARGO BANK FED ID=1210002'
SUBMATCHES lv_code lv_ref lv_from lv_fed_id.
will assign the following values as desired to the variables
lv_code = `1684609022FF`
lv_ref = `YOUR REF=000000428`
lv_from = `REC FROM=WELLS FARGO BANK `
lv_fed_id = `FED ID=1210002`
Regex is not easy to understand if you havent yet worked with it, but you can do nearly every string parsing with it. And in this case the string parsing is rather complicated so I would recommend it.
A good location to playing a bit around is for example: https://regex101.com/ where you get also a nice explanation about the above used regex.
To build the regex dynamically should be not the problem with a for loop on the entries of your table ZTFI_BAI_TEXTS.
Regards, Andreas