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: 

Reading a field

Former Member
0 Kudos

Hi All,

I have a field ztab_fld tat need to get break down after the first space.

for ex:

ztab-fld1 = 'abcde fghigjklm xxxx'

i should break as

ztab-fld1 = 'abcde'.

ztab-fld2 = 'fghijklm xxxx'

which keyword should i use ?

1 ACCEPTED SOLUTION

andreas_mann3
Active Contributor
0 Kudos

Hi,

split ztab_fld at space into ztab-fld1 ztab-fld1 .

Andreas

5 REPLIES 5

andreas_mann3
Active Contributor
0 Kudos

Hi,

split ztab_fld at space into ztab-fld1 ztab-fld1 .

Andreas

0 Kudos

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

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

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>.

To place all fragments in different target fields, you must specify enough target fields. Otherwise, the last target field is filled with the rest of the field <c> and still contains delimiters.

If all target fields are long enough and no fragment has to be truncated, SY-SUBRC is set to 0. Otherwise it is set to 4.

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.

The output appears as follows:

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

Part 1

Part 2

Part 3

Part 4 *** Part 5

Note that the contents of the fields P1 ...P4 are totally overwritten and that they are filled out with trailing blanks.

You can also split a string into the individual lines of an internal table as follows:

SPLIT <c> AT <del> INTO TABLE <itab>.

The system adds a new line to the internal table <itab> for each part of the string.

Former Member
0 Kudos

Hi,

Use,

SPLIT ztab-fld1 AT space INTO ztab-fld1 ztab-fld2.

Sri

former_member188685
Active Contributor
0 Kudos

try to use split ztab-fld1 at space into ztab-fld1

ztab-fld2.

regards

vijay~

Former Member
0 Kudos

SPLIT ztab_fld AT space

INTO ztab-fld1

ztab-fld2.

i think this will work