11 Replies Latest reply: Feb 14, 2012 9:40 AM by gopal gupta RSS

Table Control

Currently Being Moderated

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.

  • Re: Table Control
    GOPI MANJUNATH M
    Currently Being Moderated

    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

  • Re: Table Control
    KaushiK Datta
    Currently Being Moderated

    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.

  • Re: Table Control
    Currently Being Moderated

    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

    • Re: Table Control
      gaurav chawla
      Currently Being Moderated

      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

      • Re: Table Control
        gopal gupta
        Currently Being Moderated

        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

  • Re: Table Control
    Currently Being Moderated

    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.

Actions