Table control is one of a ABAP displaying mechanisms. With the help of Table control we can see the output table in different visibility approach. Here we have developed a Module Pool program where a simple table control has been incorporated.
Here we have created a simple table control where we have two screens.
First screen in the selection screen where we need to select a purchase order number
and click on the display button. After that second screen will open and it contains the
item wise detailed information.
Following is the Steps for Table Control:
Step 1:
At first we are creating a module pool program with proper naming convention and create all the include
programs as follows.
INCLUDE mz_sr_top . " global Data
INCLUDE mz_sr_o01 . " PBO-Modules
INCLUDE mz_sr_i01 . " PAI-Modules
INCLUDE mz_sr_f01 . " FORM-Routines
INCLUDE mz_sr_o01 . " PBO-Modules
INCLUDE mz_sr_i01 . " PAI-Modules
INCLUDE mz_sr_f01 . " FORM-Routines
Step 2:
Next declare all the variables, structures, tables etc at top include.
PROGRAM sapmz_sr.
*-------Declaration of tables for screen fields------------------------*
TABLES: ekko, ekpo.
*------Declaration of required structures------------------------------*
TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
ernam TYPE ekko-ernam,
lifnr TYPE ekko-lifnr,
END OF ty_ekko,
BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
END OF ty_ekpo.
*-----Declaration of user command variables----------------------------*
DATA: ok_code1 TYPE sy-ucomm,
ok_code2 TYPE sy-ucomm.
*-----Declaration of work area & table---------------------------------*
DATA: wa_ekko TYPE ty_ekko,
wa_ekpo TYPE ty_ekpo,
it_ekpo TYPE TABLE OF ty_ekpo.
*---------Declaration of Table Control---------------------------------*
CONTROLS: tab_ctrl TYPE TABLEVIEW USING SCREEN 9002.
*-------Declaration of tables for screen fields------------------------*
TABLES: ekko, ekpo.
*------Declaration of required structures------------------------------*
TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
ernam TYPE ekko-ernam,
lifnr TYPE ekko-lifnr,
END OF ty_ekko,
BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
END OF ty_ekpo.
*-----Declaration of user command variables----------------------------*
DATA: ok_code1 TYPE sy-ucomm,
ok_code2 TYPE sy-ucomm.
*-----Declaration of work area & table---------------------------------*
DATA: wa_ekko TYPE ty_ekko,
wa_ekpo TYPE ty_ekpo,
it_ekpo TYPE TABLE OF ty_ekpo.
*---------Declaration of Table Control---------------------------------*
CONTROLS: tab_ctrl TYPE TABLEVIEW USING SCREEN 9002.
Step 3:
Now create a screen 9001 which is the selection screen of purchase order.
In the elementary list we declare the sy-ucomm (ok_code).
Step 4:
Write the flow logic as follows.
PROCESS BEFORE OUTPUT. MODULE status_9001.
PROCESS AFTER INPUT. MODULE user_command_9001.
PROCESS AFTER INPUT. MODULE user_command_9001.
Step 5:
Create the layout with required buttons and input fields.
Step 6:
Create PBO and PAI module of screen 9001 as follows.
MODULE status_9001 OUTPUT.
SET PF-STATUS 'PF_PO_INP'.
SET TITLEBAR 'PO_TITLE'.
ENDMODULE. " status_9001 OUTPUT
SET PF-STATUS 'PF_PO_INP'.
SET TITLEBAR 'PO_TITLE'.
ENDMODULE. " status_9001 OUTPUT
MODULE user_command_9001 INPUT.
CASE ok_code1.
WHEN 'DISP'. "Display button
PERFORM get_po.
WHEN 'CLR'. "Clear button
CLEAR ekko-ebeln.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " user_command_9001 INPUT
CASE ok_code1.
WHEN 'DISP'. "Display button
PERFORM get_po.
WHEN 'CLR'. "Clear button
CLEAR ekko-ebeln.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " user_command_9001 INPUT
Step 7:
Now we are going to create the functionality of Display button in the subroutine as follows.
FORM get_po .
IF ekko-ebeln IS NOT INITIAL.
REFRESH: it_ekpo.
SELECT SINGLE ebeln bukrs ernam lifnr
FROM ekko INTO wa_ekko
WHERE ebeln = ekko-ebeln.
IF sy-subrc = 0.
SELECT ebeln ebelp matnr werks lgort
FROM ekpo INTO TABLE it_ekpo
WHERE ebeln = wa_ekko-ebeln.
IF sy-subrc = 0.
SORT it_ekpo.
"Refreshing the table control to have updated data
REFRESH CONTROL 'TAB_CTRL' FROM SCREEN 9002.
CALL SCREEN 9002.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " get_po
IF ekko-ebeln IS NOT INITIAL.
REFRESH: it_ekpo.
SELECT SINGLE ebeln bukrs ernam lifnr
FROM ekko INTO wa_ekko
WHERE ebeln = ekko-ebeln.
IF sy-subrc = 0.
SELECT ebeln ebelp matnr werks lgort
FROM ekpo INTO TABLE it_ekpo
WHERE ebeln = wa_ekko-ebeln.
IF sy-subrc = 0.
SORT it_ekpo.
"Refreshing the table control to have updated data
REFRESH CONTROL 'TAB_CTRL' FROM SCREEN 9002.
CALL SCREEN 9002.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " get_po
Step 8:
After that create the screen 9002 which is the table control screen of PO item wise details.
Step 9:
Write the flow logic of table control in PBO & PAI.
PROCESS BEFORE OUTPUT. MODULE status_9002.
LOOP AT it_ekpo INTO wa_ekpo WITH CONTROL tab_ctrl.
MODULE table_control.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP AT it_ekpo.
MODULE modify_table_control.
ENDLOOP.
MODULE user_command_9002.
LOOP AT it_ekpo INTO wa_ekpo WITH CONTROL tab_ctrl.
MODULE table_control.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP AT it_ekpo.
MODULE modify_table_control.
ENDLOOP.
MODULE user_command_9002.
Step 10:
Now go to layout and create the table control from palate. The name must be TAB_CTRL.
Step 11:
Click on the dictionary button and select the required fields which need to be displayed in the table control.
Step 12:
After that the table control will look like this.
We can modify the visibility length also.
Step 13:
Now we have to create the PBO module of table control as follows.
MODULE status_9002 OUTPUT.
SET PF-STATUS 'PF_PO_INP'.
SET TITLEBAR 'PO_TITLE'.
ENDMODULE. " status_9002 OUTPUT
SET PF-STATUS 'PF_PO_INP'.
SET TITLEBAR 'PO_TITLE'.
ENDMODULE. " status_9002 OUTPUT
MODULE table_control OUTPUT.
"Describing table to populate sy-dbcnt
DESCRIBE TABLE it_ekpo LINES sy-dbcnt.
"Current line populates the loop information in table control
tab_ctrl-current_line = sy-loopc.
"Lines are populated with number of table lines
tab_ctrl-lines = sy-dbcnt.
"Moving data from work area to screen fields
ekpo-ebeln = wa_ekpo-ebeln.
ekpo-ebelp = wa_ekpo-ebelp.
ekpo-matnr = wa_ekpo-matnr.
ekpo-werks = wa_ekpo-werks.
ekpo-lgort = wa_ekpo-lgort.
CLEAR wa_ekpo.
ENDMODULE. " table_control OUTPUT
"Describing table to populate sy-dbcnt
DESCRIBE TABLE it_ekpo LINES sy-dbcnt.
"Current line populates the loop information in table control
tab_ctrl-current_line = sy-loopc.
"Lines are populated with number of table lines
tab_ctrl-lines = sy-dbcnt.
"Moving data from work area to screen fields
ekpo-ebeln = wa_ekpo-ebeln.
ekpo-ebelp = wa_ekpo-ebelp.
ekpo-matnr = wa_ekpo-matnr.
ekpo-werks = wa_ekpo-werks.
ekpo-lgort = wa_ekpo-lgort.
CLEAR wa_ekpo.
ENDMODULE. " table_control OUTPUT
Step 14:
Now create the PAI module as follows.
MODULE user_command_9002 INPUT.
CASE ok_code2.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
"Due to multiple clicks user command needs to be updated
CLEAR ok_code2.
LEAVE LIST-PROCESSING.
LEAVE TO SCREEN 9001.
ENDCASE.
ENDMODULE. " user_command_9002 INPUT
CASE ok_code2.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
"Due to multiple clicks user command needs to be updated
CLEAR ok_code2.
LEAVE LIST-PROCESSING.
LEAVE TO SCREEN 9001.
ENDCASE.
ENDMODULE. " user_command_9002 INPUT
MODULE modify_table_control INPUT.
"Readin the table with current line
READ TABLE it_ekpo INTO wa_ekpo INDEX tab_ctrl-current_line.
IF sy-subrc = 0.
"Modifying the current line in table control
MODIFY it_ekpo FROM wa_ekpo INDEX tab_ctrl-current_line.
ENDIF.
ENDMODULE. " modify_table_control INPUT
"Readin the table with current line
READ TABLE it_ekpo INTO wa_ekpo INDEX tab_ctrl-current_line.
IF sy-subrc = 0.
"Modifying the current line in table control
MODIFY it_ekpo FROM wa_ekpo INDEX tab_ctrl-current_line.
ENDIF.
ENDMODULE. " modify_table_control INPUT
Step 15:
Finally create a Transaction code and run it from SAP system. The selection screen which is the
first screen will come and enter a PO number there.
now we can scroll down like this.
No comments:
Post a Comment