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

Please help me with this error in this code snippet!

Former Member
0 Likes
1,258

Code Snippet:

REPORT ZMKTEST6.

data : f1(2) type c,

f2(2) type c,

f3(10) type n value '12345'.

clear: f1 with 'X',

f2 with f1,

f3 with '3'.

write 😕 f1 ,f2, f3.

Process Error:

The field "F1" must have the length 1.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,235

Whenever you use CLEAR..WITH val, the length of val must be 1

Code Snippet:

REPORT ZMKTEST6.

data : f1(2) type c,

f2(2) type c,

f3(10) type n value '12345'.

clear: f1 with 'X',

f2 with f1,

f3 with '3'.

write 😕 f1 ,f2, f3.

Process Error:

The field "F1" must have the length 1.

9 REPLIES 9
Read only

Former Member
0 Likes
1,235

hi ,

ther is not syntax with clear with 'X".

but you can do one thing to get the one character.

REPORT ZMKTEST6.


data : f1(2) type c,
f2(2) type c,
f3(10) type n value '12345'.

clear: f1 with 'X',  "Comment this
f1 = f1+0(1).        "write this
f2 with f1,
f3 with '3'.
write :/ f1 ,f2, f3.

now f1 containd one charater instead of 2.

now you can display as usuall

Read only

Former Member
0 Likes
1,236

Whenever you use CLEAR..WITH val, the length of val must be 1

Read only

0 Likes
1,235

A variant of this snippet was given in SAMS Teach yourself ABAP in 21 days.

(Listing 9.5)

I was told that this book is flawless.

He gives this output for the code for f2 as XX

Read only

0 Likes
1,235
REPORT  YSAT_TEMP1.

data : f1(1) type c,   " -- F1 length should be 1 char type 
f2(2) type c,
f3(10) type n value '12345'.

clear: f1 with 'X',
f2 with f1,
f3 with '3'.
write :/ f1 ,f2, f3.

Result: 

X XX 3333333333

Thanks

~Satya

Read only

0 Likes
1,235

Thank You Very much.

The Literature I was referring to was for release 4.1.

Hence I had these doubts. Now it is clear.

Thanks Everyone!

Read only

former_member156446
Active Contributor
0 Likes
1,235

addition to Das's code :

data : f1(2) type c,
f2(2) type c,
f3(10) type n value '12345'.

clear: f1 with 'X'.
f2 = f1+0(1).
clear : f3 with '3'.
write :/ f1 ,f2, f3.

Read only

0 Likes
1,235

But this is showing only one X in f2. What about the other character? length of f2 has been defined as 2.

Read only

0 Likes
1,235
data : f1(2) type c,
f2(2) type c,
f3(10) type n value '12345'.
 
clear: f1 with 'XX'.  " IF YOU NEED TWO 
CELAR: f2 WITH f1.
clear : f3 with '3'.
write :/ f1 ,f2, f3.

or 

clear: f1 with 'X'.  
f2+0(1) = f1.
F2+1(1) = F1.
clear : f3 with '3'.
write :/ f1 ,f2, f3.
Read only

0 Likes
1,235

Try:

DATA : f1(2) TYPE c,
f2(2) TYPE c,
f3(10) TYPE n VALUE '12345'.

CLEAR: f1 WITH 'X',
       f2 WITH 'X',
       f3 WITH '3'.
WRITE :/ f1 ,f2, f3.

Rob