on 2024 Nov 22 2:32 PM
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:
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[] ) ).
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
17 | |
10 | |
7 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.