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

About split command....?

Former Member
0 Likes
453

Hi kindly let me know how to use the split command, pls give me one example.

Aksitha.

4 REPLIES 4
Read only

Former Member
0 Likes
431

hi,

To split a character string into two or more smaller strings, use the SPLIT statement as follows:

<b>SPLIT <c> AT <del> INTO <c1> ... <cn>.</b>

The system searches the field <c> for the separator <del>. The parts before and after the separator are placed in the target fields <c1> ... <cn>.

<b>Example</b>

DATA: STRING(60),
P1(20) VALUE '++++++++++++++++++++',
P2(20) VALUE '++++++++++++++++++++',
P3(20) VALUE '++++++++++++++++++++',
P4(20) VALUE '++++++++++++++++++++',
DEL(3) VALUE '***'.

STRING = ' Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5'.
WRITE STRING.

SPLIT STRING AT DEL INTO P1 P2 P3 P4.

WRITE / P1.
WRITE / P2.
WRITE / P3.
WRITE / P4.

<b>The output appears as follows:</b>

Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5

Part 1

Part 2

Part 3

Part 4 *** Part 5

regards,

Ashokreddy

Read only

Former Member
0 Likes
431

Hi,

OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

if sy-subrc <> 0.

PERFORM messaging USING 'E' '001' text-e10 p_file space space.

else.

DO.

READ DATASET P_file INTO WA .

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

REPLACE ALL OCCURRENCES OF '"' IN WA WITH ''.

CONDENSE WA NO-GAPS.

SPLIT WA AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

INTO wa_infile.

append wa_infile to it_infile.

clear wa_infile.

ENDDO.

endif

<b>Reward points</b>

Regards

Read only

Former Member
0 Likes
431

One more....

Data : itab type table of string with header line.

Data : str type string value 'ABC DEF GHI'.

SPLIT str AT space INTO TABLE itab.

Now the itab will have 3 entris 1)ABC 2)DEF 3)GHI

Reward for all uaseful answers.

Read only

Former Member
0 Likes
431
DATA: str1 TYPE string, 
      str2 TYPE string, 
      str3 TYPE string, 
      itab TYPE TABLE OF string, 
      text TYPE string. 

text = `What a drag it is getting old`. 

SPLIT text AT space INTO: str1 str2 str3, 
                          TABLE itab. 

The text field text is separated at its blank characters, into the three strings str1, str2, and str3, and then into an internal table with the line type string. As the three strings are not sufficient for all seven parts, after the separation, str3 contains "drag it is getting old", while the internal table contains seven lines; one for each word in text.

reward points if it is usefull ...

Girish