Jaehoon

EXT201_5.4.3

Feb 12th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 9.60 KB | None | 0 0
  1. *"* use this source file for the definition and implementation of
  2. *"* local helper classes, interface definitions and type
  3. *"* declarations
  4. CLASS lhc_travel DEFINITION INHERITING FROM cl_abap_behavior_handler.
  5.  
  6. PRIVATE SECTION.
  7.  
  8. TYPES tt_travel_update TYPE TABLE FOR UPDATE zi_travel_m_xxx.
  9.  
  10. METHODS validate_customer          FOR VALIDATION travel~validateCustomer IMPORTING keys FOR travel.
  11. METHODS validate_dates             FOR VALIDATION travel~validateDates    IMPORTING keys FOR travel.
  12. METHODS validate_travel_status     FOR VALIDATION travel~validateStatus   IMPORTING keys FOR travel.
  13.  
  14. METHODS set_status_completed       FOR MODIFY IMPORTING   keys FOR ACTION travel~acceptTravel              RESULT result.
  15. METHODS get_features               FOR FEATURES IMPORTING keys REQUEST    requested_features FOR travel    RESULT result.
  16.  
  17. ENDCLASS.
  18.  
  19. CLASS lhc_travel IMPLEMENTATION.
  20.  
  21. **********************************************************************
  22. *
  23. * Validate customer data when saving travel data
  24. *
  25. **********************************************************************
  26. METHOD validate_customer.
  27.  
  28. READ ENTITY zi_travel_m_xxx\\travel FROM VALUE #(
  29.     FOR <root_key> IN keys ( %key     = <root_key>
  30.                              %control = VALUE #( customer_id = if_abap_behv=>mk-on ) ) )
  31.     RESULT DATA(lt_travel).
  32.  
  33. DATA lt_customer TYPE SORTED TABLE OF /dmo/customer WITH UNIQUE KEY customer_id.
  34.  
  35. " Optimization of DB select: extract distinct non-initial customer IDs
  36. lt_customer = CORRESPONDING #( lt_travel DISCARDING DUPLICATES MAPPING customer_id = customer_id EXCEPT * ).
  37. DELETE lt_customer WHERE customer_id IS INITIAL.
  38. CHECK lt_customer IS NOT INITIAL.
  39.  
  40. " Check if customer ID exist
  41. SELECT FROM /dmo/customer FIELDS customer_id
  42.   FOR ALL ENTRIES IN @lt_customer
  43.   WHERE customer_id = @lt_customer-customer_id
  44.   INTO TABLE @DATA(lt_customer_db).
  45.  
  46. " Raise msg for non existing customer id
  47. LOOP AT lt_travel INTO DATA(ls_travel).
  48.   IF ls_travel-customer_id IS NOT INITIAL AND NOT line_exists( lt_customer_db[ customer_id = ls_travel-customer_id ] ).
  49.     APPEND VALUE #(  travel_id = ls_travel-travel_id ) TO failed.
  50.     APPEND VALUE #(  travel_id = ls_travel-travel_id
  51.                      %msg      = new_message( id       = /dmo/cx_flight_legacy=>customer_unkown-msgid
  52.                                               number   = /dmo/cx_flight_legacy=>customer_unkown-msgno
  53.                                               v1       = ls_travel-customer_id
  54.                                               severity = if_abap_behv_message=>severity-error )
  55.                      %element-customer_id = if_abap_behv=>mk-on ) TO reported.
  56.   ENDIF.
  57.  
  58. ENDLOOP.
  59.  
  60. ENDMETHOD.
  61.  
  62.  
  63. **********************************************************************
  64. *
  65. * Check validity of date
  66. *
  67. **********************************************************************
  68. METHOD validate_dates.
  69.  
  70. READ ENTITY zi_travel_m_xxx\\travel FROM VALUE #(
  71.     FOR <root_key> IN keys ( %key     = <root_key>
  72.                              %control = VALUE #( begin_date = if_abap_behv=>mk-on
  73.                                                  end_date   = if_abap_behv=>mk-on ) ) )
  74.     RESULT DATA(lt_travel_result).
  75.  
  76. LOOP AT lt_travel_result INTO DATA(ls_travel_result).
  77.  
  78.   IF ls_travel_result-end_date < ls_travel_result-begin_date.  "end_date before begin_date
  79.  
  80.     APPEND VALUE #( %key        = ls_travel_result-%key
  81.                     travel_id   = ls_travel_result-travel_id ) TO failed.
  82.  
  83.     APPEND VALUE #( %key     = ls_travel_result-%key
  84.                     %msg     = new_message( id       = /dmo/cx_flight_legacy=>end_date_before_begin_date-msgid
  85.                                             number   = /dmo/cx_flight_legacy=>end_date_before_begin_date-msgno
  86.                                             v1       = ls_travel_result-begin_date
  87.                                             v2       = ls_travel_result-end_date
  88.                                             v3       = ls_travel_result-travel_id
  89.                                             severity = if_abap_behv_message=>severity-error )
  90.                     %element-begin_date = if_abap_behv=>mk-on
  91.                     %element-end_date   = if_abap_behv=>mk-on ) TO reported.
  92.  
  93.   ELSEIF ls_travel_result-begin_date < cl_abap_context_info=>get_system_date( ).  "begin_date must be in the future
  94.  
  95.     APPEND VALUE #( %key        = ls_travel_result-%key
  96.                     travel_id   = ls_travel_result-travel_id ) TO failed.
  97.  
  98.     APPEND VALUE #( %key = ls_travel_result-%key
  99.                     %msg = new_message( id       = /dmo/cx_flight_legacy=>begin_date_before_system_date-msgid
  100.                                         number   = /dmo/cx_flight_legacy=>begin_date_before_system_date-msgno
  101.                                         severity = if_abap_behv_message=>severity-error )
  102.                     %element-begin_date = if_abap_behv=>mk-on
  103.                     %element-end_date   = if_abap_behv=>mk-on ) TO reported.
  104.   ENDIF.
  105.  
  106. ENDLOOP.
  107.  
  108. ENDMETHOD.
  109.  
  110. **********************************************************************
  111. *
  112. * Validate travel status when saving travel data
  113. *
  114. **********************************************************************
  115. METHOD validate_travel_status.
  116.  
  117. READ ENTITY zi_travel_m_xxx\\travel FROM VALUE #(
  118.   FOR <root_key> IN keys ( %key     = <root_key>
  119.                            %control = VALUE #( overall_status = if_abap_behv=>mk-on ) ) )
  120.   RESULT DATA(lt_travel_result).
  121.  
  122. LOOP AT lt_travel_result INTO DATA(ls_travel_result).
  123.   CASE ls_travel_result-overall_status.
  124.     WHEN 'O'.  " Open
  125.     WHEN 'X'.  " Cancelled or rejected
  126.     WHEN 'A'.  " Accepted
  127.  
  128.     WHEN OTHERS.
  129.       APPEND VALUE #( %key = ls_travel_result-%key ) TO failed.
  130.  
  131.       APPEND VALUE #( %key = ls_travel_result-%key
  132.                       %msg = new_message( id       = /dmo/cx_flight_legacy=>status_is_not_valid-msgid
  133.                                           number   = /dmo/cx_flight_legacy=>status_is_not_valid-msgno
  134.                                           v1       = ls_travel_result-overall_status
  135.                                           severity = if_abap_behv_message=>severity-error )
  136.                       %element-overall_status = if_abap_behv=>mk-on ) TO reported.
  137.   ENDCASE.
  138.  
  139. ENDLOOP.
  140.  
  141. ENDMETHOD.
  142.  
  143.  
  144. ********************************************************************************
  145. *
  146. * Implements travel action (in our case: for setting travel overall_status to completed)
  147. *
  148. ********************************************************************************
  149. METHOD set_status_completed.
  150.  
  151. " Modify in local mode: BO-related updates that are not relevant for authorization checks
  152. MODIFY ENTITIES OF zi_travel_m_xxx IN LOCAL MODE
  153.        ENTITY travel
  154.           UPDATE FROM VALUE #( for key in keys ( travel_id = key-travel_id
  155.                                                  overall_status = 'A' " Accepted
  156.                                                  %control-overall_status = if_abap_behv=>mk-on ) )
  157.        FAILED   failed
  158.        REPORTED reported.
  159.  
  160.   " Read changed data for action result
  161.   READ ENTITIES OF zi_travel_m_xxx IN LOCAL MODE
  162.        ENTITY travel
  163.        FROM VALUE #( for key in keys (  travel_id = key-travel_id
  164.                                         %control = VALUE #(
  165.                                           agency_id       = if_abap_behv=>mk-on
  166.                                           customer_id     = if_abap_behv=>mk-on
  167.                                           begin_date      = if_abap_behv=>mk-on
  168.                                           end_date        = if_abap_behv=>mk-on
  169.                                           booking_fee     = if_abap_behv=>mk-on
  170.                                           total_price     = if_abap_behv=>mk-on
  171.                                           currency_code   = if_abap_behv=>mk-on
  172.                                           overall_status  = if_abap_behv=>mk-on
  173.                                           description     = if_abap_behv=>mk-on
  174.                                           created_by      = if_abap_behv=>mk-on
  175.                                           created_at      = if_abap_behv=>mk-on
  176.                                           last_changed_by = if_abap_behv=>mk-on
  177.                                           last_changed_at = if_abap_behv=>mk-on
  178.                                         ) ) )
  179.        RESULT DATA(lt_travel).
  180.  
  181.   result = VALUE #( for travel in lt_travel ( travel_id = travel-travel_id
  182.                                               %param    = travel
  183.                                             ) ).
  184.  
  185. ENDMETHOD.
  186.  
  187. ********************************************************************************
  188. *
  189. * Implements the dynamic feature handling for travel instances
  190. *
  191. ********************************************************************************
  192. METHOD get_features.
  193.  
  194. READ ENTITY zi_travel_m_xxx FROM VALUE #( FOR keyval IN keys
  195.                                                   (  %key                    = keyval-%key
  196.                                                      %control-travel_id      = if_abap_behv=>mk-on
  197.                                                      %control-overall_status = if_abap_behv=>mk-on ) )
  198.                             RESULT DATA(lt_travel_result).
  199.  
  200.  
  201. result = VALUE #( FOR ls_travel IN lt_travel_result
  202.                    ( %key                           = ls_travel-%key
  203.                      %features-%action-acceptTravel = COND #( WHEN ls_travel-overall_status = 'A'
  204.                                                                 THEN if_abap_behv=>fc-o-disabled ELSE if_abap_behv=>fc-o-enabled   )
  205.                   ) ).
  206.  
  207. ENDMETHOD.
  208.  
  209.  
  210. ENDCLASS.
Add Comment
Please, Sign In to add comment