Reputation: 531
Error in code.
*&---------------------------------------------------------------------*
*& Report ZSUBROUTINE_TABLES
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zsubroutine_tables.
TYPES : BEGIN OF line_type,
eno(3) TYPE n,
ename(30) TYPE c,
esal TYPE i,
END OF line_type.
DATA itab TYPE line_type OCCURS 10 WITH HEADER LINE.
DATA jtab TYPE STANDARD TABLE OF line_type.
**"DATA jtab TYPE line_type OCCURS 10 WITH HEADER LINE.**
PERFORM fill TABLES itab.
jtab = itab[].
PERFORM output TABLES jtab.
*&---------------------------------------------------------------------*
*& Form fill
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ITAB text
*----------------------------------------------------------------------*
FORM fill TABLES p_itab LIKE itab[].
p_itab-eno = '14'.
p_itab-ename = 'Aman'.
p_itab-esal = 3000.
APPEND p_itab.
p_itab-eno = '142'.
p_itab-ename = 'Raman'.
p_itab-esal = 5000.
APPEND p_itab.
ENDFORM. "fill
*&---------------------------------------------------------------------*
*& Form output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_JTAB text
*----------------------------------------------------------------------*
FORM output TABLES p_jtab LIKE jtab[].
LOOP AT p_jtab.
WRITE : / p_jtab-eno, p_jtab-ename, p_jtab-esal.
ENDLOOP.
ENDFORM. "output
The code in bold if uncommented raises error, why. In the commented code, Both itab and jtab are declared in a similar way. Error: The type of "ITAB" cannot be converted to the type of "JTAB".
Upvotes: 0
Views: 286
Reputation: 2565
Note that the two definitions of JTAB are different in the sense that the commented one has a header line while the other one has not. Because ITAB[] also has no header line the assignment of ITAB[] to JTAB will only work when JTAB has no header line. If you want to use the definition of JTAB with the header line you will need to assign ITAB directly to JTAB, no need for the hooked brackets.
Upvotes: 2