This website is not affiliated with, sponsored by, or approved by SAP AG.

bapi_ptmgrattabs_mngdelete

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, Gothmog, YuriT

bapi_ptmgrattabs_mngdelete

Postby Hephaestus » Mon Jul 19, 2004 8:32 pm

Hi,

Had anybody tried using this bapi before? I encountered the problem below, can someone please kindly enlighten me what I had done wrong?

I have a half day leave for an employee on 15 July 2004 from 315am to 7am marked as leave for previous day due to it's a 3rd shift employee whose normal working hour is from 14 July 2004 11pm to 15 July 2004 7am. When I used the above BAPI in an attempt to delete this, I enter the logical system and the internal document number. When I run the BAPI, it complain that it crashed with record on 14 July 2004. There's no other leave for 14 July 2004 for this employee.
My impression is that this is suppose to be a delete function call but how come it throw error when there's a crash? I of course only want deletion only when there's an existing record right? I think it behave more like a create function call than delete function call. Can somebody please enlighten me what I had done wrong or missed out? If not, is there any other ways that you know of that I can delete away leave without using BDC? We are using the old leave management method via the infotype 5 and 2001. I had tried the other bapi BAPI_ABSENCE_DELETE and I have the same problem.

Please note that the testing on this BAPI is done via the test sequence with the enqueue function call done before this particular BAPI call.

Any help will be greatly appreciated.

Thanks in advance for any help rendered.
Hephaestus
 
Posts: 22
Joined: Sun Jun 13, 2004 9:10 pm

Re: bapi_ptmgrattabs_mngdelete

Postby diocio » Tue Mar 14, 2017 9:52 pm

Code: Select all
FUNCTION zect_postleav.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(ZPERNR) TYPE  PERSNO
*"     VALUE(ZJENCUTI) TYPE  AWART
*"     VALUE(ZNOTIKET) TYPE  CHAR30
*"  TABLES
*"      ZOLDLEAV STRUCTURE  ZTBHISTOCT OPTIONAL
*"      ZNEWLEAV STRUCTURE  ZTBHISTOCT
*"      ZRETURNMSG STRUCTURE  BAPIRETURN1
*"----------------------------------------------------------------------
  DATA: zbapihrabsatt_in TYPE TABLE OF bapihrabsatt_in WITH HEADER LINE.
  DATA: zhrabsatt_out TYPE TABLE OF bapihrabsatt_out WITH HEADER LINE.
  DATA: zbapiret2 TYPE TABLE OF bapiret2 WITH HEADER LINE.
  DATA: tglend LIKE sy-datum.
  DATA: zbapihrtimeskey LIKE bapihrtimeskey.
  TABLES: pa2001.
  DATA  roll_ret LIKE bapiret2.
  DATA: tmp1(20) TYPE c, tmp2(20) TYPE c.
  DATA: zsubrc TYPE sy-subrc.
  DATA: zdelrollback TYPE TABLE OF ztbhistoct WITH HEADER LINE.

* set period
  CONCATENATE sy-datum(4) '0101' INTO zcbegda.
  CONCATENATE sy-datum(4) '1231' INTO zcendda.

* create log
  PERFORM create_process_log USING znotiket.
  CLEAR zreturnmsg.
*  CONCATENATE 'Absent type - ' zjencuti
*              INTO zreturnmsg-message SEPARATED BY space.
*  CONCATENATE 'Pernr - ' zpernr
*              INTO zreturnmsg-message_v1 SEPARATED BY space.
*  PERFORM add_process_log
*        USING 'S' '00' '00'
*              zreturnmsg-message zreturnmsg-message_v1
*              zreturnmsg-message_v2 zreturnmsg-message_v3.
  PERFORM add_process_log
        USING 'S' '00' '00' 'Absent type:' zjencuti
              'Pernr:' zpernr.


* check employee
  CLEAR zreturnmsg.
  PERFORM check_employee USING zpernr zcbegda zcendda
                      CHANGING zreturnmsg.
  IF NOT zreturnmsg IS INITIAL.
    PERFORM add_process_log
            USING zreturnmsg-type zreturnmsg-id zreturnmsg-number
                  zreturnmsg-message zreturnmsg-message_v1
                  zreturnmsg-message_v2 zreturnmsg-message_v3.
    APPEND zreturnmsg.
    CLEAR zreturnmsg.
  ENDIF.
* check error
  READ TABLE zreturnmsg INDEX 1.
  zsubrc = sy-subrc.
  IF zsubrc EQ 0.     "found error
    PERFORM save_process_log.
  ENDIF.
  CHECK zsubrc NE 0.




* lock ee
  CLEAR zreturnmsg.
  CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
       EXPORTING
            number = zpernr
       IMPORTING
            return = zreturnmsg.
  IF NOT zreturnmsg IS INITIAL.
    PERFORM add_process_log
            USING zreturnmsg-type zreturnmsg-id zreturnmsg-number
                  zreturnmsg-message zreturnmsg-message_v1
                  zreturnmsg-message_v2 zreturnmsg-message_v3.
    IF zreturnmsg-number EQ '060'.
      zreturnmsg-message =
      'Proces tidak dapat dilakukan, tunggu beberapa saat lagi'.
    ENDIF.
    APPEND zreturnmsg.
    CLEAR zreturnmsg.
  ENDIF.
* check error
  READ TABLE zreturnmsg INDEX 1.
  zsubrc = sy-subrc.
  IF zsubrc EQ 0.     "found error
    PERFORM save_process_log.
  ENDIF.
  CHECK zsubrc NE 0.




* check parameter record table delete old leave
  READ TABLE zoldleav INDEX 1.
  IF sy-subrc EQ 0.





*-->> simulasi delete absen check error
    LOOP AT zoldleav.
*     set date
      tglend = zoldleav-endda.
      IF zoldleav-endda IS INITIAL.
        tglend = zoldleav-begda.
      ENDIF.
      CONCATENATE zoldleav-begda+6(2) '.'
                  zoldleav-begda+4(2) '.'
                  zoldleav-begda(4) INTO tmp1.
      CONCATENATE tglend+6(2) '.'
                  tglend+4(2) '.'
                  tglend(4) INTO tmp2.

*     write list to log
      CLEAR zreturnmsg.
*      CONCATENATE 'Delete date: ' zoldleav-begda '-' tglend
*                  INTO zreturnmsg-message SEPARATED BY space.
*      PERFORM add_process_log
*            USING 'S' '00' '00'
*                  zreturnmsg-message zreturnmsg-message_v1
*                  zreturnmsg-message_v2 zreturnmsg-message_v3.
      PERFORM add_process_log
            USING 'S' '00' '00'
                  'Check date: ' zoldleav-begda tglend ''.
      CLEAR zreturnmsg.

*     read leave key document number
      SELECT * FROM pa2001 WHERE pernr = zpernr AND
                                 subty = zjencuti AND
                                 endda = tglend AND
                                 begda = zoldleav-begda.
        zbapihrtimeskey-logicalsystem = pa2001-docsy.
        zbapihrtimeskey-documentnumber = pa2001-docnr.
      ENDSELECT.
      CHECK sy-subrc EQ 0.

*      CLEAR: zbapihrabsatt_in.
*      zbapihrabsatt_in-from_date = zoldleav-begda.
*      zbapihrabsatt_in-to_date = zoldleav-endda.
*      IF zoldleav-endda IS INITIAL.
*        zbapihrabsatt_in-to_date = zoldleav-begda.
*      ENDIF.
*      zbapihrabsatt_in-abs_att_hours = '8.00'.
*      zbapihrabsatt_in-all_day_flag = 'X'.
*      IF zjencuti EQ 'D006'.    "---half day
*        zbapihrabsatt_in-abs_att_hours = '4.00'.
*        zbapihrabsatt_in-all_day_flag = ' '.
*      ENDIF.

*     simulasi delete old cuti
      REFRESH zbapiret2.
      CALL FUNCTION 'BAPI_PTMGRATTABS_MNGDELETE'
           EXPORTING
                hrtimeskey  = zbapihrtimeskey
                simulate    = 'X'
*                hrabsatt_in = zbapihrabsatt_in
           TABLES
                return      = zbapiret2.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

      READ TABLE zbapiret2 WITH KEY type = 'E'.
      IF sy-subrc EQ 0.    "--->ada error
        "--collect any error
        MOVE-CORRESPONDING zbapiret2 TO zreturnmsg.
        CONCATENATE 'Simulation-delete:' tmp1 '-' tmp2
                    zbapiret2-message
                    INTO zreturnmsg-message SEPARATED BY space.
        PERFORM add_process_log
              USING zreturnmsg-type zreturnmsg-id zreturnmsg-number
                    zreturnmsg-message zreturnmsg-message_v1
                    zreturnmsg-message_v2 zreturnmsg-message_v3.
        APPEND zreturnmsg.
        CLEAR zreturnmsg.
      ENDIF.

    ENDLOOP.
*   check error
    READ TABLE zreturnmsg INDEX 1.
    zsubrc = sy-subrc.
    IF zsubrc EQ 0.     "found error
      PERFORM save_process_log.
    ENDIF.
    CHECK zsubrc NE 0.
*<<-- simulasi delete absen check error






*-->> delete old absen below
    LOOP AT zoldleav.

*     set date
      tglend = zoldleav-endda.
      IF zoldleav-endda IS INITIAL.
        tglend = zoldleav-begda.
      ENDIF.
      CONCATENATE zoldleav-begda+6(2) '.'
                  zoldleav-begda+4(2) '.'
                  zoldleav-begda(4) INTO tmp1.
      CONCATENATE tglend+6(2) '.'
                  tglend+4(2) '.'
                  tglend(4) INTO tmp2.

*     read leave key document number
      SELECT * FROM pa2001 WHERE pernr = zpernr AND
                                 subty = zjencuti AND
                                 endda = tglend AND
                                 begda = zoldleav-begda.
        zbapihrtimeskey-logicalsystem = pa2001-docsy.
        zbapihrtimeskey-documentnumber = pa2001-docnr.
      ENDSELECT.
      CHECK sy-subrc EQ 0.

*      DATA: zbapireturn1 LIKE bapireturn1.
*      CALL FUNCTION 'BAPI_ABSENCE_DELETE'
*        EXPORTING
*          employeenumber       = zpernr
*          subtype              = zjencuti
**         objectid             =
**         lockindicator        =
*          validitybegin        = zoldleav-begda
*          validityend          = zoldleav-endda
**         recordnumber         =
*         nocommit             = 'X'
*       IMPORTING
*         return               = zbapireturn1.

*     delete old cuti
      REFRESH zbapiret2.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
      CALL FUNCTION 'BAPI_PTMGRATTABS_MNGDELETE'
           EXPORTING
                hrtimeskey = zbapihrtimeskey
                simulate    = ' '
           TABLES
                return     = zbapiret2.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

*     read error process delete
      READ TABLE zbapiret2 WITH KEY type = 'E'.
      IF sy-subrc NE 0.
        PERFORM add_process_log
                USING 'S' '00' '00'
                      'Delete: ' tmp1 tmp2 ''.
      ELSE.
        LOOP AT zbapiret2.
          IF zbapiret2-type EQ 'E'.

            "--collect any error
            MOVE-CORRESPONDING zbapiret2 TO zreturnmsg.
            CONCATENATE tmp1 '-' tmp2
                        zbapiret2-message
                        INTO zreturnmsg-message SEPARATED BY space.
            PERFORM add_process_log
                  USING zreturnmsg-type zreturnmsg-id zreturnmsg-number
                        zreturnmsg-message zreturnmsg-message_v1
                        zreturnmsg-message_v2 zreturnmsg-message_v3.
            APPEND zreturnmsg.
            CLEAR zreturnmsg.

*           rollback deleted date
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
                 IMPORTING
                      return = roll_ret.
            CALL FUNCTION 'HR_PSBUFFER_INITIALIZE'.
            EXIT.
          ENDIF.
        ENDLOOP.
      ENDIF.

    ENDLOOP.
*<<-- delete old absen below






  ENDIF.

** unlocked ee
*  CALL FUNCTION 'BAPI_EMPLOYEET_DEQUEUE'
*       EXPORTING
*            number        = zpernr
*            validitybegin = zcbegda
*       IMPORTING
*            return        = zreturnmsg.
*  IF NOT zreturnmsg IS INITIAL.
*    PERFORM add_process_log
*          USING zreturnmsg-type zreturnmsg-id zreturnmsg-number
*                zreturnmsg-message zreturnmsg-message_v1
*                zreturnmsg-message_v2 zreturnmsg-message_v3.
*    APPEND zreturnmsg.
*  ENDIF.
*  CHECK zreturnmsg IS INITIAL.
*
** check error
*  READ TABLE zreturnmsg INDEX 1.
*  zsubrc = sy-subrc.
*  IF zsubrc EQ 0.     "found error
*    PERFORM save_process_log.
*  ENDIF.
*  CHECK zsubrc NE 0.





** locked ee
*  CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
*       EXPORTING
*            number = zpernr
*       IMPORTING
*            return = zreturnmsg.
*  IF NOT zreturnmsg IS INITIAL.
*    PERFORM add_process_log
*            USING zreturnmsg-type zreturnmsg-id zreturnmsg-number
*                  zreturnmsg-message zreturnmsg-message_v1
*                  zreturnmsg-message_v2 zreturnmsg-message_v3.
*    IF zreturnmsg-number EQ '060'.
*      zreturnmsg-message =
*      'Proses tidak dapat dilakukan, tunggu beberapa saat lagi'.
*    ENDIF.
*    APPEND zreturnmsg.
*    CLEAR zreturnmsg.
*  ENDIF.
*
** check error
*  READ TABLE zreturnmsg INDEX 1.
*  zsubrc = sy-subrc.
*  IF zsubrc EQ 0.     "found error
*    PERFORM save_process_log.
*  ENDIF.
*  CHECK zsubrc NE 0.





*-------- save new record
  REFRESH zbapiret2.
  LOOP AT znewleav.
    CLEAR: zbapihrabsatt_in, zhrabsatt_out, zbapiret2.
    zbapihrabsatt_in-from_date = znewleav-begda.
    zbapihrabsatt_in-to_date = znewleav-endda.
    IF znewleav-endda IS INITIAL.
      zbapihrabsatt_in-to_date = znewleav-begda.
    ENDIF.
    zbapihrabsatt_in-abs_att_hours = '8.00'.
    zbapihrabsatt_in-all_day_flag = 'X'.
    IF zjencuti EQ 'D006'.    "---half day
      zbapihrabsatt_in-abs_att_hours = '4.00'.
      zbapihrabsatt_in-all_day_flag = ' '.
    ENDIF.

    REFRESH zbapiret2.
    CALL FUNCTION 'BAPI_PTMGRATTABS_MNGCREATION'
         EXPORTING
              employeenumber = zpernr
              abs_att_type   = zjencuti
              hrabsatt_in    = zbapihrabsatt_in
              simulate       = ' '
         IMPORTING
              hrabsatt_out   = zhrabsatt_out
         TABLES
              return         = zbapiret2.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

    READ TABLE zbapiret2 WITH KEY type = 'E'.
    IF sy-subrc NE 0.
      CONCATENATE zbapihrabsatt_in-from_date+6(2) '.'
                  zbapihrabsatt_in-from_date+4(2) '.'
                  zbapihrabsatt_in-from_date(4) INTO tmp1.
      CONCATENATE zbapihrabsatt_in-to_date+6(2) '.'
                  zbapihrabsatt_in-to_date+4(2) '.'
                  zbapihrabsatt_in-to_date(4) INTO tmp2.
      PERFORM add_process_log
              USING 'S' '00' '00' 'Write: ' tmp1 tmp2 ''.
    ELSE.
      LOOP AT zbapiret2 WHERE type EQ 'E'.
        "--collect any error
        IF zbapiret2-number EQ '080'.
          zbapiret2-message =
          'Tanggal cuti bertabrakan dengan yang sudah pernah diambil'.
        ENDIF.
        IF zbapiret2-number EQ '002'.
          zbapiret2-message = 'Tanggal cuti minimal 1 hari kerja'.
        ENDIF.
        MOVE-CORRESPONDING zbapiret2 TO zreturnmsg.
        CONCATENATE znewleav-begda+6(2) '.' znewleav-begda+4(2) '.'
                    znewleav-begda(4) INTO tmp1.
        IF znewleav-endda IS INITIAL.
          tmp2 = ''.
        ELSE.
          CONCATENATE znewleav-endda+6(2) '.' znewleav-endda+4(2) '.'
                      znewleav-endda(4) INTO tmp2.
        ENDIF.
        CONCATENATE tmp1 '-' tmp2 zbapiret2-message
                    INTO zreturnmsg-message SEPARATED BY space.
        PERFORM add_process_log
            USING zreturnmsg-type zreturnmsg-id zreturnmsg-number
                  zreturnmsg-message zreturnmsg-message_v1
                  zreturnmsg-message_v2 zreturnmsg-message_v3.
        APPEND zreturnmsg.
        CLEAR zreturnmsg.
      ENDLOOP.
    ENDIF.

  ENDLOOP.






  "--- unlocked ee
  CALL FUNCTION 'BAPI_EMPLOYEET_DEQUEUE'
       EXPORTING
            number        = zpernr
            validitybegin = zcbegda
       IMPORTING
            return        = zreturnmsg.
  IF NOT zreturnmsg IS INITIAL.
    PERFORM add_process_log
            USING zreturnmsg-type zreturnmsg-id zreturnmsg-number
                  zreturnmsg-message zreturnmsg-message_v1
                  zreturnmsg-message_v2 zreturnmsg-message_v3.
    APPEND zreturnmsg.
  ENDIF.



  PERFORM save_process_log.

ENDFUNCTION.
diocio
 
Posts: 5
Joined: Mon Sep 10, 2007 11:36 pm


Return to ABAP

Who is online

Users browsing this forum: No registered users and 4 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.