table cnt rl
TRANSCRIPT
-
8/13/2019 Table Cnt Rl
1/38
ITB258ABAP Programming
Lecture 11
Using Tables in Transactions
-
8/13/2019 Table Cnt Rl
2/38
Objectives
This lecture aims to introduce the concepts
associated with:
Table controls:graphical screen elements used
for displaying more than nrows of a table on a
single screen
screen flow logicfor handling table controls
-
8/13/2019 Table Cnt Rl
3/38
Using Tables in a Screen
ABAP offers the Table Controlgraphicalelement as a mechanism for displaying and
modifying tabular data in a screen a Table Control is a screen container or
object that allows display of multiple rows ofa table (database or internal) on a screen
Good for displaying a one-to-manyrelationship on the one screen.
-
8/13/2019 Table Cnt Rl
4/38
Table Control
-
8/13/2019 Table Cnt Rl
5/38
Table Controls Table Control features allow
horizontal & vertical scrolling
column width resizing
scrolling within a field (where contents are
wider than the screen field width)reordering the sequence of columns
saving the current display settings for future use
selection of table rows & columns
Formatting features includeautomatic table resizing on window resize
separator lines between rows & columns
column header fields for all columns
-
8/13/2019 Table Cnt Rl
6/38
Creating a Table Control
In the TOP Include object:
CONTROLS ctrlTYPE TABLEVIEW
USING SCREEN scr.
TABLEVIEWcorresponds to a complex type
(CXTAB_CONTROL defined in the ABAP dictionary) USING SCREENdetermines the screen from
which the table control will get its initial values
-
8/13/2019 Table Cnt Rl
7/38
CXTAB_CONTROL
-
8/13/2019 Table Cnt Rl
8/38
-
8/13/2019 Table Cnt Rl
9/38
Adding a Table Control to a Screen
Enter a Name for the Table Control
-
8/13/2019 Table Cnt Rl
10/38
Press Dict/program fields pushbutton
Adding Fields to a Table Control
-
8/13/2019 Table Cnt Rl
11/38
Adding Fields to a Table Control
Enter database table name
Select Get From Dictionary
-
8/13/2019 Table Cnt Rl
12/38
Adding Fields to a Table Control
Enter internal table name
Select Get From program
-
8/13/2019 Table Cnt Rl
13/38
Adding Fields to a Table Control
Mark the fields to be added to the table control
Then click on Copy to select the fields
-
8/13/2019 Table Cnt Rl
14/38
-
8/13/2019 Table Cnt Rl
15/38
Adding Fields to a Table Control
The label for each column is a textfield, created by clicking on thetext field icon and then draggingthe new text field onto the headerof the column before typing in the
label
Text field icon
-
8/13/2019 Table Cnt Rl
16/38
Table Control Principles
Database Table
Internal Table
(Buffer)
1. Internal Table filled withselected data
-
8/13/2019 Table Cnt Rl
17/38
Table Control Principles
Internal Table
(Buffer)
2. Table Control contentsfilled from internal table
Table
Control
-
8/13/2019 Table Cnt Rl
18/38
Table Control Principles
Internal Table
(Buffer)
Table
Control
3. Changes to Table Controlcontents copied to internal
table
-
8/13/2019 Table Cnt Rl
19/38
Table Control Principles
Database Table
Internal Table
(Buffer)
4. When screen is closed, internal table
contents copied back to database
-
8/13/2019 Table Cnt Rl
20/38
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.
-
8/13/2019 Table Cnt Rl
21/38
-
8/13/2019 Table Cnt Rl
22/38
Table Control Principles
All screen fields that do not
belong to a table control and are
not specified in a FIELD
statement are transported to
module pool fields
Table control fields are
transported row by row to
module pool fields
Fields specified in FIELD
statements are transported
immediately before the FIELD
statement is executed
LOOP start
LOOP end
transport screen tablecontrol fields to ABAP
module pool fields
transport all fields from
the screen to ABAP fields
excluding table control fields
PROCESS AFTER INPUT
-
8/13/2019 Table Cnt Rl
23/38
-
8/13/2019 Table Cnt Rl
24/38
Table Controls in the Flow Logic
PROCESS BEFORE OUTPUT.
LOOP AT ITAB WITH CONTROL FLIGHTS
CURSOR FLIGHTS-CURRENT_LINE.ENDLOOP.
PROCESS AFTER INPUT.
LOOP AT ITAB.
MODULE MODIFY_ITAB.
ENDLOOP.
MODULE MODIFY_ITAB INPUT.
MODIFY ITAB INDEX FLIGHTS-CURRENT_LINE.
ENDMODULE.
Method 1 (table control fields = itab fields)
-
8/13/2019 Table Cnt Rl
25/38
Table Controls in the Flow Logic
Method 2 (table control fields = dict. fields)
PROCESS BEFORE OUTPUT.
LOOP WITH CONTROL FLIGHTS.
MODULE READ_ITAB.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP WITH CONTROL FLIGHTS.
MODULE MODIFY_ITAB.
ENDLOOP.
MODULE READ_ITAB OUTPUT.
READ TABLE ITAB INDEX
FLIGHTS-CURRENT_LINE.
IF SY-SUBRC EQ 0.
MOVE-CORRESPONDING ITAB TO SFLIGHT.
ELSE.
EXIT FROM STEP-LOOP.
ENDIF.
ENDMODULE.
MODULE MODIFY_ITAB INPUT.MOVE-CORRESPONDING SFLIGHT TO ITAB.
MODIFY ITAB INDEX
FLIGHTS-CURRENT_LINE.
ENDMODULE.
-
8/13/2019 Table Cnt Rl
26/38
Table Controls in the Flow Logic
PROCESS BEFORE OUTPUT.
LOOP WITH CONTROL FLIGHTS.
MODULE READ_ITAB.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP WITH CONTROL FLIGHTS.
CHAIN.
FIELD: SFLIGHT-PRICE,
SFLIGHT-FLDATE.
MODULE MODIFY_ITAB
ON CHAIN-REQUEST.ENDCHAIN.
ENDLOOP.
MODULE READ_ITAB OUTPUT.
READ TABLE ITAB INDEX
FLIGHTS-CURRENT_LINE.
IF SY-SUBRC EQ 0.
MOVE-CORRESPONDING ITAB TO SFLIGHT.
ELSE.
EXIT FROM STEP-LOOP.
ENDIF.
ENDMODULE.
MODULE MODIFY_ITAB INPUT.MOVE-CORRESPONDING SFLIGHT TO ITAB.
MODIFY ITAB INDEX
FLIGHTS-CURRENT_LINE.
ENDMODULE.
Method 2 (table control fields = dict. fields)
-
8/13/2019 Table Cnt Rl
27/38
Table Control Attributes
data: begin of cxtab_control,
...
cols type cxtab_columnoccurs 10,
end of cxtab_control.
data: begin of cxtab_column,
...
selected,
screen like screen,
end of cxtab_column.
SCREEN FIELDS:
name
length
active
...
-
8/13/2019 Table Cnt Rl
28/38
Sorting a Table Control by a
Selected Field
DATA: WA LIKE LINE OF FLIGHTS-COLS.
...
MODULE USER_COMMAND_200....
LOOP AT FLIGHTS-COLS INTO WA.
IF WA-SELECTED = X.
SORT ITAB BY (WA-SCREEN-NAME+5).ENDIF.
ENDLOOP.
ENDMODULE.
-
8/13/2019 Table Cnt Rl
29/38
-
8/13/2019 Table Cnt Rl
30/38
Sample Fields
List
Output only fields
Table Control
-
8/13/2019 Table Cnt Rl
31/38
-
8/13/2019 Table Cnt Rl
32/38
Updating the Internal Table
PROCESS AFTER INPUT.
LOOP WITH CONTROL FLIGHTS.
CHAIN.
FIELD: SFLIGHT-PRICE,
SFLIGHT-FLDATE.
MODULE MODIFY_ITABON CHAIN-REQUEST.
ENDCHAIN.
ENDLOOP.
Method 1 Method 2
PROCESS AFTER INPUT.
LOOP AT ITAB.
CHAIN.
FIELD: SFLIGHT-PRICE,
SFLIGHT-FLDATE.
MODULE MODIFY_ITABON CHAIN-REQUEST.
ENDCHAIN.
ENDLOOP.
MODULE MODIFY_ITAB INPUT.
ITAB-MARK = 'X'.MODIFY ITAB INDEX
FLIGHTS-CURRENT_LINE.
ENDMODULE.
MODULE MODIFY_ITAB INPUT.
MOVE-CORRESPONDING SFLIGHTTO ITAB.
ITAB-MARK = 'X'.
MODIFY ITAB INDEX
FLIGHTS-CURRENT_LINE.
ENDMODULE.
-
8/13/2019 Table Cnt Rl
33/38
Updating the Database
Saving the Updated Data (both methods)
MODULE USER_COMMAND_200.
CASE OK_CODE.
WHEN SAVE.
LOOP AT ITAB.
CHECK ITAB-MARK = X.
MOVE-CORRESPONDING ITAB TO SFLIGHT.
UPDATE SFLIGHT.
ENDLOOP.
WHEN ...
...
ENDCASE.
ENDMODULE.
-
8/13/2019 Table Cnt Rl
34/38
-
8/13/2019 Table Cnt Rl
35/38
Updating the database
Exit modules are
processed before any
data is transferred from
screen to program(including updating
SY-DATAR), so this is
the only way to capture
changed data if an exit
is triggered.
PROCESS AFTER INPUT.
FIELD:
MODULE SET_FLAG ON REQUEST.
MODULE SET_FLAG INPUT.
FLAG = 'X'.
ENDMODULE.
MODULE EXIT INPUT.IF FLAG = 'X'.
ENDIF.
LEAVE TO SCREEN 0.
ENDMODULE.
-
8/13/2019 Table Cnt Rl
36/38
Conclusion
This lectured examined concepts associatedwith the use of Table Controls in a screen
definitioncreation
maintenance
filling
modifying
sorting
saving
-
8/13/2019 Table Cnt Rl
37/38
Related Reading
Textbook
Ch 3.3 - Dialog Applications
On Line HelpR/3 LibraryBC..ABAP Workbench
BC ABAP Users Guide ABAP User Interface Screens
Processing User input on a Screen, Controlling theScreen Flow, Modifying the Screen, Using Tables in aScreen
-
8/13/2019 Table Cnt Rl
38/38
Next Week
Review of semester
Please ask questions!