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: 

ALV column with variable number of decimals to be displayed

Former Member
0 Kudos

Hi,

I've an ALV where I need to display a numeric column with a variable number of decimal row-by-row, from 0 (no decimals) to 4.

I've declared the numeric field as TYPE P DECIMALS 4.

I've tried with DECMLFIELD in ALV catalog, and this works for 1 to n decimals, but when I leave the field indicated in DECMLFIELD equal to 0, ALV shows the default number of decimals of the field (4 in that case).

Any help will be very appreciated.

Thanks.

Jordi

1 ACCEPTED SOLUTION

former_member226519
Active Contributor
0 Kudos

create an output structure where your field is CHAR type and WRITE the type P field to it.

8 REPLIES 8

former_member226519
Active Contributor
0 Kudos

create an output structure where your field is CHAR type and WRITE the type P field to it.

0 Kudos

Hi,

thanks. I've tried this and works for display, but then I lost the abbility to do SUM to that column. Also, I've tried to assign a DEC type in DATATYPE (ALV field catalog), and that solved the problem with the SUM but leaves another problem: Filter does not work (I'm able to enter a filter but value is not recognized correctly).

So, I was going not to use a CHAR type column, but a Numeric one.

Thanks anyway for your quick answer.

former_member226519
Active Contributor
0 Kudos

did you try EDIT_MASK ?

0 Kudos

No, I didn't try EDIT_MASK.

How should I use it to format output to display decimals or not depending on the row?

I have 2 kinds of values, all stored in a TYPE P DECIMALS 4: Those that really are an integer (decimals should not be displayed for that ones) and the values that really have 4 decimals (which should be displayed with decimals in ALV).

Example:

13,0000 should be displayed as 13

0,4567 should be displayed as 0,4567

With EDIT_MASK could I do that?

Thank you very much.

0 Kudos

jordi08028 ,

have you tried the field catalog parameter:

NO_ZERO LVC_NOZERO CHAR 1 0 ALV control: Suppress zeros for output

Bruce

0 Kudos

Hi Bruce,

NO_ZERO is to avoid display of Initial values (zero, 0), but does not work for what I need.

Anyway, thank you for your answer.

0 Kudos

Create FM CONVERSION_EXIT_ABCDE_OUTPUT with something like that:


data tmp type string.

tmp = input.

shift tmp right delete trailing '0'.

output = tmp.

Then set column edit mask to ==ABCDE.

Former Member
0 Kudos

Hello Jordi

The field that you use to indicate the decimals is the wrong type, you most likely defined it as an integer which would make sense but the ALV grid has a bug in it in the sense that it ignores your decimal field when it is initial (for integer fields this would be zero). As an example:

BEGIN OF mty_s_data,

         amount TYPE betrg,

         currency TYPE waers,

         decimals TYPE int4,          "<== This will not work since zero is seen as initial.

END OF mty_s_data,

Anyway define your decimal field to be a char type, e.g. char5, and then use it again. Zero would now be seen as non-initial and the ALV grid will use it to format your data. Example correct usage to work around ALV bug:

BEGIN OF mty_s_data,

         amount TYPE betrg,

         currency TYPE waers,

         decimals TYPE c LENGTH 5,

END OF mty_s_data,

Good luck, Ettienne