BAdI HRBAS00INFTY for Tcode Org. Management

Requirement:
Saat update infotype 1005 (Planned Compensation), secara background juga akan mengupdate infotype 1050 (Job Evaluation).

Solution:
Implement BAdI HRBAS00INFTY dan tambahkan coding di methode IN_UPDATE.
Saat insert data, gunakan FM ‘RH_INSERT_INFTY’. Bila modify data, gunakan FM ‘RH_UPDATE_INFTY’. Sedangkan untuk hapus data gunakan FM ‘RH_DELETE_INFTY’.

METHOD if_ex_hrbas00infty~in_update.
  CONSTANTS: c_infty_1005 TYPE infotyp VALUE '1005',
             c_plvar_act TYPE plvar VALUE '01',
             c_otype_pos TYPE otype VALUE 'S',
             c_delete TYPE hropera VALUE 'D',
             c_insert TYPE hropera VALUE 'I',
             c_update TYPE hropera VALUE 'U'.

  DATA: ld_opera      TYPE hropera,
        wa_new_image  TYPE wplog,
        wa_p1050      TYPE p1050,
        wa_hrp1050_old TYPE hrp1050,
        ld_lines      TYPE sy-index.

  DATA: lt_p1050 TYPE TABLE OF p1050.

  FIELD-SYMBOLS: < fs_hrdbtab >     TYPE hrdbtab,
                 < fs_old >         TYPE bef_image,
                 < fs_new >         TYPE aft_image,
                 < fs_1005 >        TYPE hri1005.

  IF sy-tcode = 'PP01' or sy-tcode = 'PP02' or sy-tcode = 'PP03' or
     sy-tcode = 'PP13'.

    UNASSIGN: < fs_hrdbtab >.
    DESCRIBE TABLE plog_tab LINES ld_lines.
    CHECK ld_lines > 0.

    READ TABLE plog_tab INDEX ld_lines ASSIGNING < fs_hrdbtab >.
    CHECK < fs_hrdbtab > IS ASSIGNED.

    CLEAR: ld_opera.
    IF < fs_hrdbtab >-plvar = c_plvar_act AND
       < fs_hrdbtab >-otype = c_otype_pos AND
       < fs_hrdbtab >-infty = c_infty_1005.
      IF new_image IS NOT INITIAL AND old_image IS INITIAL.
*   INSERT
        ld_opera = 'I'.
        LOOP AT new_image ASSIGNING < fs_new >.
          ASSIGN < fs_new >-vdata TO < fs_new > CASTING.
          IF < fs_1005 > IS ASSIGNED.
            MOVE-CORRESPONDING < fs_new > TO wa_p1050.
            wa_p1050-infty = '1050'.
            wa_p1050-subty = 'PRL'.
            wa_p1050-evpts = < fs_1005 >-trfs1.
            APPEND wa_p1050 TO lt_p1050.
          ENDIF.
        ENDLOOP.
      ELSEIF new_image IS INITIAL AND old_image IS NOT INITIAL.
*   DELETE
        ld_opera = 'D'.
        LOOP AT old_image ASSIGNING < fs_old >.
          ASSIGN < fs_old >-vdata TO  CASTING.
          IF < fs_1005 > IS ASSIGNED.
            MOVE-CORRESPONDING < fs_old > TO wa_p1050.
            wa_p1050-infty = '1050'.
            wa_p1050-subty = 'PRL'.
            wa_p1050-evpts = < fs_1005 >-trfs1.
            APPEND wa_p1050 TO lt_p1050.
          ENDIF.
        ENDLOOP.
      ELSEIF new_image IS NOT INITIAL AND old_image IS NOT INITIAL.
        IF new_image  old_image.
*   UPDATE
          ld_opera = 'U'.
          LOOP AT new_image ASSIGNING .
            ASSIGN < fs_new >-vdata TO  CASTING.
            IF < fs_1005 > IS ASSIGNED.
              MOVE-CORRESPONDING < fs_new > TO wa_p1050.
              wa_p1050-infty = '1050'.
              wa_p1050-subty = 'PRL'.
              wa_p1050-evpts = < fs_1005 >-trfs1.
              APPEND wa_p1050 TO lt_p1050.
            ENDIF.
          ENDLOOP.
        ENDIF.
      ENDIF.

      IF ld_opera = c_insert.
        SELECT SINGLE * FROM hrp1050 INTO wa_hrp1050_old
          WHERE plvar = '01'
            AND otype = wa_p1050-otype
            AND objid = wa_p1050-objid
            AND subty = wa_p1050-subty
            AND istat = wa_p1050-istat.
        IF sy-subrc = 0.
          ld_opera = c_update.
        ENDIF.
      ENDIF.

* UPDATE DATA KE HRP1050
      IF ld_opera IS NOT INITIAL.
        CASE ld_opera.
          WHEN c_insert.
            CALL FUNCTION 'RH_INSERT_INFTY'
              EXPORTING
                vtask               = 'D'
              TABLES
                innnn               = lt_p1050
              EXCEPTIONS
                no_authorization    = 1
                error_during_insert = 2
                repid_form_initial  = 3
                corr_exit           = 4
                begda_greater_endda = 5
                OTHERS              = 6.
            IF sy-subrc  0.
            ENDIF.
          WHEN c_update.
            CALL FUNCTION 'RH_UPDATE_INFTY'
              EXPORTING
                vtask               = 'D'
              TABLES
                innnn               = lt_p1050
              EXCEPTIONS
                error_during_update = 1
                no_authorization    = 2
                repid_form_initial  = 3
                corr_exit           = 4
                OTHERS              = 5.
            IF sy-subrc  0.
            ENDIF.
          WHEN c_delete.
            CALL FUNCTION 'RH_DELETE_INFTY'
              EXPORTING
                vtask               = 'D'
              TABLES
                innnn               = lt_p1050
              EXCEPTIONS
                error_during_delete = 1
                no_authorization    = 2
                delete_first_record = 3
                corr_exit           = 4
                OTHERS              = 5.
        ENDCASE.
      ENDIF.
    ENDIF.
  ENDIF.
*-----------------------------------------------------------------------
ENDMETHOD.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s