Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Totalling the columns in ALV Grid

Hello All,

I have a output with amount and currencies. The problem i am facing is, the amount is in USD and in GBP and it is giving me single value. It is not splitting the USD amount from the GBP amount.

Also, I am doing a subtotal based on material. This is the most important requirement.

Can anybody help me out in this.

Thanks,

Salil

I am giving the below piece of code if you want to refer it.

  DATA: gr_alv        TYPE REF TO cl_salv_table,
        lr_display    TYPE REF TO cl_salv_display_settings,
        lr_columns    TYPE REF TO cl_salv_columns_table,
        lr_column     TYPE REF TO cl_salv_column_table,
        lr_functions  TYPE REF TO cl_salv_functions_list,
        lr_sorts      TYPE REF TO cl_salv_sorts,
        lr_print      TYPE REF TO cl_salv_print,
        lr_column_f   TYPE REF TO cl_salv_columns,
        gr_error      TYPE REF TO cx_salv_not_found ,
        lr_layout     TYPE REF TO cl_salv_layout.

  DATA: key     TYPE salv_s_layout_key,
        gr_msg  TYPE string.

  IF NOT lt_output[] IS INITIAL.
    TRY.
* Create ALV instance - use CALL METHOD since this is a static method
        CALL METHOD cl_salv_table=>factory
          IMPORTING
            r_salv_table = gr_alv
          CHANGING
            t_table      = lt_output.

        lr_display = gr_alv->get_display_settings( ).
        lr_display->set_list_header( text-ttl ).

* Get functions object and then set all the functions to be allowed
        lr_functions = gr_alv->get_functions( ).
        lr_functions->set_all( ).

        DATA: lv_field TYPE lvc_fname.
* Get column settings object and then optimize the column widths to the
* data
        lr_columns = gr_alv->get_columns( ).
        lr_columns->set_optimize( ).

*--- set column header for custom field Difference in Qty
        TRY.
            lr_column ?= lr_columns->get_column( 'BUCHM2' ).
            lr_column->set_output_length('12').
            lr_column->set_long_text( 'Diff Qty' ).
            lr_column->set_short_text( 'Diff Qty' ).
            lr_column->set_medium_text( 'Diff Qty' ).
          CATCH cx_salv_not_found INTO gr_error.
            gr_msg = gr_error->get_text( ).
            MESSAGE gr_msg TYPE 'I'.
        ENDTRY.

*--- set column header for custom field Difference in Qty Abs
        TRY.
            lr_column ?= lr_columns->get_column( 'BUCHM3' ).
            lr_column->set_output_length('13').
            lr_column->set_long_text( 'Diff Qty(Abs)' ).
            lr_column->set_medium_text( 'Diff Qty(Abs)' ).
*            lr_column->set_short_text( 'Diff Qty(Abs)' ).
          CATCH cx_salv_not_found INTO gr_error.
            gr_msg = gr_error->get_text( ).
            MESSAGE gr_msg TYPE 'I'.
        ENDTRY.

*--- set column header for custom field Difference in Value
        TRY.
            lr_column ?= lr_columns->get_column( 'VALUE' ).
            lr_column->set_output_length('15').
            lr_column->set_long_text( 'Value Diff' ).
            lr_column->set_medium_text( 'Value Diff' ).
            lr_column->set_short_text( 'Value Diff' ).
          CATCH cx_salv_not_found INTO gr_error.
            gr_msg = gr_error->get_text( ).
            MESSAGE gr_msg TYPE 'I'.
        ENDTRY.

*--- set column header for custom field Difference in Value Abs
        TRY.
            lr_column ?= lr_columns->get_column( 'VALUE_ABS' ).
            lr_column->set_output_length('15').
            lr_column->set_long_text( 'Value Diff(Abs)' ).
            lr_column->set_medium_text( 'Value Diff(Abs)' ).
          CATCH cx_salv_not_found INTO gr_error.
            gr_msg = gr_error->get_text( ).
            MESSAGE gr_msg TYPE 'I'.
        ENDTRY.

*--- set column header for custom field Status
        TRY.
            lr_column ?= lr_columns->get_column( 'STATUS' ).
            lr_column->set_output_length('15').
            lr_column->set_long_text( 'PI Item Status' ).
            lr_column->set_medium_text( 'PI Item Status' ).
          CATCH cx_salv_not_found INTO gr_error.
            gr_msg = gr_error->get_text( ).
            MESSAGE gr_msg TYPE 'I'.
        ENDTRY.

*--- set column header for custom field Status
        TRY.
            lr_column ?= lr_columns->get_column( 'TOTAL' ).
            lr_column->set_output_length('15').
            lr_column->set_long_text( 'Total Value Diff' ).
            lr_column->set_medium_text( 'Total Value Diff' ).
          CATCH cx_salv_not_found INTO gr_error.
            gr_msg = gr_error->get_text( ).
            MESSAGE gr_msg TYPE 'I'.
        ENDTRY.

* Optimize the column widths for printing.
        lr_print = gr_alv->get_print( ).
        lr_print->set_print_parameters_enabled( value = 'X' ).
        lr_print->set_column_optimization( value = 'X' ).

*--- This code is to get the layout,save the layout and display the
*    layout
        lr_layout = gr_alv->get_layout( ).
        lr_layout->set_default( cl_salv_layout=>true ).  " allow default
        key-report = sy-repid.
        lr_layout->set_key( key ).
       lr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).

        DATA: init_layout TYPE slis_vari.
        init_layout = p_layout.
        lr_layout->set_initial_layout( init_layout ).

*--- display report
        gr_alv->display( ).

      CATCH cx_salv_msg.
        WRITE: 'Error displaying grid! - cx_salv_msg'.

      CATCH cx_salv_not_found.
        WRITE: 'Error displaying grid! - cx_salv_not_found'.

      CATCH cx_salv_data_error.
        WRITE: 'Error displaying grid! - cx_salv_data_error'.

      CATCH cx_salv_existing.
        WRITE: 'Error displaying grid! - cx_salv_existing'.
    ENDTRY.
  ELSE.
    MESSAGE s004.
  ENDIF.

Tags:
Not what you were looking for? View more on this topic or Ask a question