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

Write back values to db table

Former Member
0 Likes
1,069

Hi folks,

I want to read the description-texts from maintenance-positions, modify them a little and then write the new values back. I arranged a User-selection using select options and I can process those objects and read their descriptions, but I don't know how to write back the new values to database-table MPOS.

Here is what I have:


DATA tmpos LIKE mpos OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN  BEGIN OF BLOCK txt WITH FRAME TITLE text-001.

SELECT-OPTIONS:
t_warpl FOR tmpos-warpl.

SELECTION-SCREEN END OF BLOCK txt.

  SELECT * FROM mpos into table tmpos
  WHERE warpl IN t_warpl.
  
  LOOP AT tmpos.
      WRITE / tmpos-pstxt.
      tmpos-pstxt = 'TEST'.
      modify table tmpos.
  ENDLOOP.

It seems I just modify the temporal table, but not the one in db.

Can you help me out?

Thanx and have a nice day!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
981

Hi,

This is a very basic question.

in your abap editor press F1 on modify keyword and check documentation for Modify dbtab.

8 REPLIES 8
Read only

former_member404244
Active Contributor
0 Likes
981

Hi,

yes yor are right, you are not modifying the dbtable but the internal table.. I won't suggest updating any db table directly but then if the requirement is like that then you can try this command. I would suggest check for FM'S or Bapi's to update.. Please check the functionlaity and do it.



LOOP AT tmpos.
      WRITE / tmpos-pstxt.
      tmpos-pstxt = 'TEST'.
      modify table tmpos.
  ENDLOOP.

modify mpos from table tmpos.

if sy-subrc eq 0.

commitwork.

endif.

Regards,

Nagaraj

Read only

0 Likes
981

Hi,

you can also use function module MAINTENANCE_ITEM_POST.

Regards,

Adrian

Read only

Former Member
0 Likes
982

Hi,

This is a very basic question.

in your abap editor press F1 on modify keyword and check documentation for Modify dbtab.

Read only

Former Member
0 Likes
981

HI,

Can u elaborate what is your requirement because ur passing the description HARDCODED in the loop

LOOP AT tmpos.
      WRITE / tmpos-pstxt.
      tmpos-pstxt = 'TEST'. "I did n't get ur changing this description with a hardcoded value 
      modify table tmpos.
  ENDLOOP.

The solution for this is update the PSTXT in the loop of tmpos

Regards,

Madhukar Shetty

Read only

Former Member
0 Likes
981

Hello Nagaraj,

you mean commit work (with backspace in between I think).

Looks promising, but doesn't update the db.

sy-subrc is 0, I checked that with an additional Write-command, but if I enter the corresponding maintenance-position I can still see the old text, instead of TEST.

Thank you!

Read only

0 Likes
981

Hi,

First check what adrian suggested the FM,. Please try the below code.Put a break point and see whether pstxt value is chnaged in the loop.



LOOP AT tmpos.
      WRITE / tmpos-pstxt.
      tmpos-pstxt = 'TEST'.
      modify  tmpos transporting pstxt.
  ENDLOOP.
 
modify mpos from table tmpos.
 
if sy-subrc eq 0.
 
commit work.
 
endif.
 

Regards,

Nagaraj

Read only

0 Likes
981

Hi Andreas,

It is not advisable to update the standard SAP tables by using MODIFY or UPDATE statements in the program. It is dangerous and can cause data inconsistency.

Check if any standard FM or BAPI is available to change the text.

Regards,

Immanuel.

Read only

Former Member
0 Likes
981

Hi Andreas,

Please use update statement after modifying your internal table.

Check below code. Takecare while updating the database tabels.

LOOP AT tmpos.
  WRITE / tmpos-pstxt.
  tmpos-pstxt = 'TEST'.
*      modify table tmpos.
  MODIFY tmpos TRANSPORTING pstxt.
ENDLOOP.

UPDATE mpos FROM TABLE tmpos.

Thanks,

Kavitha.