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

Problem regarding Update-Statement on se11 table

Former Member
0 Likes
1,038

Hello I tried to update a dataset in a se11 table using UPDATE Statement.

It doesn't work and I get a sy-subrc = 4.

That is my code:

TABLES ZTDM_SAPOUTPUT.

* Arbeitsbereich definieren
DATA:
wa_ZTDM_SAPOUTPUT LIKE ZTDM_SAPOUTPUT.


wa_ZTDM_SAPOUTPUT-PK = '1'.
wa_ZTDM_SAPOUTPUT-FNCODE = '3'.
wa_ZTDM_SAPOUTPUT-MATNR = '3'.
wa_ZTDM_SAPOUTPUT-MAKTX = '3'.
wa_ZTDM_SAPOUTPUT-ZEINR = '3'.
wa_ZTDM_SAPOUTPUT-MATKL = '3'.
wa_ZTDM_SAPOUTPUT-STATE = '1'.


UPDATE ZTDM_SAPOUTPUT FROM wa_ZTDM_SAPOUTPUT.
Write: 'UPDATE returned' , sy-subrc.
SKIP.

The given Dataset having PK=1 doesn't get updated.

Maybe my understanding is wrong:

Is it correct that the updated dataset ist defined by the primary key in this workingarea?

My Primary Key is PK.

Can you see the error?

5 REPLIES 5
Read only

Former Member
0 Likes
854

UPDATE dbtab FROM wa.

Changes one single line in a database table, using a primary key to identify the line and taking the values to be changed from the specified work area, wa. The data is read out of wa from left to right, matching the line structure of the database table dbtab. The structure of wa remains unchanged. This means that wa must be at least as wide (see DATA) as the line structure of dbtab, and have the same alignment. Otherwise, a runtime error occurs.

If either the database table, dbtab, or the work area, wa, contain Strings, wa must be compatible with the line structure of dbtab.

Example

Changing the telephone number of the customer with customer number '12400177' in the current client:

DATA wa TYPE scustom.

SELECT SINGLE * FROM scustom INTO wa

WHERE id = '12400177'.

wa-telephone = '06201/44889'.

UPDATE scustom FROM wa.

When the command has been executed, the system field SY-DBCNT contains the number of updated lines (0 or 1).

Examples

Update discount for the customer with the customer number '00017777' to 3 percent (in the current client):

DATA: wa TYPE scustom.

SELECT SINGLE * FROM scustom INTO wa

WHERE id = '00017777'.

wa-discount = '003'.

UPDATE scustom FROM wa.

The Return Code is set as follows:

SY-SUBRC = 0:

The specified line has been updated.

SY-SUBRC = 4:

The system could not update any line in the table, since there is no line with the specified primary key.

rwrd if helpful

Bhupal

Read only

Former Member
0 Likes
854

UPDATE dbtab FROM wa. or

UPDATE (dbtabname) FROM wa.

Changes one single line in a database table, using a primary key to identify the line and taking the values to be changed from the specified work area, wa. The data is read out of wa from left to right, matching the line structure of the database table dbtab. The structure of wa remains unchanged. This means that wa must be at least as wide (see DATA) as the line structure of dbtab, and have the same alignment. Otherwise, a runtime error occurs.

If either the database table, dbtab, or the work area, wa, contain Strings, wa must be compatible with the line structure of dbtab.

Example

Changing the telephone number of the customer with customer number '12400177' in the current client:

DATA wa TYPE scustom.

SELECT SINGLE * FROM scustom INTO wa

WHERE id = '12400177'.

wa-telephone = '06201/44889'.

UPDATE scustom FROM wa.

When the command has been executed, the system field SY-DBCNT contains the number of updated lines (0 or 1).

Examples

Update discount for the customer with the customer number '00017777' to 3 percent (in the current client):

DATA: wa TYPE scustom.

SELECT SINGLE * FROM scustom INTO wa

WHERE id = '00017777'.

wa-discount = '003'.

UPDATE scustom FROM wa.

The Return Code is set as follows:

SY-SUBRC = 0:

The specified line has been updated.

SY-SUBRC = 4:

The system could not update any line in the table, since there is no line with the specified primary key.

rwrd if helpful

bhupal

Read only

Former Member
0 Likes
854

Hi!

Update is working only is the key ('1') already EXISTS in the table. Check out this using SE16 transaction.

If it do not exists, use INSERT or MODIFY statements.

About update:

Addition 1

... FROM wa

Effect

Takes the values for the line to be updated not from thetable work area dbtab, but from the explicitly specified workarea wa. Here, the data is taken from wa, moving fromleft to right according to the structure of the table work areadbtab (defined with TABLES).Since the structure of wa is ignored, the work area wamust be at least as wide (see DATA) asthe table work area dbtab and the alignment of the work area wa must correspond to the alignment of thetable work area. Otherwise, a runtime error occurs

Example

Update the telephone number of the customer with thecustomer number '12400177' in the current client:

TABLES SCUSTOM.

DATA WA LIKE SCUSTOM.

WA-ID = '12400177'.

WA-TELEPHONE = '06201/44889'.

UPDATE SCUSTOM FROM WA.

Note

If you do not explicitly specify a work area, the valuesfor the line to be updated are taken from the table work area dbtab, even if the statement appears in a FORM or FUNCTION where the tablework area is held in a formal parameter or a local variable.

Regards

Tamá

Read only

Former Member
0 Likes
854

You can not modify/update the primary key in any table.

delete the data in Ztab, and then create a new entry with the field updated.

Read only

0 Likes
854

I do not modify the pk. The value for Pk is the same it was before. When I leave that field empty, how does sap know then which dataset to change?

The Key '1' does exist.

Edited by: Daniel Gerne on May 30, 2008 1:53 PM