Skip to Content
avatar image
Former Member

Split string

Hello

I have a variable string which has the value:

'string1;string2;string3;string4;string5'

I want to use each individual string from the list.

i.e. loop through all the strings[n] and process them.

What are your views on the best way to extract these string?

Can I split them into a table and loop through the table? What would be the syntax for this?

I am new to ABAP and interested in the best way to carry out processing.

Cheers

Andrew

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Aug 20, 2007 at 05:41 AM

    split it once.. check if the first of the new strings is the same as the original string

    if it is different, then split it again till it becomes the same

    run it in a loop

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 05:22 AM

    Hi,

    do like this.

    DATA: string(60) TYPE c value 'string1;string2;string3;string4;string5',

    p1(20),

    p2(20),

    p3(20),

    p4(20),

    P5(20),

    del VALUE ';'.

    WRITE string.

    SPLIT string AT del INTO p1 p2 p3 p4 p5.

    WRITE / p1.

    WRITE / p2.

    WRITE / p3.

    WRITE / p4.

    WRITE / p5.

    rgds,

    bharat.

    Message was edited by:

    Bharat Kalagara

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 20, 2007 at 05:24 AM

    try this

    split mainstring at ';' into string1 string2 string3 string4 string5.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 05:31 AM

    Hi,

    DATA: string(400) TYPE c VALUE 'abac;abdfa;adfa;adsf'. " this is your string.

    DATA: char1(400) TYPE c,

    char2(400) TYPE c.

    DATA: string1(400) TYPE c.

    DATA: y TYPE i.

    DATA: num TYPE i.

    num = STRLEN( string ).

    char1 = string.

    string1 = string.

    DO num TIMES.

    SEARCH string FOR ';' .

    IF sy-subrc EQ 0.

    SPLIT string AT ';' INTO char1 char2.

    y = y + 1.

    CLEAR: string.

    string = char2.

    ENDIF.

    ENDDO.

    data: begin of itab occurs 0,

    field(400) type c,

    end of itab.

    CLEAR: char1 , char2.

    DO y TIMES.

    SPLIT string1 AT ';' INTO char1 char2.

    itab-field = char1.

    write:/ itab-field.

    append itab.

    clear: string1.

    string1 = char2.

    ENDDO.

    thanks & regards,

    Venkatesh

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 20, 2007 at 05:27 AM

    Hey guys thanks for your answers

    I forgot to mention that the number of strings is not set. The number changes. So I need smething a bit more flexible than the static solution.

    Cheers

    Andrew

    Add comment
    10|10000 characters needed characters exceeded

    • when the no. of occurrences of the string is unknow the , best, simple approach would be to use the following method.

      data: string_tab type standard table of string .

      data: temp_string type string .

      refres: string_tab .

      split mainstring at ';' into table string_tab .

      loop at string_tab into temp_string .

      • do some processing of each split string .

      clear temp_string .

      endloop .