Skip to Content
avatar image
Former Member

GET REFERENCE OF Select-Options INTO range table

Hello gurus,

Does anyone know why I cannot get the refence of a Select-Options into a range table?

Example:

TYPES: ty_r_matnr TYPE RANGE OF matnr.

DATA: lv_matnr TYPE        matnr,
      lr_matnr TYPE REF TO ty_r_matnr.

SELECT-OPTIONS: s_matnr FOR lv_matnr.


AT SELECTION-SCREEN OUTPUT.

  GET REFERENCE OF s_matnr[] INTO lr_matnr.

This previous code does not compile.

Thanks a lot!,

Eloi

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Feb 02, 2017 at 07:44 AM

    I tend to think that you found a bug. Your program should work as written above.

    I tested as follows:

    DATA number TYPE i.
    TYPES: BEGIN OF linetype,
             sign   TYPE c LENGTH 1,
             option TYPE c LENGTH 2,
             low    LIKE number,
             high   LIKE number,
           END OF linetype.
    
    DATA range1 LIKE RANGE OF number.
    DATA range2 TYPE TABLE OF linetype.
    DATA range3 TYPE TABLE OF linetype WITH HEADER LINE.
    SELECT-OPTIONS seltab FOR number.
    
    DATA dref1 LIKE REF TO range1.
    DATA dref2 LIKE REF TO range2.
    DATA dref3 LIKE REF TO range3[].
    DATA dref4 LIKE REF TO seltab[].
    
    "GET REFERENCE OF seltab[] INTO dref1. "Syntax error
    "GET REFERENCE OF seltab[] INTO dref2. "Syntax error
    "GET REFERENCE OF seltab[] INTO dref3. "Syntax error
    GET REFERENCE OF seltab[] INTO dref4. "OK
    
    dref1 = dref4. "OK
    dref2 = dref4. "OK
    dref3 = dref4. "OK
    
    BREAK-POINT.
    

    Since you can assign the reference to the table body of seltab via an up cast to the reference variables of ranges tables, this should also work directly with GET REFERENCE.

    B.t.w., it is not because of the header line.

    DATA itab1 TYPE TABLE OF scarr.
    DATA itab2 TYPE TABLE OF scarr WITH HEADER LINE.
    
    DATA dref1 LIKE REF TO itab1.
    DATA dref2 LIKE REF TO itab2[].
    
    GET REFERENCE OF itab2[] INTO dref1. "OK
    GET REFERENCE OF itab2[] INTO dref2. "OK
    
    

    I'll report the strange behavior to kernel development.

    Thanks for notifying.

    Add comment
    10|10000 characters needed characters exceeded

    • Yeah, kind of confusing. We even had a meeting about that today to get our thoughts straight.

      Up and down cast come into play, because assignments of data reference variables are treated exactly like those of object reference variables. And since we have only one "generic" type, DATA, for data references, all other types must be exactly the same for assignable data reference variables (remember, object reference variables of classes from different inheritance trees cannot be assigned, even if the classes have exactly the same components).

      This design decision might be questionable, a cast for data references could also be something else, but that's how it is.

  • Feb 01, 2017 at 03:07 PM

    Hi:

    You're issue is that lr_matnr is type ty_r_matnr which is a structure not a table thus you try to assign the reference of a table to it.... :)

    That should do the trick:

    TYPES: ty_t_matnr type table of ty_r_matnr

    DATA: lr_matnr type ref to ty_t_matnr

    Best,

    Antoine

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 01, 2017 at 05:11 PM

    The problem seems to be, although having the same components, the types of the ranges table and the body of the selection table are regarded as different.

    I'll look into that tomorrow. Because according to http://help.sap.com/abapdocu_751/en/index.htm?file=abenconversion_references_data.htm and the documentation of GET REFERENCE one might expect it to work.

    Independent of that, a

    DATA dref LIKE REF TO seltab[ ] should work.

    Add comment
    10|10000 characters needed characters exceeded