Skip to Content

ABAP 7.40: using function 'segment' instead of command 'split'

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?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Apr 23, 2016 at 06:23 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.