In ABAP reports, very often we will be having a situation where we need to store single record of a table or take input from user and append that record to table, both at runtime. In this situation we will need a structure which has all the fields of that particular table with the same namespace. Every time the content of the table changes, we will have to update our structure. So, instead of using structure we can use something called work area that is the replica of single row of that table with same fields.

Definition

A work area in ABAP represents single row of an internal table and it is used to process internal table line by line. It holds only single data at runtime.

ABAP Work Area

ABAP Work Area- Image Illustration

Syntax

A workarea can be defined in a report in two ways.

Case 1: Predefining the type of work area and allocating memory to it.

DATA: <YOUR_WORK_AREA_NAME> TYPE <Structure, Table, Line Type, View>.

Case 2: Using Open SQL to allocate memory and type to work area at runtime.

SELECT SINGLE * FROM <YOUR_TABLE_NAME> INTO DATA (<YOUR_WORK_AREA_NAME>).

*** Exclude the parenthesis <> from above while using them in your programs.

Examples

Case 1:

DATA: wa_emp TYPE zemployee.
SELECT SINGLE * FROM zemployee INTO wa_emp.

Note: If your work area does not match the structure of the table from which data is being pulled, you can write following:

SELECT SINGLE * FROM zemployee INTO CORRESPONDING FIELDS OF wa_emp.

Case 2:

SELECT SINGLE * FROM zemployee INTO DATA (wa_emp).

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Translate »