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

Strings Operations

Hi. I have the follow problem.

Data: a(16) TYPE c.

How can I do to get the last ten digits of this data, if this variable not always has the same number of characters???

For example:

a = '123456789abcdefg' OR

a = '123456789abc'.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 05:34 PM

    try to do this:

    Data: a(16) TYPE c.
    data: leng type i,
          first type i.
    data: last10(10) type c.
    
    leng = strlen( a ).
    first = leng - 10.
    
    last10 = a+first(10).

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 05:54 PM

    small change in above code

    DATA: a(16) TYPE c.

    DATA: b(10) TYPE c.

    DATA: len TYPE i.

    a = '123456789abcdefg'.

    len = STRLEN( a ).

    if len Gt 10.

    len = len - 10.

    b = a+len(10).

    else.

    b = a.

    endif.

    WRITE: / b.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 05:36 PM

    use :

    a+n

    a(n)

    a+n(n)

    where n is the position to move the cursor or the number of char to get..

    For example:

    a = '123456789abcdefg'

    a(3) = '123'.

    a+4(5) = '5678a'.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 05:38 PM

    Hi,

    check this example.

    DATA: a(16) TYPE c.
      DATA: b(10) TYPE c.
    
      DATA: len  TYPE i.
    
      a = '123456789abcdefg'.
    
      len = STRLEN( a ).
    
      len = len - 10.
    
      b = a+len(10).
    
      WRITE: / b.

    THanks

    Naren

    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.