Thursday, 13 April 2017

HRSFI_COMP_SALARY_ACTIVATION






********************************************************************************
method if_hrsfi_comp_data_activation~activate_changes.

  data:
    ls_message        type bapiret2,
    lt_messages       type bapirettab,
    lv_hourly         type abap_bool,
    lv_frequency      type t549r-zeinh,
    lv_increase       type ansal,
    lv_expected_begda type sydatum,
    ls_p0008_new      type p0008,
    lv_dummy_message  type string.                          "#EC NEEDED

  field-symbols:
    <p0001> type p0001,
    <p0008> type p0008.

  ev_error abap_false.
  clear et_messages.

*>>>1. Begin of changes - Employee Benefits - 22-Apr-2016
  datals_p9012 type p9012.

  " Read the infotype 1 records; these will be needed for activation
  cl_hrsfi_comp_utilities=>infotype_readexporting iv_pernr    mv_pernr
                                                    iv_infty    '0001'
                                                    iv_begda    mv_effective_date
                                          importing et_infotype mt_0001
                                                    ev_error    ev_error
                                                    es_message  ls_message  ).
  if ls_message is not initial.
    append ls_message to et_messages.
  endif.
  if ev_error eq abap_false.

    loop at mt_0001 assigning <p0001> where begda le mv_effective_date
                                        and endda ge mv_effective_date.
      cl_hrsfi_comp_utilities=>get_molgaexporting  iv_pernr mv_pernr
                                                     iv_werks <p0001>-werks
                                          importing  ev_molga mv_molga ).
      exit.
    endloop.
    if mv_molga eq '40'.
      if mv_app is not initial or
         mv_opp is not initial or
         mv_car_lease is not initial or
         mv_employer_pf is not initial or
         mv_ipp is not initial or
         mv_upp is not initial.
        clear ls_p9012.
        ls_p9012-pernr mv_pernr.
        ls_p9012-endda '99991231'.
        ls_p9012-begda mv_effective_date.
        ls_p9012-infty '9012'.
        ls_p9012-car_lease mv_car_lease.
        ls_p9012-emp_pf mv_employer_pf.
        ls_p9012-vc_ipp mv_ipp.
        ls_p9012-vc_upp mv_upp.
        ls_p9012-vc_app mv_app.
        ls_p9012-vc_opp mv_opp.

        ls_p9012-night_alw mv_nightshift_allowance.
        ls_p9012-ons_alw mv_onsite_allowance.
        ls_p9012-lng_alw mv_language_allowance.
        ls_p9012-var_per_pay mv_vpp.

        cl_hrsfi_comp_utilities=>infotype_insertexporting is_pnnnn    ls_p9012
                                                  importing ev_error    ev_error
                                                            et_messages lt_messages ).
        if ev_error eq abap_true.
          " 120  An error occurred when writing infotype Basic Pay (0008)
          clear ls_message.
          ls_message-type     if_hrsfi_empl_data_c=>gc_exception_type_e.
          ls_message-id       cl_hrsfi_comp_constants=>cv_comp_message_class.
          ls_message-number   129.
          message e129(hrsfi_comp_datainto ls_message-message.
          append ls_message to et_messages.
        endif.
      endif.
      if mv_basic_salary is not initial or
         mv_hra is not initial or
         mv_transport_allowance is not initial or
         mv_special_allowance is not initial or
         mv_statutory_bonus is not initial or
         mv_medical is not initial.

        clearls_p0008_newev_errorlt_messagesls_message.
        " Read Infotype 8 starting at the effective date
        cl_hrsfi_comp_utilities=>infotype_readexporting iv_pernr    mv_pernr
                                                          iv_infty    '0008'
                                                          iv_subty    '0   '
                                                          iv_begda    mv_effective_date
                                                importing et_infotype mt_0008
                                                          ev_error    ev_error
                                                          es_message  ls_message ).
        if ls_message is not initial.
          append ls_message to et_messages.
        endif.
        if ev_error eq abap_false.
          read table mt_0008 assigning <p0008> index 1.
          if sy-subrc ne 0
          or <p0008>-begda gt mv_effective_date.

            " 117  No data were found for infotype Basic Pay; activation not possible
            message e118(hrsfi_comp_datainto lv_dummy_message.
            ls_message-type       if_hrsfi_empl_data_c=>gc_exception_type_e.
            ls_message-id         cl_hrsfi_comp_constants=>cv_comp_message_class.
            ls_message-number     117.
            append ls_message to et_messages.
            ev_error abap_true.
          else.
            if <p0008> is assigned.
              move-corresponding <p0008> to ls_p0008_new.
            endif.
            ls_p0008_new-pernr mv_pernr.
            ls_p0008_new-subty '0   '.
            ls_p0008_new-endda '99991231'.
            ls_p0008_new-begda mv_effective_date.
            ls_p0008_new-infty '0008'.
            ls_p0008_new-aedtm sy-datum.
            ls_p0008_new-uname sy-uname.
            clearls_p0008_new-lga01,
                   ls_p0008_new-bet01,
                   ls_p0008_new-lga02,
                   ls_p0008_new-bet02,
                   ls_p0008_new-lga03,
                   ls_p0008_new-bet03,
                   ls_p0008_new-lga04,
                   ls_p0008_new-bet04,
                   ls_p0008_new-lga05,
                   ls_p0008_new-bet05,
                   ls_p0008_new-lga06,
                   ls_p0008_new-bet06.
            if mv_basic_salary is not initial.
              ls_p0008_new-lga01 '1000'.
              ls_p0008_new-bet01 mv_basic_salary / 12.
            endif.
            if mv_hra is not initial.
              ls_p0008_new-lga02 '1001'.
              ls_p0008_new-bet02 mv_hra / 12.
            endif.
            if mv_transport_allowance is not initial.
              ls_p0008_new-lga03 '1002'.
              ls_p0008_new-bet03 mv_transport_allowance  / 12.
            endif.
            if mv_special_allowance is not initial.
              ls_p0008_new-lga04 '1003'.
              ls_p0008_new-bet04 mv_special_allowance / 12.
            endif.
            if mv_statutory_bonus is not initial.
              ls_p0008_new-lga05 '1004'.
              ls_p0008_new-bet05 mv_statutory_bonus / 12.
            endif.
            if mv_medical is not initial.
              ls_p0008_new-lga06 '1006'.
              ls_p0008_new-bet06 mv_medical / 12.
            endif.
            cl_hrsfi_comp_utilities=>infotype_insertexporting is_pnnnn    ls_p0008_new
                                                      importing ev_error    ev_error
                                                                et_messages lt_messages ).
            if ev_error eq abap_true.
              " 120  An error occurred when writing infotype Basic Pay (0008)
              clear ls_message.
              ls_message-type     if_hrsfi_empl_data_c=>gc_exception_type_e.
              ls_message-id       cl_hrsfi_comp_constants=>cv_comp_message_class.
              ls_message-number   130.
              message e120(hrsfi_comp_datainto ls_message-message.
              append ls_message to et_messages.

*        EXIT.
            endif.
          endif.
        endif.
      endif.
    endif.
  endif.
  clearls_p0008_newev_errorlt_messagesls_message.
*<<<1. End of changes - Employee Benefits - 22-Apr-2016

  " Pay changes of 0 are ignored:
  "   No infotype updates are performed
  "   No messages are returned
  check mv_sal_increase        is not initial
     or mv_sal_ann_increase    is not initial
     or mv_sal_ann100_increase is not initial.

  " Read Infotype 8 starting at the effective date
  cl_hrsfi_comp_utilities=>infotype_readexporting iv_pernr    mv_pernr
                                                    iv_infty    '0008'
                                                    iv_subty    '0   '
                                                    iv_begda    mv_effective_date
                                          importing et_infotype mt_0008
                                                    ev_error    ev_error
                                                    es_message  ls_message ).
  if ls_message is not initial.
    append ls_message to et_messages.
  endif.
  check ev_error eq abap_false.


  read table mt_0008 assigning <p0008> index 1.
  if sy-subrc ne 0
  or <p0008>-begda gt mv_effective_date.

    " 117  No data were found for infotype Basic Pay; activation not possible
    message e118(hrsfi_comp_datainto lv_dummy_message.
    ls_message-type       if_hrsfi_empl_data_c=>gc_exception_type_e.
    ls_message-id         cl_hrsfi_comp_constants=>cv_comp_message_class.
    ls_message-number     117.
    append ls_message to et_messages.

    ev_error abap_true.
    return.
  endif.

  " Read the infotype 1 records; these will be needed for activation
  cl_hrsfi_comp_utilities=>infotype_readexporting iv_pernr    mv_pernr
                                                    iv_infty    '0001'
                                                    iv_begda    mv_effective_date
                                          importing et_infotype mt_0001
                                                    ev_error    ev_error
                                                    es_message  ls_message  ).
  if ls_message is not initial.
    append ls_message to et_messages.
  endif.
  check ev_error eq abap_false.

  loop at mt_0001 assigning <p0001> where begda le mv_effective_date
                                      and endda ge mv_effective_date.
    cl_hrsfi_comp_utilities=>get_molgaexporting  iv_pernr mv_pernr
                                                   iv_werks <p0001>-werks
                                        importing  ev_molga mv_molga ).
    exit.
  endloop.
  if sy-subrc ne 0
  or mv_molga is initial.
    " 118  No country grouping could be determined; activation not possible
    message e118(hrsfi_comp_datainto lv_dummy_message.
    ls_message-type       if_hrsfi_empl_data_c=>gc_exception_type_e.
    ls_message-id         cl_hrsfi_comp_constants=>cv_comp_message_class.
    ls_message-number     118.
    append ls_message to et_messages.

    ev_error abap_true.
    return.
  endif.

*  IF mv_sal_increase IS NOT INITIAL.
*
*    lv_increase = mv_sal_increase.
*
*    cl_hrsfi_comp_utilities_salary=>get_payroll_frequency( EXPORTING iv_keydate = mv_effective_date
*                                                                     iv_persg   = <p0001>-persg
*                                                                     iv_persk   = <p0001>-persk
*                                                                     iv_trfar   = <p0008>-trfar
*                                                                     iv_trfgb   = <p0008>-trfgb
*                                                                     iv_molga   = mv_molga
*                                                           IMPORTING ev_hourly  = lv_hourly
*                                                                     ev_freq    = lv_frequency ).
*
*  ELSEIF mv_sal_ann_increase IS NOT INITIAL.
*    lv_frequency = cl_hrsfi_comp_constants=>cv_payroll_frequency_annual.
*    lv_increase  = mv_sal_ann_increase.
*    lv_hourly    = abap_false.
*
*  ELSEIF mv_sal_ann100_increase IS NOT INITIAL.
*
*    lv_frequency = cl_hrsfi_comp_constants=>cv_payroll_frequency_annual.
*    lv_hourly    = abap_false.
*    lv_increase  = mv_sal_ann100_increase.
*
*    " Exported 100% Salary is calculated with BSGRD
*    " Reduce here via the same method
*    CALL FUNCTION 'HR_REDUCE_SALARY'
*      EXPORTING
*        red_meth = '2'
*        bsgrd    = <p0008>-bsgrd
*      CHANGING
*        amount   = lv_increase
*      EXCEPTIONS
*        OTHERS   = 0.
*  ENDIF.

  " Now LV_INCREASE  contains the total salary increase
  "     LV_FREQUENCY contains the payroll frequency of the increase
  "     LV_HOURLY    contains the hourly flag
  " Loop over the infotype 8 records and update

  loop at mt_0008 assigning <p0008>.
    if  lv_expected_begda is not initial
    and <p0008>-begda     gt lv_expected_begda.
      " There is a gap in the IT8 records; processing is stopped
      exit.
    else.

      move-corresponding <p0008> to ls_p0008_new.
      move mv_effective_date to ls_p0008_new-begda.

*      get_changed_it_record( EXPORTING iv_increase  = lv_increase
*                                       iv_frequency = lv_frequency
*                                       iv_hourly    = lv_hourly
*                                       is_p0008     = <p0008>
*                                       is_p0001     = <p0001>
*                             IMPORTING es_p0008_new = ls_p0008_new
*                                       ev_error     = ev_error
*                                       es_message   = ls_message ).
      if ls_message is not initial.
        append ls_message to et_messages.
      endif.
      if ev_error eq abap_true.

        exit.
      endif.

      ls_p0008_new-ansal  mv_sal_ann_increase.
      cl_hrsfi_comp_utilities=>infotype_insertexporting is_pnnnn    ls_p0008_new
                                                importing ev_error    ev_error
                                                          et_messages lt_messages ).
      if ev_error eq abap_true.
        " 120  An error occurred when writing infotype Basic Pay (0008)
        clear ls_message.
        ls_message-type     if_hrsfi_empl_data_c=>gc_exception_type_e.
        ls_message-id       cl_hrsfi_comp_constants=>cv_comp_message_class.
        ls_message-number   120.
        message e120(hrsfi_comp_datainto ls_message-message.
        append ls_message to et_messages.

        exit.
      endif.
*     Un-comment this line to include infotype messages in the compensation monitor:
*     APPEND LINES OF lt_messages TO et_messages.
      lv_expected_begda <p0008>-endda + 1.
    endif.
  endloop.

endmethod.


****************************************************************************

METHOD IF_HRSFI_COMP_DATA_ACTIVATION~CALL_FIELD_F4.

  DATA:
    lv_value   TYPE help_info-fldvalue,
    lt_fields  TYPE STANDARD TABLE OF dfies.

  DATA:
      lv_repid       TYPE syrepid,
      lv_dynnr       TYPE sydynnr,
      lv_stepl       TYPE systepl,
      lv_retfield    TYPE dfies-fieldname,
      lv_dynprofield TYPE help_info-dynprofld.

  DATA:
    lt_reasons      TYPE STANDARD TABLE OF t530f,
    lt_wagetypes    TYPE STANDARD TABLE OF h_t512z,
    lt_wagetype_tab TYPE SORTED TABLE OF h_t512z
                    WITH UNIQUE KEY molga lgart.

  DATA:
    lt_excluded_wagetypes TYPE STANDARD TABLE OF t511,
    lv_dummy_modna        TYPE t511-modna.

  FIELD-SYMBOLS:
    <wtype>     TYPE t511,
    <lt_values> TYPE STANDARD TABLE.

  lv_value iv_field_content.
  lv_repid sy-cprog.
  lv_dynnr sy-dynnr.

  CALL FUNCTION 'DYNP_GET_STEPL'
    IMPORTING
      povstepl lv_stepl
    EXCEPTIONS
      OTHERS   0.

  CASE iv_field_id.
    WHEN 'REASON'.
      lv_retfield    'PREAS'.
      lv_dynprofield 'LS_FIELD_INPUT-FIELD_CONTENT'.
      ASSIGN lt_reasons TO <lt_values>.

      " Get PREAS for Infotype 0008 with text
      SELECT l~preas AS preas r~rtext AS rtext
        INTO CORRESPONDING FIELDS OF TABLE lt_reasons
        FROM t530e AS l
        LEFT OUTER JOIN t530f AS r                     "#EC CI_BUFFJOIN
        ON  l~infty r~infty
        AND l~preas r~preas
        AND r~sprsl sy-langu
        WHERE l~infty EQ '0008'.

      " Get field information for help popup
      CALL FUNCTION 'DDIF_FIELDINFO_GET'
        EXPORTING
          tabname   'T530F'
        TABLES
          dfies_tab lt_fields
        EXCEPTIONS
          OTHERS    0.
      DELETE lt_fields WHERE fieldname NE 'PREAS'
                           AND fieldname NE 'RTEXT' ).

    WHEN 'WAGETYPE'.
      lv_retfield    'LGART'.
      lv_dynprofield 'LS_FIELD_INPUT-FIELD_CONTENT'.
      ASSIGN lt_wagetypes TO <lt_values>.

      " Get wagetypes allowed in infotype 0008
      SELECT l~molga AS molga                   "#EC CI_BUFFJOIN
             l~lgart AS lgart
             l~begda AS begda
             l~endda AS endda
             r~lgtxt AS lgtxt
         INTO CORRESPONDING FIELDS OF TABLE lt_wagetype_tab
         FROM t512z AS l
         LEFT OUTER JOIN t512t AS r
           ON  l~molga r~molga
           AND l~lgart r~lgart
           AND r~sprsl sy-langu
         WHERE l~infty '0008'
           AND l~endda GE sy-datum
           AND l~begda LE sy-datum.

      SELECT FROM t511    "#EC CI_GENBUFF
         INTO CORRESPONDING FIELDS OF TABLE lt_excluded_wagetypes
         WHERE endda GE sy-datum
           AND begda LE sy-datum
           AND mod02 EQ 'F'
           AND modna NE lv_dummy_modna.
      LOOP AT lt_excluded_wagetypes ASSIGNING <wtype>.
        DELETE lt_wagetype_tab WHERE molga EQ <wtype>-molga
                                 AND lgart EQ <wtype>-lgart.
      ENDLOOP.
      lt_wagetypes lt_wagetype_tab.

      " Get field information for help popup
      CALL FUNCTION 'DDIF_FIELDINFO_GET'
        EXPORTING
          tabname   'H_T512Z'
        TABLES
          dfies_tab lt_fields
        EXCEPTIONS
          OTHERS    0.

      DELETE lt_fields WHERE fieldname NE 'MOLGA'
                           AND fieldname NE 'LGART'
                           AND fieldname NE 'LGTXT'
                           AND fieldname NE 'BEGDA'
                           AND fieldname NE 'ENDDA' ).

    WHEN OTHERS.
      " Do nothing; no f4 provided
      RETURN.
  ENDCASE.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        lv_retfield
      dynpprog        lv_repid
      dynpnr          lv_dynnr
      dynprofield     lv_dynprofield
      stepl           lv_stepl
      value           lv_value
      value_org       'S'
    TABLES
      value_tab       <lt_values>
      field_tab       lt_fields
    EXCEPTIONS
      parameter_error 1
      no_values_found 2
      OTHERS          3.

  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDMETHOD.


****************************************************************************

METHOD IF_HRSFI_COMP_DATA_ACTIVATION~GET_FIELD_LIST.

  DATA:
    ls_field_list TYPE hrsfi_s_comp_badi_fields.

  CLEAR et_field_list.

  ls_field_list-int_field        'EFFECTIVE_DATE'.
  ls_field_list-required         cl_hrsfi_comp_constants=>cv_required_yes.
  ls_field_list-data_element     'SYDATUM'.
  ls_field_list-field_text       text-f01.
  ls_field_list-badi_provides_f4 abap_false.
  APPEND ls_field_list TO et_field_list.

  ls_field_list-int_field        'CURRENCY'.
  ls_field_list-required         cl_hrsfi_comp_constants=>cv_required_yes.
  ls_field_list-data_element     'WAERS'.
  ls_field_list-field_text       text-f02.
  ls_field_list-badi_provides_f4 abap_false.
  APPEND ls_field_list TO et_field_list.

  ls_field_list-int_field        'REASON'.
  ls_field_list-required         cl_hrsfi_comp_constants=>cv_required_no.
  ls_field_list-data_element     'PREAS'.
  ls_field_list-field_text       text-f03.
  ls_field_list-badi_provides_f4 abap_true.
  APPEND ls_field_list TO et_field_list.

  " Empty wagetype => Activate into first available
  ls_field_list-int_field        'WAGETYPE'.
  ls_field_list-required         cl_hrsfi_comp_constants=>cv_required_no.
  ls_field_list-data_element     'LGART'.
  ls_field_list-field_text       text-f04.
  ls_field_list-badi_provides_f4 abap_true.
  APPEND ls_field_list TO et_field_list.

  " Three salary increase fields => At least one must be selected
  ls_field_list-int_field        'SALARY_INCREASE'.
  ls_field_list-required         cl_hrsfi_comp_constants=>cv_required_no.
  ls_field_list-data_element     'ANSAL'.
  ls_field_list-field_text       text-f05.
  ls_field_list-badi_provides_f4 abap_false.
  APPEND ls_field_list TO et_field_list.

  ls_field_list-int_field        'ANNUAL_SALARY_INCREASE'.
  ls_field_list-required         cl_hrsfi_comp_constants=>cv_required_no.
  ls_field_list-data_element     'ANSAL'.
  ls_field_list-field_text       text-f06.
  ls_field_list-badi_provides_f4 abap_false.
  APPEND ls_field_list TO et_field_list.

  ls_field_list-int_field        'ANNUAL_100PCT_SALARY_INCREASE'.
  ls_field_list-required         cl_hrsfi_comp_constants=>cv_required_no.
  ls_field_list-data_element     'ANSAL'.
  ls_field_list-field_text       text-f07.
  ls_field_list-badi_provides_f4 abap_false.
  APPEND ls_field_list TO et_field_list.

ENDMETHOD.


*********************************************************************************

method if_hrsfi_comp_data_activation~set_activation_fields.

  data:
    ls_message             type bapiret2,
    lv_dummy_message       type string,                     "#EC NEEDED
    lv_sal_increase        type string,
    lv_sal_ann_increase    type string,
    lv_sal_ann100_increase type string.

*Begin of change 1 - 25.04.2016
  datalv_app                  type string,
        lv_basic_salary         type string,
        lv_car_lease            type string,
        lv_employer_pf          type string,
        lv_hra                  type string,
        lv_ipp                  type string,
        lv_medical              type string,
        lv_opp                  type string,
        lv_special_allowance    type string,
        lv_statutory_bonus      type string,
        lv_transport_allowance  type string,
        lv_upp                  type string,
*End of change 1 - 25.04.2016
        lv_nightshift_allowance type string,
        lv_language_allowance   type string,
        lv_onsite_allowance     type string,
        lv_vpp           type string.
*End of change 1 - 06.04.2017
  field-symbols:
    <activation_field> type hrsfi_s_comp_mapped_fields.

  clear et_messages.
  ev_error         abap_false.
  mv_pernr         iv_pernr.
  mv_field_mapping iv_field_mapping.

  clear:
    mv_currency,
    mv_effective_date,
    mv_molga,
    mv_reason,
    mv_sal_ann100_increase,
    mv_sal_ann_increase,
    mv_sal_increase,
    mv_wagetype,
    mt_0001,
    mt_0008.

  try.
      loop at it_activation_fields assigning <activation_field>.
        case <activation_field>-field_id.
          when 'EFFECTIVE_DATE'.
            move <activation_field>-field_content to mv_effective_date.
          when 'REASON'.
            move <activation_field>-field_content to mv_reason.
          when 'CURRENCY'.
            move <activation_field>-field_content to mv_currency.
            if mv_currency is initial.
              " 116  No currency was specified; activation not possible
              message e116(hrsfi_comp_datainto lv_dummy_message.
              ls_message-type       if_hrsfi_empl_data_c=>gc_exception_type_e.
              ls_message-id         'HRSFI_COMP_DATA'.
              ls_message-number     116.
              append ls_message to et_messages.
              ev_error abap_true.
              return.
            endif.
          when 'WAGETYPE'.
            move <activation_field>-field_content to mv_wagetype.
          when 'SALARY_INCREASE'.
            move <activation_field>-field_content to lv_sal_increase.
          when 'ANNUAL_SALARY_INCREASE'.
            move <activation_field>-field_content to lv_sal_ann_increase.
          when 'ANNUAL_100PCT_SALARY_INCREASE'.
            move <activation_field>-field_content to lv_sal_ann100_increase.
*Begin of change 2 - 25.04.2016
          when 'APP'.
            move <activation_field>-field_content to lv_app.
          when 'BASIC_SALARY'.
            move <activation_field>-field_content to lv_basic_salary.
          when 'CAR_LEASE'.
            move <activation_field>-field_content to lv_car_lease.
          when 'EMPLOYER_PF'.
            move <activation_field>-field_content to lv_employer_pf.
          when 'HRA'.
            move <activation_field>-field_content to lv_hra.
          when 'IPP'.
            move <activation_field>-field_content to lv_ipp.
          when 'MEDICAL'.
            move <activation_field>-field_content to lv_medical.
          when 'OPP'.
            move <activation_field>-field_content to lv_opp.
          when 'SPECIAL_ALLOWANCE'.
            move <activation_field>-field_content to lv_special_allowance.
          when 'STATUTORY_BONUS'.
            move <activation_field>-field_content to lv_statutory_bonus.
          when 'TRANSPORT_ALLOWANCE'.
            move <activation_field>-field_content to lv_transport_allowance.
          when 'UPP'.
            move <activation_field>-field_content to lv_upp.
*End of change 2 - 25.04.2016
          when 'NIGHTSHIFT_ALLOWANCE'.
            move <activation_field>-field_content to lv_nightshift_allowance.
          when 'LANGUAGE_ALLOWANCE'.
            move <activation_field>-field_content to lv_language_allowance.
          when 'ONSITE_ALLOWANCE'.
            move <activation_field>-field_content to lv_onsite_allowance.
          when 'VPP'.
            move <activation_field>-field_content to lv_vpp.
*End of change 1 - 06.04.2017
          when others.
        endcase.

      endloop.

**      IF lv_sal_increase IS NOT INITIAL.
*      CALL FUNCTION 'HRSFI_CONVERT_STRING_WITH_CURR'
*        EXPORTING
*          iv_input_string  = lv_sal_increase
*          iv_currency      = mv_currency
*        IMPORTING
*          ev_packed_field  = mv_sal_increase
*        EXCEPTIONS
*          conversion_error = 1
*          OTHERS           = 2.

*      ELSEIF lv_sal_ann_increase IS NOT INITIAL.
      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_sal_ann_increase
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_sal_ann_increase
        exceptions
          conversion_error 1
          others           2.

*      ELSEIF lv_sal_ann100_increase IS NOT INITIAL.
      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_sal_ann100_increase
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_sal_ann100_increase
        exceptions
          conversion_error 1
          others           2.

*Begin of change 3 - 25.04.2016
      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_app
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_app
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_basic_salary
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_basic_salary
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_car_lease
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_car_lease
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_employer_pf
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_employer_pf
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_hra
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_hra
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_ipp
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_ipp
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_medical
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_medical
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_opp
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_opp
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_special_allowance
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_special_allowance
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_statutory_bonus
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_statutory_bonus
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_transport_allowance
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_transport_allowance
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_upp
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_upp
        exceptions
          conversion_error 1
          others           2.
*End of change 3 - 25.04.2016
      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_nightshift_allowance
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_nightshift_allowance
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_language_allowance
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_language_allowance
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_onsite_allowance
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_onsite_allowance
        exceptions
          conversion_error 1
          others           2.

      call function 'HRSFI_CONVERT_STRING_WITH_CURR'
        exporting
          iv_input_string  lv_vpp
          iv_currency      mv_currency
        importing
          ev_packed_field  mv_vpp
        exceptions
          conversion_error 1
          others           2.
*End of change 1 - 06.04.2017
      if sy-subrc ne 0.
        ev_error abap_true.
        ls_message-type       sy-msgty.
        ls_message-id         sy-msgid.
        ls_message-number     sy-msgno.
        ls_message-message_v1 sy-msgv1.
        ls_message-message_v2 sy-msgv2.
        ls_message-message_v3 sy-msgv3.
        ls_message-message_v4 sy-msgv4.
        append ls_message to et_messages.
      endif.

    catch cx_sy_conversion_no_number
          cx_sy_conversion_overflow
          cx_sy_move_cast_error.
      " 106  Field &1 could not be read for mapping &2
      ev_error abap_true.
      message e106(hrsfi_comp_datawith <activation_field>-field_id mv_field_mapping
                                    into lv_dummy_message.
      ls_message-type       if_hrsfi_empl_data_c=>gc_exception_type_e.
      ls_message-id         'HRSFI_COMP_DATA'.
      ls_message-number     106.
      ls_message-message_v1 <activation_field>-field_id.
      ls_message-message_v2 mv_field_mapping.
      append ls_message to et_messages.
      return.
  endtry.

endmethod.



*******************************************************************************

METHOD GET_CHANGED_IT_RECORD.
  "
  " This is copied from HR_ECM_CALC_SAL_ADJUSTMENT
  "
  DATA:
    ls_p0008_new    TYPE p0008,
    lv_increase_tmp TYPE ansal,
    lv_increase     TYPE ansal,
    lv_hourly       TYPE abap_bool,
    lv_freq         TYPE t549r-zeinh,
    lv_convdate     TYPE sydatum.

  ev_error abap_false.
  CLEAR es_message.

  ls_p0008_new is_p0008.

  IF mv_effective_date LT ls_p0008_new-begda.
    " IT 8 record is after change:  update data but not dates
  ELSEIF mv_effective_date LE ls_p0008_new-endda.
    " IT 8 record is valid on change date:  delimit
    ls_p0008_new-begda mv_effective_date.
  ELSE.
    " IT 8 record is before change:  This should never occur
    ev_error abap_true.
    RETURN.
  ENDIF.

  ls_p0008_new-preas mv_reason.
  CLEAR ls_p0008_new-ansal.

  " Dates of next increase
  IF mv_effective_date > ls_p0008_new-stvor.
    CLEAR ls_p0008_new-stvor.
  ENDIF.
  IF mv_effective_date > ls_p0008_new-vglsv.
    CLEAR ls_p0008_new-vglsv.
  ENDIF.

  IF ls_p0008_new-waers NE mv_currency.
    " Convert currency if required
    " Normally this should not occur
    lv_convdate get_conversion_date).

    CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
      EXPORTING
        date             lv_convdate
        foreign_amount   iv_increase
        foreign_currency mv_currency
        local_currency   ls_p0008_new-waers
        type_of_rate     cv_rate_type
      IMPORTING
        local_amount     lv_increase_tmp
      EXCEPTIONS
        no_rate_found    1
        overflow         2
        no_factors_found 3
        no_spread_found  4
        OTHERS           5.
    IF sy-subrc NE 0.
      es_message-type       sy-msgty.
      es_message-id         sy-msgid.
      es_message-number     sy-msgno.
      es_message-message_v1 sy-msgv1.
      es_message-message_v2 sy-msgv2.
      es_message-message_v3 sy-msgv3.
      es_message-message_v4 sy-msgv4.
      ev_error abap_true.
      RETURN.
    ENDIF.
  ELSE.
    lv_increase_tmp iv_increase.
  ENDIF.

  " Convert to basic pay frequency if required
  cl_hrsfi_comp_utilities_salary=>get_payroll_frequencyEXPORTING iv_keydate ls_p0008_new-begda
                                                                   iv_persg   is_p0001-persg
                                                                   iv_persk   is_p0001-persk
                                                                   iv_trfar   ls_p0008_new-trfar
                                                                   iv_trfgb   ls_p0008_new-trfgb
                                                                   iv_molga   mv_molga
                                                         IMPORTING ev_hourly  lv_hourly
                                                                   ev_freq    lv_freq ).

  CALL FUNCTION 'RP_FROM_PERIOD_TO_PERIOD'
    EXPORTING
      frequ_in          iv_frequency
      hourly_in         iv_hourly
      frequ_out         lv_freq
      hourly_out        lv_hourly
      molga             mv_molga
      divgv             ls_p0008_new-divgv
      amount_in         lv_increase_tmp
      pernr             mv_pernr
      date              ls_p0008_new-begda
    IMPORTING
      amount_out        lv_increase
    EXCEPTIONS
      illegal_frequency 1
      amount_too_big    2
      feature_error     3
      OTHERS            4.

  IF sy-subrc NE 0.
    es_message-type       sy-msgty.
    es_message-id         sy-msgid.
    es_message-number     sy-msgno.
    es_message-message_v1 sy-msgv1.
    es_message-message_v2 sy-msgv2.
    es_message-message_v3 sy-msgv3.
    es_message-message_v4 sy-msgv4.
    ev_error abap_true.
    RETURN.
  ENDIF.

  DATA:
    lv_n_wagetypes TYPE i,
    BEGIN OF ls_str_p0008,
      lgart TYPE p0008-lga01,
      betrg TYPE p0008-bet01,
      anzhl TYPE p0008-anz01,
      zeinh TYPE p0008-ein01,
      opken TYPE p0008-opk01,
    END OF ls_str_p0008,
    BEGIN OF ls_str_indbw,
      indbw TYPE p0008-ind01,
    END OF ls_str_indbw,
    ls_t511 TYPE t511.


  " Update or add specified wage type
  CALL FUNCTION 'RP_NUMBER_OF_WAGETYPES_0008'
    IMPORTING
      wt_count lv_n_wagetypes.

  DO lv_n_wagetypes TIMES
     VARYING ls_str_p0008-lgart FROM ls_p0008_new-lga01
                                NEXT ls_p0008_new-lga02
     VARYING ls_str_p0008-betrg FROM ls_p0008_new-bet01
                                NEXT ls_p0008_new-bet02
     VARYING ls_str_p0008-anzhl FROM ls_p0008_new-anz01
                                NEXT ls_p0008_new-anz02
     VARYING ls_str_p0008-zeinh FROM ls_p0008_new-ein01
                                NEXT ls_p0008_new-ein02
     VARYING ls_str_p0008-opken FROM ls_p0008_new-opk01
                                NEXT ls_p0008_new-opk02
     VARYING ls_str_indbw-indbw FROM ls_p0008_new-ind01
                                NEXT ls_p0008_new-ind02.

    IF ls_str_p0008-lgart EQ mv_wagetype   " Current wagetype is increase wagetype
    OR ls_str_p0008-lgart IS INITIAL       " Increase wagetype was not found
    OR mv_wagetype        IS INITIAL.      " Increase first wagetype

      IF ls_str_p0008-lgart IS INITIAL.
        ls_str_p0008-lgart mv_wagetype.
      ENDIF.

      " check that wage type can be overwritten
      IF ls_t511-molga NE mv_molga
      OR ls_t511-lgart NE ls_str_p0008-lgart
      OR ls_t511-begda GT ls_p0008_new-begda
      OR ls_t511-endda LT ls_p0008_new-begda.
        SELECT FROM t511 UP TO ROWS INTO ls_t511
          WHERE
            molga  mv_molga AND
            lgart  ls_str_p0008-lgart AND
            endda >= ls_p0008_new-begda AND
            begda <= ls_p0008_new-begda.
        ENDSELECT.
        IF sy-subrc NE 0.
          " Wage type definition is missing
          " 120  An error occurred when writing infotype Basic Pay (0008)
          es_message-type       if_hrsfi_empl_data_c=>gc_exception_type_e.
          es_message-id         cl_hrsfi_comp_constants=>cv_comp_message_class.
          es_message-number     121.
          MESSAGE e120(hrsfi_comp_dataINTO es_message-message.

          ev_error abap_true.
          EXIT.
        ENDIF.
      ENDIF.

      IF  ls_t511-mod02 EQ 'F'
      AND ls_t511-modna IS NOT INITIAL.
        " Wage type cannot be changed
        " 120  An error occurred when writing infotype Basic Pay (0008)
        es_message-type       if_hrsfi_empl_data_c=>gc_exception_type_e.
        es_message-id         cl_hrsfi_comp_constants=>cv_comp_message_class.
        es_message-number     121.
        MESSAGE e120(hrsfi_comp_dataINTO es_message-message.

        ev_error abap_true.
        EXIT.
      ENDIF.

      IF ls_str_indbw-indbw IS NOT INITIAL.
        get_indirect_wagetypesEXPORTING  is_p0008    ls_p0008_new
                                           is_p0001    is_p0001
                                           iv_wagetype ls_str_p0008-lgart
                                IMPORTING  ev_amount   ls_str_p0008-betrg
                                           ev_error    ev_error
                                           es_message  es_message ).
        IF ev_error EQ abap_true.
          EXIT.
        ENDIF.
      ENDIF.

      ls_str_p0008-betrg ls_str_p0008-betrg + lv_increase.
      CLEAR ls_str_p0008-anzhl.
      CLEAR ls_str_p0008-zeinh.
      CLEAR ls_str_indbw.
*     Leave OPKEN unchanged
      EXIT.
    ENDIF.
  ENDDO.
  IF ev_error EQ abap_false.
    es_p0008_new ls_p0008_new.
  ENDIF.


ENDMETHOD.


*******************************************************************


METHOD GET_CONVERSION_DATE.

  re_conversion_date sy-datum.

ENDMETHOD.



********************************************************************


METHOD GET_INDIRECT_WAGETYPES.

  DATA lt_p0001               TYPE p0001_tab.
  DATA lt_p0008               TYPE p0008_tab.
  DATA lt_evaluated_wagetypes TYPE TABLE OF pbwla.
  DATA ls_evaluated_wagetype  TYPE pbwla.
  DATA lv_convdate            TYPE sydatum.

  ev_error abap_false.

  APPEND is_p0008 TO lt_p0008.
  APPEND is_p0001 TO lt_p0001.

  CALL FUNCTION 'RP_FILL_WAGE_TYPE_TABLE'
    EXPORTING
      begda                              is_p0008-begda
      endda                              is_p0008-begda
      infty                              '0008'
      pernr                              mv_pernr
*     CONV_CURR                          = 'X'
    TABLES
      ppbwla                             lt_evaluated_wagetypes
      pp0001                             lt_p0001
      pp0008                             lt_p0008
    EXCEPTIONS
      error_at_indirect_evaluation       1
      OTHERS                             2.
  IF sy-subrc <> 0.

    es_message-type       sy-msgty.
    es_message-id         sy-msgid.
    es_message-number     sy-msgno.
    es_message-message_v1 sy-msgv1.
    es_message-message_v2 sy-msgv2.
    es_message-message_v3 sy-msgv3.
    es_message-message_v4 sy-msgv4.

    ev_error abap_true.
    EXIT.
  ENDIF.

  READ TABLE lt_evaluated_wagetypes INTO ls_evaluated_wagetype
         WITH KEY lgart iv_wagetype.

  IF sy-subrc <> 0.
    " This should not occur
    ev_error abap_true.
    EXIT.
  ENDIF.

  IF ls_evaluated_wagetype-waers <> is_p0008-waers.

    lv_convdate get_conversion_date).

    CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
      EXPORTING
        date             lv_convdate
        foreign_amount   ls_evaluated_wagetype-betrg
        foreign_currency ls_evaluated_wagetype-waers
        local_currency   is_p0008-waers
        type_of_rate     cv_rate_type
      IMPORTING
        local_amount     ev_amount
      EXCEPTIONS
        no_rate_found    1
        overflow         2
        no_factors_found 3
        no_spread_found  4
        OTHERS           5.
    IF sy-subrc NE 0.
      es_message-type       sy-msgty.
      es_message-id         sy-msgid.
      es_message-number     sy-msgno.
      es_message-message_v1 sy-msgv1.
      es_message-message_v2 sy-msgv2.
      es_message-message_v3 sy-msgv3.
      es_message-message_v4 sy-msgv4.
      ev_error abap_true.
      RETURN.
    ENDIF.
  ELSE.
    ev_amount ls_evaluated_wagetype-betrg.
  ENDIF.

ENDMETHOD.


********************************************************

No comments:

Post a Comment