Application Development and Automation 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: 
Read only

Not able to update database?

Former Member
0 Likes
785

Hello gururs,

i have created a structure which contains data from mara and makt tables. now i want to data of this structure to my own created database table starting with 'z'. program is done in module screen, where user enters data. so when user hits save button, it select data from mara and makt and save it in 'z' database. now data is coming in strcure not passing it to database..

for that i have used following code.

data : i_tab type ztest_cm(standard table).

WHEN 'SAVE'. status in program

PERFORM UPDATE_DB.

SELECT SINGLE * FROM MAKT INTO CORRESPONDING FIELDS OF ZSTRUC_CM(structure) working

WHERE MATNR = ZSTRUC_CM-MATNR.

SELECT SINGLE MEINS FROM MARA INTO CORRESPONDING FIELDS OF ZSTRUC_CM working

WHERE MATNR = ZSTRUC_CM-MATNR.

MOVE-CORRESPONDING ZSTRUC_CM TO I_TAB. not working

UPDATE ZTEST_CM FROM ZSTRUC_CM. not working

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
728

Hi Vikram,

New entry into database table should be through INSERT statement.

If you want to modify the record which is already present in a atbale, then use MODIFY or UPDATE.

And try checking Sy-subrc after each database statements so that you will know the type of error based on the value returned by sy-subrc.

Hope this helps

Rgds,

Sripal

4 REPLIES 4
Read only

Former Member
0 Likes
728

update statement work if the entries already exist in z table, otherwise it wont work, use Insert ot Modify statement..

Read only

Former Member
0 Likes
728

Hi,

>

> MOVE-CORRESPONDING ZSTRUC_CM TO I_TAB. not working

>

> UPDATE ZTEST_CM FROM ZSTRUC_CM. not working

Instead of the move statement you need to use the append work area to internal table statement. you need to have the same structure for the work area and the internal tbale.

Then use the modify data base table from internal table statement.

Regards

Ansari

Read only

Former Member
0 Likes
728

Use

MODIFY ZTEST_CM FROM TABLE ZSTRUC_CM.

COMMIT WORK.

Always use modify as it take cares to check which records already exists in table based on primary fields and updates only the ones not present.

Always while updating in Z tables or any transaparent tables, you have to use COMMIT WORK as it commits your data to the data base level.

Please search the forum before asking these questions;you will get your solution .

Thanks .

Read only

Former Member
0 Likes
729

Hi Vikram,

New entry into database table should be through INSERT statement.

If you want to modify the record which is already present in a atbale, then use MODIFY or UPDATE.

And try checking Sy-subrc after each database statements so that you will know the type of error based on the value returned by sy-subrc.

Hope this helps

Rgds,

Sripal