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

Problems to split string long

Former Member
0 Likes
671

Hello, I am trying to split a long string in parts equals for after to insert this information on fields different, for example:

Split to var_textlong and put each result on:

v_text1 that after will be inserted on  text1 of my table Z.

v_text2 that after will be inserted on  text2 of my table Z.

Etc..
This is like the SAP ERP saves information with a lot of characters in its tables.

I try to making this of the next form but I have problems with the validation, if a valor be passed to split the string, my code broke

v_str = 'A long text.....'

v_value1 = STRLEN( v_str ) / 3.

v_value2 = v_value1 + v_value1.

v_desc1 = v_str(v_value1).

v_desc2 = v_str+v_value1(v_value1).

v_desc3 = v_str+v_value2(v_value1).

2 REPLIES 2
Read only

prajeshdesai
Contributor
0 Likes
527

Did you tried below?,


DATA:   LONGSTR TYPE STRING,

            PARTLEN TYPE I.

DATA IST_ZTAB TYPE TABLE OF CHAR100.

LONGSTR = 'THIS IS PART1 THIS IS PART2 THIS IS PART3'.

PARTLEN = STRLEN( LONGSTR ) / 3.

CALL FUNCTION 'SOTR_SERV_STRING_TO_TABLE'

   EXPORTING

     TEXT                           = LONGSTR

     LINE_LENGTH             = PARTLEN

   TABLES

     TEXT_TAB                   = IST_ZTAB

                         .

Hope this helps.

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
527

DATA(str) = sy-abcde && sy-abcde && sy-abcde && sy-abcde.

DATA itab TYPE TABLE OF string.

DATA(pos) = strlen( str ).

DATA(length) = pos / 3.

WHILE pos > length.

  APPEND str(length) TO itab.

  SHIFT str LEFT BY length PLACES.

  pos = pos - length.

ENDWHILE.

APPEND str TO itab.

cl_demo_output=>display( itab ).