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 7.40: using function 'segment' instead of command 'split'

ralf_wenzel_heuristika
Active Participant
0 Likes
13,857

The following coding has to be translated into ABAP 7.40:

DATA:

  source    TYPE string VALUE 'MARA-MATNR=12345',

  tabname   TYPE tabname,

  fieldname TYPE fieldname,

  attribute TYPE string.

  SPLIT:

    source AT '-'

           INTO tabname fieldname,

    fieldname AT '='

              into fieldname attribute.

  " RESULT: tabname = 'MARA', fieldname = 'MATNR', attribute = '12345' !

I do not understand the F1 help of "segment" functions' features....

appendix:

via trial & error:

tabname    = segment( val = source index = 1 sep = '-' ).
fieldname  = segment( val = segment( val = source index = 2 sep = '-' ) index = 1 sep = '=' ).
attribute  = segment( val = source index = 2 sep = '=' ).

any shorter codings?

2 REPLIES 2
Read only

Clemenss
Active Contributor
0 Likes
6,517

Hi Ralf,

the documentation ABAP Keyword Documentation looka quite clear, But I don't see any advantage over SPLIT in this context.

Your code will run in 740 as it is. Translation is 1 : 1.

I have no idea what the special purpose of segment function may be - don't eve like the sample code for determining min an max as given here ABAP Keyword Documentation.

Regards Clemens

Read only

0 Likes
6,517

I am just training 7.40.... So my example may offer no advantages. But it IS an advantage to append a part of a field to an internal table without using help variables, for instance. In my example:

data:

  tabnames type table of tabname. 

append to_upper( segment val = source index = 1 sep = '-' ) ) to tabnames.

instead of

data:

  tabnames type table of tab name,

  helpfield_1 type tabname,

  helpfield_2 type string.

split source at '-'

into helpfield_1  " only used as split target field

     helpfield_2. " helpfield_2 never used, just a dummy!

translate helpfield_1 to upper case.

append helpfield_1 to tabnames.