Code: Alles auswählen.
DATA: lt_mara1 TYPE TABLE OF mara,
lt_mara2 TYPE TABLE OF mara WITH HEADER LINE,
lr_type_descr1 TYPE REF TO cl_abap_typedescr,
lr_type_descr2 TYPE REF TO cl_abap_typedescr.
lr_type_descr1 ?= cl_abap_typedescr=>describe_by_data( lt_mara1 ).
lr_type_descr2 ?= cl_abap_typedescr=>describe_by_data( lt_mara1[] ).
IF ( lr_type_descr1->kind = lr_type_descr1->kind_table ) AND ( lr_type_descr2->kind = lr_type_descr2->kind_table ).
" Zwangsläufig beides "Table" -> also keine Kopfzeile
WRITE:/ 'lt_mara1 ist ohne Header'.
ELSEIF ( lr_type_descr1->kind = lr_type_descr2->kind_struct ) AND ( lr_type_descr2->kind = lr_type_descr2->kind_table ).
" Das eine ist Struktur, das andere Table, also Kopfzeile
WRITE:/ 'lt_mara1 ist mit Header'.
ENDIF.
lr_type_descr1 ?= cl_abap_typedescr=>describe_by_data( lt_mara2 ).
lr_type_descr2 ?= cl_abap_typedescr=>describe_by_data( lt_mara2[] ).
IF ( lr_type_descr1->kind = lr_type_descr1->kind_table ) AND ( lr_type_descr2->kind = lr_type_descr2->kind_table ).
" Zwangsläufig beides "Table" -> also keine Kopfzeile
WRITE:/ 'lt_mara2 ist ohne Header'.
ELSEIF ( lr_type_descr1->kind = lr_type_descr2->kind_struct ) AND ( lr_type_descr2->kind = lr_type_descr2->kind_table ).
" Das eine ist Struktur, das andere Table, also Kopfzeile
WRITE:/ 'lt_mara2 ist mit Header'.
ENDIF.
Code: Alles auswählen.
GET REFERENCE OF ITAB INTO dref1.
GET REFERENCE OF ITAB[] INTO dref2.
IF dref1 = dref2.
* ohne Kopfzeile
else.
* mit Kopfzeile
endif.
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag (Insgesamt 2):
Somani • ewx
ABAP Compiler hat geschrieben:"ITAB" und "ITAB" dürfen nicht verglichen werden.
Code: Alles auswählen.
REPORT ZTEST5.
TYPES: BEGIN OF BEST,
PLANR TYPE C,
END OF BEST.
DATA: T1 TYPE TABLE OF BEST WITH HEADER LINE,
T2 TYPE TABLE OF BEST.
PERFORM TEST USING T1 T1{}. " geschweifte Klammern, weil eckige in den Forums-code-Tags nicht funktionieren.
*&---------------------------------------------------------------------*
*& Form TEST USING T1 TYPE ANY T2 TYPE ANY
*&---------------------------------------------------------------------*
FORM TEST USING T1 TYPE ANY T2 TYPE ANY.
TRY.
IF T1 = T2.
WRITE 'yes'.
ENDIF.
CATCH CX_ROOT.
WRITE 'no'.
ENDTRY.
ENDFORM.
Code: Alles auswählen.
REPORT ZTEST5.
TYPES: BEGIN OF BEST,
PLANR TYPE C,
END OF BEST.
DATA: T1 TYPE TABLE OF BEST WITH HEADER LINE.
PERFORM TEST USING T1.
*&---------------------------------------------------------------------*
*& Form TEST USING T1 TYPE ANY
*&---------------------------------------------------------------------*
FORM TEST USING T1 TYPE ANY.
FIELD-SYMBOLS <T> TYPE TABLE.
ASSIGN T1 TO <T>.
IF SY-SUBRC = 0.
WRITE 'yes'.
ELSE.
WRITE 'no'.
ENDIF.
ENDFORM.