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: 

Last character

Former Member
0 Kudos

Hi,

I would like to ask how to identify the suffix for a particular field.

Suppose I have one field value MANGO. Now I would like to set the last character of a field i.e. I wanted to see

the output like O only. But remember the field lengths are different.

i,e,

Field

MANGO

APPLE

BANANA

so I wanted to see output like O, E, A.

Anybody will pls help me.

7 REPLIES 7

Former Member
0 Kudos

Hi,

Check this example..

DATA: V_CHAR(10) VALUE 'MANGO'.

DATA: V_LEN TYPE I.

DATA: V_OUTPUT.

V_LEN = STRLEN( V_CHAR ).

v_len = v_len - 1.

V_OUTPUT = V_CHAR+V_LEN(1).

WRITE:/ V_OUTPUT.

Thanks,

Naren

Former Member
0 Kudos
data : v_var(10) value 'MANGO',
         v_len type i,
         last(1).

v_len = strlen( v_var ).
v_len = v_len - 1.
last = v_var+v_len(1).

write : / last.

null

Message was edited by:

Chandrasekhar Jagarlamudi

Former Member
0 Kudos

1. simple.

2. this is one way.

we have to use strlen, and offset concept.

3. just copy paste in new program.

report abc.

*----


data : str(10) type c.

data : l type i.

str = 'ABAP'.

*----


l = strlen( str ).

l = l - 1.

write 😕 str+l.

regards

navjot

Former Member
0 Kudos

Hi,

Check this code.

DATA: str(10) TYPE c VALUE 'MANGO',
      char    TYPE c.

DATA: length TYPE i.

length = strlen( str ).
length = length - 1.

char = str+length(1).

Here, 'str' can have any value. The variable 'char' will always be last character.

Regards,

RS

Former Member
0 Kudos

Hi Nehu

You could do something like.

REPORT ZZGAZTEST .

field-symbols <fname>.

Data: l_stringlen type i,

l_lastchar type c,

l_number type n,

l_dummy(25) type c,

field(10) type c value 'MANGO'.

l_stringlen = strlen( field ). "Gives length of the data string 'MANGO'

*(5)

l_number = l_stringlen - 1.

concatenate 'field+' l_number '(1)' into l_dummy.

assign (l_dummy) to <fname>.

l_lastchar = <fname>.

Write l_lastchar.

Regards

Gareth

Former Member
0 Kudos

hI..NEHA..

as u are given somany options..

try this also which is different:

data: w_test type string value 'Rammohan rao'.

DATA: C1 type string VALUE 'ABCDEFGHIJRAMMOHANRAOKW4FTHZ',

C2 type string.

<b>MOVE C1 TO C2 PERCENTAGE 98.

REPLACE C2 IN C1 WITH SPACE.

WRITE C1.</b>

0 Kudos

Hi Rammohan,

I'd forgotten Move - Percentage. Nice one.

But don't forget not to use in ABAP Objects: The statement MOVE PERCENTAGE is not allowed in ABAP Objects.

Poor old move-percentage joins the list of statements made obsolete by ABAP Objects

Regards

Gareth