Skip to Content
author's profile photo Former Member
Former Member

Is it Necessary to lock the table while accessing the entries from table

Hi Gurus,

While optimization of the Program i came through one type of coding is in inside the Loop of The internal table which is processing BDC call transcation through updating the Custom table.

Before processing the BDC, the Custom table has been locked and read the entries from same custom table ,if the process fails then it waits for another 20 seconds and retrying the same for another time .I could not able to understand the Logic behind this.if it is not the Correct way then i can straight away remove this Part which is very well improve the perfromance of the Object.

For Your Better Understanding i have attached the Snippet of the Code .Please find the Code and advice me the same .

+LOOP AT i_stk_req INTO wa_stk_req.+

+** Lock is set to '0',meaning that no lock exist.+

++v_lock = 0. "FALSE.++

++* Preparing variable key for locking.++

++CLEAR v_key.++

++v_key = sy-mandt.++

++v_key+3(3) = wa_stk_req-lgnum.++

++v_key+6(4) = wa_stk_req-werks.++

++v_key+10(18) = wa_stk_req-matnr.++

++v_key+28(10) = wa_stk_req-charg.++

++* Try to lock the row for max of 100 times.++

++DO 10 TIMES.++

++* this perform sends sy-subrc EQ 1. in case of foreign lock.++

+PERFORM enqueue_tab IN PROGRAM saplsvix USING 'ZSDT_STK_REQ' v_key c_e c_e.+

+IF sy-subrc EQ 0. "If Enqueue is successful.+

+** set lock as TRUE+

++v_lock = 1. "TRUE++

++* selecting the latest entry for the table(Entry might have changed-refer to++

+SELECT SINGLE *+

++FROM zsdt_stk_req++

++INTO wa_stk_req++

++WHERE lgnum = wa_stk_req-lgnum++

++AND werks = wa_stk_req-werks++

++AND matnr = wa_stk_req-matnr++

++AND charg = wa_stk_req-charg.++

++IF sy-subrc NE 0. "Checking if select statement was successful++

++* Unlock the table row.++

++PERFORM enqueue_tab IN PROGRAM saplsvix USING c_table v_key c_e c_d.++

++v_lock = 0. "If unsuccessful.Then we set lock as FALSE.++

++EXIT.++

++ENDIF.++

++EXIT.++

++* If unsuccessful in locking then wait for 1 sec.++

+ELSE.+

+WAIT UP TO 20 SECONDS.+

+ENDIF.+

+** exit from DO. ENDDO.+

++ENDDO.++

++* v_lock will be FALSE if all attempts for lock was unsuccessful or++

++* if there is a problem in select single after lock.++

++IF v_lock = 0.++

++NEW-PAGE.++

++CLEAR v_display.++

++CONCATENATE text-004 text-012 wa_stk_req-matnr text-011 wa_stk_req-werks++

++text-019 wa_stk_req-lgnum text-020 wa_stk_req-charg INTO v_display SEPARATED BY space.++

++WRITE :/ v_display.++

++ENDIF.++

++* Only to process if lock is successful.++

++CHECK v_lock NE 0.++

++* If UPDATE IS FALSE that means that no updates need to be done.++

++* So we set v_update as FALSE in its initial state.++

++v_update = 0.++

++* Begin of Insert Optima App - 053++

++SELECT lgnum++

++lqnum++

++matnr++

++werks++

++charg++

++lgtyp++

++meins++

++verme++

++lgort++

++qplos++

++bestq++

++FROM lqua++

++INTO TABLE i_lqua1++

++WHERE lgnum EQ wa_lqua-lgnum++

++AND matnr EQ wa_lqua-matnr++

++AND werks EQ wa_lqua-werks++

++AND charg EQ wa_lqua-charg++

++AND bestq EQ wa_lqua-bestq++

++AND lgort EQ wa_lqua-lgort++

++AND verme GE 0.++

++* End of Insert Optima App - 053++

++* IF a requirement still exists.++

++IF wa_stk_req-verme > 0.++

++LOOP AT i_lqua INTO wa_lqua WHERE bestq = 'Q'++

++AND qplos NE 0++

++AND lgnum = wa_stk_req-lgnum++

++AND werks = wa_stk_req-werks++

++AND matnr = wa_stk_req-matnr++

++AND charg = wa_stk_req-charg.++

++CLEAR v_target.++

++CHECK wa_stk_req-lgtyp = wa_lqua-lgtyp OR wa_stk_req-lgtyp IS INITIAL.++

++* checking if still some stock needs to be transported.++

++IF wa_stk_req-verme < 0.++

++EXIT.++

++ENDIF.++

++* we need to send the entire lot if the stock belongs to quality inspection++

++IF wa_stk_req-verme >= wa_lqua-verme.++

++IF wa_stk_req-lgort IS INITIAL.++

++* fetch the Storage location value from the two custom tables.++

++PERFORM f_fetch_lgort.++

++ELSE.++

++v_lgort = wa_stk_req-lgort.++

++ENDIF.++

++* checking if v_lgort is not initial.++

++CHECK NOT v_lgort IS INITIAL.++

++* Calling QAC2++

++PERFORM f_qac2.++

++* Checking if Post Good was successful.++

+IF NOT wa_qamb-mblnr IS INITIAL.+

+REFRESH i_lqua1.+

+SELECT lgnum+

+lqnum+

+matnr+

+werks+

+charg+

+lgtyp+

+meins+

+verme+

+lgort+

+qplos+

+bestq+

+FROM lqua+

+INTO TABLE i_lqua1+

+WHERE lgnum EQ wa_lqua-lgnum+

+AND matnr EQ wa_lqua-matnr+

+AND werks EQ wa_lqua-werks+

+AND charg EQ wa_lqua-charg+

+AND bestq EQ wa_lqua-bestq+

+AND lgort EQ wa_lqua-lgort+

+AND verme GE 0.+

+SORT i_lqua1 BY lgtyp.+

+CLEAR: wa_lqua1,+

+v_position.+

+READ TABLE i_lqua1 INTO wa_lqua1 WITH KEY lgtyp = wa_lqua-lgtyp.+

+IF sy-subrc EQ 0.+

+v_position = sy-tabix.+

+ENDIF.+

+SELECT SINGLE lgnum+

+ubnum+

+FROM lubu+

+INTO wa_lubu+

+WHERE lgnum = wa_lqua-lgnum+

+AND mblnr = wa_qamb-mblnr.+

+CLEAR i_bdcdata.+

+REFRESH i_bdcdata.+

+REFRESH i_messtab.+

+CLEAR wa_bdcdata.+

+wa_bdcdata-program = 'SAPML03T' .+

+wa_bdcdata-dynpro = '0141' .+

+wa_bdcdata-dynbegin = 'X' .+

+APPEND wa_bdcdata TO i_bdcdata .+

+CLEAR wa_bdcdata .+

+wa_bdcdata-fnam = 'BDC_OKCODE' .+

+wa_bdcdata-fval = '/00' .+

+APPEND wa_bdcdata TO i_bdcdata .+

+CLEAR wa_bdcdata .+

+wa_bdcdata-fnam = 'LUBU-UBNUM'.+

+wa_bdcdata-fval = wa_lubu-ubnum.+

+APPEND wa_bdcdata TO i_bdcdata .+

+CLEAR wa_bdcdata .+

+wa_bdcdata-fnam = 'LUBU-LGNUM'.+

+wa_bdcdata-fval = wa_lqua-lgnum.+

+APPEND wa_bdcdata TO i_bdcdata .+

+CLEAR wa_bdcdata .+

+wa_bdcdata-fnam = 'RL03T-DUNKL'.+

+wa_bdcdata-fval = 'H'.+

+APPEND wa_bdcdata TO i_bdcdata .+

+CLEAR wa_bdcdata.+

+wa_bdcdata-program = 'SAPML03T' .+

+wa_bdcdata-dynpro = '0143' .+

+wa_bdcdata-dynbegin = 'X' .+

+APPEND wa_bdcdata TO i_bdcdata .+

+CONCATENATE 'RL03T-SELKZ('+

+v_position+

+')'+

+INTO v_str.+

+CLEAR wa_bdcdata .+

+wa_bdcdata-fnam = v_str.+

+wa_bdcdata-fval = 'X'.+

+APPEND wa_bdcdata TO i_bdcdata .+

+CLEAR wa_bdcdata .+

+wa_bdcdata-fnam = 'BDC_OKCODE' .+

+wa_bdcdata-fval = 'BU' .+

+APPEND wa_bdcdata TO i_bdcdata .+

+CLEAR wa_bdcdata.+

+wa_bdcdata-program = 'SAPML03T' .+

+wa_bdcdata-dynpro = '0142' .+

+wa_bdcdata-dynbegin = 'X' .+

+APPEND wa_bdcdata TO i_bdcdata .+

+CLEAR wa_bdcdata .+

+wa_bdcdata-fnam = 'BDC_OKCODE' .+

+wa_bdcdata-fval = 'BU' .+

+APPEND wa_bdcdata TO i_bdcdata .+

+*......changes as per ticket 44206+

++* CLEAR wa_bdcdata .++

++* wa_bdcdata-fnam = 'LQUAU-KZUAP(01)'.++

++* wa_bdcdata-fval = 'X'.++

++* APPEND wa_bdcdata TO i_bdcdata .++

+*......end of changes as per ticket 44206+

+CALL TRANSACTION 'LT05' USING i_bdcdata+

+OPTIONS FROM wa_ctu_params+

+MESSAGES INTO i_messtab.+

Regards,

Raja

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 22, 2008 at 11:41 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 22, 2008 at 12:05 PM

    Hi Raj,

    While reading table it is not neccesary to lock the table.Its require only when you insert or update the records.

    i belive Waiting for the 20 seconds statement is no need here.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 22, 2008 at 12:23 PM

    Lock is not necessary while reading.

    It could have been put in the first place because of update expected in data.

    But in any condition it makes little sense to have Lock before reading data.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.