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

Type casting decimal and char

Former Member
0 Likes
3,257

I have a column in a report that needs to display both char values and type p decimals 3 (dataelemet labst) values.

What type should I define the field so it can hold both values ( 1.01 or PASS)

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,173

Rich

WRITE works to display it on the output. But i need to store it as a column for an ALV report and display it in ALV. It doesnt work there

I have a column in a report that needs to display both char values and type p decimals 3 (dataelemet labst) values.

What type should I define the field so it can hold both values ( 1.01 or PASS)

12 REPLIES 12
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,173

You should type it as CHAR, because if you try to pass PASS to a type p field, you will get an abap dump.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
2,173

I tried to type it as char16. But then it does not display any values on the report. Just blanks and zeros.

wa_char_results-mean_value type labst
wa_zbdprt_alv-mean_value type char16
wa_zbdprt_alv-mean_value = wa_char_results-mean_value.

Read only

0 Likes
2,173

When writing the numeric value to the field, please try doing this, this will apply the formatting.

write wa_char_results-mean_value to wa_zbdprt_alv-mean_value.

Regards,

RIch Heilman

Read only

0 Likes
2,173

Before passing ,please condense the value and move it.

wa_char_results-mean_value type labst

wa_zbdprt_alv-mean_value type char16

Condese wa_char_results-mean_value.

wa_zbdprt_alv-mean_value = wa_char_results-mean_value.

Thanks

Seshu

Read only

Former Member
0 Likes
2,173

write wa_char_results-mean_value to wa_zbdprt_alv-mean_value. does not work

When I CONDENSE, it works but it does not give me consistent number of decimal places. I need 3 decimal places. How to accomplish this.

Read only

0 Likes
2,173

Try making your character fields a little bigger. Like try 20 characters instead.

Then the WRITE may work a little better.

Regards,

Rich Heilman

Read only

0 Likes
2,173

Hi,

Try this.

data: lv_test(6) type p decimals 3,

lv_test2(10) type c.

lv_test = 900 / 27.

lv_test2 = lv_test.

condense lv_test2.

If you debug this code, you will see the exact solution i think.

Regards,

Reward points

Read only

0 Likes
2,173

For example this code works perfectly fine. No need to CONDENSE, just write the value to the field.



report zrich_0001 .


data:

    wa_char_results-mean_value type labst value '123456123.789',
    wa_zbdprt_alv-mean_value type char16.


write wa_char_results-mean_value to wa_zbdprt_alv-mean_value .


write:/ wa_zbdprt_alv-mean_value.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
2,174

Rich

WRITE works to display it on the output. But i need to store it as a column for an ALV report and display it in ALV. It doesnt work there

Read only

0 Likes
2,173

Oh boy, you didn't even try it did ya? the WRITE ... TO .... statement is used to write a value from one field to another and if required, apply formatting. So when you use the WRITE statement( the first one in my example above ) the system will write the value 123456123.789 to your character field like this. 123,456,123.789, now you can used this field(column) in your ALV, no problem, it will not write to the list display(the second WRITE in my examle above will, this was just for testing).

Regards,

Rich Heilman

Read only

Former Member
0 Likes
2,173

Rich

That worked!!!

I had tried the WRITE after your first post and it gave me the blank output which I used to get. Perhaps the program wasnt activated. But yeah you are right, no need to CONDENSE.

Thanks

Read only

0 Likes
2,173

I wouldn't steer ya wrong.

Regards,

Rich Heilman