简体   繁体   English

在ABAP中复制内部表

[英]Copying Internal Tables in ABAP

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. 在注释的代码中,itab和jtab都以类似的方式声明。 Error: The type of "ITAB" cannot be converted to the type of "JTAB". 错误:无法将“ ITAB”的类型转换为“ JTAB”的类型。

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. 请注意,JTAB的两种定义是不同的,因为注释的一个具有标题行,而另一个没有。 Because ITAB[] also has no header line the assignment of ITAB[] to JTAB will only work when JTAB has no header line. 因为ITAB []也没有标题行,所以将ITAB []分配给JTAB仅在JTAB没有标题行时起作用。 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. 如果要在标题行中使用JTAB的定义,则需要直接将ITAB分配给JTAB,而无需使用钩括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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