简体   繁体   中英

Sorted table with parameter t_table of cl_salv_table class

If I use the internal table as a standard table the parameter T_TABLE accepts normally, but when I declare as a sorted table this error happen: "ITUSER" is not type-compatible with formal parameter "T_TABLE".

Can you guys help me identify why this happens?

TABLES: USER_ADDR,USR41.

TYPES: BEGIN OF LINE02_TYPE,
         Z_BNAME TYPE USER_ADDR-BNAME,
         Z_NAME  TYPE USER_ADDR-NAME_FIRST,
         Z_LAST  TYPE USER_ADDR-NAME_LAST,
         Z_TERMI TYPE USR41-TERMINAL,
         Z_LASTD TYPE USR41-LOGON_DATE,
         Z_KOSTL TYPE USER_ADDR-KOSTL,
       END OF LINE02_TYPE.

DATA: ITUSER  TYPE SORTED TABLE OF LINE02_TYPE WITH UNIQUE KEY Z_BNAME,
      "ITUSER TYPE standard TABLE OF line02_type,
      R_TABLE TYPE REF TO CL_SALV_TABLE.

START-OF-SELECTION.

  SELECT A~BNAME A~NAME_FIRST A~NAME_LAST B~TERMINAL B~LOGON_DATE A~KOSTL  FROM USER_ADDR AS A
    LEFT JOIN USR41 AS B ON B~BNAME = A~BNAME
     INTO TABLE ITUSER.

  CALL METHOD CL_SALV_TABLE=>FACTORY
    IMPORTING
      R_SALV_TABLE = R_TABLE
    CHANGING
      T_TABLE      = ITUSER.

  CALL METHOD R_TABLE->DISPLAY.

Unfortunately I do not see it is documented anywhere but T_TABLE has to be a STANDARD TABLE . If you dig deeper into FACTORY method the T_TABLE parameter is passed to SET_DATA method which requires the table as STANDARD TABLE

  try.
      r_salv_table->set_data(
        changing
          t_table = t_table ).
    catch cx_salv_no_new_data_allowed.                  "#EC NO_HANDLER
  endtry.

Moreover if you define the parameter as TABLE a STANDARD TABLE is implicitely meant. Here is the reference

As already pointed out, the signature for factory is changing t_table type table . TABLE is a generic ABAP type which is the old way to say STANDARD TABLE .

This is required since actions you perform via the ALV are reflected on the table itself. When you press the sort button the internal table will also be sorted (hence also changing ). So when you get eg the double click event, you can safely access my_table[ row ] since it's sorted in the same way as it's displayed to the user. Such a sorting cannot be represented in HASHED TABLE or SORTED TABLE (sort can be on any column/s).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM