SAP ABAP Table Control with Examples

โšก Smart Summary

SAP ABAP Table Control displays an internal table as a scrollable grid on a screen built in the Screen Painter. This page explains its features, the CONTROLS declaration, cursor handling, the PBO and PAI loops, and column attributes.

  • ๐Ÿ–ฅ๏ธ Core Definition: A table control is an improved step loop that shows table data with the look and feel of a desktop application grid.
  • ๐Ÿงฐ Built-in Features: Scrolling, column resizing, column reordering, row selection, and saved display settings are handled by the SAPgui frontend.
  • ๐Ÿ“œ Single Line Rule: A step loop row may span several screen lines, while a table control row must always fit on one line.
  • โŒจ๏ธ Declaration: CONTROLS <ctrl> TYPE TABLEVIEW USING SCREEN <scr> links the screen element to the ABAP program.
  • ๐ŸŽฏ Cursor Handling: SET CURSOR positions the cursor at PBO, and GET CURSOR reads the field and row at PAI.
  • ๐Ÿ” Data Transfer: LOOP AT … USING CONTROL runs at PBO and a plain LOOP AT runs at PAI, and data moves between screen and internal table inside those loops.
  • ๐ŸŽจ Dynamic Attributes: The SCREEN table and the <cntrl>-cols structure change column visibility and formatting at runtime.

SAP ABAP Table Control

What is a Table Control in SAP ABAP?

Table controls and step loops are objects for screen table display that you add to a screen in the Screen Painter.

From a programming standpoint, table controls and step loops are almost exactly the same. Table controls are simply improved step loops that display data with the look and feel associated with tables in desktop applications.

Features of ABAP Table Control

With table controls, the user can:

  • Scroll through the table vertically and horizontally
  • Re-size the width of a column
  • Scroll within a field (when field contents are wider than the field)
  • Select table rows or columns
  • Re-order the sequence of columns
  • Save the current display settings for future use

Table controls also offer special formatting features (some automatic, some optional) that make tables easier to look at and use. Table Control provides –

  • automatic table resizing (vertical and horizontal) when the user resizes the window
  • separator lines between rows and between columns (vertical and horizontal)
  • column header fields for all columns

In general, many of the features provided by the table control are handled locally by your system’s SAPgui frontend, so you do not need to program them yourself. The only notable exception to this is vertical scrolling.

Example (Transaction TZ60)

SAP ABAP Table Control

Transaction TZ60 above shows the finished result: a grid with column headers, separator lines, and a selection column. The differences from the older step loop are summarised next.

Table Control vs Step Loop

One feature of step loops is that their table rows can span more than one line on the screen. A row of a table control, on the other hand, must always be contained in a single line (although scrolling is possible). The table below compares the two screen elements.

Criteria Table Control Step Loop
Row layout One row is always one screen line One row may span several screen lines
Column handling Columns can be resized, reordered, and hidden by the user Fixed column layout defined on the screen
Scrolling Horizontal scrolling by the frontend, vertical scrolling programmed in PAI Programmed entirely in the ABAP code
Declaration CONTROLS … TYPE TABLEVIEW USING SCREEN No control structure in the program
Display settings The user can save a personal layout Not available

Because the table control is the modern element, the rest of this page programs that one.

How to Create and Program a Table Control

A table control needs a screen element, a control structure in the program, and a loop in both PBO and PAI. The subsections below follow that order.

Declaring the control

To handle table controls in ABAP programs, you must declare a control in the declaration part of the program for each table control using the following statement:

CONTROLS <ctrl> TYPE TABLEVIEW USING SCREEN <scr>

where <ctrl> is the name of the table control on a screen in the ABAP program. The control allows the ABAP program to read the attributes of the table control and to influence the control .Here, <scr> is the screen number where the initial values of the table are loaded.

Setting and reading the cursor position

Cursor Position for a table control can be set in following ways:

At PBO you can set the cursor on a specific field of a specific row of a table control.

SET CURSOR FIELD <f> LINE <lin> [OFFSET <off>]

Using the optional addition OFFSET, you can enter the offset of the cursor in the field as described under Setting the Cursor Position.

At PAI you can read the current cursor position.

GET CURSOR FIELD <f> LINE <lin> ...

In addition to the information given under Finding Out the Cursor Position, field <lin> contains information on which row of the table control the cursor is currently on. You can also use

GET CURSOR LINE <lin>.

to determine the row of the table control. SY-SUBRC allows you to check if the cursor is placed in a row of a table control.

Reading the corresponding internal table line

For getting the corresponding line of the internal table:

GET CURSOR line <lin>.

ind = <table_control>-top_line + <lin> - 1.

Read table <itab> index ind.

The system variable stepl – contains the current table line index in a loop … endloop. Loopc – contains number of lines visible in the table

Creating the control in the Screen Painter

To create a table control

  1. Add a table control element to your screen
  2. Give a name to the table control. In the ABAP program declare a structure with the same ( CONTROLS <tcl> type TABLEVIEW USING SCREEN <scrn >)
  3. To create fields go to the Dict./Program fields function.
    • Enter the name of the structure whose fields you want. (If you want it to pick it from dictionary of your program click the relevant puhbutton).
    • In the field list choose the fields you want and choose ok.
    • Click in the table control area

If you want a selection column, check the appropriate check box in the attributes and give it a name. Create the field in the ABAP program.

Coding the PBO and PAI loops

In the PBO you should have the statement

LOOP at <itab> USING CONTROL <cntrl_name>.

ENDLOOP.

In the PAI you should have.

LOOP at <itab>.

ENDLOOP.

It is within the loops that data transfer happens between the screen and the internal table.When you populate the internal table use DESCRIBE TABLE <itab> LINES <cntrl_name>-lines, to store the total number of lines in the control.The FIELD statement can be used to control when the data transfer happens

โš ๏ธ Warning: The PBO loop must name the control with USING CONTROL. Without it the control does not know how many lines exist, and vertical scrolling stops working.

Changing column attributes at runtime

To change the attributes of individual cells temporarily change the SCREEN table in the PBO. You can change the attributes of the structure created by the CONTROLS statement

<cntrl>-fixed_cols etc are the attributes of the control

<cntrl>-cols-index etc are the attributes of the columns.

<cntrl>-cols-screen-invisible etc are the screen attributes of each column.

๐Ÿ’ก Tip: Loop over <cntrl>-cols in the PBO to hide or protect a column for a given user role, rather than building a second screen.

FAQs

The frontend handles horizontal scrolling, but vertical scrolling is coded in PAI. Evaluate SY-UCOMM for the scroll function codes and move the top_line field of the control structure before the next PBO runs.

An ALV grid supplies sorting, filtering, totals, and export without extra code, so it suits display lists. A table control is preferred when the screen needs custom input logic and full control over each cell.

SY-STEPL holds the index of the row currently processed inside the screen loop, and SY-LOOPC holds the number of rows visible on the screen. Both are only filled inside the LOOP … ENDLOOP of the control.

Yes. AI assistants in ABAP development tools draft the CONTROLS declaration, both screen loops, and the scrolling logic from a description of the internal table. The generated flow logic still needs testing in the Screen Painter.

AI analysis tools read the flow logic of a dynpro, list the fields and function codes, and propose an equivalent Fiori or ALV based design. The proposal shortens the analysis phase of a modernization project.

Summarize this post with: