Skip to Content
author's profile photo Former Member
Former Member

String porcessing:

hello Friends,

I need to know the string processing way in ABAP:

Actually there is a filed, say name2 in dd, and is stored in various formats:

Name2 : (DSP: 51297)

Name2 : (C620 DSP)

Name2 : ( license 73866 )

Name2 : ( license: 84421 )

Name2 : European Headquarters (E293)

Name2 : (Peregrine Ltd.) (88115)

So I have to extract the nos e.g in the above example I need to extract followings.

l_name = 51297

l_name = C620

l_name = 73866

l_name = 84421

l_name = E293

l_name = 88115

where is l_name is the field, which I get after string processing ?

so can I loop over the string in abap as I can do in java or so ?

Regards,

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 01:40 PM

    Hi,

    You can try offset..

    for example l_name = Name2+5(5) = 51297( for the first value)....

    I assume the first value is DSP:<space> 51297

    position starts with 0... 'D' is at 0 position...

    l_name = Name2+5(5); this means starting from 5 position(given before brackets) get 5 characters(given in brackets)... this is going to extract 51297 and assign to l_name...

    -Muktar

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Shah,

      this logic should help you extract numeric value from a string...

      data: lv_text type string,

      lv_temp(1),

      lv_len type i,

      temp type i value '0',

      lv_new(10) type c,

      lv_check(4).

      lv_text = 'text123'.

      lv_len = STRLEN( lv_text ).

      while temp < lv_len.

      lv_temp = lv_text+temp(1).

      CALL FUNCTION 'NUMERIC_CHECK'

      EXPORTING

      STRING_IN = lv_temp

      IMPORTING

      • STRING_OUT =

      HTYPE = lv_check

      .

      if lv_check = 'NUMC'.

      concatenate lv_temp lv_new into lv_new.

      endif.

      temp = temp + 1.

      endwhile.

      CALL FUNCTION 'STRING_REVERSE'

      EXPORTING

      STRING = lv_new

      LANG = 'E'

      IMPORTING

      RSTRING = lv_new

      EXCEPTIONS

      TOO_SMALL = 1

      OTHERS = 2

      .

      IF SY-SUBRC <> 0.

      • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

      ENDIF.

      write: lv_new.

      -Muktar

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 02:15 PM
    DATA : BEGIN OF itab OCCURS 0,
    str TYPE string,
    l_name(20),
    END OF itab.
    
    DATA : BEGIN OF itab2 OCCURS 0,
    st1(20),
    END OF itab2.
    DATA : idx TYPE sy-tabix.
    
    itab-str = 'European Headquarters (E293)'.
    APPEND itab.
    itab-str = '(DSP: 51297)'.
    APPEND itab.
    itab-str = '( license 73866 )'.
    APPEND itab.
    itab-str = '(C620 DSP)'.
    APPEND itab.
    itab-str = '(Peregrine Ltd.) (88115)'.
    APPEND itab.
    
    
    LOOP AT itab.
      idx = sy-tabix.
      SPLIT itab-str AT space INTO TABLE itab2..
      LOOP AT itab2 WHERE st1 CA '0123456789'.
        REPLACE ALL OCCURRENCES OF '(' IN itab2-st1 WITH space.
        REPLACE ALL OCCURRENCES OF ')' IN itab2-st1 WITH space.
        CONDENSE itab2-st1.
        itab-l_name = itab2-st1.
        MODIFY itab INDEX idx.
      ENDLOOP.
    ENDLOOP.
    
    LOOP AT itab.
      WRITE :/ itab-l_name.
    ENDLOOP.
    
    
    Add a comment
    10|10000 characters needed characters exceeded

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.