07-14-2015 8:29 PM
Hi, I have some text fields I need to parse and could use some help. The fields I have to parse have an ID followed by a space and then more text.
I would like to capture the left most text/id before the first space only. I know with all the new abap functions there must be a quick function to accomplish this. I tried one of the substr functions but it didn't like using SPACE as a separator.
Thanks for any help
Example:
Field Text | Result Value |
---|---|
AB1 Reason Code 1 | AB1 |
AB2 Reason Code 3 | AB2 |
AA Reason Code 3 | AA |
AB Reason Code 4 | AB |
1266 Reason Code NA | 1266 |
18222 Reason Code High | 18222 |
07-14-2015 9:11 PM
I got this working using SPLIT, but I have to output to 2 target fields even though I only need the first one. Anyone know of any of the newer functions like substring might also do the trick?
07-14-2015 9:11 PM
I got this working using SPLIT, but I have to output to 2 target fields even though I only need the first one. Anyone know of any of the newer functions like substring might also do the trick?
07-15-2015 11:36 AM
Hi Kenneth,
Try this.
DATA: lv_space TYPE xfeld VALUE IS INITIAL,
lv_postn TYPE i VALUE IS INITIAL,
lv_char1 TYPE char1,
lv_subst TYPE char5 VALUE IS INITIAL. "Choose the max. number of char you need
WHILE lv_space NE 'X'.
CLEAR: lv_char1.
lv_char1 = your_string+lv_postn(1).
IF lv_char1 EQ space. "Check if space
lv_space = 'X'.
ELSE.
CONCATENATE lv_subst lv_char1 INTO lv_subst.
ENDIF.
lv_postn = lv_postn + 1.
ENDWHILE.
Regards,
Sam,
07-15-2015 12:08 PM
Hi,
Try.
DATA lv_text type string value 'AB1 Reason Code 1'.
DATA: itab type table of string,
wa like line of itab.
SPLIT lv_text at ' ' into table itab.
READ TABLE itab into wa INDEX 1.
WRITE wa.
Hope it helpful,
Regars,
Venkat.
07-15-2015 4:28 PM
This is one I did not think of although it might be more processing intensive.
Thanks for the reply back.
07-16-2015 5:22 AM
Hi,
Try below code it works for me.
DATA: lv_street TYPE string,
lv_off TYPE i.
lv_street = 'AB1 Reason Code 1'.
FIND FIRST OCCURRENCE OF REGEX '\s' IN lv_street MATCH OFFSET lv_off.
lv_street = lv_street(lv_off).
WRITE:/ lv_street.
Output : AB1
Regards,
Hitesh
07-17-2015 4:44 AM
Hi Kenneth,
If your problem solved then mark answer as Helpful or Correct.
Regards,
Hitesh