Skip to Content
author's profile photo Former Member
Former Member

How to capture first two digit in a number

Hi,

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

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 12:55 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 12:56 PM

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

    MOVE lv_char+0(2) TO lv_first_two.
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 01:05 PM

    hi subhasis

    use a "+" operator like this

    data : a1 type I.
    
    a1 = HSDAT+0(2).
    
    

    hope uill get the solution.

    Regards,

    Abhilash

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 01:14 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 01:31 PM

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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.