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

Remove last 3 char ..

Former Member
0 Likes
3,869

Hi ,

I need to remove last 3 char from my varible which is char 30.

For example : WERKS = 1000 and .

I need to remove last 3 char (and) from the above varibale .Kindly guide this

Regards,

VC

Hi ,

I need to remove last 3 char from my varible which is char 30.

For example : WERKS = 1000 and .

I need to remove last 3 char (and) from the above varibale .Kindly guide this

Regards,

VC

7 REPLIES 7
Read only

Former Member
0 Likes
2,060

Hi Veerachamy,

Jusy offset the value..

Example..

data:
w_char(30) type c,
wtmp(30) type c.

w_tmp = w_char+0(27).

write: w_tmp.

it will remove the last three characters from the filed.

Regards

Kiran

Read only

0 Likes
2,060

Hi Kiran,

Thanks for your reply.

But my varible will not always char30 . it may be dynamic.how to do for this ?

Regards,

Vc

Read only

0 Likes
2,060

Hi veerachamy,

Just copy this code..it will work fine even if the field changes dynamically..

I took w_char as 30 char..u can give ur field name there...

data:
w_char(30) type c value 'asdfghjklpoiu',
w_tmp(30) type c,
w_tmp1 type i.
w_tmp1 = strlen( w_char ).
w_tmp1 = w_tmp1 - 3.

w_tmp = w_char+0(w_tmp1).

write: w_tmp.

Hope it resolves the issue...

Regards

Kiran

Read only

0 Likes
2,060

Hi,

Then find string length of your variable like below.

DATA: dat(30) TYPE c,

dat1 type string,

len type i.

dat = '123456789012345678901234567890'.

len = strlen( dat ).

len = len - 3. " To remove last 3 characters

dat1 = dat(len).

Read only

0 Likes
2,060

shift the variable by 3 + (30 - length) places.

data : s1 type char30.
DATA : i1 type i.
s1 = 'asdasd12345'.
i1 = strlen( s1 ).
i1 = : 30 - i1, i1 + 3.
SHIFT s1 by i1 PLACES RIGHT.

WRITE s1.

Read only

Nawanandana
Active Contributor
0 Likes
2,060

hi

you can used this logic for it




data:  V_CHAR(30) type c,
       SWT_LENTH TYPE I,
       wearks(12) value '10000'.


SWT_LENTH = STRLEN( wearks ).  "get the lenth of ur variable

SWT_LENTH = SWT_LENTH - 3.

V_CHAR = wearks+0(SWT_LENTH).

write: V_CHAR.

regard

nawa

Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
2,060

Hi

Using OFFSET Methodology,we can get that as follows:

w_char type char30,

wtmp type char27..

w_tmp = w_char+0(27).

w_tmp contains only 27 chars by not taking last 3.

Regards,

Sreeram