Quantcast
Viewing latest article 9
Browse Latest Browse All 249

Additional driver person is created for preliminary data creation in offline form scenario

I have couple of offline forms for incident and near-miss recording, having sections to capture driver details for the vehicle involved cases. They are based on standard EHHSS_INCIDENT business object.

 

Problem arises when we have more than one driver persons with 'External' Person group (i.e. not an employee, so no Person Number). I create a row for involved person node with preliminary data updating person group and create person role, person initial, person statement node rows accordingly and updating driver details to respective vehicle asset node. The party key ID for such involved persons is auto-generated starting with an 'I' (like I00000631) instead of 'A' in case of an employee.

 

The row count of person involved node remains consistent with what I am intending to do till the end of persistent class STORE_DATA method where I am coding. However, after service manager SAVE() method at very end, I check in pre-exit of PERSON_GROUP determination and find that there are additional (duplicate) driver person created for 'External' Person group cases only and that too only for second such driver person onwards (not for first driver person). We have other sections on the form with other involved person roles like Reporting Person, Injured Person, Treatment Provider etc. but such discrepancy does not happen anywhere else.

 

This is a bit strange and I am yet to figure out where it is going wrong: my persistent class code or somewhere within service manager SAVE() method for any reason.

 

Please let me know if there is anything in BOPF that may drive this behavior. I am putting my code snippet below for better understanding:

 

    LOOP AT <ls_interf_str>-inv_pers-vehicle_drivers  REFERENCE INTO l_driver.    "Start of Driver Person Loop
      CLEAR: ls_driver_key_refs.
      zl_index = sy-tabix.
      lv_person_exist  = abap_false.
      lv_create_hr  = abap_false.
      lv_pers_no = l_driver->person_data-person_initial-person_number.
      lv_first_name = l_driver->person_data-person_initial-first_name.
      lv_last_name  = l_driver->person_data-person_initial-last_name.
      cl_ehhss_aif_inc_person_helper=>get_party_key_by_person_number(
        EXPORTING
          iv_person_number =  lv_pers_no "Personnel Number
          iv_first_name =  lv_first_name"First Name of Driver
          iv_last_name =  lv_last_name"Last Name of Driver
        IMPORTING
          ev_hr_per_exists = lv_person_exist"Driver Exist
          ev_party_key = ls_veh_dri_party_key"Combined Party ID
          ev_create_hr = lv_create_hr"HR data exist
      ).
      IF lv_person_exist = abap_true AND lv_create_hr = abap_true.
    "If an existing employee - this case works fine
    .
    .
    .
      ELSE.

*-----------------------------------------------------------------------------------------

* Invalid Personnel Number - unable to read the data by the proxy ( create person Initial)

*-----------------------------------------------------------------------------------------

* create  driver person - Combined Party ID is initial

     IF lv_driver_added EQ abap_false.
        lo_inv_pers = lo_root_node->get_subnode_by_key( if_ehhss_inc_c=>sc_association-root-person_involved ).
        lr_s_person_involved ?= lo_inv_pers->create_empty_row( ).
        lo_inv_pers->insert_and_focus( lr_s_person_involved ).
        lr_s_person_involved ?= lo_inv_pers->get_current_row( ).
        "Update Person Group
        IF l_driver->person_data-per_group IS NOT INITIAL.
              lr_s_person_involved->per_group = l_driver->person_data-per_group.
        ENDIF.
        CALL METHOD lo_inv_pers->update
          EXPORTING
                ir_s_update_row   = lr_s_person_involved
          RECEIVING
                rv_success          = lv_success.

* create  driver person initial

        lo_inv_pers_initial = lo_inv_pers->get_subnode_by_key( if_ehhss_inc_c=>sc_association-person_involved-person_initial ).
        lr_s_person_initial ?= lo_inv_pers_initial->create_empty_row( ) .

 

        IF   l_driver->person_data-person_initial-first_name IS NOT INITIAL
              OR l_driver->person_data-person_initial-last_name IS NOT INITIAL
              OR l_driver->person_data-person_initial-telephone_number IS NOT INITIAL
              OR l_driver->person_data-person_initial-email IS NOT INITIAL
              OR l_driver->person_data-person_initial-person_number IS NOT INITIAL.

 

 

          IF l_driver->person_data-person_initial-first_name IS  INITIAL
              OR l_driver->person_data-person_initial-last_name IS INITIAL.
            lv_otr = cl_wd_utilities=>get_otr_text_by_alias( alias = 'EHHSS_UI_INC_COMMON/UNKNOWN_PERSON' language = <ls_interf_str>-meta_data-langu ).
            lr_s_person_initial->last_name    = lv_otr.
          ELSE.
            lr_s_person_initial->first_name = l_driver->person_data-person_initial-first_name.
            lr_s_person_initial->last_name = l_driver->person_data-person_initial-last_name.

 

 

          ENDIF.

 

          lr_s_person_initial->telephone_number = l_driver->person_data-person_initial-telephone_number.
          lr_s_person_initial->email = l_driver->person_data-person_initial-email.

 

          lo_inv_pers_initial->insert( lr_s_person_initial ).

 

          "Statement
          IF l_driver->person_data-statem_of_pers-text IS NOT INITIAL AND l_driver->person_data-statem_of_pers-text NE space.
            lo_driver_stmt = lo_inv_pers->get_subnode_by_key( if_ehhss_inc_c=>sc_association-person_involved-person_statem ).

 

            lr_s_driver_stmt ?= lo_driver_stmt->create_empty_row( ) .
            lr_s_driver_stmt->text = l_driver->person_data-statem_of_pers-text.
            lr_s_driver_stmt->per_stat_date = <ls_interf_str>-basicinfo-start_date.

 

            IF <ls_interf_str>-basicinfo-start_time IS NOT INITIAL.
              CLEAR lv_ehfnd_time.
              CALL FUNCTION 'CONVERSION_EXIT_THHMM_INPUT'
                EXPORTING
                  input = <ls_interf_str>-basicinfo-start_time  
                IMPORTING
                  output   = lv_ehfnd_time
                EXCEPTIONS
                  time_invalid = 1
                  OTHERS    = 2.
              IF sy-subrc EQ 0.
                lr_s_driver_stmt->per_stat_time = lv_ehfnd_time.
              ENDIF.
            ENDIF.
            lo_driver_stmt->insert( lr_s_driver_stmt ).
          ENDIF.

* Create driver person role

          lo_veh_inv_pers_role = lo_inv_pers->get_subnode_by_key( if_ehhss_inc_c=>sc_association-person_involved-person_role ).

 

          lr_s_veh_driver_role ?= lo_veh_inv_pers_role->create_empty_row( ).
          lr_s_veh_driver_role->role = if_ehhss_inc_impl_c=>sc_person_role-vehicle_driver.
          lr_s_veh_driver_role->key_ref = lr_s_veh_driver_role->parent_key.
          lo_veh_inv_pers_role->insert( lr_s_veh_driver_role ).
          APPEND ls_veh_dri_party_key TO lt_veh_party_keys.

 

          "To update Driver under vehicle
          ls_driver_key_refs-driver_ref_key = lr_s_veh_driver_role->parent_key.
          ls_driver_key_refs-create_hr  = lv_create_hr.
          ls_driver_key_refs-exist_hr   = lv_person_exist.
          APPEND ls_driver_key_refs TO lt_driver_key_refs.
        ELSE.
          lo_inv_pers->delete( ).
        ENDIF.
        ENDIF.
      ENDIF.
      CLEAR:  lr_s_person_involved, lr_s_veh_driver_role, lr_s_driver_stmt, ls_driver_key_refs,
      lr_s_person_initial, ls_party_roles, ls_driver_key_refs, ls_veh_dri_party_key.
    ENDLOOP.   "End of Driver Person Loop

****-------------------------------------------------------------------------------------------------------

 

    LOOP AT lt_vehicle REFERENCE INTO l_vehicle.   "Start of Vehicle Loop
      zl_pass_index = sy-tabix.
    .
    .
    .
      READ TABLE lt_driver_key_refs INTO ls_driver_key_refs INDEX zl_pass_index.   
      IF sy-subrc EQ 0.   "Driver Added
        READ TABLE lt_veh_party_keys INTO ls_veh_dri_party_key INDEX zl_pass_index.
        IF sy-subrc EQ 0.   "Driver Added with Person Number - Employee
          IF ls_driver_key_refs-create_hr EQ abap_true AND ls_driver_key_refs-exist_hr EQ abap_true.
            lr_s_vehicle->driver_id  = ls_veh_dri_party_key-id_combined.
          ELSE.
            READ TABLE <ls_interf_str>-inv_pers-vehicle_drivers  REFERENCE INTO l_driver INDEX zl_pass_index.
            IF sy-subrc EQ 0.
              IF ls_veh_dri_party_key-id_combined IS NOT INITIAL.
                lr_s_vehicle->driver_id     = ls_veh_dri_party_key-id_combined.
              ELSE.   "Driver Added as External Person
                CLEAR: lr_s_person_involved, lr_s_veh_driver_role, lv_role_found.
                lo_inv_pers = lo_root_node->get_subnode_by_key( if_ehhss_inc_c=>sc_association-root-person_involved ).
                zl_count = lo_inv_pers->count( ).
                WHILE lo_inv_pers->has_more_rows( ) = abap_true.   "Get auto ID from Involved Person Node
                  lr_s_person_involved ?= lo_inv_pers->get_next_row( ).
                  IF lr_s_person_involved->key eq ls_driver_key_refs-driver_ref_key.
                    lr_s_vehicle->driver_id   = lr_s_person_involved->id.
                    EXIT.
                  ENDIF.
                ENDWHILE.
              ENDIF.
              lr_s_vehicle->driver_fi_name= l_driver->person_data-person_initial-first_name.
              lr_s_vehicle->driver_last_name  = l_driver->person_data-person_initial-last_name.
              CONCATENATE   l_driver->person_data-person_initial-first_name
                            l_driver->person_data-person_initial-last_name
                     INTO   zl_driver_name
              SEPARATED BY  space.
              lr_s_vehicle->driver_name   =  zl_driver_name.
              lr_s_vehicle->driver_email  = l_driver->person_data-person_initial-email.
              lr_s_vehicle->driver_tel_num= l_driver->person_data-person_initial-telephone_number.
            ENDIF.
          ENDIF.
          lv_driver_id  = ls_veh_dri_party_key-id_combined.
        ENDIF.
      ENDIF.

      .

   .   
      lo_inv_veh->insert_and_focus( lr_s_vehicle ).

      .

      .

      CLEAR:  lr_s_person_involved, lr_s_person_details, lr_s_veh_driver_role,
              ls_r_pers_role_rev_key, lv_role_found, lr_s_person_initial.
      lo_inv_pers = lo_root_node->get_subnode_by_key( if_ehhss_inc_c=>sc_association-root-person_involved ).
      zl_count = lo_inv_pers->count( ).

      "Setting Vehicle key into Driver Role node's key_ref field and Involved Person key as parent key for

      "person_role_rev_for_key node under vehicle

      WHILE lo_inv_pers->has_more_rows( ) = abap_true.
        lr_s_person_involved ?= lo_inv_pers->get_next_row( ).
        IF ( lr_s_person_involved->id eq lv_driver_id AND lv_driver_id IS NOT INITIAL ) or
           ( lr_s_person_involved->key eq ls_driver_key_refs-driver_ref_key ).
          lv_role_found = abap_true.
        ELSE.
          lo_inv_pers_details = lo_inv_pers->get_subnode_by_key( if_ehhss_inc_c=>sc_association-person_involved-person_detail ).
          zl_count = lo_inv_pers_details->count( ).
          WHILE lo_inv_pers_details->has_more_rows( ) = abap_true.
            lr_s_person_details ?= lo_inv_pers_details->get_next_row( ).
            IF lr_s_person_details->id eq lv_driver_id AND lv_driver_id IS NOT INITIAL AND lr_s_person_details->parent_key eq lr_s_person_involved->key.
              lv_role_found = abap_true.
              EXIT.
            ENDIF.
          ENDWHILE.
          IF lv_role_found ne abap_true.
            lo_inv_pers_initial = lo_inv_pers->get_subnode_by_key( if_ehhss_inc_c=>sc_association-person_involved-person_initial ).
            zl_count = lo_inv_pers_initial->count( ).
            WHILE lo_inv_pers_initial->has_more_rows( ) = abap_true.
              lr_s_person_initial ?= lo_inv_pers_initial->get_next_row( ).
              IF lr_s_person_initial->id eq lv_driver_id AND lv_driver_id IS NOT INITIAL AND lr_s_person_initial->parent_key eq lr_s_person_involved->key.
                lv_role_found = abap_true.
                EXIT.
              ENDIF.
            ENDWHILE.
          ENDIF.
        ENDIF.
        IF lv_role_found ne abap_true.
          CONTINUE.
        ENDIF.
        lo_veh_inv_pers_role = lo_inv_pers->get_subnode_by_key( if_ehhss_inc_c=>sc_association-person_involved-person_role ).
        zl_count = lo_veh_inv_pers_role->count( ).
        WHILE lo_veh_inv_pers_role->has_more_rows( ) = abap_true.
          lr_s_veh_driver_role ?= lo_veh_inv_pers_role->get_next_row( ).
          IF  lr_s_veh_driver_role->role EQ if_ehhss_inc_impl_c=>sc_person_role-vehicle_driver AND
              lr_s_veh_driver_role->parent_key EQ lr_s_person_involved->key .
                lr_s_veh_driver_role->key_ref = lr_s_vehicle->key.
                lo_veh_inv_pers_role->update( lr_s_veh_driver_role ).
          ENDIF.
        ENDWHILE.
        READ TABLE lt_driver_key_refs INTO ls_driver_key_refs INDEX zl_pass_index.  "zl_index.
        IF sy-subrc EQ 0.
          lo_pers_role_rev_key = lo_inv_veh->get_subnode_by_key( if_ehhss_inc_c=>sc_association-vehicle-person_role_rev_for_key ).
          ls_r_pers_role_rev_key ?= lo_pers_role_rev_key->create_empty_row( ).
          ls_r_pers_role_rev_key->key_ref = lr_s_vehicle->key.
          ls_r_pers_role_rev_key->role   = if_ehhss_inc_impl_c=>sc_person_role-vehicle_driver.
          ls_r_pers_role_rev_key->parent_key = lr_s_person_involved->key.
          lo_pers_role_rev_key->insert( ls_r_pers_role_rev_key ).
        ENDIF.
        CLEAR: lr_s_person_involved, lr_s_person_details, lr_s_veh_driver_role,
               ls_r_pers_role_rev_key, lv_role_found, lr_s_person_initial.
      ENDWHILE.
      CLEAR: lv_driver_id, lr_s_person_involved, lr_s_veh_driver_role, lv_role_found.
    ENDLOOP.   "End of Vehicle Loop

Viewing latest article 9
Browse Latest Browse All 249

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>