ABAP Obsolete Statement: TABLES

 As part of the Obsolete statement series, today's post is about TABLES statement. 

Syntax: TABLES wa_table.

Example:

REPORT sy-repid.
TABLES: mara.
START-OF-SELECTION.
mara-matnr = 'Test'.
write:/ mara-matnr.
view raw tables_ex1.abap hosted with ❤ by GitHub

It declares a data object wa_table as a table work area whose data type is taken from the identically named table wa_table in the ABAP dictionary. DB tables and views can be used to declare their work areas using TABLES statement.

Table work areas declared using TABLES are interface work areas( a special data object that can act as a cross-program interface between program and screens or logical databases.

The statement TABLES is not allowed within classes anyway. Since obsolete database accesses requiring the statement TABLES and shared data areas between programs are not allowed, there is no need to use the statement TABLES.

In other words

The main purpose of the TABLES statement is to act as an interface work area to share data across programs and screens, since the shared data areas between programs are not allowed, the tables statement becomes obsolete except for classic dynpros.

If dynpro fields in classic dynpros are defined with reference to flat structures in ABAP Dictionary, the identically named global data objects of the ABAP program must be declared with the statement TABLES. Otherwise, the data objects of the ABAP program are not linked to the dynpro fields, and their content cannot be accessed.

In addition,

TABLES is also required for declaring specific work areas when handling function codes of selection screens.

In conclusion,

Even though TABLES statement is obsolete, it is still needed to transfer data from dynpros whose fields are declared referencing flat structures from ABAP data dictionary or dealing with selection screen fields.
An Example of where TABLES statement is still relevant.
REPORT syst-repid.
TABLES sscrfields."Needed to capture Selection screen fields.
SELECTION-SCREEN BEGIN OF SCREEN 1100.
PARAMETERS: p_carrid TYPE s_carr_id,
p_cityfr TYPE s_from_cit.
SELECTION-SCREEN: FUNCTION KEY 1,
FUNCTION KEY 2.
SELECTION-SCREEN END OF SCREEN 1100.
"Class
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
start,
handle_at_sel_screen.
ENDCLASS.
CLASS lcl_main IMPLEMENTATION.
METHOD start.
sscrfields-functxt_01 = 'Lufthansa'.
sscrfields-functxt_02 = 'United Airlines'.
CALL SELECTION-SCREEN 1100 .
ENDMETHOD.
METHOD handle_at_sel_screen .
"On press of these buttons, fill data on screen.
CASE sscrfields-ucomm.
WHEN'FC01'.
p_carrid = 'LH'.
p_cityfr = 'Frankfurt'.
WHEN 'FC02'.
p_carrid = 'UA'.
p_cityfr = 'Chicago'.
ENDCASE.
ENDMETHOD.
ENDCLASS.
"Program Logic
AT SELECTION-SCREEN.
lcl_main=>handle_at_sel_screen( ).
START-OF-SELECTION.
lcl_main=>start( ).
Thanks for reading and as always I hope this post helps you in your day to day development.

Popular posts from this blog

ABAP convert internal table to excel (.xlsx) format and Send email or download

ABAP read excel(.XLSX) file to internal table in ABAP using CL_FDT_XL_SPREADSHEET

Use CL_BCS library to send email with ABAP