Application Development and Automation 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: 
Read only

ABAP String Opration

Former Member
0 Likes
1,489

HI ,

I have a String(lenth40) = 'ABCDEFGH'

and i want to split it like this AB,CD,EF,GH.

any clue.

please help.

regards,

Sanjeev

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,444

Hi, try this:


DATA: text(40) VALUE 'ABCDEFGH',
      tab TYPE trtexts.


CALL FUNCTION 'TR_SPLIT_TEXT'
  EXPORTING
    iv_text  = text
    iv_len   = 2
  IMPORTING
    et_lines = tab.

Then LOOP AT tab and get the elements.

Cheers,

Bart

11 REPLIES 11
Read only

Former Member
0 Likes
1,444

Hi Sanjeev,

Create 5 variables of your required data type.

Use offset and keep 4 alphabets in each variable like +0(4).

Use concatenate statement and separate it by using Comma (,).

Manas M.

Read only

Former Member
0 Likes
1,444

Hello

Use FM RKD_WORD_WRAP for this with OUTPUTLEN = 2

Read only

0 Likes
1,444

HI ,

ithe len. is 40 char and cant create so many variable..

any thing else we can do with it ?

thanks

sanjeev

Read only

0 Likes
1,444

Hello

You do not need create variables.

This FM return table OUT_LINES.

Just loop on this table and concatenate values into your string separated by comma.

Read only

0 Likes
1,444

Thanks. solved

Read only

0 Likes
1,444

Hello

Bartosz Bijak has rendered you help.

Read only

Former Member
0 Likes
1,444

Hi

split the string ,store it in different variables and then concatenate all the variables with "," and store it in a variable.

Thanks

Subha

Read only

Former Member
0 Likes
1,444

Hi

Check below blogs for details.

Also in this case you need to split String manuallly as there is no seperater attached to it.

Regards

GAurav

Read only

vinod_vemuru2
Active Contributor
0 Likes
1,444

Hi,

Below is the logic.


TYPES: BEGIN OF t_tab,
        val(2) TYPE c,
       END OF t_tab.

DATA: l_off TYPE i ,
      l_len TYPE i,
      l_string TYPE string,
      itab TYPE TABLE OF t_tab,
      wa TYPE t_tab.

l_string = 'ABCDEFGHIJK'.

l_len = strlen( l_string ).

DO.
  IF l_len GT 2.
    MOVE l_string+l_off(2) TO wa-val.
    APPEND wa TO itab.
    ADD 2 TO l_off.
    l_len = l_len - 2.
  ELSE.
    MOVE l_string+l_off(1) TO wa-val.
    APPEND wa TO itab.
    EXIT.
  ENDIF.
ENDDO.

itab has the required data. If you want it to variables then you have to use those many variables instead of itab..

Thanks,

Vinod.

Read only

Former Member
0 Likes
1,444

Hi

You can use FM RKD_WORD_WRAP and then concatenate the spiltted variables.

Example -

Import parameters Value

TEXTLINE ABCDEFGH

DELIMITER ,

OUTPUTLEN 2

Export parameters Value

OUT_LINE1 AB

OUT_LINE2 CD

OUT_LINE3 EF

Tables Value

OUT_LINES 0 Entries

Result: 4 Entries

Read only

Former Member
0 Likes
1,445

Hi, try this:


DATA: text(40) VALUE 'ABCDEFGH',
      tab TYPE trtexts.


CALL FUNCTION 'TR_SPLIT_TEXT'
  EXPORTING
    iv_text  = text
    iv_len   = 2
  IMPORTING
    et_lines = tab.

Then LOOP AT tab and get the elements.

Cheers,

Bart