✒️ABAP Las tablas de control
ABAP Las tablas de control
Control tables
Control tables in SAP are fundamental tools for visualizing and modifying data in internal tables, databases, or SAP data structures. They are similar to spreadsheets that can be found in transaction SM30 when viewing a database table.
To create a control table, there are two methods: manually or using the WIZARD assistant. Below is the creation process using the wizard:
Preparation
- Create a data Include where you declare an internal table named TI_USERS, containing all the fields of the database table plus a 'mark' field as the first field.
DATA: BEGIN OF ti_users OCCURS 0,
mark(1) TYPE c,
dni TYPE z_dni,
civil_status TYPE z_civil_status,
END OF ti_users.
- Declare a structure named ST_USERS of the same type as the internal table TI_USERS.
DATA: st_users LIKE LINE OF ti_users.
Design in Screen Painter
- Select the 'Table Control' icon using the wizard and drag it onto the screen, adjusting its size.
Configuration with the Wizard Assistant
- Start the wizard and provide the name of the control table, for example, TC_USERS.
- Specify the program's internal table (TI_USERS) and the work area table (ST_USERS).
- Select the fields from the table that will be displayed in the control table, excluding the 'mark' field.
- Configure the attributes of the control table, such as whether it will be for display only or also for updating, whether it will have column headers, and the type of row selection.
- Choose additional functions, such as the option to navigate pages to add keys below the control table.
- Specify the Includes where the control table code will be generated. If these Includes do not exist, the wizard will create them automatically.
Completion
- Press the Finish key to generate all the necessary objects for the control table according to the specified attributes. At this point, you can adjust the width of the columns and modify the titles if necessary.
Within the generated code in the program, the declaration of the control table can be found, for example:
CONTROLS: tc_users TYPE TABLEVIEW USING SCREEN 0200.
The TABLEVIEW type corresponds to the CXTAB_CONTROL structure and has the following fields:
- FIXED_COLS TYPE I: Number of fixed columns
- LINEZ TYPE I: Number of lines for vertical scrolling
- TOP_LINE TYPE I: First line on the next PBO
- CURRENT_LINE TYPE I: Current line (in a LOOP...ENDLOOP)
- LEFT_COL TYPE I: First displayed and movable column
- LINE_SEL_MODE TYPE I: Line selection (0=none, 1=single, 2=multiple)
- LINE_SELECTOR: Indicator of selected line
- V_SCROLL: Indicator of vertical scroll bar
- H_GRID: Indicator of horizontal grid line
- V_GRID: Indicator of vertical grid line
The COLS type CXTAB_COLUMN consists of the following fields:
- SCREEN LIKE SCREEN: Attributes of the SCREEN structure
- INDEX TYPE I: Column position (display sequence)
- SELECTED: Indicator of selected column
- VISIBLE LIKE ICON-OLENG: Visible width of the column
- INVISIBLE: Indicator of invisible column.
This structure stores the data defining the control table, such as the number of fixed columns, the number of lines for vertical scrolling, etc. Additionally, it contains a table of columns (cols) that defines the characteristics of each column, such as its position, visibility, and selection.
In the PBO (Process Before Output) event of the dynpro processing logic, we have the following code generated:
PROCESS BEFORE OUTPUT.
MODULE status_0200.
MODULE cargar_tc_0200.
*&spwizard: pbo flow logic FOR tablecontrol 'TC_USERS'
MODULE tc_users_change_tc_attr.
*&spwizard: MODULE tc_users_change_col_attr.
LOOP AT ti_users_tc INTO st_users_tc WITH CONTROL tc_users CURSOR tc_users-current_line.
MODULE tc_users_get_lines.
*&spwizard: MODULE tc_users_change_field_attr
ENDLOOP.
And in the PAI (Process After Input) event:
PROCESS AFTER INPUT.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TC_USERS'
LOOP AT ti_users_tc.
CHAIN.
FIELD st_users_tc-dni.
FIELD st_users_tc-name.
FIELD st_users_tc-age.
FIELD st_users_tc-address.
FIELD st_users_tc-birth_date.
FIELD st_users_tc-marital_status.
FIELD st_users_tc-postal_code.
ENDCHAIN.
FIELD st_users_tc-mark MODULE tc_users_mark ON REQUEST.
ENDLOOP.
MODULE tc_users_user_command.
We use the LOOP-ENDLOOP statement to iterate through each element of the control table. Within this statement, there may be other statements like FIELD, MODULE, SELECT, VALUES, and CHAIN-ENDCHAIN.
It's essential to have a LOOP-ENDLOOP statement both in the PBO and PAI for each control table of the screen. This is because this statement is responsible for copying fields between the ABAP program and the screen, and vice versa.
In the PBO, the system field SY-LOOPC contains the current number of lines of the control table. In the PAI, it contains the number of currently filled lines.
Finally, to populate the control table with data, we perform the loading of it in the PBO:
PROCESS BEFORE OUTPUT.
MODULE cargar_tc_200.
*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TC_USERS'
MODULE tc_users_change_tc_attr.
*&SPWIZARD: MODULE TC_USERS_CHANGE_COL_ATTR.
LOOP AT ti_users_tc INTO st_users_tc WITH CONTROL tc_users CURSOR tc_users-current_line.
MODULE tc_users_get_lines.
*&SPWIZARD: MODULE TC_USERS_CHANGE_FIELD_ATTR
ENDLOOP.
And within the cargar_tc_200 module, we introduce the following code:
MODULE cargar_tc_200 OUTPUT.
CLEAR: ti_users, st_users_tc, ti_users_tc.
REFRESH: ti_users, ti_users_tc.
IF NOT wa_screen_0100-dni IS INITIAL.
SELECT * FROM zcvs_users INTO TABLE ti_users WHERE dni EQ wa_screen_0100-dni.
ELSE.
SELECT * FROM zcvs_users INTO TABLE ti_users.
ENDIF.
LOOP AT ti_users INTO st_users.
CLEAR st_users_tc.
st_users_tc-dni = st_users-dni.
st_users_tc-name = st_users-name.
st_users_tc-age = st_users-age.
st_users_tc-address = st_users-address.
st_users_tc-birth_date = st_users-birth_date.
st_users_tc-marital_status = st_users-marital_status.
st_users_tc-postal_code = st_users-postal_code.
APPEND st_users_tc TO ti_users_tc.
ENDLOOP.
ENDMODULE.
This module is responsible for loading data into the control table. It clears and refreshes the necessary internal tables, then retrieves data from the database based on certain conditions (such as the entered ID). Finally, it transfers the retrieved data into the control table for display on the screen.
 
 
 
Sobre el autor
Publicación académica de Jaime Eduardo Gomez Arango, en su ámbito de estudios para la Carrera Consultor ABAP.
Jaime Eduardo Gomez Arango
Profesión: Ingeniero de Sistemas y Computación - España - Legajo: SW34C
✒️Autor de: 108 Publicaciones Académicas
🎓Cursando Actualmente: Consultor ABAP Nivel Avanzado
🎓Egresado del módulo:
Disponibilidad Laboral: FullTime
Presentación:
Ingeniero de sistemas y computación con 8 años de experiencia el desarrollo frontend & backend (react/node) y en cloud (aws), actualmente desarrollando habilidades en sap btp, ui5, abap y fiori.
Certificación Académica de Jaime Gomez