Professional Documents
Culture Documents
Manipulation of Table Control
Manipulation of Table Control
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.
Resizable table for displaying and editing data. The user or program can change the column width and position, save the changes, and reload them later. Check column for marking lines; marked lines are highlighted in a different color. Line selection: single lines, multiple lines, all lines, and deselection. Column headings double as pushbuttons for marking columns. Scrollbars for horizontal and vertical scrolling. Any number of key (leading) columns can be set.
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)
Enter the structure defined in the program and click GET FROM PROGRAM and select all fields
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 and activate program
(Cont.)
(Cont.)
(Cont.)
(Cont.)
(Cont.)
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
Deselect All
Invert Selection
Delete Rows
Complete Coding in text format 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 restoratio n 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 cont rol 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
Screen Flow Logic PROCESS BEFORE OUTPUT.MODULE STATUS_9000.LOOP AT LT_SOURCE INTO LS_SOURC E WITH CONTROL SOURCE.ENDLOOP.LOOP AT LT_DESTINATION INTO LS_DESTINATION WITH CONTROL DESTINATION.ENDLOOP.
PBO (Module STATUS_9000 output) module STATUS_9000 output.* SET PF-STATUS 'xxxxxxxx'. * SET TITLEBAR 'xxx'. *To fill table control(SOURCE) once IF FLAG = ''.*Data selection for source table SELECT * UP TO 5 ROWS FROM MARA INTO CORRESPONDING FIELDS OF TABLE LT_SOURCE. FLAG = 'X'.ENDIF.*If internal table is not empty IF NOT LINES( LT_SOURCE ) = 0.*Set no. of table control lines(SOURCE) SOURCE-LINES = LINES( LT_SOURCE ).ELSE.*Disable table control lines SOURCE-LINES = -1.ENDIF.*If internal table is not empty IF NOT LINES( LT_DESTINATION ) = 0.*Set no. of table control lines(DESTINATION) DESTINATION-LINES = LINES( LT_DESTINATION ).ELSE.*Disable table control lines DESTINATION-LINES = -1.ENDIF."To set all columns in read only mode LOOP AT DESTINATION-COLS INTO LS_DST_COL. LS_DST_COL-SCREEN-INPUT = ''.MODIFY DESTINATION-COLS FROM LS_DST_COL .ENDLOOP."To set all columns in read only mode LOOP AT SOURCE-COLS INTO LS_SRC_COL. LS_SRC_COL-SCREEN-INPUT = ''.MODIFY SOURCE-COLS FROM LS_SRC_COL .ENDLOOP.endmodule. " STATUS_9000 OUTPUT PAI ( Module MODIFY_SOURCE input) module MODIFY_SOURCE input."Updating changes from table control to internal table MODIFY LT_SOURCE FROM LS_SOURCE INDEX SOURCE-CURRENT_LINE.endmodule. " MODIFY_SOURCE INPUT PAI ( Module USER_COMMAND_9000 input) module USER_COMMAND_9000 input."User command field DATA OK_CODE TYPE SY-UCOMM. OK_CODE = SY-UCOMM.CASE OK_CODE. WHEN 'DELETE'. "Retrieving record selected LOOP AT LT_SOURCE INTO LS_SOURCE WHERE MARK = 'X'. "Appending record to be deleted in restore table APPEND LS_SOURCE TO LT_RESTORE. "Deleting record to be deleted DELETE TABLE LT_SOURCE FROM LS_SOURCE. "Decrementing table control line by one SOURCE-LINES = SOURCE-LINES - 1. ENDLOOP.
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.