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: 

How to capture first two digit in a number

Former Member
0 Kudos

Hi,

I have numbers with differeent lenth in a variable How to capture first two digit??

Thanks.

5 REPLIES 5

Former Member
0 Kudos

Hi,

Copy the number to char and use offset to capture first two character or define a 2 char variable pass the int and then pass the variable back to int field.

THanks,

Anmol.

Former Member
0 Kudos

You can move the variable to another char variable and use offset


MOVE lv_char+0(2) TO lv_first_two.

Former Member
0 Kudos

hi subhasis

use a "+" operator like this


data : a1 type I.

a1 = HSDAT+0(2).

hope uill get the solution.

Regards,

Abhilash

Former Member
0 Kudos

Hi,

We can achieve that using the following methods:

DATA : loc_1 type string,

loc_2(2) type c.

loc_1 = '123423428340923990'.

loc_2 = loc_1+0(2).

Here you will get only the first two digits.

You can use move statement also.

MOVE LOC_1(2) TO loc_2.

If you are having mixed string with characters and digits mixed together i.e. like this 'test01test03sample01'.

You can so that using this method.

data : lv_length type I.

loc_1 = 'test01test03sample0'.

LV_LENGTH = STRLEN( loc_1 ).

DO LV_LENGTH TIMES.

*&-- Read from first string validing the numeric fields and move your first two digits to the required variable --&*

ENDDO.

Hope it will be useful.

Regards,

Sakthi

Edited by: Sakthi Saravanan C on Oct 8, 2010 6:45 PM

Former Member
0 Kudos

Moderator message - Please do not ask or answer basic questions - thread locked Rob