Application Development and Automation 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: 
Read only

Strings Operations

Former Member
0 Likes
922

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
Read only

Former Member
0 Likes
853

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

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

4 REPLIES 4
Read only

Former Member
0 Likes
854

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

Read only

Former Member
0 Likes
853

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

Read only

Former Member
0 Likes
853

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

Read only

Former Member
0 Likes
853

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.