读写并插入内部表

使用标题行读取,写入和插入内部表:

" Read from table with header (using a loop):
LOOP AT i_compc_all.              " Loop over table i_compc_all and assign header line
  CASE i_compc_all-ftype.         " Read cell ftype from header line from table i_compc_all 
    WHEN 'B'.                     " Bill-to customer number transformation
      i_compc_bil = i_compc_all.  " Assign header line of table i_compc_bil with content of header line i_compc_all
      APPEND i_compc_bil.         " Insert header line of table i_compc_bil into table i_compc_bil
    " ... more WHENs
  ENDCASE.
ENDLOOP.

提醒:在面向对象的上下文中禁止带有标题行的内部表。始终建议使用不带标题行的内部表。

在没有标题行的情况下读取,写入和插入内部表:

" Loop over table i_compc_all and assign current line to structure i_compc_all_line
LOOP AT i_compc_all INTO i_compc_all_line.      
  CASE i_compc_all_line-ftype.                " Read column ftype from current line (which as assigned into i_compc_all_line)
    WHEN 'B'.                                 " Bill-to customer number transformation
      i_compc_bil_line = i_compc_all_line.    " Copy structure
      APPEND i_compc_bil_line TO i_compc_bil. " Append structure to table
    " more WHENs ...
  ENDCASE.
ENDLOOP.

" Insert into table with Header:
INSERT TABLE i_sap_knb1.                      " insert into TABLE WITH HEADER: insert table header into it's content
insert i_sap_knb1_line into table i_sap_knb1. " insert into HASHED TABLE: insert structure i_sap_knb1_line into hashed table i_sap_knb1
APPEND p_t_errorlog_line to p_t_errorlog.     " insert into STANDARD TABLE: insert structure / wa p_t_errorlog_line into table p_t_errorlog_line