简体   繁体   中英

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?

PS How to filter the JSON is not part of the question

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

If there is a color column in an ALV grid, it will be of type LVC_T_SCOL . So you may detect it by using an RTTI class like CL_ABAP_TYPEDESCR.

Of course, a general method working for all reports to get the color column in ALVs won't work if:

  • Some ALVs don't output any color at all (so possibly no color column)
  • Only columns of ALVs are colorized, it doesn't need a color column, instead the field catalog is used to set the color.
  • Many reports don't even produce an ALV of type "grid" (which is your case). Some reports use ALV lists (same kind of remarks than above but the type of the color column is different).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM