diff --git a/src/z2ui5_cl_demo_app_135.clas.abap b/src/z2ui5_cl_demo_app_135.clas.abap new file mode 100644 index 0000000..963a42f --- /dev/null +++ b/src/z2ui5_cl_demo_app_135.clas.abap @@ -0,0 +1,160 @@ +CLASS z2ui5_cl_demo_app_135 DEFINITION + PUBLIC + CREATE PUBLIC . + + PUBLIC SECTION. + + INTERFACES if_serializable_object . + INTERFACES z2ui5_if_app . + + DATA lock_counter TYPE i READ-ONLY . + DATA check_initialized TYPE abap_bool READ-ONLY . + DATA session_is_stateful TYPE abap_bool READ-ONLY . + DATA session_text TYPE string READ-ONLY . + DATA lock_text TYPE string READ-ONLY . + DATA: + BEGIN OF error READ-ONLY, + text TYPE string, + flag TYPE abap_bool, + END OF error. + + PROTECTED SECTION. + PRIVATE SECTION. + + METHODS initialize_view + IMPORTING + client TYPE REF TO z2ui5_if_client. + + METHODS on_event + IMPORTING + client TYPE REF TO z2ui5_if_client. + + METHODS set_session_stateful + IMPORTING + client TYPE REF TO z2ui5_if_client + stateful TYPE abap_bool. + + METHODS update_lock_counter. + +ENDCLASS. + + + +CLASS z2ui5_cl_demo_app_135 IMPLEMENTATION. + + METHOD initialize_view. + set_session_stateful( client = client stateful = abap_true ). + + DATA(view) = z2ui5_cl_xml_view=>factory( ). + + DATA(page) = view->shell( )->page( + title = `abap2UI5 - Sample: Sticky Session with locks` + navbuttonpress = client->_event( 'BACK' ) + shownavbutton = xsdbool( client->get( )-s_draft-id_prev_app_stack IS NOT INITIAL ) ). + + page->message_strip( + text = client->_bind( error-text ) + type = 'Error' + visible = client->_bind( error-flag ) ). + + DATA(vbox) = page->vbox( ). + + DATA(hbox) = vbox->hbox( alignitems = 'Center' ). + + hbox->info_label( text = client->_bind( session_text ) ). + + hbox->button( + text = 'End session' + press = client->_event( 'END_SESSION' ) ). + + hbox->button( + text = 'Start session again' + press = client->_event( 'START_SESSION' ) ). + + hbox = vbox->hbox( alignitems = 'Center' ). + hbox->label( text = 'press button to create lock entry (SM12) in backend session' class = 'sapUiTinyMarginEnd' ). + hbox->button( + text = 'Lock' + press = client->_event( 'LOCK' ) + type = 'Emphasized' ). + + hbox = vbox->hbox( ). + + hbox->button( + text = 'Refresh lock counter' + press = client->_event( 'REFRESH' ) ). + + hbox->button( + text = 'Rollback Work' + press = client->_event( 'ROLLBACK' ) ). + + vbox->hbox( )->info_label( client->_bind( lock_text ) ). + + client->view_display( view->stringify( ) ). + ENDMETHOD. + + + METHOD on_event. + CASE client->get( )-event. + WHEN 'BACK'. + client->nav_app_leave( ). + WHEN 'LOCK'. + lcl_locking=>acquire_lock( ). + client->message_toast_display( `Lock acquired. Press 'Refresh lock counter'` ). + client->view_model_update( ). + WHEN 'END_SESSION'. + set_session_stateful( client = client stateful = abap_false ). + WHEN 'START_SESSION'. + set_session_stateful( client = client stateful = abap_true ). + WHEN 'REFRESH'. + update_lock_counter( ). + client->view_model_update( ). + WHEN 'ROLLBACK'. + ROLLBACK WORK. + client->message_toast_display( |ROLLBACK WORK done, { lock_counter } locks released. Press 'Refresh lock counter'| ). + ENDCASE. + ENDMETHOD. + + + METHOD set_session_stateful. + client->set_session_stateful( stateful ). + session_is_stateful = stateful. + IF stateful = abap_true. + session_text = 'Session ON (stateful)'. + ELSE. + session_text = 'Session OFF (stateless)'. + ENDIF. + client->view_model_update( ). + ENDMETHOD. + + + METHOD z2ui5_if_app~main. + + CLEAR error. + + IF check_initialized = abap_false. + check_initialized = abap_true. + update_lock_counter( ). + initialize_view( client ). + ENDIF. + + TRY. + on_event( client ). + CATCH z2ui5_cx_util_error INTO DATA(x_error). + error-text = x_error->get_text( ). + error-flag = abap_true. + client->view_model_update( ). + ENDTRY. + + ENDMETHOD. + + + METHOD update_lock_counter. + + lock_counter = lcl_locking=>get_lock_counter( ). + lock_text = |There are { lock_counter } SM12 locks|. + + ENDMETHOD. + +ENDCLASS. + diff --git a/src/z2ui5_cl_demo_app_135.clas.locals_imp.abap b/src/z2ui5_cl_demo_app_135.clas.locals_imp.abap new file mode 100644 index 0000000..6083b55 --- /dev/null +++ b/src/z2ui5_cl_demo_app_135.clas.locals_imp.abap @@ -0,0 +1,55 @@ +CLASS lcl_locking DEFINITION CREATE PRIVATE FINAL. + PUBLIC SECTION. + CLASS-METHODS acquire_lock. + CLASS-METHODS get_lock_counter + RETURNING + VALUE(result) TYPE i. + PROTECTED SECTION. + PRIVATE SECTION. +ENDCLASS. + +CLASS lcl_locking IMPLEMENTATION. + + METHOD acquire_lock. + + CALL FUNCTION 'ENQUEUE_E_TABLE' + EXPORTING + tabname = 'ZTEST' + varkey = 'Z100' + EXCEPTIONS + foreign_lock = 1 + system_failure = 2 + OTHERS = 3. + IF sy-subrc <> 0. + MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO DATA(error_text). + RAISE EXCEPTION TYPE z2ui5_cx_util_error EXPORTING val = error_text. + ENDIF. + + ENDMETHOD. + + + METHOD get_lock_counter. + DATA: enqueue_table TYPE STANDARD TABLE OF seqg3. + + DATA(argument) = CONV eqegraarg( |ZTEST Z100*| ). + + CALL FUNCTION 'ENQUEUE_READ' + EXPORTING + garg = argument + guname = sy-uname + TABLES + enq = enqueue_table + EXCEPTIONS + communication_failure = 1 + system_failure = 2 + OTHERS = 3. + IF sy-subrc <> 0. + MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO DATA(error_text). + RAISE EXCEPTION TYPE z2ui5_cx_util_error EXPORTING val = error_text. + ENDIF. + + result = VALUE #( enqueue_table[ 1 ]-gusevb OPTIONAL ). + + ENDMETHOD. + +ENDCLASS. diff --git a/src/z2ui5_cl_demo_app_135.clas.xml b/src/z2ui5_cl_demo_app_135.clas.xml new file mode 100644 index 0000000..4e2e1f2 --- /dev/null +++ b/src/z2ui5_cl_demo_app_135.clas.xml @@ -0,0 +1,16 @@ + + + + + + Z2UI5_CL_DEMO_APP_135 + E + Sticky session with locking + 1 + X + X + X + + + +