Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Strings Operations

Former Member
0 Kudos

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'.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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).

4 REPLIES 4

Former Member
0 Kudos

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).

Former Member
0 Kudos

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'.

Former Member
0 Kudos

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

Former Member
0 Kudos

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.