Application Development and Automation 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: 
Read only

Select first 4 char

Former Member
0 Likes
11,305

Hi all,

I am new to ABAP.

I want select first 4 char of variable.

Example:

X = '627128891'.

i want first 4 char of X save to Y.

Y= '6271'.

How can I do it with ABAP statement?

Thanks

Shiva.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,556
X = '627128891'.

Y = X+0(4).
8 REPLIES 8
Read only

Former Member
0 Likes
3,557
X = '627128891'.

Y = X+0(4).
Read only

Former Member
0 Likes
3,556

DATA : X(10) TYPE C VALUE '627128891',

Y(4).

Y = X+0(4).

WRITE : / Y.

REGARDS

SHIBA DUTTA

Read only

Former Member
0 Likes
3,556

You can also do the following in this way..

Data: x(9) type c value '627128891',

y(4) type c.

x = y.

so when you do this assignment then automatically only the first four value will onlu come bz it is of lenght 4.

I hope that it solves your query.

Regards,

Jayant

Read only

Former Member
0 Likes
3,556

DATA:

a(10) value '12345678',

b(4).

b = a(4).

write: b.

Read only

Former Member
0 Likes
3,556

hi,

data x(10) type c value '1234567'.

data y(4) type c.

y = x0(4). " xn(m) n is the starting position and m no of character from n.

output y = 1234.. first four characters

y = x+2(2).

output y = 34 ..

rewards if understood..

regards,

nazeer

Read only

Former Member
0 Likes
3,556

hi,

data:

x(10) type c,

y(10) type c.

x = '123456767'.

y = x+0(4).

write: y.

regards,

Naresh.

Read only

Former Member
0 Likes
3,556

Hi Shiva,

Try Y= X(4).

Regards,

Feroz Gandhi

Read only

Former Member
0 Likes
3,556

X = '627128891'

to get first 4 chars

X(4) this gives first 4 characters

concatenate X(4) Y into Y.

data X(10).

data y(10) value '6271'.

X = '627128891'.

concatenate X(4) Y into Y.

write : / Y.