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

how to get last 4 digits of a particular field?

Hi to all,

here i have three fields,

f1 length 18 char,

f2 length 4 char,

f3 length 4 char,

now i want to take last 4 char of f1 to f2 and the same i have to pass to f3.

how to do this?

regards,

swami

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

12 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 09:44 AM

    f2 = f1+14(4)

    Alternatively you can use strlen() to get the length of the field and adjust accordingly

    l_len = strlen(f1)

    subtract 4 from l_len

    f2 = f1+l_len(4)

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 09:46 AM

    f1 length 18 char,

    f2 length 4 char,

    f3 length 4 char,

    f2 = f1 + 15(4).

    move f2 to f3.

    Pls reward pts if help.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 09:46 AM
    DATA : l_var(12) VALUE 'SOMETEXT'. "this logic works on any length not only 18 chars
    
    DATA : l_len TYPE i.
    
    l_len = strlen( l_var ).
    
    l_len = l_len - 4 .
    
    
    "your case..
    
    f2 = f3 = l_var+l_len(4).
    
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 09:46 AM

    Hi,

    pls refer the below sample code.

    data:

    f1(18) type c value 'asjfkas',

    f2(4) type c,

    f3(4) type c,

    l_len type i.

    l_len = strlen( f1 ).

    l_len = l_len - 4.

    f2 = f1+l_len(4).

    f3 = f2.

    write:/ f2, f3.

    Reward if useful.

    Thanks,

    Sreeram.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 09:46 AM

    V1 = f1 + 15(4) ,

    concatenate f2 V1 into f2,

    concatenate f3 V1 into f3.

    Reward if useful

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 09:46 AM

    Hi,

    f2 = f1+14(4).

    f3 = f2.

    regards,

    Santosh Thorat

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 09:47 AM

    Hi,

    w_int = 18 - 4.

    w_str = f1+w_int(4).

    w_str1 =f2+w_int(4).

    concatenate w_str w_str1 into f3.

    Plzzz reward points if it helps.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 09:48 AM

    Hi ,

    do like this

    f2 = f1+14(4).

    f3 = f2.

    +<postion> ( length )

    reward and close if answered,

    taher

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 09:54 AM

    Hi Swami,

    You can use offset of f1, ie

    f1 +14(4). then concatenate f1 and f2 and pass to f3.

    I think it solves ur problem.

    Regards,

    DVNS.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 10:03 AM

    Hi,

    1. Take the maximum length of the field. Pass it to an integer variable. Lets say L1.

    2. Subtract this variable by 4. Move this value to another variable. Lets say L2.

    3. WRITE F1+L2(4) TO F3.

    Sample Code.

    REPORT zmaytest.

    DATA : f1 TYPE string VALUE 'abcdefghijk',

    f2(4) TYPE C,

    f3(4) TYPE C.

    DATA : l1 TYPE i,

    l2 TYPE i.

    START-OF-SELECTION.

    l1 = STRLEN( f1 ).

    l2 = l1 - 4.

    WRITE f1+l2(4) TO f2.

    WRITE f1+l2(4) TO f3.

    WRITE: / 'F2', F2.

    WRITE: / 'F3', F3.

    Regards,

    Mayank

    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.