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

10|10000 characters needed characters exceeded

### Related questions

• 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)

10|10000 characters needed characters exceeded
• 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.

10|10000 characters needed characters exceeded
• 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 .

f2 = f3 = l_var+l_len(4).
```
10|10000 characters needed characters exceeded
• 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.

10|10000 characters needed characters exceeded
• 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

10|10000 characters needed characters exceeded
• Former Member
Posted on Jan 28, 2008 at 09:46 AM

Hi,

f2 = f1+14(4).

f3 = f2.

regards,

Santosh Thorat

10|10000 characters needed characters exceeded
• 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.

10|10000 characters needed characters exceeded
• Former Member
Posted on Jan 28, 2008 at 09:48 AM

Hi ,

do like this

f2 = f1+14(4).

f3 = f2.

+<postion> ( length )

taher

10|10000 characters needed characters exceeded
• 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.

10|10000 characters needed characters exceeded
• 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