7 Replies Latest reply: Sep 12, 2008 11:00 AM by Amit Kumar RSS

how to trim a string

Currently Being Moderated

Hi,

I have a problem where in I have to trim the characters from the second name.e.g.Manish Kumar should be trimmed to Manish K.

Regards,

Manish

  • Re: how to trim a string
    Kiran K
    Currently Being Moderated

    Manish,

     

    Use the Offset Concept.Check the field length and use it accordingly.

     

    ex:-syntax WA_EMP-JOBTI+27(56) where u want to access starting from the 27th character to 56th character.

     

    K.Kiran.

  • Re: how to trim a string
    Eric Cartman
    Currently Being Moderated

    hi Manish,

     

    you can do something like this:

     

    SPLIT name AT space INTO itab.
    gv_lines = lines( itab ). "in case there are more first names
    READ TABLE itab INTO wa INDEX gv_lines. "this will be the last name
    wa = wa(1).
    MODIFY itab FROM wa INDEX gv_lines.
    CONCATENATE itab INTO name.

     

    hope this helps

    ec

  • Re: how to trim a string
    Sharin Varghese
    Currently Being Moderated

    Hi,

     

    Try this.

     

    data: off type i.

     

    c1='Manish kumar'.

     

    find ' ' in c match offset off.

     

    c2 = c1+0(off + 1).

     

     

     

     

    Sharin.

  • Re: how to trim a string
    Always Learner
    Currently Being Moderated

    hi Manish ,

     

    See pseudo code

     

    DATA name(50) TYPE c VALUE 'manish kumar'.
    
    DATA : BEGIN OF itab OCCURS 0,
           a(50),
           b(50),
           END OF itab.
    
    SPLIT name AT space INTO itab-a
                             itab-b.
    
    CONCATENATE itab-a itab-b+0(1) INTO name separated by space.
    
    write name.

     

    Regards

  • Re: how to trim a string
    Subhankar Garani
    Currently Being Moderated

    HI...

    Please see this example...

     

     

    data:  l_str1 TYPE string,

          l_str2  TYPE string,

          l_str3  TYPE string.

     

     

    l_str1 = 'Subhankar Garani'.

     

    SPLIT l_str1 at space INTO l_str2 l_str3.

     

    CLEAR: l_str1.

    CONCATENATE l_str2 l_str3(1) INTO l_str1 SEPARATED BY space.

    WRITE: l_str1.

  • Re: how to trim a string
    Amit Kumar
    Currently Being Moderated

    Hi,

     

    Check this code:

     

     

    LOOP AT itab INTO wa_itab.

      SPLIT wa_itab-name AT space INTO name1 name2.

      CONCATENATE name1 name2(1) INTO wa_itab-name separated by space.

      MODIFY itab FROM wa_itab.

    ENDLOOP.

     

     

    Regards,

    Amit

  • Re: how to trim a string
    Currently Being Moderated

    Try to get the length of string of second name by some coding say it is n

    now

     

    shift <name> by n-1 places right

    condense <name>

Actions