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

Question reqarding filling variable with spaces

former_member188498
Active Participant
0 Likes
3,365

Hi,

when I try this:

DATA: field(6) TYPE c VALUE '______'. ( ______ - six spaces )

or this:

field = '______'.

or this

field = `______`.

the variable field is empty (has no spaces inside).

But when I try this:

DATA: field2 TYPE string.

field2 = `______`.

the variable has spaces inside.

Can somebody explain me how to assign spaces to a variable of type c?

Regards,

Ladislav

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,797

Hello,

If you declare data as below, it will definitly have spaces,1

DATA: field(6) TYPE c VALUE '______'. ( ______ - six spaces )

to test the same try some thing like this.

data: w_test type string.

concatenate field 'This is a test' into w_test RESPECTING BLANKS.

Hope this will help.

Thanks,

Jayant

11 REPLIES 11
Read only

Former Member
0 Likes
1,797

Hi,

Check this code. If i understood your query.Its leaving spaces for Char type also in my program. Hope you understand. Revert back to me if there is any concern..

DATA: field1 TYPE c VALUE 'a'.

DATA: field2(6) TYPE c VALUE ' '.

DATA: field3 TYPE c VALUE 'b'.

write: field1, field2, field3.

Thanks

Nitesh

Read only

Former Member
0 Likes
1,797

give directly default valuses.

Read only

Pawan_Kesari
Active Contributor
0 Likes
1,797

How do you know 'field(6) TYPE c' doesn;t have spaces in it?

Read only

0 Likes
1,797

I have the same question

As both


DATA: field1 TYPE c VALUE 'a'.
DATA: field2(6) TYPE c VALUE ' '.
DATA: field3 TYPE c VALUE 'b'.
write: field1,field2,field3.

and


DATA: field1 TYPE c VALUE 'a'.
DATA: field2(6) TYPE c.
DATA: field3 TYPE c VALUE 'b'.
write: field1,field2,field3.

have same output you dont have to give default value as ' '.

Edited by: mrugesh phatak on Dec 5, 2008 10:47 AM

Read only

Former Member
0 Likes
1,797

HI,

check this thread

hope it may helps you.

thanks n regards

Sachin

Read only

Former Member
0 Likes
1,798

Hello,

If you declare data as below, it will definitly have spaces,1

DATA: field(6) TYPE c VALUE '______'. ( ______ - six spaces )

to test the same try some thing like this.

data: w_test type string.

concatenate field 'This is a test' into w_test RESPECTING BLANKS.

Hope this will help.

Thanks,

Jayant

Read only

Former Member
0 Likes
1,797

hi,

DATA: field(6) TYPE c .

the value of the field will be space until you assign any value to it.

or try

DATA: field(6) TYPE c value space.

thanks.

Read only

Former Member
0 Likes
1,797

hiii

try using Respecting blanks statement like below code.

data:
material type mara-matnr value '  ',
batchno(6) type c value ' 1',
w_string(24) type c.

concatenate material batchno into w_string respecting blanks.

write : w_string.

regards

twinkal

Read only

0 Likes
1,797

Hi,

thank you all. The responses were helpful, I wish I could give you all full points.

I found out that I was using after that a CONCATENATE statement but without RESPECTING BLANKS addition (we have ecc 5.0) and that was the cause. Time for a coffee

Regards,

Ladislav

Read only

rainer_hbenthal
Active Contributor
0 Likes
1,797

Charactervariables have always a fixed length, so even when they are initial they contain spaces. If you store 5 Character in a c-Var length 10, it will contain 5 spaces at the end. So how should the compiler decide if these spaces at the end belongs to the content or are just there becase of the fixed length? He cant decide, so he always cuts off spaces at the end.

Strings do have a variable length and it is stored with a length counter. Spaces at the end are always taken into account.

Assume you habe this content: "XYZ##" (# and _ will indicate spaces. If you put that into a c(10) field you will have "XYZ##_____". Cause there is no length indicator you can not decide if the spaces belongs to the content or belongs to the fill up. A string variable will contain "XYZ##" and its clear that the spaces belongs to the content.

The disadvantage of strings is that they are incompatible with a lot of function modules and because they are deep structures they arent allowed in RFC function modules.

Besides that i'm only using strings instead of c fields.

Read only

0 Likes
1,797

this works only when you want to output to the file.

BEGIN OF ls_abody, "25

matnr TYPE mast-matnr,

rtype TYPE c,

seque(3),

bmein TYPE stko-bmein,

dummy(92),

pb(02) VALUE cl_abap_char_utilities=>cr_lf,

END OF ls_abody.

In this case say we want 94 spaces. so we make a field dummy of length 92 and then make a pagebreak variable of length two. In my interface I transfer internal tables of different structures and the requirement is that all lines are of equal length.

Edited by: Maksims Jegorovcevs on Feb 10, 2009 11:37 AM