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: 

Extract part of a string

Former Member
0 Kudos
768

Hi guys,

We are trying to extract a part of a string from a textu2019s string like in the following example:

Price (AC)

Quantity (AT)

Material (CS)

u2026u2026.

We want try to extract the text in brackets that has a variable position into the complete string. The result has to be this:

AC

AT

CS

u2026u2026

Does anybody know a standard function to fix this case?

We are waiting an answer, thank you.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
402

Try below code....

data: l_str type i,

l_str1 type i.

l_str = strlen(field).

l_str1 = l_str - 3.

split field into field1 field2 at l_str1.

field3 = field2+0(2).

10 REPLIES 10

Former Member
0 Kudos
402

try using split command ....split at '(' into var1 var2....

Former Member
0 Kudos
402

Hi Gabriele,

Try SPLIT command.

Thanks,

Sai

Former Member
0 Kudos
403

Try below code....

data: l_str type i,

l_str1 type i.

l_str = strlen(field).

l_str1 = l_str - 3.

split field into field1 field2 at l_str1.

field3 = field2+0(2).

Former Member
0 Kudos
402

Hi,

Suppose that field is v_str1.

data:v_len type i,

v_len1 type i,

v_str2 type string,

v_str1 type string value 'Price (AC)'.

v_len = STRLEN( v_str1 ).

v_len1 = v_len - 3.

v_str2 = v_str1+v_len1(2).

write v_str2.

Regards,

Nitin.

Mohamed_Mukhtar
Active Contributor
0 Kudos
402

hi,

Pseudo code

DATA : wa_text TYPE string VALUE 'Price (AC)',
       len TYPE i,
       wa_part(3).
len = STRLEN( wa_text ).
len = len - 3.
wa_part = wa_text+len.
WRITE wa_part+0(2).

OUTPUT : AC

Thanks & Regards

Former Member
0 Kudos
402

Hi,

See the following code

DATA:
  i_data type table of string,
  w_data type string,
  split1 type string,
  split2 type string.

PERFORM fill_data.
PERFORM split_data.
PERFORM test.

form fill_data.
  w_data = 'Price (AC)'.
  APPEND w_data to i_data.
  clear w_data.

  w_data = 'Quantity (AT)'.
  APPEND w_data to i_data.
  clear w_data.

  w_data = 'Material (CS)'.
  APPEND w_data to i_data.
  clear w_data.
endform.

form split_data.
  loop at i_data into w_data.
    SPLIT w_data at '(' INTO split1 split2.
    clear split1.
    SPLIT split2 at ')' INTO split1 split2.
    w_data = split1.
    modify i_data from w_data.
  ENDLOOP.
endform.

form test.
  LOOP at i_data into w_data.
    write:/ w_data.
  endloop.
endform.

Former Member
0 Kudos
402

Hi Gabriele..

You can use the fucntion module SWA_STRING_SPLIT to split a string into

smaller strings or use function module SWA_STRING_SPLIT

Regards

RachelArun

Former Member
0 Kudos
402

Hi,

Just look at this code snippet. Its only for Price (AC).

DATA: str1 TYPE string,

str2 TYPE string,

str3 TYPE string,

itab TYPE TABLE OF string,

text TYPE string.

text = `Price (AC)`.

SPLIT text AT '(' INTO: str1 str2 str3,

TABLE itab.

SPLIT str2 AT ')' INTO: str1 str3,

TABLE itab.

write: str1.

Thanks

Former Member
0 Kudos
402

Thank you for the helpfull resolutions proposed.

(Points Assigned!)

Former Member
0 Kudos
402

DATA: A(50) TYPE C VALUE 'any data(abc)',

B(50) TYPE C,

C,

N(2) TYPE N,

FLAG.

N = STRLEN( A ).

DO N TIMES VARYING C FROM A0(1) NEXT A1(1) RANGE A.

IF C = '('.

FLAG = 'X'.

ELSEIF C = ')'.

CLEAR FLAG.

ENDIF.

IF FLAG IS NOT INITIAL.

IF C <> '('.

CONCATENATE B C INTO B.

ENDIF.

ENDIF.

ENDDO.

WRITE: B.