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: 

how to update contents in a table created using module pool programming? unable to do that process for the below code

Former Member
0 Kudos

*&---------------------------------------------------------------------*

*& Module Pool       ZCDSHOP

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

PROGRAM  ZCDSHOP.

tables : zcustomer.

CONTROLS MATERIAL TYPE TABLEVIEW USING SCREEN 2000.

TYPES: BEGIN OF ST_zCUSTOMER,

       zfirstname type zcustomer-zfirstname,

       zlastname type  zcustomer-zlastname,

       zadress type zcustomer-zadress,

       zcdname type zcustomer-zcdname,

       ztakendate type zcustomer-ztakendate,

       zlastdate type zcustomer-zlastdate,

       zamount type zcustomer-zamount,

       END OF ST_zCUSTOMER.

DATA: IT_ST TYPE TABLE OF ST_zCUSTOMER,

       WA_ST TYPE ST_zCUSTOMER,

       IT_zCUSTOMER TYPE zCUSTOMER,

       WA_zCUSTOMER TYPE zCUSTOMER,

       OK_CODE LIKE SY-UCOMM.

start-of-selection.

CALL SCREEN 2000.

*&---------------------------------------------------------------------*

*&      Module  V1  INPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE V1 INPUT.

CASE OK_CODE.

WHEN 'SAVE'.

WA_ST-zfirstname = zCUSTOMER-zfirstname.

WA_ST-zlastname = zCUSTOMER-zlastname.

WA_ST-zadress = zcUSTOMER-zadress.

WA_ST-zcdname = zCUSTOMER-zcdname.

WA_ST-ztakendate = zCUSTOMER-ztakendate.

WA_ST-zlastdate = zCUSTOMER-zlastdate.

WA_ST-zamount = zCUSTOMER-zamount.

MOVE-CORRESPONDING WA_ST TO WA_zCUSTOMER.

INSERT INTO zCUSTOMER VALUES WA_zCUSTOMER.

WHEN 'DELETE'.

WA_ST-zfirstname = zCUSTOMER-zfirstname.

WA_ST-zlastname = zCUSTOMER-zlastname.

WA_ST-zadress = zcUSTOMER-zadress.

WA_ST-zcdname = zCUSTOMER-zcdname.

WA_ST-ztakendate = zCUSTOMER-ztakendate.

WA_ST-zlastdate = zCUSTOMER-zlastdate.

WA_ST-zamount = zCUSTOMER-zamount.

MOVE-CORRESPONDING  WA_ST TO WA_zCUSTOMER.

DELETE zCUSTOMER FROM WA_zCUSTOMER.

WHEN 'MODIFY'.

WA_ST-zfirstname = zCUSTOMER-zfirstname.

WA_ST-zlastname = zCUSTOMER-zlastname.

WA_ST-zadress = zcUSTOMER-zadress.

WA_ST-zcdname = zCUSTOMER-zcdname.

WA_ST-ztakendate = zCUSTOMER-ztakendate.

WA_ST-zlastdate = zCUSTOMER-zlastdate.

WA_ST-zamount = zCUSTOMER-zamount.

MODIFY zCUSTOMER FROM WA_zCUSTOMER.

ENDCASE.

ENDMODULE.                 " V1  INPUT

*&---------------------------------------------------------------------*

*&      Module  EXIT  INPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE EXIT INPUT.

IF OK_CODE = 'EXIT'.

LEAVE PROGRAM.

ENDIF.

ENDMODULE.                 " EXIT  INPUT

*&---------------------------------------------------------------------*

*&      Module  STATUS_2000  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

module STATUS_2000 output.

*  SET PF-STATUS 'xxxxxxxx'.

*  SET TITLEBAR 'xxx'.

endmodule.                 " STATUS_2000  OUTPUT

1 ACCEPTED SOLUTION

former_member213851
Active Contributor
0 Kudos

Hi Ranjith,

Instead of INSERT staement in SAVE , use below statements  

MODIFY zCUSTOMER FROM  WA_zCUSTOMER.
    COMMIT WORK.                "To write  records on Database

Best Regards,

Sachin

5 REPLIES 5

Former Member
0 Kudos

Hi Ranjith

From your code I take it that your SAVE function is not working....

Try changing your Insert to Modify zdbtzb from itab.

In this if the record (comparing keys) exists then the table is updated and if it doesn't then it will be inserted.

Hope this Helps

Regards

Vic

Former Member
0 Kudos

Hi Ranjith,

               In modify part you are missing the move corresponding statement.

MOVE-CORRESPONDING  WA_ST TO WA_zCUSTOMER.

Please add this statement and your code would work.

former_member213851
Active Contributor
0 Kudos

Hi Ranjith,

Instead of INSERT staement in SAVE , use below statements  

MODIFY zCUSTOMER FROM  WA_zCUSTOMER.
    COMMIT WORK.                "To write  records on Database

Best Regards,

Sachin

0 Kudos

Hi Ranjith,

Seems to be a simple utility to play with the contents of the table.

Is there any specific reason that you are not creating "Table Maintenance Generator" for this requirement.

You can achieve all this without bothering about any coding part.

Former Member
0 Kudos

Hi Ranjit,

To update a transparent table from a workarea or an internal table, you must declare the internal table/workarea of exactly the same type as the transparent table. You will also have to declare field MANDT (if present in transparent table).

Regards,

Prashant