Example Transaction: Table Controls 

SCREEN

SCREEN

Cursorposition festlegen

Cursorposition bestimmen

Transaction TZ60 is an example of programming with table controls. It displays flight information on two screens. On the first, the user specifies a flight connection and requests the detailed information. On the second (screen 200), the transaction displays all flights scheduled for the connection:

There are two important things to notice in this program:

The fields in the table control are declared as database fields (table SFLIGHTS) in the ABAP program. To store several SFLIGHTS rows at a time, the program uses the internal table INT_FLIGHTS.

  1. During PAI for screen 100, the program selects all flights for the given connection and stores them in internal table INT_FLIGHTS.
  2. AT PBO for screen 200, the LOOP statement loops through INT_FLIGHTS, calling the module DISPLAY_FLIGHTS for each row. DISPLAY_FLIGHTS transfers an INT_FLIGHTS row to the SFLIGHTS work area. The SFLIGHTS fields match the screen table names, so at the end of each loop pass, the system transfers the ABAP values to the screen table fields.

Table controls contain information for managing scrolling. This includes fields telling how many table rows are filled and which table row should be first in the screen display into the table. For both step loops and table controls, the system manages scrolling with the scroll bars automatically. This includes scrolling the actual screen display, as well as resetting scrolling variables. However, the example program offers scrolling with the F21 - F24 keys. In this case, the program must implement these functions explicitly.

  1. During PAI for screen 100, the program initializes the "first-table-row" variable (field TOP_LINE) to 1.
  2. At PAI for screen 200, the program resets scrolling variables, especially the TOP_LINE field, if the user has scrolled with the F21 - F24 function keys.

Screen Flow Logic

The screen flow logic (PAI only) for screen 200 in transaction TZ60 looks as follows.

*---------------------------------------------------------------*
* Screen 200: Flow Logic *
*&--------------------------------------------------------------*
PROCESS BEFORE OUTPUT.
  MODULE STATUS_0200.
    LOOP AT INT_FLIGHTS WITH CONTROL FLIGHTS
                      CURSOR FLIGHTS-CURRENT_LINE.
      MODULE DISPLAY_FLIGHTS.
ENDLOOP.
*
*
PROCESS AFTER INPUT.
  LOOP AT INT_FLIGHTS.
    MODULE SET_LINE_COUNT.
ENDLOOP.
  MODULE USER_COMMAND_0200.

 

ABAP Code

The following section of the TOP-module code shows the definitions relevant to the following code.

*----------------------------------------------------------------*
* INCLUDE MTD40TOP *
*----------------------------------------------------------------*
PROGRAM SAPMTZ60 MESSAGE-ID A&.
  TABLES: SFLIGHT.
  <....Other declarations....>
  DATA INT_FLIGHTS LIKE SFLIGHT OCCURS 1 WITH HEADER LINE.

  DATA: LINE_COUNT TYPE I.

CONTROLS: FLIGHTS TYPE TABLEVIEW USING SCREEN 200.

 

The following PBO module transfers internal table fields to the proper screen table fields at PBO.

*&---------------------------------------------------------------*
*& Module DISPLAY_FLIGHTS OUTPUT
*&---------------------------------------------------------------*
MODULE DISPLAY_FLIGHTS OUTPUT.
  SFLIGHT-FLDATE = INT_FLIGHTS-FLDATE.
  SFLIGHT-PRICE = INT_FLIGHTS-PRICE.
  SFLIGHT-CURRENCY = INT_FLIGHTS-CURRENCY.
  SFLIGHT-PLANETYPE = INT_FLIGHTS-PLANETYPE.
  SFLIGHT-SEATSMAX = INT_FLIGHTS-SEATSMAX.
  SFLIGHT-SEATSOCC = INT_FLIGHTS-SEATSOCC.
ENDMODULE.

 

At PAI, the program must loop again, to transfer screen table fields back to the program. During this looping, the program can use SY_LOOPC to find out how many rows were transferred. SY_LOOPC is a system variable telling the total number of rows currently showing in the display.

*&---------------------------------------------------------------*
*& Module SET_LINE_COUNT INPUT
*&---------------------------------------------------------------*
MODULE SET_LINE_COUNT INPUT.
  LINE-COUNT = SY-LOOPC.
ENDMODULE

 

Transaction TZ60 lets the user press function keys ( F21 - F24 ) to scroll the display. The system handles scrolling with the scroll bars automatically, but not scrolling with function keys. So PAI for screen 200 must implement function-key scrolling explicitly:

MODULE USER_COMMAND_0200 INPUT.
  CASE OK_CODE.
WHEN 'CANC'...
WHEN 'EXIT'...
WHEN 'BACK'...
WHEN 'NEW'...
    WHEN 'P--'.
      CLEAR OK_CODE.
      PERFORM PAGING USING 'P--'.
    WHEN 'P-'.
      CLEAR OK_CODE.
      PERFORM PAGING USING 'P-'.
    WHEN 'P+'.
      CLEAR OK_CODE.
      PERFORM PAGING USING 'P+'.
    WHEN 'P++'.
      CLEAR OK_CODE.
      PERFORM PAGING USING 'P++'.
  ENDCASE.
ENDMODULE.

 

The PAGING routine causes the system to scroll the display by re-setting the table control field TOP_LINE to a new value. The TOP_LINE field tells the LOOP statement where to start looping at PBO.

*&---------------------------------------------------------------*
*& Form PAGING
*&---------------------------------------------------------------*
FORM PAGING USING CODE.
  DATA: I TYPE I.
J TYPE I.

CASE CODE.
    WHEN 'P--'. FLIGHTS-TOP_LINE = 1.
    WHEN 'P-'.  FLIGHTS-TOP_LINE = FLIGHTS-TOP_LINE - LINE_COUNT.
                IF FLIGHTS-TOP_LINE LE 0.
                   FLIGHTS-TOP_LINE = 1. ENDIF.
    WHEN 'P+'.  I = FLIGHTS-TOP_LINE + LINE_COUNT.
                J = FLIGHTS-LINES - LINE_COUNT + 1.
                IF J LE 0.
                   J = 1. ENDIF.
                IF I LE J.
FLIGHTS-TOP_LINE = I.
ELSE. FLIGHTS-TOP_LINE = J.
ENDIF.
    WHEN 'P++'. FLIGHTS-TOP_LINE = FLIGHTS-LINES - LINE_COUNT + 1.
                IF FLIGHTS-TOP_LINE LE 0.
                   FLIGHTS-TOP_LINE = 1. ENDIF.
  ENDCASE.
ENDFORM.