1

I have ABAP code which works fine, if the report has data.

But if there is no data found, then I get:

GETWA_NOT_ASSIGNED

The error happens in the line marked with "**************"

" Let know the model"
cl_salv_bs_runtime_info=>set(
 EXPORTING
   display  = abap_false
   metadata = abap_false
   data     = abap_true
).

* WERKS = '0557'

data selection_table TYPE TABLE OF RSPARAMS.
data key_value TYPE wdy_key_value.
data selection_row TYPE RSPARAMS.

LOOP AT IV_STATIC_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 selection_table.
ENDLOOP.


SUBMIT (IV_REPORT_NAME)
   WITH SELECTION-TABLE selection_table
  AND RETURN.


DATA: lo_data        TYPE REF TO data.

cl_salv_bs_runtime_info=>get_data_ref(
      IMPORTING
        r_data = lo_data
).

field-SYMBOLS <lv_data> type any table.
ASSIGN lo_data->* TO <lv_data>.
ev_result_json = /ui2/cl_json=>serialize( 
  data = <lv_data> 
  pretty_name = /ui2/cl_json=>pretty_mode-low_case ). ********

cl_salv_bs_runtime_info=>clear_all( ).

What is the most feasible way to handle the case when the report does not find any data? Other improvements are appreciated

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
guettli
  • 25,042
  • 81
  • 346
  • 663

2 Answers2

3

After the assignment, check if the field symbol contains something:

ASSIGN lo_data->* TO <lv_data>.
IF <lv_data> IS NOT ASSIGNED.
  EXIT.
ENDIF.

Or, before ASSIGN, you can check if lo_data is bound:

IF lo_data IS NOT BOUND. 
  EXIT. 
ENDIF.
András
  • 1,326
  • 4
  • 16
  • 26
3

Here is what my code does:

  • code will only be executed if field symbol <lv_data> is assigned otherwise clear all.

  • table has some rows then transfer to data otherwise clear all.

    ASSIGN lo_data->* TO <lv_data>.
    IF <lv_data> IS ASSIGNED.
     IF lines( <lv_data> ) > 0.
      ev_result_json = /ui2/cl_json=>serialize( data = <lv_data> ).   
     ENDIF.
    cl_salv_bs_runtime_info=>clear_all( ).
    ENDIF.
    
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Umar Abdullah
  • 1,282
  • 1
  • 19
  • 37
  • You do the same answer as András (but you're less specific because you repeat the whole original code + corrections, without saying explicitly what is to be changed), so your answer does not add value. – Sandra Rossi Oct 31 '18 at 07:22
  • 3
    Andras answer will not clear runtime info only exit. There is some difference in my answer. I have also removed original code. Now correction and suggestion is there. – Umar Abdullah Oct 31 '18 at 07:48