Skip to Content

String Processsing

What is the ABAP code to find the first n characters of a string?

Moderator Message: Very basic question. Please search before posting your question

Message was edited by: Suhas Saha

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on May 27, 2013 at 08:01 AM

    search more pls. this is very basic you can find it with F1 ( help )

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 27, 2013 at 08:06 AM

    Did you try to look at F1 help index on Abap source Editor or at a site like http://help.sap.com/abapdocu_731/en/abenabap.htm ?

    Regards,

    Raymond

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 27, 2013 at 08:08 AM

    Hi Chandan,

    Just an Example:

    str is a string variable.

    <pattern> - search pattern

    Statement to search for a pattern for the first n characters:

    SEARCH str FOR <patter> ENDING AT n.

    Please refer to http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb33cc358411d1829f0000e829fbfe/content.htm

    -

    Karan

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 27, 2013 at 08:16 AM

    DATA : lv_string TYPE STRING VALUE 'ABCDEFGH IJKL',

    lv_find TYPE STRING VALUE 'CD'.



    FIND LV_FIND IN LV_STRING.

    IF sy-subrc IS INITIAL.

    write : 'success'.

    else.

    write : 'failure'.

    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 27, 2013 at 09:02 AM

    Let me put my question more clearly,

    Scenario:

    There are two field-symbols containig strings :

    <ls_record>-string type C(1000) and <ls_descr>-description type C(40)

    and I am doing:

    CONCATENATE <ls_record>-string <ls_descr>-description INTO <ls_record>-string.

    Here, I want to add the value of <ls_descr>-description to <ls_record>-string only after first 37th position of <ls_record>-string.

    It doesn't matter for me, whether <ls_record>-string containing values till 37th or not. Values can be less than 37th position also. but I have to concatenate second string only after 37th position of first one.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      Get the character length of first variable <ls_record>-string if its more than 37. Then offset and concatenate a blank character variable with just spaces say e.g.

      DATA: var1(37) type c value space.

      Then say strlen() gives value 20 in variable len where len is type i then

      offset = 37 - len

      CONCATENATE

      <ls_record>-string

      var1(offset)

      <ls_descr>-description

      INTO

      <ls_record>-string RESPECTING BLANKS.

      Cheers,

      Arindam



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.