Você está na página 1de 8

ABAP Code Sample for Table Controls

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

include z_k_table1_pbo. *for pai event in screen programming include z_k_table1_pai.

INCLUDE PROGRAM FOR PBO

*---------------------------------------------------------------------* * * INCLUDE Z_K_TABLE1_PBO

*---------------------------------------------------------------------* *&--------------------------------------------------------------------* *& 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

INCLUDE PROGRAM FOR PAI *---------------------------------------------------------------------* * * INCLUDE Z_K_TABLE1_PAI

*---------------------------------------------------------------------* *&--------------------------------------------------------------------* *& 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

*&--------------------------------------------------------------------* *& Module update_tab_control1 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

Flow Logic process before output.

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.

Disclaimer & Liability Notice


This document may discuss sample coding, which does not include official interfaces and therefore is not supported. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing of the code and methods suggested here, and anyone using these methods, is doing it under his/her own responsibility. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of the technical article, including any liability resulting from incompatibility between the content of the technical article and the materials and services offered by SAP. You agree that you will not hold SAP responsible or liable with respect to the content of the Technical Article or seek to do so.
Copyright 2004 SAP AG, Inc. All Rights Reserved. SAP, mySAP, mySAP.com, xApps, xApp, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product, service names, trademarks and registered trademarks mentioned are the trademarks of their respective owners.

Você também pode gostar