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

split field

Former Member
0 Likes
726

hi,

i have field type char40 (name) with 4 words and space between them

what is the best way to part the word to 4 different fields.

e.g.

name

abc defg aaaa bbbb

i wont

field1 - abc

field2 - defg

field3 - aaaa

field4 - bbbb

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
696

data : begin of itab occurs 0,

field(20),

end of itab.

SPLIT name at ' ' into itab.

(OR)

data: f1(20), f2(20), f3(20), f4(20).

Split name at ' ' into f1 f2 f3 f4.

awrd points if useful

Bhupal

6 REPLIES 6
Read only

Former Member
0 Likes
696

Use Key word SPLIT.

Sample code:

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.

Hope this helps.

Regards

Vinayak

Read only

Former Member
0 Likes
697

data : begin of itab occurs 0,

field(20),

end of itab.

SPLIT name at ' ' into itab.

(OR)

data: f1(20), f2(20), f3(20), f4(20).

Split name at ' ' into f1 f2 f3 f4.

awrd points if useful

Bhupal

Read only

Former Member
0 Likes
696

Hi,

Please Use the code below

DATA: NAMES(40) TYPE C VALUE 'abc defg aaaa bbbb',

ONE(10) TYPE C,

TWO(10) TYPE C,

THREE(10) TYPE C,

FOUR(10) TYPE C.

SPLIT NAMES AT ' ' INTO ONE TWO THREE FOUR.

WRITE 😕 ONE , TWO , THREE , FOUR.

Reward if helpful.

Read only

Former Member
0 Likes
696

Depending on if you have a known number of words or not, both options shown here.


DATA:
  text40(40).

DATA:
  f1(40),
  f2(40),
  f3(40),
  f4(40).

DATA:
  BEGIN OF out_rec,
    fld(40),
  END OF out_rec,
  it_tab LIKE STANDARD TABLE OF out_rec.

START-OF-SELECTION.

  text40 = 'Field1 Field2 Field3 Field4'.

  SPLIT text40 AT space INTO f1 f2 f3 f4.

  REFRESH it_tab.

  SPLIT text40 AT space INTO TABLE it_tab.

  WRITE:/ f1, f2, f3, f4.

  LOOP AT it_tab INTO out_rec.
    WRITE:/ out_rec-fld.
  ENDLOOP.

Read only

Former Member
0 Likes
696

"If your filed always contains 4 fields separated by space
"then use following method otherwise use TABLE.

DATA: name1 TYPE string,
      name2 TYPE string,
      name3 TYPE string,
      name4 TYPE string,
      name  TYPE string.

name = 'abc defg aaaa bbbb'.

SPLIT name AT space INTO : name1
                           name2
                           name3
                           name4.

WRITE :/ name1,
       / name2,
       / name2,
       / name4.
Read only

Former Member
0 Likes
696

Use:

split name at space into field1 field2 field3 field4.