This document discusses using table controls in ABAP transactions. It introduces table controls as graphical screen elements for displaying multiple rows of tabular data on a single screen. It covers creating and adding table controls to screens, filling them from internal tables, updating the internal tables from changes to the table control, and saving updated data back to the database. Methods for handling table control flow logic, updating the internal table, and detecting and saving changes are presented.
8. Adding a Table Control to a Screen In the Graphical Fullscreen Editor choose the Table Control element button. Use the left mouse button to position and size the control on the screen.
9. Adding a Table Control to a Screen Enter a Name for the Table Control
10. Adding Fields to a Table Control Press Dict/program fields pushbutton
11. Adding Fields to a Table Control Enter database table name Select Get From Dictionary
12. Adding Fields to a Table Control Enter internal table name Select Get From program
13. Adding Fields to a Table Control Mark the fields to be added to the table control Then click on Copy to select the fields
14. Adding Fields to a Table Control Drag the selected fields into the table control, then release the mouse button.
15. Adding Fields to a Table Control The label for each column is a text field, created by clicking on the text field icon and then dragging the new text field onto the header of the column before typing in the label Text field icon
16. Table Control Principles Database Table Internal Table (Buffer) 1. Internal Table filled with selected data
17. Table Control Principles Internal Table (Buffer) 2. Table Control contents filled from internal table Table Control
18. Table Control Principles Internal Table (Buffer) Table Control 3. Changes to Table Control contents copied to internal table
19. Table Control Principles Database Table Internal Table (Buffer) 4. When screen is closed, internal table contents copied back to database
20. Table Control Principles PBO PAI Select rows from the database into an internal table Screen 1 PBO PAI Screen 2 ( with table control ) LOOP ... read internal table into table control line by line ENDLOOP. LOOP ... update internal table from table control line by line ENDLOOP.
21.
22.
23.
24.
25.
26.
27. Table Control Attributes data: begin of cxtab_control, ... cols type cxtab_column occurs 10, end of cxtab_control. data: begin of cxtab_column, ... selected, screen like screen , end of cxtab_column. SCREEN FIELDS: name length active ...
31. Handling Line Selection PROCESS AFTER INPUT. LOOP AT ITAB. FIELD ITAB-MARK MODULE MODIFY_ITAB ON REQUEST. ENDLOOP. MODULE MODIFY_ITAB INPUT. MODIFY ITAB INDEX FLIGHTS-CURRENT_LINE. ENDMODULE.
32. Updating the Internal Table PROCESS AFTER INPUT. LOOP WITH CONTROL FLIGHTS. CHAIN. FIELD: SFLIGHT-PRICE, SFLIGHT-FLDATE. MODULE MODIFY_ITAB ON CHAIN-REQUEST. ENDCHAIN. ENDLOOP. Method 1 Method 2 PROCESS AFTER INPUT. LOOP AT ITAB. CHAIN. FIELD: SFLIGHT-PRICE, SFLIGHT-FLDATE. MODULE MODIFY_ITAB ON CHAIN-REQUEST. ENDCHAIN. ENDLOOP. MODULE MODIFY_ITAB INPUT. ITAB-MARK = 'X'. MODIFY ITAB INDEX FLIGHTS-CURRENT_LINE. ENDMODULE. MODULE MODIFY_ITAB INPUT. MOVE-CORRESPONDING SFLIGHT TO ITAB. ITAB-MARK = 'X'. MODIFY ITAB INDEX FLIGHTS-CURRENT_LINE. ENDMODULE.
33.
34.
35.
36.
37.
38.
Editor's Notes
Very often it is desirable to be able to represent a one-to-many relationship on the screen. For instance, given an airline carrier and a flight code show all the scheduled flights. (Or given an order number show all the ordered products.) ABAP provides the ‘table control’ as a graphical element on a screen that is capable of holding and displaying multiple rows of a table in a ‘spreadsheet’ format.
This slide illustrates a table control object in a screen.
The table control object has many features built in to enhance screen display and usability. They include the ability to scroll through records (horizontally and vertically) and inside a field if the field width is greater than the table control’s column width. Table controls also allow the user to dynamically resize column widths, reorder columns, and select columns and rows for subsequent processing.
As well as drawing the table control on the screen it is necessary to declare the table control as a data item (in the TOP include program for the transaction).
To view the structure of the cxtab-control object use the Repository Browser and choose Dictionary Objects…Choose the Type Group radiobutton and enter CXTAB…Press the Display icon on the application toolbar. Note that a component of the object is an internal table, cols. Each displayed field of the table control will have a row in the cols internal table which describes various attributes of the field.
There are a set of programming principles that should be adhered to when using table controls and step loops. Data from the database should be initially loaded into an internal table. (This means that the database is accessed for read purposes only once in the transaction.) Next the rows of the internal table are loaded into the table control Any changes that are made to the data are then saved back to the internal table. At the end of the transaction, the contents of the internal table can be written back to the database, again to minimise database I/O.
There are a set of programming principles that should be adhered to when using table controls and step loops. Data from the database should be initially loaded into an internal table. (This means that the database is accessed for read purposes only once in the transaction.) Next the rows of the internal table are loaded into the table control Any changes that are made to the data are then saved back to the internal table. At the end of the transaction, the contents of the internal table can be written back to the database, again to minimise database I/O.
There are a set of programming principles that should be adhered to when using table controls and step loops. Data from the database should be initially loaded into an internal table. (This means that the database is accessed for read purposes only once in the transaction.) Next the rows of the internal table are loaded into the table control Any changes that are made to the data are then saved back to the internal table. At the end of the transaction, the contents of the internal table can be written back to the database, again to minimise database I/O.
There are a set of programming principles that should be adhered to when using table controls and step loops. Data from the database should be initially loaded into an internal table. (This means that the database is accessed for read purposes only once in the transaction.) Next the rows of the internal table are loaded into the table control Any changes that are made to the data are then saved back to the internal table. At the end of the transaction, the contents of the internal table can be written back to the database, again to minimise database I/O.
PAI logic for screen 1 loads the internal table with data from the database according to the entries supplied by the user. PBO logic for screen 2 populates the table control from the internal table (buffer). User action in screen 2 triggers the PAI logic. PAI logic updates the internal table with new values entered (into the table control screen fields) by the user. PAI logic is triggered by actions such as scrolling down a single row as well as actions such as BACK, EXIT, etc. Unless the user action causes the transaction to leave the current screen, after the PAI modules have been executed, the PBO modules for the screen are executed again. Thus the table control fields are updated/refreshed after every user action.
In PBO processing fields are transported from the module pool to the screen in a predefined order. 1. The table control step loop is processed row by row. Fields with corresponding names are transported from the module pool to the screen. 2. After the step loop has been processed all remaining module pool fields are transported to the screen.
The ABAP language provides two mechanisms for loading the table control with data from the internal table and then storing the altered rows of the table control back to the internal table.
In the flow logic you can read an internal table using the LOOP statement. You define the reference to the relevant able control by specifying WITH CONTROL <ctrl> You determine which table entry is to be read by specifying CURSOR <ctrl>-CURRENT_LINE. After the read operation the field contents are placed in the header line of the internal table. If the fields in the table control have the same name as the internal they will be filled automatically. (Otherwise you need to write a module to transfer the internal table fields to the screen fields.) You must reflect any changes the user makes to the fields of the table control in the internal table otherwise they will not appear when the screen is redisplayed after PBO processing, (eg, after the user presses Enter or scrolls) However, this processing should be performed only if changes have actually been made to the screen fields of the table control (hence the use of the ON REQUEST)
If you use a LOOP statement without an internal table in the flow logic, you must read the data in a PBO module which is called each time the loop is processed. Since, in this case, the system cannot determine the number of internal table entries itself, you must use the EXIT FROM STEP-LOOP statement to ensure that no blank lines are displayed in the table control if there are no more corresponding entries in the internal table.
If you use a LOOP statement without an internal table in the flow logic, you must read the data in a PBO module which is called each time the loop is processed. Since, in this case, the system cannot determine the number of internal table entries itself, you must use the EXIT FROM STEP-LOOP statement to ensure that no blank lines are displayed in the table control if there are no more corresponding entries in the internal table.
Sorting the display by a selected column is very simple to implement using the table control attributes <ctrl>-SELECTED and <ctrl>-SCREEN-NAME. Here we assume that the table control displays the fields of an internal table (ITAB) as per Option 1 discussed previously. WA-SCREEN-NAME refers to the name of the selected column of the table control. The expression (WA-SCREEN-NAME+5) refers to the contents of the variable offset 5 characters from the left. In this example WA-SCREEN-NAME will have a value like ITAB-PRICE. The expression (WA-SCREEN-NAME+5) will have the value PRICE. SORT ITAB BY (WA-SCREEN-NAME+5) will resolve to SORT ITAB BY PRICE. To adjust this code for use in your own program substitute the name of the control used in your program and calculate the offset required to trim the structure name from the selected SCREEN-NAME.
This slide illustrates a table control object in a screen.