
- SAP ABAP - Home
- SAP ABAP - Overview
- SAP ABAP - Environment
- SAP ABAP - Screen Navigation
- SAP ABAP - Basic Syntax
- SAP ABAP - Data Types
- SAP ABAP - Variables
- SAP ABAP - Constants & Literals
- SAP ABAP - Operators
- SAP ABAP - Loop Control
- SAP ABAP - Decisions
- SAP ABAP - Strings
- SAP ABAP - Date & Time
- SAP ABAP - Formatting Data
- SAP ABAP - Exception Handling
- SAP ABAP - Dictionary
- SAP ABAP - Domains
- SAP ABAP - Data Elements
- SAP ABAP - Tables
- SAP ABAP - Structures
- SAP ABAP - Views
- SAP ABAP - Search Help
- SAP ABAP - Lock Objects
- SAP ABAP - Modularization
- SAP ABAP - Subroutines
- SAP ABAP - Macros
- SAP ABAP - Function Modules
- SAP ABAP - Include Programs
- SAP ABAP - Open SQL Overview
- SAP ABAP - Native SQL Overview
- SAP ABAP - Internal Tables
- SAP ABAP - Creating Internal Tables
- ABAP - Populating Internal Tables
- SAP ABAP - Copying Internal Tables
- SAP ABAP - Reading Internal Tables
- SAP ABAP - Deleting Internal Tables
- SAP ABAP - Object Orientation
- SAP ABAP - Objects
- SAP ABAP - Classes
- SAP ABAP - Inheritance
- SAP ABAP - Polymorphism
- SAP ABAP - Encapsulation
- SAP ABAP - Interfaces
- SAP ABAP - Object Events
- SAP ABAP - Report Programming
- SAP ABAP - Dialog Programming
- SAP ABAP - Smart Forms
- SAP ABAP - SAPscripts
- SAP ABAP - Customer Exits
- SAP ABAP - User Exits
- SAP ABAP - Business Add-Ins
- SAP ABAP - Web Dynpro
SAP ABAP - Copying Internal Tables
When we read a record from an internal table with a header line, that record is moved from the table itself into the header line. It is then the header line that our program works with. The same applies while creating a new record. It is the header line with which you work with and from which the new record is sent to the table body itself.
To copy the records, we can use a SELECT statement to select all of the records from the table and then use MOVE statement that will move the records from the original table into the new internal table into the fields where the names correspond.
Following is the syntax for MOVE statement −
MOVE <table_field> TO <internal_tab_field>.
Example
REPORT ZCUSLIST1. TABLES: ZCUSTOMERS1. DATA: BEGIN OF itab01 Occurs 0, name LIKE ZCUSTOMERS1-name, dob LIKE ZCUSTOMERS1-dob, END OF itab01. Select * FROM ZCUSTOMERS1. MOVE ZCUSTOMERS1-name TO itab01-name. MOVE ZCUSTOMERS1-dob TO itab01-dob. ENDSELECT. Write: / itab01-name, itab01-dob.
The above code produces the following output −
MARGARET 02.11.1994
The select loop fills each field one at a time, using the MOVE statement to move the data from one tables field to the other. In the above example, MOVE statements were used to move the contents of the ZCUSTOMERS1 table to the corresponding fields in the internal table. You can accomplish this action with just one line of code. You can use the MOVECORRESPONDING statement.
Following is the syntax for MOVE-CORRESPONDING statement −
MOVE-CORRESPONDING <table_name> TO <internal_tab>.
It tells the system to move the data from the fields of ZCUSTOMERS1 to their corresponding fields in itab01.
Example
REPORT ZCUSTOMERLIST. TABLES: ZCUSTOMERS1. DATA: Begin of itab01 occurs 0, customer LIKE ZCUSTOMERS1-customer, name LIKE ZCUSTOMERS1-name, title LIKE ZCUSTOMERS1-title, dob LIKE ZCUSTOMERS1-dob, END OF itab01. SELECT * from ZCUSTOMERS1. MOVE-Corresponding ZCUSTOMERS1 TO itab01. APPEND itab01. ENDSELECT. LOOP AT itab01. Write: / itab01-name, itab01-dob. ENDLOOP.
The above code produces the following output −
MARK 21.05.1981 JAMES 14.08.1977 AURIELE 19.06.1990 STEPHEN 22.07.1985 MARGARET 02.11.1994
This is made possible by the fact that both have matching field names. When making use of this statement, you need to make sure that both fields have matching data types and lengths. It has been done here with the LIKE statement previously.