From 610145608219b171801472e6042f1aaa20d3e28c Mon Sep 17 00:00:00 2001 From: "b.santos" Date: Mon, 7 Jul 2025 17:33:08 +0000 Subject: [PATCH] Enviar arquivos para "src" --- src/zbp_demo_abap_rap_draft_m.clas.abap | 20 ++ ...demo_abap_rap_draft_m.clas.locals_imp.abap | 240 ++++++++++++++++++ src/zbp_demo_abap_rap_draft_m.clas.xml | 18 ++ 3 files changed, 278 insertions(+) create mode 100644 src/zbp_demo_abap_rap_draft_m.clas.abap create mode 100644 src/zbp_demo_abap_rap_draft_m.clas.locals_imp.abap create mode 100644 src/zbp_demo_abap_rap_draft_m.clas.xml diff --git a/src/zbp_demo_abap_rap_draft_m.clas.abap b/src/zbp_demo_abap_rap_draft_m.clas.abap new file mode 100644 index 0000000..1ad11b7 --- /dev/null +++ b/src/zbp_demo_abap_rap_draft_m.clas.abap @@ -0,0 +1,20 @@ +*********************************************************************** +* +* RAP BO provider (i. e. ABAP behavior pool/ABP) +* for a RAP demo scenario +* +* See more information in the CCIMP include (local types tab in ADT). +* +********************************************************************** +"!

Behavior implementation for RAP demo scenario (draft BO)

+"! The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario +"! (managed, draft-enabled RAP BO with late numbering). +CLASS zbp_demo_abap_rap_draft_m DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_draft_m. + PROTECTED SECTION. + PRIVATE SECTION. +ENDCLASS. + + + +CLASS ZBP_DEMO_ABAP_RAP_DRAFT_M IMPLEMENTATION. +ENDCLASS. diff --git a/src/zbp_demo_abap_rap_draft_m.clas.locals_imp.abap b/src/zbp_demo_abap_rap_draft_m.clas.locals_imp.abap new file mode 100644 index 0000000..44035f0 --- /dev/null +++ b/src/zbp_demo_abap_rap_draft_m.clas.locals_imp.abap @@ -0,0 +1,240 @@ +*********************************************************************** +* +* RAP BO provider (i. e. ABAP behavior pool/ABP) +* for a RAP demo scenario +* +* - RAP scenario: "RAP calculator" (managed, draft-enabled RAP BO with +* late numbering) +* - Data model: Consists of a root entity alone. +* The BDEF defines the behavior for this entity. The definitions in the +* BDEF determine which methods must be implemented in the ABAP behavior +* pool (ABP). Note that the view contains many annotations for the +* SAP Fiori UI. +* +* ----------------------------- NOTE ----------------------------------- +* This simplified example is not a real life scenario and rather +* focuses on the technical side by giving an idea how the communication +* and data exchange between a RAP BO consumer, which is a class +* in this case, and RAP BO provider can work. Additionally, it shows +* how the methods for non-standard RAP BO operations might be +* self-implemented in an ABP. The example is intentionally kept +* short and simple and focuses on specific RAP aspects. For this reason, +* the example might not fully meet the requirements of the RAP BO contract. +* +* You can also use side effects to trigger data +* changes (in terms of this example, the recalculation of the calculation +* result) and other things based on data changes in UI scenarios with +* draft-enabled BOs. +* +* The code presented in this class is intended only to support the ABAP +* cheat sheets. It is not intended for direct use in a production system +* environment. The code examples in the ABAP cheat sheets are primarily +* intended to provide a better explanation and visualization of the +* syntax and semantics of ABAP statements, not to solve concrete +* programming tasks. For production application programs, you should +* always work out your own solution for each individual case. There is +* no guarantee for the correctness or completeness of the code. +* Furthermore, there is no legal responsibility or liability for any +* errors or their consequences that may occur when using the the example +* code. +* +*********************************************************************** + +CLASS lhc_calc DEFINITION INHERITING FROM cl_abap_behavior_handler. + PRIVATE SECTION. + + METHODS delete_all FOR MODIFY + IMPORTING keys FOR ACTION calc~delete_all. + + METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION + IMPORTING REQUEST requested_authorizations FOR calc RESULT result. + + METHODS validate FOR VALIDATE ON SAVE + IMPORTING keys FOR calc~validate. + + METHODS det_modify FOR DETERMINE ON MODIFY + IMPORTING keys FOR calc~det_modify. + + METHODS calculation FOR MODIFY + IMPORTING keys FOR ACTION calc~calculation. + +ENDCLASS. + +CLASS lhc_calc IMPLEMENTATION. + + METHOD delete_all. + "Purpose: The method deletes all persisted database entries. + + DATA all_keys TYPE TABLE FOR DELETE zdemo_abap_rap_draft_m. + + SELECT id FROM zdemo_abap_tabca INTO CORRESPONDING FIELDS OF TABLE @all_keys. + + READ ENTITIES OF zdemo_abap_rap_draft_m IN LOCAL MODE + ENTITY calc + ALL FIELDS WITH CORRESPONDING #( all_keys ) + RESULT DATA(lt_del). + + IF lt_del IS NOT INITIAL. + + MODIFY ENTITY IN LOCAL MODE zdemo_abap_rap_draft_m + DELETE FROM CORRESPONDING #( lt_del ). + + APPEND VALUE #( %msg = new_message_with_text( text = 'All persisted calculations were deleted.' + severity = if_abap_behv_message=>severity-information ) + ) TO reported-calc. + + ELSE. + APPEND VALUE #( %msg = new_message_with_text( text = 'No persisted calculations available.' + severity = if_abap_behv_message=>severity-information ) + ) TO reported-calc. + + ENDIF. + + ENDMETHOD. + + METHOD get_global_authorizations. + "Purposely kept without implementation. + ENDMETHOD. + + METHOD validate. + + "Retrieving instances based on requested keys + READ ENTITIES OF zdemo_abap_rap_draft_m IN LOCAL MODE + ENTITY calc + ALL FIELDS + WITH CORRESPONDING #( keys ) + RESULT DATA(result_validate) + FAILED DATA(f). + + CHECK result_validate IS NOT INITIAL. + + "Various calculation errors are handled. + LOOP AT result_validate ASSIGNING FIELD-SYMBOL(). + + APPEND VALUE #( %tky = -%tky + %state_area = 'VALIDATE_CALCULATION' + ) TO reported-calc. + + IF -calc_result = `Wrong operator`. + APPEND VALUE #( %tky = -%tky ) TO failed-calc. + + APPEND VALUE #( %tky = -%tky + %state_area = 'VALIDATE_CALCULATION' + %msg = new_message_with_text( text = 'Only + - * / P allowed as operators.' + severity = if_abap_behv_message=>severity-error ) + "%element highlights the input field + %element-arithm_op = if_abap_behv=>mk-on + ) TO reported-calc. + + ELSEIF -calc_result = `Division by 0`. + + APPEND VALUE #( %tky = -%tky ) TO failed-calc. + + APPEND VALUE #( %tky = -%tky + %state_area = 'VALIDATE_CALCULATION' + %msg = new_message_with_text( text = 'Zero division not possible.' + severity = if_abap_behv_message=>severity-error ) + %element-arithm_op = if_abap_behv=>mk-on + %element-num2 = if_abap_behv=>mk-on + ) TO reported-calc. + + ELSEIF -calc_result = `Overflow error`. + + APPEND VALUE #( %tky = -%tky ) TO failed-calc. + + APPEND VALUE #( %tky = -%tky + %state_area = 'VALIDATE_CALCULATION' + %msg = new_message_with_text( text = 'Check the numbers. Try smaller ones.' + severity = if_abap_behv_message=>severity-error ) + %element-num1 = if_abap_behv=>mk-on + %element-num2 = if_abap_behv=>mk-on + ) TO reported-calc. + ENDIF. + + ENDLOOP. + + ENDMETHOD. + + METHOD det_modify. + + MODIFY ENTITIES OF zdemo_abap_rap_draft_m IN LOCAL MODE + ENTITY calc + EXECUTE calculation + FROM CORRESPONDING #( keys ). + + ENDMETHOD. + + METHOD calculation. + + READ ENTITIES OF zdemo_abap_rap_draft_m IN LOCAL MODE + ENTITY calc + FIELDS ( num1 num2 arithm_op ) WITH CORRESPONDING #( keys ) + RESULT DATA(lt_calc) + FAILED DATA(f). + + LOOP AT lt_calc ASSIGNING FIELD-SYMBOL(). + + TRY. + -calc_result = SWITCH #( -arithm_op + WHEN `+` THEN -num1 + -num2 + WHEN `-` THEN -num1 - -num2 + WHEN `*` THEN -num1 * -num2 + WHEN `/` THEN -num1 / -num2 + WHEN `P` THEN ipow( base = -num1 exp = -num2 ) + ELSE `Wrong operator` ). + "Bringing "-" to the front in case of negative values in the string + IF -calc_result CA `-`. + -calc_result = shift_right( val = -calc_result circular = 1 ). + ENDIF. + + "Removing trailing .0 from the string + REPLACE PCRE `\.0+\b` IN -calc_result WITH ``. + + "Handling the fact that ABAP allows division by zero if the dividend itself is zero. + IF -num1 = 0 AND -num2 = 0 AND -arithm_op = `/`. + -calc_result = `Division by 0`. + ENDIF. + + CATCH cx_sy_zerodivide. + -calc_result = `Division by 0`. + + CATCH cx_sy_arithmetic_overflow. + -calc_result = `Overflow error`. + + ENDTRY. + + ENDLOOP. + + MODIFY ENTITY IN LOCAL MODE zdemo_abap_rap_draft_m + UPDATE FIELDS ( calc_result ) + WITH CORRESPONDING #( lt_calc ). + + ENDMETHOD. + +ENDCLASS. + +CLASS lsc_zdemo_abap_rap_draft_m DEFINITION INHERITING FROM cl_abap_behavior_saver. + PROTECTED SECTION. + + METHODS adjust_numbers REDEFINITION. + +ENDCLASS. + +CLASS lsc_zdemo_abap_rap_draft_m IMPLEMENTATION. + + METHOD adjust_numbers. + + "The newly created entity instances are given their final key + "only shortly before saving in the database in the adjust_numbers method. + "Until then, the business logic uses a temporary key that has to be replaced. + "In this very simplified example, the key 'id' is purposely typed with the + "type sysuuid_x16 which can accept the value used in %pid to finally ensure + "that there is a unique key and the instance can be stored in the database. + "Hence, the final key 'id' is in this example just the value used for %pid. + LOOP AT mapped-calc ASSIGNING FIELD-SYMBOL(). + -%key-id = -%pid. + ENDLOOP. + + ENDMETHOD. + +ENDCLASS. diff --git a/src/zbp_demo_abap_rap_draft_m.clas.xml b/src/zbp_demo_abap_rap_draft_m.clas.xml new file mode 100644 index 0000000..86c9a76 --- /dev/null +++ b/src/zbp_demo_abap_rap_draft_m.clas.xml @@ -0,0 +1,18 @@ + + + + + + ZBP_DEMO_ABAP_RAP_DRAFT_M + E + Behavior implementation for RAP demo scenario (draft BO) + 06 + 1 + X + X + X + ZDEMO_ABAP_RAP_DRAFT_M + + + +