Skip to Content

ALV Tree- Negative Values are not alligned

Hi All,

I created a custom ABAP report using ALV Tree Layout and I have a problem with numbers in ALV Tree column. Since numbers by default are right hand side aligned and by default negative numbers have the negative sign to the right hand side, when negative and positive values are into the same column on an ALV Tree layout the number alignment includes the sign so the decimal values are never aligned between each others, something like this:



Notice in the image below how the "positive" value is not aligned among the other values.

I am using the class CL_GUI_ALV_TREE.

Thanks in advance

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Feb 22, 2019 at 04:07 PM

    Technically, the ALV tree is an adaptation of the CL_GUI_COLUMN_TREE control (which is not an ALV at all), so the control completely ignores the data types, it handles them all like texts, so the left and right spaces are ignored. If you compare with the CL_GUI_ALV_GRID control, there is a space for the sign for positive numbers because the control considers the data types.

    There is a trick but you must change the standard control class (it will recompile all standard programs which use the control), a good place being at the end of method SET_ITEMS_FOR_COLUMN in class CL_ALV_TREE_BASE, add a non-breaking space (U+00A0) :

      IF sy-cprog(1) = 'Z'                            " limit risks - only Z programs
            AND is_fieldcatalog-inttype = 'P'         " packed field (DEC, CURR, QUAN)
            AND is_fieldcatalog-no_sign = abap_false. " only signed numeric fields
        LOOP AT et_items ASSIGNING FIELD-SYMBOL(<zz_item>).
          IF <zz_item>-text np '*-'. " add non breaking space only for positive numbers
            <zz_item>-text = <zz_item>-text && cl_abap_conv_in_ce=>uccpi( 160 ).

    But at your own risk - side effects unknown !! (personally, I wouldn't do it) It might not work in the Web Gui.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.