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

Get 2 characters from a string.

Hi Experts,

I need a formula / ABAP code to get 2 characters from a string. String cannot be hard coded. I need to get the CW moved into an info object.

AT-CEF-CW-EDP-XXX-XXXX

Kindly advise how to achieve this

Regards

Las

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Jul 22, 2016 at 12:27 AM

    Hi Las,

    Do you want to get the 8th and 9th character of the string? if you only want to get the 8th and 9th character, then i believe you can do something like this

    DATA : lv_container TYPE c LENGTH 2,

    lv_string TYPE string VALUE 'AT-CEF-CW-EDP-XXX-XXXX'.

    lv_container = lv_string+7(2).

    Reward as needed.

    KR,

    DF

    Add a comment
    10|10000 characters needed characters exceeded

    • You can code in End / Field routine .

      I already provided what needs to be done in case of Field Routine . For End Routine , use code like below .

      LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS> .
      IF <RESULT_FIELDS>-FUNC_LOC IS NOT INITIAL .
      <RESULT_FIELDS>-Target_InfoObject = <RESULT_FIELDS>-FUNC_LOC+7(2) .
      ENDIF.
      ENDLOOP. 
      

      Before writing this piece of code, add InfoObject to target ( DSO or Cube ) .

      *I did not write this code in ABAP editor, so some syntax error expected. You can write it in ABAP editor and in case face any issue, pass the code here.

      Regards

      Anindya

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2016 at 05:59 AM

    Hi Las W,

    You can write code in routine as below.

    DATA: lf_str TYPE string,

    lf_ce TYPE char2.

    lf_str = 'AT-CEF-CW-EDP-XXX-XXXX'.

    IF lf_str CS 'CW'.

    lf_ce = 'CW'.

    ENDIF.


    Regards,

    PrAvIn

    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.