Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

CL_SALV_TABLE with dynamin table: typing issue

Hi, everyone.

I need help in solving the following issue. Consider the code:

DATA: lr_table TYPE REF TO STANDARD TABLE,

      lo_salv TYPE REF TO cl_salv_table.

FIELD-SYMBOLS: <lt_table> TYPE TABLE.

GET REFERENCE OF some_table INTO lr_table.

ASSIGN lr_table->* TO <lt_table>.

cl_salv_table=>factory(

  IMPORTING r_salv_table = lo_salv

  CHANGING t_table = <lt_table> ).

This code throws an exception on FACTORY method: the T_TABLE parameter is said to have invalid type. Meanwhile, under debugger I can see that this field-symbol points to a valid standard table.

Now I try to use a specific internal table instead of generic reference:

DATA: lt_table TYPE STANDARD TABLE OF some_thing,

      lo_salv TYPE REF TO cl_salv_table.


FIELD-SYMBOLS: <lt_table> TYPE TABLE.

ASSIGN lt_table TO <lt_table>.


cl_salv_table=>factory(

  IMPORTING r_salv_table = lo_salv

  CHANGING t_table = <lt_table> ).


  And now it works like a charm, while the field-symbol type remains the same. BTW, the lt_table in this example is the same table, that is referenced by lr_table in the first code snippet.

So, the question is: what am I doing wrong in the first code sample? Why is field-symbol considered invalid?

Thank you in advance.

Tags:
replied

Hello Alex.

The problem is, that the CONSTRUCTOR has an IMPORTING parameter. You can not change an importing parameter and so you also cannot change a reference of it. The factory-method uses the parameter as CHANGING and that causes the dump. A working solution is this. Use a method with a changing parameter instead of the constructor and it will work:

CLASS lcl_my_class DEFINITION.

  PUBLIC SECTION.

    METHODS: set_data   CHANGING im_data TYPE STANDARD TABLE, "<-----

             show_grid.

  PRIVATE SECTION.

    DATA: mr_data TYPE REF TO data.

ENDCLASS.                    "lcl_my_class DEFINITION

CLASS lcl_my_class IMPLEMENTATION.

  METHOD set_data.

    GET REFERENCE OF im_data INTO me->mr_data.

  ENDMETHOD.   

               

  METHOD show_grid.

    DATA: lo_grid TYPE REF TO cl_salv_table.

    FIELD-SYMBOLS: <lt_data> TYPE table.

    ASSIGN me->mr_data->* TO <lt_data>.

    cl_salv_table=>factory( IMPORTING r_salv_table = lo_grid

                            CHANGING  t_table      = <lt_data> ).

    lo_grid->display( ).

  ENDMETHOD.                    "show_grid

ENDCLASS.                    "lcl_my_class IMPLEMENTATION

START-OF-SELECTION.

  DATA: lo_cls   TYPE REF TO            lcl_my_class,

            lt_table TYPE STANDARD TABLE OF vbak.

  CREATE OBJECT lo_cls.

  lo_cls->set_data( CHANGING im_data = lt_table ).  "<-----

  lo_cls->show_grid( ).

regards,

Peer.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question