[SAP ABAP] - Custome Create HR Payment (Infotype 15)


*&---------------------------------------------------------------------*
*& Report  YO_CC_TEST01
*&
*&---------------------------------------------------------------------*
*& Module : HR
*&
*&---------------------------------------------------------------------*

REPORT  yo_cc_test01.

PARAMETERS p_pernr LIKE pa0000-pernr DEFAULT '20130002',
             p_begda LIKE pa0000-begda DEFAULT '20130430',
             p_subty LIKE pa0015-subty DEFAULT '9522',
             p_amt   LIKE pa0015-betrg DEFAULT '100000'.
*             p_endda LIKE pa0000-endda DEFAULT '20130430'.

START-OF-SELECTION.
  DATA lv_message_v1 LIKE sy-lisel.

  MESSAGE lv_message_v1 TYPE 'I'.

  PERFORM fm_upload_add_payment USING p_pernr p_begda p_subty p_amt
                              CHANGING lv_message_v1.

*&---------------------------------------------------------------------*
*&      Form  fm_upload_add_payment
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FU_PERNR   text
*      -->FU_DATE    text
*      -->FU_SUBTY   text
*      -->FU_AMOUNT  text
*      -->FC_MESSAGE text
*----------------------------------------------------------------------*
FORM fm_upload_add_payment USING fu_pernr fu_date fu_subty fu_amount
                        CHANGING fc_message.
*--------------------------------------------------------------------*
* Operation
*--------------------------------------------------------------------*
*  COP = Copy
*  DEL = Delete
*  DIS = Display
*  EDQ = Lock/unlock
*  INS = Create
*  LIS9 = Delimit
*  MOD = Change
*  INSS = Create for Actions is not converted to Change
*--------------------------------------------------------------------*

  DATA lw_data LIKE p0015,
         lw_p0015 LIKE p0015,
         lw_return LIKE bapireturn1.

  DATA li_p0015 LIKE STANDARD TABLE OF p0015 WITH HEADER LINE.

  DATA lv_date1 LIKE sy-datum,
         lv_date2 LIKE sy-datum.

  "Data PA0015
  lw_data-pernr fu_pernr.
  lw_data-begda fu_date.
  lw_data-endda fu_date.
  lw_data-lgart fu_subty.
  lw_data-betrg fu_amount.
  lw_data-waers 'IDR'.


  "Check Data didalam bulan yg sama
  CALL FUNCTION 'OIL_MONTH_GET_FIRST_LAST'
    EXPORTING
      i_date      lw_data-begda
    IMPORTING
      e_first_day lv_date1
      e_last_day  lv_date2.

  SELECT INTO CORRESPONDING FIELDS OF TABLE li_p0015
  FROM pa0015
  WHERE pernr lw_data-pernr AND
        begda BETWEEN lv_date1 AND lv_date2.



  "Mulai Mengupload Data
  CALL FUNCTION 'ENQUEUE_EPPRELE'
    EXPORTING
      mode_prel      'E'
      mandt          sy-mandt
      pernr          lw_data-pernr
      infty          '0015'
      subty          lw_data-lgart
      endda          lw_data-endda
      begda          lw_data-begda
      _scope         '1'
    EXCEPTIONS
      foreign_lock   1
      system_failure 2
      OTHERS         3.
  IF sy-subrc NE .
*    MESSAGE 'User is locked.' TYPE 'I'.
*    EXIT.
  ENDIF.

  IF LINESli_p0015 0.
    "Harus didelete dulu datanya.
    LOOP AT li_p0015 INTO lw_p0015.
      CALL FUNCTION 'HR_INFOTYPE_OPERATION'
        EXPORTING
          infty         '0015'
          number        lw_p0015-pernr
          subtype       lw_p0015-lgart
          validityend   lw_p0015-endda
          validitybegin lw_p0015-begda
          record        lw_p0015
          operation     'DEL'
          tclas         'A'
          nocommit      space
        IMPORTING
          return        lw_return.


    ENDLOOP.

  ENDIF.

  CALL FUNCTION 'HR_INFOTYPE_OPERATION'
    EXPORTING
      infty         '0015'
      number        lw_data-pernr
      subtype       lw_data-lgart
      validityend   lw_data-endda
      validitybegin lw_data-begda
      record        lw_data
      operation     'INS'
      tclas         'A'
      nocommit      space
    IMPORTING
      return        lw_return.

  CALL FUNCTION 'RPY_MESSAGE_COMPOSE'
  EXPORTING
    language                sy-langu
    message_id              lw_return-id
    message_number          lw_return-number
    message_var1            lw_return-message_v1
    message_var2            lw_return-message_v2
    message_var3            lw_return-message_v3
    message_var4            lw_return-message_v4
  IMPORTING
    message_text            fc_message
*      TABLES
*        LONGTEXT                =
  EXCEPTIONS
    message_not_found       1
    OTHERS                  2.

  CALL FUNCTION 'DEQUEUE_EPPRELE'
    EXPORTING
      mode_prel 'E'
      mandt     sy-mandt
      pernr     lw_data-pernr
      infty     '0015'
      subty     lw_data-lgart
      endda     lw_data-endda
      begda     lw_data-begda.

ENDFORM.                    "

Comments