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.
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.
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.
SELECT SINGLE * FROM zemployee INTO DATA (wa_emp).