Professional Documents
Culture Documents
Introduction
A table control is an area on the screen in which the system displays data in tabular form. It is processed using a
loop.
Select type as ‘MODULE POOL’ and status as ‘TEST PROGRAM’ and click ‘SAVE’
Select Local Object ( You can also select your own package and save)
Write the below coding (Defining Internal tables for table controls SOURCE and DESTINATION)
(Cont.)Define table controls SORUCE and DESTINATION to be created in the screen
Provide the following attributes in the attribute panel for each table control
Create push buttons as shown below using ‘PUSH BUTTON’ icon in the toolbar and provide attributes for
each element as following and Save the screen
Double click on screen 9000 and enter the below code in the flow logic tab
(Cont.)
(Cont.)
Add a code ‘MODULE modify_source’ and double click on it and select ‘YES’
Write the below code in the generated module block
Write the below code in the generated module block and activate program
(Cont.)
(Cont.)
(Cont.)
(Cont.)
(Cont.)
Right click on program name and select Create->Transaction
Provide attributes shown below and save and execute the program
EXECUTE : Activate Program and Right click Program name and select
Execute->In a new window
OUTPUT :
Select All
Deselect All
Invert Selection
Delete Rows
Program
*General Structure
TYPES : BEGIN OF LS,
MATNR TYPE MARA-MATNR,
ERNAM TYPE MARA-ERNAM,
MTART TYPE MARA-MTART,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
MARK,
END OF LS.*Work area and internal table for both table control with similiar data
DATA : LS_SOURCE TYPE LS,
LS_DESTINATION TYPE LS,
LT_SOURCE LIKE TABLE OF LS_SOURCE,
LT_DESTINATION LIKE TABLE OF LS_DESTINATION.*Internal table for restoration data
DATA : LT_RESTORE LIKE TABLE OF LS_SOURCE.*Table controls
CONTROLS : SOURCE TYPE TABLEVIEW USING SCREEN 9000,
DESTINATION TYPE TABLEVIEW USING SCREEN 9000.*Work area for table control columns
DATA : LS_SRC_COL LIKE LINE OF SOURCE-COLS,
LS_DST_COL LIKE LINE OF DESTINATION-
COLS.DATA : FLAG, "To fill source table once
FIELD(20). "To store column name in table control
WHEN 'RESTORE'.
"Moving records from restore table to source table
APPEND LINES OF LT_RESTORE TO LT_SOURCE.
"Sorting source table in ascending order
SORT LT_SOURCE BY MATNR.
"Clearing contents in restore table
REFRESH LT_RESTORE.
WHEN 'MOVE'.
"Retrieving record selected
LOOP AT LT_SOURCE INTO LS_SOURCE WHERE MARK = 'X'.
"Making records being not selected
CLEAR LS_SOURCE-MARK.
"Moving record to destination table
APPEND LS_SOURCE TO LT_DESTINATION.
ENDLOOP.
"Sorting destination table in ascending order
SORT LT_DESTINATION.
"Deleting duplicate records
DELETE ADJACENT DUPLICATES FROM LT_DESTINATION COMPARING ALL FIELDS.
WHEN 'SELECT'.
"Retrieving record being not selected
LOOP AT LT_SOURCE INTO LS_SOURCE WHERE MARK <> 'X'.
"Making record being selected
LS_SOURCE-MARK = 'X'.
"Updating Changes to source table
MODIFY LT_SOURCE FROM LS_SOURCE TRANSPORTING MARK.
ENDLOOP.
WHEN 'DESELECT'.
"Retrieving record being selected
LOOP AT LT_SOURCE INTO LS_SOURCE WHERE MARK = 'X'.
"Making record being not selected
LS_SOURCE-MARK = ''.
"Updating Changes to source table
MODIFY LT_SOURCE FROM LS_SOURCE TRANSPORTING MARK.
ENDLOOP.
WHEN 'INVERT'.
"Retrieving record being selected
LOOP AT LT_SOURCE INTO LS_SOURCE WHERE MARK = 'X'.
"Setting mark value to temporary value other than 'X' or space( here 'Y')
LS_SOURCE-MARK = 'Y'.
MODIFY LT_SOURCE FROM LS_SOURCE TRANSPORTING MARK.
ENDLOOP.
"Retreiving record being not selected
LOOP AT LT_SOURCE INTO LS_SOURCE WHERE MARK = ''.
"Making record being selected
LS_SOURCE-MARK = 'X'.
MODIFY LT_SOURCE FROM LS_SOURCE TRANSPORTING MARK.
ENDLOOP.
"Retrieving record whose mark value has been set to temporary value( here 'Y')
LOOP AT LT_SOURCE INTO LS_SOURCE WHERE MARK = 'Y'.
"Making record being not selected
LS_SOURCE-MARK = ''.
MODIFY LT_SOURCE FROM LS_SOURCE TRANSPORTING MARK.
ENDLOOP.
WHEN 'SORT_A'.
"Retrieving column being selected
READ TABLE SOURCE-COLS INTO LS_SRC_COL WITH KEY SELECTED = 'X'.
"Assigning column name to variable
FIELD = LS_SRC_COL-SCREEN-NAME+10(10).
IF SY-SUBRC = 0.
"Sorting source table in ascending order if any column selected
SORT LT_SOURCE BY (FIELD).
ENDIF.
WHEN 'SORT_D'.
"Retrieving column being selected
READ TABLE SOURCE-COLS INTO LS_SRC_COL WITH KEY SELECTED = 'X'.
"Assigning column name to variable
FIELD = LS_SRC_COL-SCREEN-NAME+10(10).
IF SY-SUBRC = 0.
"Sorting source table in descending order if any column selected
SORT LT_SOURCE BY (FIELD) DESCENDING.
ENDIF.
WHEN 'EXIT'.
"Leaving program
LEAVE PROGRAM.
ENDCASE.endmodule. " USER_COMMAND_9000 INPUT