Monday, February 7, 2011

Inserting data into the database table using Classes

Go to Class Builder and create a new class

Provide the method name.

Go to parameters and provide the attributes.

Go back to methods. And provide the logic by double click on the method name.

Then save it, check it, activate it and execute it.

Press F8.

The data is stored in database.

To verify, go to VBAK table (SE16) and check whether the data is stored or not.

Now we will create a program using the above class for inserting the data into the database table.

Go to SE38 and create a program.

Select create button.

After that provide the following logic.

*&---------------------------------------------------------------------*
*& Report ZPG_INSERTINTODB *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT  ZPG_INSERTINTODB.
*provide the object for the class
DATA: OBJ_INSERT TYPE REF TO ZCL_INSERTDB.
*provide parameters
PARAMETERS: V_VBELN TYPE VBELN,
V_ERDAT TYPE ERDAT,
V_ERZET TYPE ERZET.
*provide work area
DATA: WA TYPE VBAK.
*create the object
START-OF-SELECTION.
CREATE OBJECT OBJ_INSERT.
*provide insert method
CALL METHOD OBJ_INSERT->INSERT_DATA
*provide exporting parameters
EXPORTING
P_VBELN = V_VBELN
P_ERDAT = V_ERDAT
P_ERZET = V_ERZET
*provide import parameters
IMPORTING
WA_VBAK = WA.
*display the data.
WRITE:/ WA-VBELN,
WA-ERDAT,
WA-ERZET.

Save it , activate it, execute it .

The screen is like this.

Provide values.

Execute it.

Following is the sample output of the same:

No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites