06-25-2008 7:36 AM
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.
06-25-2008 7:42 AM
06-25-2008 7:42 AM
06-25-2008 7:43 AM
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.
06-25-2008 7:46 AM
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.
06-25-2008 7:50 AM
can you show me the sample code where you do this.. so that i can try to help u
06-25-2008 7:56 AM
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.
06-25-2008 8:01 AM
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.
06-25-2008 8:03 AM
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.
06-25-2008 8:14 AM
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?