How to implementing locking mechanism in abap?

Hi
     my program run by different users. I want
     to ensure that at a particular point of time only
     one instance of my program running, and all others
     should be in wait.
     if have a solution for this. i can make use of a flag
     (global flag ) i set/get this flag from import/export
     mechanism. for example.
     do.
     import v_flag = v_flag from MEMORY id 'ZFLAG'.
     if v_flag is initial.
         v_flag = '1'.
         export v_flag to memory id 'ZFLAG'.
         exit.
     endif.  
     enddo.
     ***Rest of the program main code****
     clear v_flag.
     export v_flag to memory id 'ZFLAG'.
     is this ok? or any other locking mechanism supported
     by abap.
Regards,
Abhimanyu.L

Hi
Check the following,
http://help.sap.com/saphelp_nw04/helpdata/en/7b/f9813712f7434be10000009b38f8cf/content.htm
http://help.sap.com/saphelp_nw04s/helpdata/en/aa/fd823730fa874ae10000009b38f8cf/content.htm
http://www.sapdb.org/7.4/htmhelp/7d/75d34a6a210b4b95f232e5f9acd232/content.htm
http://www.sapdb.org/7.4/htmhelp/6e/ab5d79286b3d4a9f72ef140191d208/content.htm
http://sapdb.net/7.4/htmhelp/43/151d12671a2240947990c5152a4bbd/content.htm
Please reward if it helps.

Similar Messages

  • How to implement locking in ABAP

    Hello everyone,
        I am doing dialog programming and I have a screen that creates some template. When the user opens up the screen it defualts to next available template number to be created (for example if template No 1 exists then it will default to template no 2 so template 2 will be created). But if multiple users open up the screen then it will show template 2 for both of them and I want to avoid this, i.e. I like to implement some locking mechanism so one user opens up the screen that template is locked and the other cannot create the same template. Please share any ideas and suggestions, how I can imeplement this!
    Thanks.
    Mithun

    Hai  Mithun Dha
    Lock Objects
    The R/3 System synchronizes simultaneous access of several users to the same data records with a lock mechanism. When interactive transactions are programmed, locks are set and released by calling function modules (see Function Modules for Lock Requests). These function modules are automatically generated from the definition of lock objects in the ABAP Dictionary.
    Structure of a Lock Object
    The tables in which data records should be locked with a lock request are defined in a lock object together with their key fields. When tables are selected, one table (the primary table) is first selected. Further tables (secondary tables) can also be added using foreign key relationships (see also Conditions for Foreign Keys).
    Lock Arguments
    The lock argument of a table in the lock object consists of the key fields of the table.
    The lock argument fields of a lock object are used as input parameters in the function modules for setting and removing locks generated from the lock object definition. When these function modules are called, the table rows to be locked or unlocked are specified by defining certain values in these fields. These values can also be generic. The lock argument fields therefore define which subset of the table rows should be locked.
    The simplest case of a lock object consists of exactly one table and the lock argument of the table is the primary key of this table. Several tables can also be included in a lock object. A lock request therefore can lock an entire logical object, and not only a record of a table. Such a logical object can be for example a document comprising an entry in a header table and N entries in a position table.
    Locks can also be set from programs in other systems with the corresponding interfaces if the lock object was defined with RFC authorization.
    A lock mode can be assigned for each table in the lock object. This mode defines how other users can access a locked record of the table.
    Table SFLIGHT in the  flight model contains all the scheduled flights of a carrier. Field SEATSMAX contains the number of seats available. Field SEATSOCC contains the number of seats already booked. If a booking is made for a customer (by a travel agency or sales desk), you must check whether there are enough seats available. The number of seats booked is incremented when the booking is made.
    This mechanism must ensure that two sales desks do not make the same booking at the same time and that the flight is not overbooked.
    This can be done by creating lock object ESFLIGHT. Only the table SFLIGHT must be included in this lock object. The flight can then be locked (with the function modules generated from the lock object) when booking. If another sales desk also wants to book seats for this flight, the lock will prevent the flight from being overbooked.
    Activating a lock object in the ABAP Dictionary automatically creates function modules for setting (ENQUEUE_<lock object name>) and releasing (DEQUEUE_<lock object name>) locks.
    The generated function modules are automatically assigned to function groups. You should not change these function modules and their assignment to function groups since the function modules are generated again each time the lock object is activated.
    Never transport the function groups, which contain the automatically generated function modules. The generated function modules of a lock object could reside in a different function group in the target system. Always transport the lock objects. When a lock object is activated in the target system, the function modules are generated again and correctly assigned to function groups.
    Parameters of the Function Modules
    Field Names of the Lock Object
    The keys to be locked must be passed here.
    A further parameter X_<field> that defines the lock behavior when the initial value is passed exists for every lock field <field>. If the initial value is assigned to <field> and X_<field>, then a generic lock is initialized with respect to <field>. If <field> is assigned the initial value and X_<field> is defined as X, the lock is set with exactly the initial value of <field>.
    Parameters for Passing Locks to the Update Program
    A lock is generally removed at the end of the transaction or when the corresponding DEQUEUE function module is called. However, this is not the case if the transaction has called update routines. In this case a parameter must check that the lock has been removed.
    Parameter _SCOPE controls how the lock or lock release is passed to the update program (see The Owner Concept for Locks). You have the following options:
    _SCOPE = 1: Locks and lock releases are not passed to the update program. The lock is removed when the transaction is ended.
    _SCOPE = 2: The lock or lock release is passed to the update program. The update program is responsible for removing the lock. The interactive program with which the lock was requested no longer has an influence on the lock behavior. This is the standard setting for the ENQUEUE function module.
    _SCOPE = 3: The lock or lock release is also passed to the update program. The lock must be removed in both the interactive program and in the update program. This is the standard setting for the DEQUEUE function module.
    Parameters for Lock Mode
    A parameter MODE_<TAB> exists for each base table TAB of the lock object. The lock mode for this base table can be set dynamically with this parameter. Valid values for this parameter are S (shared), E (exclusive) and X (exclusive but not cumulative).
    The lock mode specified when the lock object for the table is created is the default value for this parameter. This default value can however be overridden as required when the function module is called.
    If a lock set with a lock mode is to be removed by calling the DEQUEUE function module, this call must have the same value for the parameter MODE_<TAB>.
    Controlling Lock Transmission
    Parameter _COLLECT controls whether the lock request or lock release should be performed directly or whether it should first be written to the local lock container. This parameter can have the following values:
    Initial value: The lock request or lock release is sent directly to the lock server.
    X : The lock request or lock release is placed in the local lock container. The lock requests and lock releases collected in this lock container can then be sent to the lock server at a later time as a group by calling the function module FLUSH_ENQUEUE.
    Behavior for Lock Conflicts (ENQUEUE only)
    The ENQUEUE function module also has the parameter _WAIT. This parameter determines the lock behavior when there is a lock conflict.
    You have the following options:
    Initial value: If a lock attempt fails because there is a competing lock, the exception FOREIGN_LOCK is triggered.
    X : If a lock attempt fails because there is a competing lock, the lock attempt is repeated after waiting for a certain time. The exception FOREIGN_LOCK is triggered only if a certain time limit has elapsed since the first lock attempt. The waiting time and the time limit are defined by profile parameters.
    Controlling Deletion of the Lock Entry (DEQUEUE only)
    The DEQUEUE function module also has the parameter _SYNCHRON.
    If X is passed, the DEQUEUE function waits until the entry has been removed from the lock table. Otherwise it is deleted asynchronously, that is, if the lock table of the system is read directly after the lock is removed, the entry in the lock table may still exist.
    Exceptions of the ENQUEUE Function Module
    FOREIGN_LOCK: A competing lock already exists. You can find out the name of the user holding the lock by looking at system variable SY-MSGV1.
    SYSTEM_FAILURE: This exception is triggered when the lock server reports that a problem occurred while setting the lock. In this case, the lock could not be set.
    If the exceptions are not processed by the calling program itself, appropriate messages are issued for all exceptions.
    Reference Fields for RFC-Enabled Lock Objects
    The type of an RFC-enabled function module must be completely defined. The parameters of the generated function module therefore have the following reference fields for RFC-enabled lock objects:
    Parameters
    Reference fields
    X_<field name>
    DDENQ_LIKE-XPARFLAG
    _WAIT
    DDENQ_LIKE-WAITFLAG
    _SCOPE
    DDENQ_LIKE-SCOPE
    _SYNCHRON
    DDENQ_LIKE-SYNCHRON
    All the tables that can be included in a lock object must be linked with  foreign keys. There are a number of restrictions to the valid relationships.
    The foreign key relationships of the tables of the lock object must form a tree. The tables are the nodes of the tree. The links of the tree mean is the check table of.
    The foreign key fields must be key fields of the foreign key table.
    The foreign key relationships defined between the base tables of the lock objects may not have any field that is checked against more than one other field. A field therefore may not occur twice as foreign key field in a relationship and may not be checked against two different fields in two different foreign key relationships.
    You must keep one restriction in mind for  multi-structured foreign keys. If a field is assigned to a field that is outside the check table, the table containing this field must be in a sub-tree that contains the check table of this foreign key relationship as a root.
    These conditions are always satisfied if the key of the foreign key table is an extension of the key of the check table.
    Conditions 2, 3 and 4 are meaningless if the particular foreign key field was excluded from the assignment to the key fields of the check table by  marking it as generic or setting it to a constant. This is also true for multi-structured foreign keys if the foreign key field refers to a table that is not contained in the lock object.
    Regards.
    Eshwar.

  • How to implement Strategy pattern in ABAP Objects?

    Hello,
    I have a problem where I need to implement different algorithms, depending on the type of input. Example: I have to calculate a Present Value, sometimes with payments in advance, sometimes payment in arrear.
    From documentation and to enhance my ABAP Objects skills, I would like to implement the strategy pattern. It sounds the right solution for the problem.
    Hence I need some help in implementing this pattern in OO. I have some basic OO skills, but still learning.
    Has somebody already implemented this pattern in ABAP OO and can give me some input. Or is there any documentation how to implement it?
    Thanks and regards,
    Tapio

    Keshav has already outlined required logic, so let me fulfill his answer with a snippet
    An Interface
    INTERFACE lif_payment.
      METHODS pay CHANGING c_val TYPE p.
    ENDINTERFACE.
    Payment implementations
    CLASS lcl_payment_1 DEFINITION.
      PUBLIC SECTION.
      INTERFACES lif_payment.
      ALIASES pay for lif_payment~pay.
    ENDCLASS.                 
    CLASS lcl_payment_2 DEFINITION.
      PUBLIC SECTION.
      INTERFACES lif_payment.
      ALIASES pay for lif_payment~pay.
    ENDCLASS.                   
    CLASS lcl_payment_1 IMPLEMENTATION.
      METHOD pay.
        "do something with c_val i.e.
        c_val = c_val - 10.
      ENDMETHOD.                   
    ENDCLASS.                  
    CLASS lcl_payment_2 IMPLEMENTATION.
      METHOD pay.
        "do something else with c_val i.e.
        c_val = c_val + 10.
      ENDMETHOD.  
    Main class which uses strategy pattern
    CLASS lcl_main DEFINITION.
      PUBLIC SECTION.
        "during main object creation you pass which payment you want to use for this object
        METHODS constructor IMPORTING ir_payment TYPE REF TO lif_payment.
        "later on you can change this dynamicaly
        METHODS set_payment IMPORTING ir_payment TYPE REF TO lif_payment.
        METHODS show_payment_val.
        METHODS pay.
      PRIVATE SECTION.
        DATA payment_value TYPE p.
        "reference to your interface whcih you will be working with
        "polimorphically
        DATA mr_payment TYPE REF TO lif_payment.
    ENDCLASS.                  
    CLASS lcl_main IMPLEMENTATION.
      METHOD constructor.
        IF ir_payment IS BOUND.
          me->mr_payment = ir_payment.
        ENDIF.
      ENDMETHOD.                  
      METHOD set_payment.
        IF ir_payment IS BOUND.
          me->mr_payment = ir_payment.
        ENDIF.
      ENDMETHOD.                  
      METHOD show_payment_val.
        WRITE /: 'Payment value is now ', me->payment_value.
      ENDMETHOD.                  
      "hide fact that you are using composition to access pay method
      METHOD pay.
        mr_payment->pay( CHANGING c_val = payment_value ).
      ENDMETHOD.                   ENDCLASS.                  
    Client application
    PARAMETERS pa_pay TYPE c. "1 - first payment, 2 - second
    DATA gr_main TYPE REF TO lcl_main.
    DATA gr_payment TYPE REF TO lif_payment.
    START-OF-SELECTION.
      "client application (which uses stategy pattern)
      CASE pa_pay.
        WHEN 1.
          "create first type of payment
          CREATE OBJECT gr_payment TYPE lcl_payment_1.
        WHEN 2.
          "create second type of payment
          CREATE OBJECT gr_payment TYPE lcl_payment_2.
      ENDCASE.
      "pass payment type to main object
      CREATE OBJECT gr_main
        EXPORTING
          ir_payment = gr_payment.
      gr_main->show_payment_val( ).
      "now client doesn't know which object it is working with
      gr_main->pay( ).
      gr_main->show_payment_val( ).
      "you can also use set_payment method to set payment type dynamically
      "client would see no change
      if pa_pay = 1.
        "now create different payment to set it dynamically
        CREATE OBJECT gr_payment TYPE lcl_payment_2.
        gr_main->set_payment( gr_payment ).
        gr_main->pay( ).
        gr_main->show_payment_val( ).
      endif.
    Regads
    Marcin

  • How to implement registration mechanism in JavaME

    I have my game in JavaME completed and ready to sell it. How do I implement registration mechanism so that only the user who paid can run my game?Thanks in advance

    No answer? I guess the registration mechanism does not have to be JavaME specific. Can someone point me to a link/tutorial on how software registration is implemented? I found one link on Nokia forum where someone said that he would create a unique RMS record when the software runs the first time. After that, just check against this record. But I don't see how this will protect my software from being used by un-authenticated users?

  • How to implement user logoff with ABAP

    Hi NG,
    how do I implement a user logoff in ABAP?
    Kind regrads
    Stefan

    use the function module "TH_DELETE_USER"
    and send the user name whom you want to exit from SAP.
    but i am not very sure can we use this function module in our programs or not.
    Regards
    srikanth

  • How to implement ESS Logoff through ABAP

    Hi,
    I need to implement Logoff Functionality in ESS through ABAP code.
    Note that our ESS works through ITS server.
    I have tried SPH_R3_LOGOFF and LMBP_RESOURCE_LOGOFF.
    But these FM's dont work in ESS environment (through ITS).
    Please anyone help me in this regard.

    Hi,
    The following SAP Note has some correction instruction which has some logging out code.
    Note 142724 - Prevention of multiple SAPGUI logons
    Maybe that helps.
    Regards,
    Siddhesh

  • How to implement resend mechanism in BPM in order?

    I have a requirement to implement a synchronous scenario in BPM,which doe sthe following steps
    1)Recieves a transformed idoc message
    2)Sends the message to a webservice synchronously
    3)Waits for the response for a duration of 1 min
    4)Resends it again if no response.
    Could you please suggest a way to implement this processing in order in such a way that,if the idocs are sent in queued manner to the BPM,the second idoc is only sent after the complete processing of the first one is over,ie after the resend of the first idoc is completed?

    Hi,
    Does anyone have any suggestion regarding this.
    For better clarity i will tell my requirement once gain.
    I am implementing an idoc to synchronous web service scenario using BPM in between.The BPM have to recieve the idocs in order.This has been implemented successfully.
    Now the BPM should accept each idoc,sent it to the synchronous web service,wait for the response and if no response available ,it should resend.If resend also not successful, then the other suceeding idocs should not be sent and should be stuck in queue,until we resolve the issue.Once the issue is solved,we should be able to resend the messages in the queue in the same order.
    So al together,the entire processing should take place in Exactly Once in Order and the unprocessed idocs should be stuck in queue,if there is any sending or recieving issues.
    I have currently implemented the BPM in such a way that i have a recieve step in loop with correltion as IDOC TYP so that it recievs all idocs to the same process instance.The same loop contains a transformation and also a  sync send step with no exception handler defined  to catch system sending errors.Hence the BPM will go into error status and the rest of the idocs will be stuck in the queue.And the BPM can be restarted after solving the communication issues. And all the messages will be resend.
    If no sending errors,also,I suppose the synch send step willitself go into error state after it waits for the response for some seconds.Am i correct in this approach??
    I would like to know your suggestions whether it will wrk fine or not.
    Edited by: janice ann george on Jan 14, 2009 11:35 AM

  • How to impement Webi Report locking mechanism

    Hi ,
    Can you please suggest me how to implement Webi Report Locing Mechanism .
    Thanks & Regards
    Venkat

    Hi ,
    Thanks for your reply .
    we have comments column in our report .  for each we have added one blank cell to give the comments purpose .
    But Multiple Users are trying to edit the report same time  so who ever saved the report those comments only available .
    To avoid multiple users to edit the same report we want to implement the report locking mechanism similar to Universe Locking mechanism in Designer .
    appreciate your speedy response .
    Thanks & Regards,
    Venkat

  • How to implement this calendar function in ABAP code

    Hi everyone,
    Our requirement is : Give a date (e.g. YYYY.MM.DD, 1983.12.26), then we need to know which weekday it is. Is there a existing FM for this fuction? or how to implement it in ABAP?
    Thanks a lot for any hint
    Best regards
    Deyang

    Hi Deyang Liu,
        Could you please check these the below links they would give you some idea ....[SAP Calendar Control|http://help.sap.com/printdocu/core/print46b/en/data/en/pdf/BCCICALENDAR/SAP_KALENDER.pdf]
    [Calendar functions |http://help.sap.com/saphelp_nw04/Helpdata/EN/2a/fa00f6493111d182b70000e829fbfe/content.htm]
    [SAP Functions|http://abap4.tripod.com/SAP_Functions.html]
    [Determine calendar |http://help.sap.com/saphelp_nw04/helpdata/en/2a/fa00e9493111d182b70000e829fbfe/content.htm]
    Regards,
    S.Manu

  • How to implement the shared lock in a  table view

    Hi,
    How to implement the shared lock in a  table view.for multiple users to edit on this same table.
    Thanks in advance
    Swathi

    Hi,
    Please refer this link to find solution to your querry.
    Hope it helps.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c322c690-0201-0010-fb86-811c52b0acc2.
    Regards,
    Rahul

  • How to Implement Sort, Filter funtinality in Normal web dynpro ABAP Table

    Hello,
    How to Implement Sort, Filter funtinality in Normal web dynpro ABAP Table ?
    Thanks

    hi,
    Check out this link for sorting in Table.
    Sorting option in WebDynPro ABAP UI Table
    steps to follow :
    ->Have the data in internal table (itab).
    ->Now use sort command for the particular column which ever you want to sort.
      e.g sort itab descending by <Column>.
    ->Now you can bind the internal table with the Context Node which is binded to Table.
    I hope it helps.
    Thanx.

  • How to implement BSP in wed dynpro abap

    Hi experts how to implement BSP application into
    web dynpro abap, Plz send the application procedure in detail....

    how to implement BSP application into
    web dynpro abap
    If i understand your question correctly, you want to use BSP application inside your web dynpro ABAP application,
    There are some ways to do:
    if you want to simply navigate to BSP application from WDA application then you can use Exit Plugs
    http://help.sap.com/saphelp_nw04s/helpdata/en/45/1bc575ba064574e10000000a114a6b/content.htm
    If you want to navigate between BSP and WDA application you have to use Suspend and Resume Plugs
    http://help.sap.com/saphelp_nw04s/helpdata/en/45/19bf8c16f25d7ae10000000a11466f/content.htm
    Abhi

  • How to implement html in ABAP ?

    Hello i want o know how to implement html code in sap ?
    Is there any procedure for which if yes please do share with me.
    Points will be rewarded for the helpful answer.
    Thks

    hi Balu,
    what ever Mr. Nikhil said is suitable to ur requirement..
    Webdynpro for ABAP & BSP concepts serve u. At the end they both will generate a
    URL ...
    When we run this url ...
    required screen is called and what ever we entered in screen saved in ssap backend tables..
    hopes u got ur ans...
    Go through WEBDYNPRO FOR ABAP & BSP DOCs..
    Regards..
    Raju Mummidi.

  • How to implement the pessimistic locking using toplink with sybase

    we want to allocate the unique primary key to each row when many user try to insert the records concurrently..So what we are trying to do is we calculate the maximum of Primary Key and incremented it by 1. Now we want to Apply the locking concept on the so that unique key will be allocated to each newly inserted row
    Can you please tell me
    1. how we can genrate unique primary key in toplink using sybase?
    2.how to implement the pessimistic or optimistic locking ?which one will be preferable?

    Hi brother
    I think that this link can help you
    http://download-east.oracle.com/docs/cd/A97688_16/toplink.903/b10064/database.htm#1007986
    Good luck

  • How to removed Editor Lock from an ABAP program

    Hello, I would like to know how to remove an editor lock from an ABAP  program that someone placed?   The person who placed the lock is no longer active in the system.   When I try to remove the lock, I get the message that the person placed the lock can remove it.  Looks like only that person can remove the lock.  Is there a way around this?  Reactivating his id is not an option, in our case.

    Hi,
    I'm able to see the program in table TRDIR, but not able to edit it.
    I have find one more table where we can edit is "PROGDIR"
    Goto table " PROGDIR"
    give the program name and execute
    select the program and choose edit button
    and remove "X" from the field "EDTX" to remove the lock for the program.
    Regards,
    Vaira.

Maybe you are looking for

  • Can running Macbook Pro in Clamshell Mode cause problems for Macbook Display?

    Hi, I recently got a new monitor (Dell U2711) and it is stunning when running at full resolution through a mini displayport to displayport adapter. However, i ran my MBP in Clamshell Mode and after rebooting (without the display this time) i had horr

  • Lightroom 5.7  Lens Correction

    i have lightroom 5.7 but the Lens Correction area is not showing in my develop module - does it have to be enabled somehow?

  • How to add JVM option???

    i am facing problem of permgen memory exceprion.. i got solution as to add following JVM option Increasing the PermSpace of the JVM with -XX:MaxPermSize=256M or higher only i don't know how to add JVM option... GOOGLING DIDNT WORK

  • Mail Archive folder showing empty

    I posted this question yesterday but didn't specify that the Archive folder I was referring to was in Mail.  I can't understand why the folder is showing as empty on both my iMac and MacBook Pro (Mavericks) whilst the same folder shows all its conten

  • Corporate Email won't configure via BIS

    I work for HP and am not able to configure my email using BIS via IMAP. I have confirmed the IMAP works on my system, via Outlook Express, but cannot get the BB (Storm) to connect at all. I am using the settings provided and have talked to Verizon fo