cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Pass select-options by reference

dschiener
Participant
0 Kudos
173

Hi there,

I want to pass a range table initialized by select-options by reference to an object.

Unfortunately, I receive a syntax error according to a type mismatch, and I don't know why.

Sure, the range table of select-options are declared with header line.
But even if I skip the header line and perform a direct access to the table body, it does not work...

Can anyone help out?

Restrictions:

  1. I would like to prefer a non generic solution. So any solution NOT based on TYPE REF TO data.
  2. I am not interessted in any obscure function modules like REFRESH_SELECT_OPTIONS or any like that.

Here is my coding to test:

DATA time_period TYPE d.

SELECT-OPTIONS s_timper FOR time_period NO-EXTENSION.

CLASS class DEFINITION
  FINAL
  CREATE PRIVATE.

  PUBLIC SECTION.
    TYPES period_range TYPE RANGE OF d.

    CLASS-METHODS by_reference
      IMPORTING
        period TYPE REF TO period_range.

    CLASS-METHODS by_value
      IMPORTING
        period TYPE period_range.

    CLASS-METHODS by_reference_like
      IMPORTING
        period LIKE REF TO s_timper[].
ENDCLASS.

CLASS class IMPLEMENTATION.
  METHOD by_reference.
    DATA(tmp) = period.
  ENDMETHOD.

  METHOD by_reference_like.
    DATA(tmp) = period.
  ENDMETHOD.

  METHOD by_value.
    DATA(tmp) = period.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  " Works!
  class=>by_value( period = s_timper[] ).
  
  " ERROR
  " type period = range of d with header line
  " type s_timper = range of d
  class=>by_reference( period = REF #( s_timper[] ) ).
  
  " Works
  class=>by_reference_like( period = REF #( s_timper[] ) ).

Accepted Solutions (0)

Answers (1)

Answers (1)

holm
Participant
0 Kudos

Hi,

the types being referenced must be identical to assign a reference (or castable, not relevant here).
But the table type being defined implicitly by SELECT-OPTIONS is simply not the same as period_range, even if they are structurally identical.

Look at this example: 

    TYPES: tt_one   TYPE RANGE OF d,
           tt_two   TYPE RANGE OF d,
           tr_one   TYPE REF TO tt_one,
           tr_two   TYPE REF TO tt_two,
           tr_three TYPE REF TO tt_two.

    DATA: a TYPE tr_one,
          b TYPE tr_two,
          c TYPE tr_three.

    a = b.  " The type of "B" cannot be converted to the type of "A"     
    b = c.  " fine

If you really need a reference (probably to manipulate the contents?), i would pass the select-options as changing parameter (preferably to the constructor) and get the REF inside.

BR,
holm