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: 

Problem in table update.

Former Member
0 Kudos

Hi All.

I am facing one problem while updating the Ztable. The scnerio is like that we are tracking PO changes. So we created one Ztable to store PO changes. In this table we ahve Sr No field as primary key. When user press SAVE button, first maximum Sr No is selected from table and with addition of 1 new record is created with taht PO number. Now problem is that when two users save different PO at same time , them only one entry is saved in table.

Can i use enque deque or any other login I have to use for this?

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

U have to use enque deque..... no other way....

8 REPLIES 8

Former Member
0 Kudos

U have to use enque deque..... no other way....

GauthamV
Active Contributor
0 Kudos

hi,

all changes done to po's will be stored in CDPOS ,CDHDR tables.

if u still want to go with ur ztables check the functionality of that tables.

Former Member
0 Kudos

Hi ,

Actually I am using this logic in user exit which trigger while saving PO. This Ztable will be read from non sap application through RFC.

I there any solution for this problem.

Former Member
0 Kudos

can you show me the sample code where you do this.. so that i can try to help u

Former Member
0 Kudos

Hy PKB,

Use Enque and Deque method..

your problem will be solve.

Create a lock object via SE11->Lock object and call the ENQUEUE_EZ_<TABLE> before updating the table and DEQUEUE_EZ_<TABLE> to unlock after updating the table ...

Requesting an SAP lock

When a lock object obj is activated, two function modules (see CALL

FUNCTION) with the names ENQUEUE_obj and DEQUEUE_obj are generated.

These lock modules are used to explicitly request or release SAP locks

in an ABAP program. The SAP lock concept thus assumes a cooperative

behavior by all the programs involved. This means that access from

programs that do not call the specified modules are not protected.

The lock conditions and lock modes for the requested locks are defined

by the IMPORT parameters of the lock modules.

The lock conditions are defined by the lock parameters of the lock

object. If the lock object has only one base table, each primary key

field of the table corresponds to exactly one lock parameter. Apart from

this, a lock parameter corresponds to a group of primary key fields that

are identified by the join conditions. For each lock parameter par, the

lock modules have two IMPORT parameters with the names par and X_par.

The lock condition is defined by these parameters. If a parameter par is

not defined or if it is defined with the initial value, this means that

the corresponding key fields should be locked generically. If you really

want to lock the key field with the initial value, you must also define

the parameter X_par with the value 'X'.

To define the lock modes, the lock modules have an IMPORT parameter

MODE_tab for each base table tab, with which the lock mode for this

table can be defined. A default value must already be set for this

parameter in the definition of the lock object.

this is second procedure.

each explicit locking process assumes that all programs which perform database accesses work together in a cooperative manner. If a program does not behave in this way, i.e. it reads or changes data without locking it beforehand, this may result in a conflict with another program, even this other program has locked data correctly.

The following program fragment presents a solution to this problem:

TABLES: SFLIGHT, SBOOK.

CALL FUNCTION 'ENQUEUE_ESFLIGHT'

EXPORTING MANDT = SY-MANDT

CARRID = 'LH'

CONNID = '0400'

FLDATE = '19960516'

MODE_SFLIGHT = 'E'

EXCEPTIONS FOREIGN_LOCK = 1

OTHERS = 2.

CASE SY-SUBRC.

WHEN 1. ...

WHEN 2. ...

ENDCASE.

SELECT SINGLE * FROM SFLIGHT

WHERE

CARRID = 'LH' AND

CONNID = '0400' AND

FLDATE = '19960516'.

IF SY-SUBRC 0.

MESSAGE E...

ENDIF.

IF SFLIGHT-SEATSOCC < SFLIGHT-SEATSMAX.

SBOOK-CARRID = 'LH'.

SBOOK-CONNID = '0400'.

SBOOK-FLDATE = '19960516'.

...

INSERT SBOOK.

IF SY-SUBRC <> 0.

MESSAGE E...

ENDIF.

UPDATE SFLIGHT

SET

SEATSOCC = SEATSOCC + 1

WHERE

CARRID = 'LH ' AND

CONNID = '0400' AND

FLDATE = '19960516'.

ELSE.

MESSAGE E...

ENDIF.

CALL FUNCTION 'DEQUEUE_ESFLIGHT'

EXPORTING MANDT = SY-MANDT

CARRID = 'LH'

CONNID = '0400'

FLDATE = '19960516'

MODE_SFLIGHT = 'E'.

COMMIT WORK.

Former Member
0 Kudos

This is my code............

select max( id ) from zams_t_doc_chng into v_id.

wa_zams_t_doc_chng-id = v_id + 1.

wa_zams_t_doc_chng-pdoc = i_ekko-ebeln.

wa_zams_t_doc_chng-cdate = sy-datum.

wa_zams_t_doc_chng-ctime = sy-uzeit.

read table tekpo index 1.

wa_zams_t_doc_chng-plant = tekpo-werks.

wa_zams_t_doc_chng-status = ' '.

if wa_zams_t_doc_chng-pdoc is not initial.

INSERT INTO zams_t_doc_chng VALUES wa_zams_t_doc_chng.

endif.

Problen is when more than one user save POs same code executes and same ID is selected and only one able to save the record.

How it is possible that one user to select ID at a time and other to wait. After completing first work another user in queue should do the same.

Thanks.

Former Member
0 Kudos

Hi,

The database system automatically sets database locks when it receives change statements (INSERT, UPDATE, MODIFY, DELETE) from a program.

So if you are updating a database table we need to lock.

You must first create a lock object in the ABAP Dictionary. A lock object definition contains the database tables and their key fields on the basis of which you want to set a lock. When you create a lock object, the system automatically generates two function modules with the names ENQUEUE_<lock object name> and DEQUEUE_<lock object name>. You can then set and release SAP locks in your ABAP program by calling these function modules in a CALL FUNCTION statement.

hope this will help you.

plz reward if useful.

thanks,

dhanashri.

0 Kudos

Hi,

I think problem is not in updaing process. Actually first the maximum ID is selected. Now if two users saving PO at same time, same maximum ID get selected for both. Ans new ID = old id + 1. is created for both and only one is get updated. So in this case if i use enque deque then both will able to save the data?