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

update database table fields

Former Member
0 Likes
1,797

Hi Friends,

I am using update statement to change LIPS field value.

I have used below code to change the field and it worked fine in dev server. But, in Q while delivery creation(VL01N), for update satement, sy-subrc is 4 and commit work is not happening. In VL02n it's working fine.

*LIPS-MTVFP = ZGL_VL10G_ATP-ZNEW_ATP.

update *LIPS.

if sy-subrc eq 0.

commit work and wait.

endif.

LIPS-MTVFP = ZGL_VL10G_ATP-ZNEW_ATP.

update LIPS.

if sy-subrc eq 0.

commit work and wait.

endif.

kindly suggest on this issue.

Thanks.

Bharat.

9 REPLIES 9
Read only

Former Member
0 Likes
1,436

Hi

FIRST THING: don't change a value of std field directly, u shoudl use a BAPI or another std fm;

SECOND THING: NEVER NEVER NEVER call a COMMIT in a std transaction

Now if in VL01 you can't update the LIPS is because the record doesn't exist in database yet.

So u make sure the record u need to update is in database.

Max

Read only

0 Likes
1,436

Hello max,

the things is that the code worked fine in development server. it's giving problem in Q.

Thanks.

Bharat

Read only

0 Likes
1,436

Hi

I can only think if an UPDATE fails is because the record u want to update is not in db yet.

So u should give us more informations: for example which record u want to update: the item of the delivery u're creating by VL01N or another one?

Max

Read only

0 Likes
1,436

Hello Max,

I'm changing LIPS-MTVFP value based on some condition.

Earlier value of LIPS-MTVFP = 'Z3' and am chaning it to 'Z4'.

LIPS-MTVFP = .'Z4'

update LIPS.

if sy-subrc eq 0.

commit work and wait.

endif.

Thanks,

Bharat.

Read only

0 Likes
1,436

Ok

But where u're doing it?

In exit of VL01N?

and which are the keys of LIPS?

There's the delivery number (LIPS-VBELN) or not?

Read only

0 Likes
1,436

Yes, I'm using it in delivery user exit MV50AFZ1.

The key for LIPS is VBELN and it contain the value.

Read only

0 Likes
1,436

Hi

- I'm using it in delivery user exit MV50AFZ1

Are u using th exit USEREXIT_MOVE_FIELD_TO_LIPS?

- The key for LIPS is VBELN and it contain the value

Yes I know it, but which is the document? i.e it's the current document or another one?

Anyway if you try to update the current document u should consider when the exit USEREXIT_MOVE_FIELD_TO_LIPS (but also all exits defined in MV50AFZ1) is called the current delivery is not stored in db yet, so for trx VL01N it means there's no record to be updated in DB.

So the strange behavior is not for quality system, but it's for the dev system.

I think u shouldn't use the UPDATE statament but only u should move the new value, the system'll save it automatically as soon as the user presses save button:

IF LIPS-MTVFP = 'Z3'.
  LIPS-MTVFP = .'Z4'
ENDIF.

Now probably the problem is the std program replace your new value with the old one again, if it's so u should change the point where u move the value (try to use the exit (try to use the exit USEREXIT_SAVE_DOCUMENT_PREPARE).

Max

Edited by: max bianchi on May 16, 2008 4:09 PM

Read only

0 Likes
1,436

I have put my code in FORM USEREXIT_SAVE_DOCUMENT.

And the LIPS-VBELN is having delivery number which is going to be created.

Read only

0 Likes
1,436

Hi

It's ok, that explains why the statament UPDATE fails in that exit: here the delivery is not stored in db yet.

The exit USEREXIT_SAVE_DOCUMENT should be use only to store some data in additional custom tables, so it's not a good plave to change a value of delivery.

U should use the USEREXIT_SAVE_DOCUMENT_PREPARE instead of USEREXIT_SAVE_DOCUMENT, here u don't need any UPDATE statament: delete it from your code.

In this new exit u have to loop the internal table XLIPS and change here the value:

LOOP AT XLIPS WHERE MTVFP = 'Z3'.
  XLIPS-MTVFP = 'Z4'.
* Check the flag for updating, it has to be:
* I for creating the items (so VL01N);
* U for updating the items (so VL02N)
  IF XLIPS-UPDKZ IS INITIAL.
    XLIPS-UPDKZ = 'U'.
  ENDIF.
  MODIFY XLIPS.
ENDLOOP.

Max