abapalv

Detect color column in ALV-grid


I am exporting reports with this abap function in json format

cl_salv_bs_runtime_info=>set(
 EXPORTING
   display  = abap_false
   metadata = abap_false
   data     = abap_true
).


data selection_table TYPE TABLE OF RSPARAMS.

PERFORM GET_REPORT_READ_PARAMETER
    USING IV_DYNAMIC_PARAMETER_LIST
   CHANGING selection_table.


if IV_SELECTION_SET_VARIANT is INITIAL.
  SUBMIT (IV_REPORT_NAME)
     WITH SELECTION-TABLE selection_table
    AND RETURN.
ELSE.
  SUBMIT (IV_REPORT_NAME)
     WITH SELECTION-TABLE selection_table
     USING SELECTION-SET IV_SELECTION_SET_VARIANT
    AND RETURN.
endif.


FIELD-SYMBOLS <lt_data>             TYPE ANY TABLE.
FIELD-SYMBOLS <lt_data_line>        TYPE ANY TABLE.

DATA          lr_data               TYPE REF TO data.
DATA          lr_data_line          TYPE REF TO data.
DATA          lr_data_descr          TYPE REF TO cl_abap_datadescr.
DATA          lr_data_line_descr    TYPE REF TO cl_abap_datadescr.

cl_salv_bs_runtime_info=>get_data_ref(
     IMPORTING r_data_descr      = lr_data_descr
               r_data_line_descr = lr_data_line_descr ).

IF lr_data_descr IS NOT BOUND.
  ev_result_json = '[]'.
  EXIT.
ENDIF.


CREATE DATA lr_data         TYPE HANDLE lr_data_descr.
CREATE DATA lr_data_line    TYPE HANDLE lr_data_line_descr.

ASSIGN lr_data->*           TO <lt_data>.
ASSIGN lr_data_line->*      TO <lt_data_line>.

DATA lx_runtime_info TYPE REF TO cx_salv_bs_sc_runtime_info.

TRY.

* hierarchical report

  cl_salv_bs_runtime_info=>get_data(
    IMPORTING
      t_data      = <lt_data>
      t_data_line = <lt_data_line>
         ).
  ev_result_json = /ui2/cl_json=>serialize( data = <lt_data_line> pretty_name = /ui2/cl_json=>pretty_mode-low_case ).

CATCH cx_salv_bs_sc_runtime_info INTO lx_runtime_info.
* normal (flat) report
  cl_salv_bs_runtime_info=>get_data(
    IMPORTING
      t_data      = <lt_data>
         ).
  ev_result_json = /ui2/cl_json=>serialize( data = <lt_data> pretty_name = /ui2/cl_json=>pretty_mode-low_case ).

ENDTRY.
cl_salv_bs_runtime_info=>clear_all( ).

ENDFUNCTION.


FORM GET_REPORT_READ_PARAMETER
  USING parameter_list TYPE  WDY_KEY_VALUE_LIST
  CHANGING sel_table TYPE RSPARAMS_TT.


data key_value TYPE wdy_key_value.
data key_value2 TYPE wdy_key_value.
data selection_row TYPE RSPARAMS.

LOOP AT parameter_list INTO key_value.
    selection_row-selname = key_value-key.
    selection_row-low = key_value-value.
    selection_row-sign = 'I'.
    selection_row-option = 'EQ'.
   APPEND selection_row to sel_table.
ENDLOOP.

ENDFORM.

The tabluar JSON result contains a column called "farbe". Which is german in means "color". Here the content of this column. AFAIK there is a dict for every row of the tabular result.

[
  {
    "color": {
      "int": 0, 
      "inv": 0, 
      "col": 0
    }, 
    "fieldname": "LABST", 
    "nokeycol": ""
  }, 
  {
    "color": {
      "int": 0, 
      "inv": 0, 
      "col": 0
    }, 
    "fieldname": "MEINS", 
    "nokeycol": ""
  }, 
 ....
 ]

I would like to remove this column called "farbe", but I would like this to work for all sap reports.

I am unsure if this column is called different on a non German system. Maybe it is called "color" in English system?

How to find the column name (in this case "farbe") which contains the not needed color information?

P.S. How to filter the JSON is not part of the question


Solution

  • You can't know the names used in the ALVs, that may differ from a report to another.

    In your code, cl_salv_bs_runtime_info=>get_data_ref returns a pointer to a copy of the internal table storing the data of the ALV grid.

    If there are some colors in the ALV grid, there can be several options:

    NB: the question is column-oriented, so I didn't talk about whole lines which can be colorized by using a field in the internal table whose name is indicated in the field info_fname of the metadata layout; the field in the internal table should be of type lvc_emphsz.