Displaying a table with cl_salv_table: "itab is not type compatible with formal parameter t_table"

1.3k views Asked by At

I need to display an internal table with cl_salv_table. Currently I take the bkpf table, cut out three columns and insert them into the internal table. But now it's saying that the parameter and lt_bkpf are type-incompatible.

Here is my Code:

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 5(15) p_name1 FOR FIELD p_blart.
PARAMETERS: p_blart TYPE blart.

SELECTION-SCREEN END OF LINE.

AT SELECTION-SCREEN OUTPUT.
  p_name1 = 'Belegart'.

INITIALIZATION.
  p_blart = 'DD'. "Set default value
END-OF-SELECTION.

Data:
BEGIN OF gt_bkpf OCCURS 0,
  bukrs LIKE bkpf-bukrs,
  blart LIKE bkpf-blart,
  gjahr LIKE bkpf-gjahr,
END OF gt_bkpf.

SELECT bukrs, blart, gjahr
  FROM bkpf
  WHERE blart LIKE @p_blart
  INTO CORRESPONDING FIELDS OF @gt_bkpf.
ENDSELECT.

cl_salv_table=>factory( IMPORTING r_salv_table = go_table
                        CHANGING t_table = gt_bkpf ).

  go_table->display( ).
1

There are 1 answers

3
József Szikszai On BEST ANSWER

The internal table is declared with header line (because of OCCURS), this is obsolete and not supported in OO environment. You have to declare the table like this:

TYPES: BEGIN OF ty_bkpf,
  bukrs TYPE bkpf-bukrs,
  blart TYPE bkpf-blart,
  gjahr TYPE bkpf-gjahr,
END OF ty_bkpf.

DATA: lt_bkpf TYPE STANDARD TABLE OF ty_bkpf.

Please note the LIKE is also replaced by TYPE.