Lock object in Unmanaged scenario in RAP

 

 Lock Object Unmanaged RAP:

  • RAP provides a lock method in the behavior definition.

  • You must manually implement lock logic in the behavior implementation class.

  • RAP does not lock automatically in unmanaged scenarios.


Steps to implement lock object in RAP.

Step 1: Check the behavior definition whether lock master is declared or not.

Step 2: Create lock object for that table - ztl_ab_stuh_13.
        
            * Right click on dictionary - Lock object
            * Give name, Description and Primary table as - ztl_ab_stuh_13.
            * Click on next and select TR and finish.
            * Lock object name starts with E.

            * Select write lock.
            * Check and activate.
            * Once the lock object is activated the Lock and Unlock FM are created.

Step 3: Implement the lock method in behavior implementation.

CLASS lhc_Student DEFINITION INHERITING FROM cl_abap_behavior_handler.

PRIVATE SECTION.


METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION

IMPORTING keys REQUEST requested_authorizations FOR Student RESULT result.


METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION

IMPORTING REQUEST requested_authorizations FOR Student RESULT result.


METHODS create FOR MODIFY

IMPORTING entities FOR CREATE Student.


METHODS earlynumbering_create FOR NUMBERING

IMPORTING entities FOR CREATE Student.


METHODS update FOR MODIFY

IMPORTING entities FOR UPDATE Student.


METHODS delete FOR MODIFY

IMPORTING keys FOR DELETE Student.


METHODS read FOR READ

IMPORTING keys FOR READ Student RESULT result.


METHODS lock FOR LOCK

IMPORTING keys FOR LOCK Student.


METHODS rba_Result FOR READ

IMPORTING keys_rba FOR READ Student\_Result FULL result_requested RESULT result LINK association_links.


METHODS cba_Result FOR MODIFY

IMPORTING entities_cba FOR CREATE Student\_Result.


METHODS earlynumbering_cba_Result FOR NUMBERING

IMPORTING entities FOR CREATE Student\_Result.


ENDCLASS.


CLASS lhc_Student IMPLEMENTATION.


METHOD get_instance_authorizations.

ENDMETHOD.


METHOD get_global_authorizations.

ENDMETHOD.


METHOD create.

zcl_ab_stuh_13=>get_instance( )->create_student(

EXPORTING

entities = entities

CHANGING

failed = failed

mapped = mapped

reported = reported ).

ENDMETHOD.


METHOD earlynumbering_create.

TRY.

zcl_ab_stuh_13=>get_instance( )->earlynumbering_create(

EXPORTING

entities = entities

CHANGING

failed = failed

mapped = mapped

reported = reported ).

CATCH cx_uuid_error.

"handle exception

ENDTRY.


ENDMETHOD.


METHOD update.

zcl_ab_stuh_13=>get_instance( )->update(

EXPORTING

entities = entities

CHANGING

mapped = mapped

failed = failed

reported = reported

).

ENDMETHOD.


METHOD delete.

zcl_ab_stuh_13=>get_instance( )->delete(

EXPORTING

keys = keys

CHANGING

mapped = mapped

failed = failed

reported = reported

).

ENDMETHOD.


METHOD read.

zcl_ab_stuh_13=>get_instance( )->read_student(

EXPORTING

keys = keys

CHANGING

result = result

failed = failed

reported = reported

).

ENDMETHOD.


METHOD lock.

TRY.

DATA(lv_lock) = cl_abap_lock_object_factory=>get_instance( iv_name = 'EZSTUDENT_13' ).

CATCH cx_abap_lock_failure INTO DATA(exception).

RAISE SHORTDUMP exception.

ENDTRY.

LOOP AT keys ASSIGNING FIELD-SYMBOL(<ls_keys>).

TRY.

lv_lock->enqueue(

it_parameter = VALUE #( ( name = 'ID' value = REF #( <ls_keys>-Id ) ) )


).

CATCH cx_abap_foreign_lock INTO DATA(foreign_lock).

APPEND VALUE #(

id = keys[ 1 ]-Id

%msg = new_message_with_text(

severity = if_abap_behv_message=>severity-error

text = 'Record is Locked By' && foreign_lock->user_name

)

) TO reported-student.

APPEND VALUE #(

id = keys[ 1 ]-Id

) TO failed-student.

CATCH cx_abap_lock_failure INTO exception.

RAISE SHORTDUMP exception.

ENDTRY.

ENDLOOP.

ENDMETHOD.


METHOD rba_Result.

ENDMETHOD.


METHOD cba_Result.

zcl_ab_stuh_13=>get_instance( )->cba_result_create(

EXPORTING

entities_cba = entities_cba

CHANGING

mapped = mapped

failed = failed

reported = reported

).


ENDMETHOD.


METHOD earlynumbering_cba_Result.

zcl_ab_stuh_13=>get_instance( )->earlynumbering_cba_result(

EXPORTING

entities = entities

CHANGING

mapped = mapped

failed = failed

reported = reported

).

ENDMETHOD.



ENDCLASS.


CLASS lhc_Result DEFINITION INHERITING FROM cl_abap_behavior_handler.

PRIVATE SECTION.


METHODS update FOR MODIFY

IMPORTING entities FOR UPDATE Result.


METHODS delete FOR MODIFY

IMPORTING keys FOR DELETE Result.


METHODS read FOR READ

IMPORTING keys FOR READ Result RESULT result.


METHODS rba_Student FOR READ

IMPORTING keys_rba FOR READ Result\_Student FULL result_requested RESULT result LINK association_links.


ENDCLASS.


CLASS lhc_Result IMPLEMENTATION.


METHOD update.

ENDMETHOD.


METHOD delete.

ENDMETHOD.


METHOD read.

ENDMETHOD.


METHOD rba_Student.

ENDMETHOD.


ENDCLASS.


CLASS lsc_ZIV_AB_STUH_13 DEFINITION INHERITING FROM cl_abap_behavior_saver.

PROTECTED SECTION.


METHODS finalize REDEFINITION.


METHODS check_before_save REDEFINITION.


METHODS save REDEFINITION.


METHODS cleanup REDEFINITION.


METHODS cleanup_finalize REDEFINITION.


ENDCLASS.


CLASS lsc_ZIV_AB_STUH_13 IMPLEMENTATION.


METHOD finalize.

ENDMETHOD.


METHOD check_before_save.

ENDMETHOD.


METHOD save.

zcl_ab_stuh_13=>get_instance( )->save_data(

CHANGING

reported = reported ).

ENDMETHOD.


METHOD cleanup.

ENDMETHOD.


METHOD cleanup_finalize.

ENDMETHOD.


ENDCLASS.

    
******************************Thank you*******************************

Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).