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 get last 4 digits of a particular field?

Former Member
0 Kudos

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

12 REPLIES 12

Former Member
0 Kudos

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)

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

V1 = f1 + 15(4) ,

concatenate f2 V1 into f2,

concatenate f3 V1 into f3.

Reward if useful

Former Member
0 Kudos

Hi,

f2 = f1+14(4).

f3 = f2.

regards,

Santosh Thorat

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hi ,

do like this

f2 = f1+14(4).

f3 = f2.

+<postion> ( length )

reward and close if answered,

taher

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Use following statement,you will get result.Reward me

data a TYPE string VALUE 'abcdef'.

SHIFT a BY 4 PLACES RIGHT CIRCULAR .

WRITE a+(4).

L.Velu

Former Member
0 Kudos

Hi Dear,

U can write like this.

f1_last4char = f1+14(4).

move f1_last4char to f2.

move f2 to f3.

If it helps reward me points.

Regards

AshokChowdhary