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: 

To remove last 2 digit from the field

Former Member
0 Kudos

Hello Guys,

I want to remove the last 2digit from the string.

how to remove this. The string length is 30.

But it can store variable data.

1.250 km iwant 1.250 or

1,810.00 kg i want 18100.00. like this

how to do this

thanks & regards

Nitin

1 ACCEPTED SOLUTION

Former Member
0 Kudos

data: a(50) type c value 'any data',

b(2) type n.

b = strlen( a ).

b = b - 2.

a = a(b).

write: a.

13 REPLIES 13

Former Member
0 Kudos

Hi,

Better you use the variable as

DATA: VAR1 type P DECIMALS 2.

It will give only 2 digits after decimal point.

Thanks

0 Kudos

there is last 2 digit are the unit.

Like KM KG GM .

I dont want this two digit.

1.526 km ====> 1.256 like this

0 Kudos

Hi,

As u want to remove last two digits only..u can try like this

data : lv_number(3) type c,

lv_data(30) type c.

lv_number = strlen ( give ur variable ).

lv_number = lv_number - 2.

now lv_number will have the length of ur variable.

lv_data = variable+0(lv_number).

condense : lv_data

lv_data will have ur expected result..

Regards,

Nagaraj

Former Member
0 Kudos

data: a(50) type c value 'any data',

b(2) type n.

b = strlen( a ).

b = b - 2.

a = a(b).

write: a.

Former Member
0 Kudos

data: l_strlen type i,

l_strlen1 type i.

l_strlen = strlen(field).

l_strlen1 = l_strlen - 2.

split field into field 1 field2 at l_strlen.

So, field1 will hold the value.

Former Member
0 Kudos

you can calculate the string lengt using STRLEN command...if it shows length = 10 then you can copy upto 8 chars into another variable...

Former Member
0 Kudos
data : var type string,
         l_len type i.

l_len = strlen( var ).

if l_len > 2.
l_len l_len - 2.
var = var+0(l_len).
endif.

Regards,

Mohaiyuddin

Edited by: Mohaiyuddin Soniwala on Nov 21, 2008 3:03 PM

Former Member
0 Kudos

Hi,

If there is a space between the value and the unit of measure, you can use the split statment to achieve this.

SPLIT f AT g INTO h1 ... hn. 

So you can spilt your variable into 2 at SPACE.

See F1 help for split statement

regards,

Advait

Edited by: Advait Gode on Nov 21, 2008 10:36 AM

Former Member
0 Kudos

Hi,

Try to split the statement when u get sapce

for ex: 1.250 kg split

data:

lv_string type string,

lv_st1 type string,

lv_st2 type string.

lv_string = '1.234 kr'.

split lv_string at space into lv_st1 lv_st2.

write : lv_st1, lv_st2.

regards,

Kalp

Former Member
0 Kudos

Hi Nitn,

Then use split statement at space.

Refer this code snippet.

DATA: str1 TYPE string,

str2 TYPE string,

str3 TYPE string,

itab TYPE TABLE OF string,

text TYPE string.

text = `What a drag it is getting old`.

SPLIT text AT space INTO: str1 str2 str3,

TABLE itab.

Thanks

Former Member
0 Kudos

hi

I hope we can write an offset

string1 = '012345678901234567890123456789'.

string2 = string1+0(28).

u will get fst 28 digits

u can use this abap statment for ur 2nd query.

REPLACE ALL OCCURRENCES OF ',' in <field> with '.'.

Help for UN world food program

Regards

Rasheed.

Edited by: Rasheed salman on Nov 21, 2008 10:48 AM

Former Member
0 Kudos

Hi

Try this u will get the output u expected

data: var(30).

data:str(30).

str = '987we'.

var = STRLEN( str ) - 2.

str = str+0(var).

write str.

output: str = 987.

regards

Former Member
0 Kudos

Data: a(30) value '118.00 KM',

x(30),

x1(30).

split a at 'KM' into x x1.

write:/ x, x1.

Rajneesh Gupta