Copying Internal Tables in ABAP

*&---------------------------------------------------------------------*
*& 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".
gram77Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Onn LightSAP Technical ConsultantCommented:
Dear gram77

If you want to declare variable jtab as below

DATA jtab TYPE line_type OCCURS 10 WITH HEADER LINE.

Open in new window


than the assignment statement
jtab = itab[].

Open in new window

will need to be changed to
jtab[] = itab[].

Open in new window


This is due to the HEADER LINE clause in the Data declaration clause for jtab.

According to SAP help



... WITH HEADER LINE ...



Effect

This addition to the statements DATA TABLE OF, DATA RANGE OF, and the obsolete statement DATA OCCURS (which is not allowed in classes) declares a further data object alongside the internal table, known as the header line. This object has exactly the same name as the internal table and has the row type of the internal table as its data type. A header line cannot be declared for internal tables with a table-like row type. This is possible for structured row types with table-like components, however.

If you specify the name of an internal table itab in an operand position of an ABAP statement, the statement determines whether the table body or header line is used. As a rule, all table-specific statements such as SORT or LOOP use the internal table, whereas all other statements use the header line. Exceptions to this rule are listed under Internal Tables with Header Line.

To address the table body instead of the header line in statements, you can append [] to the table name:

... itab[] ...

For internal tables without a header line, the table body is always used. An internal table with a header line cannot be a component of a structure or a row of another internal table.



Thanks and Regards
onn
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gram77Author Commented:
Excellent.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SAP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.