Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Table Control

Former Member
0 Kudos

Hi Everyone,

I have created a table control and my further task is to make data entries into the table control .

Upon entering the values in table control and pressing SAVE button the values entered should be entered into the corresponding database table,

Suggestions on how to do that as i have created two tables ZEMP_CG and ZEMP_CG_LEAVE where employee id is the

primary key in ZEMP_CG and the foreign key in ZEMP_CG_LEAVE.

The Combination of Employee ID and a field called zcount is the primary key in* ZEMP_CG_LEAVE* table.

What is it that i need to do such that the data i enter in the TABLE control , upon pressing SAVE gets added to the table ZEMP_CG_LEAVE.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hera is sample program for table control

REPORT Z_DB_TABLECONTROL.

TABLES: MARA.

CONTROLS MATERIAL TYPE TABLEVIEW USING SCREEN 130.

TYPES: BEGIN OF ST_MARA,

MATNR TYPE MARA-MATNR,

ERSDA TYPE MARA-ERSDA,

ERNAM TYPE MARA-ERNAM,

LAEDA TYPE MARA-LAEDA,

END OF ST_MARA.

DATA: IT_ST TYPE TABLE OF ST_MARA,

WA_ST TYPE ST_MARA,

IT_MARA TYPE MARA,

WA_MARA TYPE MARA,

OK_CODE LIKE SY-UCOMM.

CALL SCREEN 130.

&----


*& Module V1 INPUT

&----


  • text

----


MODULE V1 INPUT.

CASE OK_CODE.

WHEN 'SAVE'.

WA_ST-MATNR = MARA-MATNR.

WA_ST-ERSDA = MARA-ERSDA.

WA_ST-ERNAM = MARA-ERNAM.

WA_ST-LAEDA = MARA-LAEDA.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

INSERT INTO MARA VALUES WA_MARA.

WHEN 'DELETE'.

WA_ST-MATNR = MARA-MATNR.

WA_ST-ERSDA = MARA-ERSDA.

WA_ST-ERNAM = MARA-ERNAM.

WA_ST-LAEDA = MARA-LAEDA.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

DELETE MARA FROM WA_MARA.

WHEN 'MODIFY'.

WA_ST-MATNR = MARA-MATNR.

WA_ST-ERSDA = MARA-ERSDA.

WA_ST-ERNAM = MARA-ERNAM.

WA_ST-LAEDA = MARA-LAEDA.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

MODIFY MARA FROM WA_MARA.

ENDCASE.

ENDMODULE. " V1 INPUT

&----


*& Module EXIT INPUT

&----


  • text

----


MODULE EXIT INPUT.

IF OK_CODE = 'EXIT'.

LEAVE PROGRAM.

ENDIF.

ENDMODULE. " EXIT INPUT

Edited by: gop4sap11 on Feb 10, 2012 7:08 AM

11 REPLIES 11

Former Member
0 Kudos

hera is sample program for table control

REPORT Z_DB_TABLECONTROL.

TABLES: MARA.

CONTROLS MATERIAL TYPE TABLEVIEW USING SCREEN 130.

TYPES: BEGIN OF ST_MARA,

MATNR TYPE MARA-MATNR,

ERSDA TYPE MARA-ERSDA,

ERNAM TYPE MARA-ERNAM,

LAEDA TYPE MARA-LAEDA,

END OF ST_MARA.

DATA: IT_ST TYPE TABLE OF ST_MARA,

WA_ST TYPE ST_MARA,

IT_MARA TYPE MARA,

WA_MARA TYPE MARA,

OK_CODE LIKE SY-UCOMM.

CALL SCREEN 130.

&----


*& Module V1 INPUT

&----


  • text

----


MODULE V1 INPUT.

CASE OK_CODE.

WHEN 'SAVE'.

WA_ST-MATNR = MARA-MATNR.

WA_ST-ERSDA = MARA-ERSDA.

WA_ST-ERNAM = MARA-ERNAM.

WA_ST-LAEDA = MARA-LAEDA.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

INSERT INTO MARA VALUES WA_MARA.

WHEN 'DELETE'.

WA_ST-MATNR = MARA-MATNR.

WA_ST-ERSDA = MARA-ERSDA.

WA_ST-ERNAM = MARA-ERNAM.

WA_ST-LAEDA = MARA-LAEDA.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

DELETE MARA FROM WA_MARA.

WHEN 'MODIFY'.

WA_ST-MATNR = MARA-MATNR.

WA_ST-ERSDA = MARA-ERSDA.

WA_ST-ERNAM = MARA-ERNAM.

WA_ST-LAEDA = MARA-LAEDA.

MOVE-CORRESPONDING WA_ST TO WA_MARA.

MODIFY MARA FROM WA_MARA.

ENDCASE.

ENDMODULE. " V1 INPUT

&----


*& Module EXIT INPUT

&----


  • text

----


MODULE EXIT INPUT.

IF OK_CODE = 'EXIT'.

LEAVE PROGRAM.

ENDIF.

ENDMODULE. " EXIT INPUT

Edited by: gop4sap11 on Feb 10, 2012 7:08 AM

0 Kudos

Hi,

I didnt get the clear picture of your requirement, what is got is that on pressing save the enteries should go into the corresponding table.

If this is the case, write the code in the PAI and as there is FK, so entry should go into the main table then into the reference table.

Let me know if this is not your actual requirement.

Regards,

Gopal Gupta

0 Kudos

Hi Gopal,

The requirement is that the entries in the table control should go to the reference table alone.. When i give entries in the

Table control, it should fill the reference table with the entered contents.

0 Kudos

Hi,

Try Cluster view .

http://wiki.sdn.sap.com/wiki/display/ABAP/ViewClusters-CreationanditsBenefits

0 Kudos

Hi,

Is emp_id is the part of table control fields, if so then its sime write the insert code into the ok_code of save button. But make sure emp_id is present in the Main Table.

Regards,

gopal

former_member198275
Active Contributor
0 Kudos

Here is one option :

Go to SE11 for ZEMP_CG > Utilities >Table Maintenance generator > environment > modification > events

New entries > select 02 or 05 and give Form routine name , and write code in editor for populating data in your other table ZEMP_CG_LEAVE.

Former Member
0 Kudos

Sorry for providing the inadequate information , I would like to make it clear bout the fields present in both the tables.

ZEMPCG_ - + EMPID(primary key), EMPNAME , DOB,POSITION ,LOCATION ,DEPARTMENT +

*_ZEMP_CG_LEAVE_ *- EMPID(foreign key),zcount, MONTH,YEAR,ABSENCE TYPE,START DATE,END DATE,APPROVED BY

In ZEMP_CG_LEAVE the combination of ZCOUNT and EMPID is the primary key.

In the table control the fields used are ABSENCETYPE START DATE,END DATE,APPROVED BY.

the the normal input fields used are EMPLOYEE ID,MONTH & YEAR.

Upon entering the values in the respective fields mentioned above, the details should be filled in the second table

i . e. ZEMP_CG_LEAVE upon pressing the SAVE button.

Edited by: BharatPanda on Feb 10, 2012 4:26 PM

0 Kudos

Hi Bharat,

IN PAI,

store the data entered in table control into an internal table.

After that in module user_command write code for save.

Find below the logic for the same.

process after input.

loop at gt_tab.

module t_modify. ( Modify or update internal table in this module from table control )

endloop.

module user_command_0110.

(In module user_command_0110 write the code for save.)

Loop at your internal table ( Structure of internal table same as ZEMP_CG_LEAVE).

Get the last entry from database table ZEMP_CG_LEAVE to get last ZCOUNT.

Update this ZCOUNT in internal table and update the database table.

Regards,

gaurav.

Edited by: cg.chawla on Feb 14, 2012 9:00 AM

Edited by: cg.chawla on Feb 14, 2012 9:01 AM

0 Kudos

Hi Bharat,

simply writing the modify statement will not work as whatever the values is getting entered from the table control will not modify the itab, so to modify the itab first you need to write the logic.

use the below code in the PAI .

chain.

**write the fields name if you want to do validation

    • module modify_itab.

endchain.

Note:

In the module write the logic to modify your itab, if your itab's value gets modified then u will see the changes done in the table control.

and for making changes into the DB loop at the modified itab and modify .

Hope it will solve yours issue

Regards,

Gopal

Former Member
0 Kudos

Hi Bharat,

Please do as below:

PROCESS AFTER INPUT.

MODULE user_command INPUT.

CASE sy-ucomm.

WHEN 'SAVE'.

<<Loop on your table control and update the database table.>>

ENDCASE.

0 Kudos

@rafia.

Hi rafia,

<<Loop on your table control and update the database table.>>

can you give sample code for writiing that loop

Edited by: GUBBEE on Feb 14, 2012 7:13 AM