- SAP ABAP - Web Dynpro
- SAP ABAP - Business Add-Ins
- SAP ABAP - User Exits
- SAP ABAP - Customer Exits
- SAP ABAP - SAPscripts
- SAP ABAP - Smart Forms
- SAP ABAP - Dialog Programming
- SAP ABAP - Report Programming
- SAP ABAP - Object Events
- SAP ABAP - Interfaces
- SAP ABAP - Encapsulation
- SAP ABAP - Polymorphism
- SAP ABAP - Inheritance
- SAP ABAP - Classes
- SAP ABAP - Objects
- SAP ABAP - Object Orientation
- SAP ABAP - Deleting Internal Tables
- SAP ABAP - Reading Internal Tables
- SAP ABAP - Copying Internal Tables
- ABAP - Populating Internal Tables
- SAP ABAP - Creating Internal Tables
- SAP ABAP - Internal Tables
- SAP ABAP - Native SQL Overview
- SAP ABAP - Open SQL Overview
- SAP ABAP - Include Programs
- SAP ABAP - Function Modules
- SAP ABAP - Macros
- SAP ABAP - Subroutines
- SAP ABAP - Modularization
- SAP ABAP - Lock Objects
- SAP ABAP - Search Help
- SAP ABAP - Views
- SAP ABAP - Structures
- SAP ABAP - Tables
- SAP ABAP - Data Elements
- SAP ABAP - Domains
- SAP ABAP - Dictionary
- SAP ABAP - Exception Handling
- SAP ABAP - Formatting Data
- SAP ABAP - Date & Time
- SAP ABAP - Strings
- SAP ABAP - Decisions
- SAP ABAP - Loop Control
- SAP ABAP - Operators
- SAP ABAP - Constants & Literals
- SAP ABAP - Variables
- SAP ABAP - Data Types
- SAP ABAP - Basic Syntax
- SAP ABAP - Screen Navigation
- SAP ABAP - Environment
- SAP ABAP - Overview
- SAP ABAP - Home
SAP ABAP Useful Resources
- SAP ABAP - Discussion
- SAP ABAP - Useful Resources
- SAP ABAP - Quick Guide
- SAP ABAP - Questions Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
SAP ABAP - Copying Internal Tables
When we read a record from an internal table with a header pne, that record is moved from the table itself into the header pne. It is then the header pne that our program works with. The same apppes while creating a new record. It is the header pne 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 table’s 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 accomppsh this action with just one pne 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.
Advertisements