Escolar Documentos
Profissional Documentos
Cultura Documentos
Code samples are intended for educational use only, not deployment. They are untested and unsupported by SAP. SAP disclaims all liability to any person in respect to any damage that is incurred, whether wholly or partially, from use of the code.
Applies To:
ABAP
Summary
This code sample illustrates how to use table controls to display records from database tables, modify the records, and insert new records to database tables via table control. It is simple and easy to understand for all levels of ABAP programmers. It illustrates the basics involved in using table control. By: Kavitha Bhuvaneswaran Company: Wipro Technologies Date: 7 Feb 2005
Code
program z_k_table1 . *tables declaration tables : zemploykk. *data declaration data : ok_code type sy-ucomm. data : v_lines type i. data : i_final type table of zemploykk. *for using table control controls : tabcont type tableview using screen '3000'. *for pbo event in screen programming
*---------------------------------------------------------------------* *&--------------------------------------------------------------------* *& Module STATUS_3000 OUTPUT *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* module status_3000 output. set pf-status 'DEMO'. set titlebar 'TABLE1'. describe table i_final lines tabcont-lines. endmodule. " STATUS_3000 OUTPUT
*&--------------------------------------------------------------------* *& Module output OUTPUT *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* " output OUTPUT
*---------------------------------------------------------------------* *&--------------------------------------------------------------------* *& Module USER_COMMAND_3000 INPUT *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* module user_command_3000 input. case ok_code. when 'DISPLAY'. if i_final is initial. select * from zemploykk into table i_final. endif. when 'BACK'. leave to screen '0'. when 'CLEAR'. clear i_final. when 'MODIFY'. update zemploykk from table i_final. clear i_final. when 'INSERT'. insert zemploykk from table i_final. clear i_final. endcase. endmodule. " USER_COMMAND_3000 INPUT
*&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* module update_tab_control1 input. describe table i_final lines v_lines. if v_lines < tabcont-current_line. append zemploykk to i_final. else. modify i_final from zemploykk index tabcont-current_line. endif. endmodule. " update_tab_control1 INPUT
Screen Design
module status_3000. loop at i_final into zemploykk with control tabcont. endloop. process after input. loop at i_final. module update_tab_control1. endloop. module user_command_3000.
Output When the user enters the transaction code associated for this module pool program , we get the below screen.
when the user clicks display button, the table contents are displayed.
Clear button clears the screen. When the user enters a new record after clearing the contents and presses insert button , the record gets inserted.
When the user makes modifications to existing records and clicks modify button , modifications get updated.