Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Function for deleting and modifying Infotype 2011 : HR_TMW_DB_UPDATE_TEVENT

Former Member
0 Kudos

Hello experts,

we have and requirement where we have to insert/delete or modify specific clock in/out posts from infotype 2011. Looking trough this forum I was not able to find how to delete or modify specific events from SAP correctly.

We are able to insert new record via FM : HR_INFOTYPE_OPERATION with ease, but can not use the same function module to either delete or modify the same record.

I was able to find FM: HR_TMW_DB_UPDATE_TEVENT and tried it in combination with HR_TMW_DB_READ_TEVENT, with out any succes.

My question is: in what way must the tables be filled for deletion or modification, for FM HR_TMW_DB_UPDATE_TEVENT to work?

With testing deleting a record, function explicitly demands taht all four tables are set

  • del_teven = t_teven_del

  • ins_teven = t_teven_ind

  • del_teven_more = t_teven_more_del

  • ins_teven_more = t_teven_more_ins

, but still the record is not deleted form table TEVEN.

Thank you in advance for any given anwsers,

Matevž

1 ACCEPTED SOLUTION

rajesh_paruchuru
Active Participant
0 Kudos

> My question is: in what way must the tables be filled for deletion or modification, for FM HR_TMW_DB_UPDATE_TEVENT to work?

>

While inserting records in TEVEN/TEVEN_MORE using the above FM, the first step would be to generate PDSNR, this can be done using the FM NUMBER_GET_NEXT( Number range - 01 and Object PD_SEQ_NR ) then populate the internal tables with the PDSNR generated in the first step and trasfer the internal tables to the corresponding parameters of the FM..

and for deletion, this FM righly doesn't physically delete the records from the database, it just sets the 'STOKZ' to 'X', while reading the TEVEN/TEVEN_MORE entries, the read FM ignores the records with 'STOKZ' as 'X'.

You may have to issue a explict COMMIT WORK statement after calling this FM to commit the changes to the database.

The source code of both the read/update FMs is easy to read and follow.

-Rajesh.

12 REPLIES 12

former_member1052991
Active Participant
0 Kudos

Hi Matevž,

What error are you getting if you use FM HR_INFOTYPE_OPERATION. Bcos' we can use the same FM to update table.

Regards,

Guna

0 Kudos

Hello Guna,

if tested via se37, the FM does not show any erorrs, but does not do anything either. But when ran from custom program, we get short dump with error saying that parameters are missing (either INS_TEVEN or DEL_TEVEN).

This is the reason why I am asking how to populate these tables.

When deleteing, I tried populating DEL_TEVEN and DEL_TEVEN_MORE. But with no success.

Thank you for your time and any possible help.

Kind regards,

Matevž

Former Member
0 Kudos

Hi,

Check the include LHRTIM00_TMWBUFFERCB9 and check how the tables are being filled for deletion.

Regards,

Srini.

rajesh_paruchuru
Active Participant
0 Kudos

> My question is: in what way must the tables be filled for deletion or modification, for FM HR_TMW_DB_UPDATE_TEVENT to work?

>

While inserting records in TEVEN/TEVEN_MORE using the above FM, the first step would be to generate PDSNR, this can be done using the FM NUMBER_GET_NEXT( Number range - 01 and Object PD_SEQ_NR ) then populate the internal tables with the PDSNR generated in the first step and trasfer the internal tables to the corresponding parameters of the FM..

and for deletion, this FM righly doesn't physically delete the records from the database, it just sets the 'STOKZ' to 'X', while reading the TEVEN/TEVEN_MORE entries, the read FM ignores the records with 'STOKZ' as 'X'.

You may have to issue a explict COMMIT WORK statement after calling this FM to commit the changes to the database.

The source code of both the read/update FMs is easy to read and follow.

-Rajesh.

0 Kudos

Hello Rajesh,

thank you for your anwser. By filing all the tables, I was able to modify selected records for deletions in table TEVEN. The only consern is, that although FM now does what it needs to, it still sends out error no. 2 (Update failed). This status is strange, since the database table has been changed.

The code now runs as such:

FM: HR_EMPLOYEE_ENQUEUE

FM: HR_PSBUFFER_INITIALIZE

FM: HR_TMW_DB_READ_TEVENT

Preparing tables:


          MOVE-CORRESPONDING s_teven TO s_teven_more.

          APPEND s_teven TO t_teven_del.
          APPEND s_teven_more TO t_teven_more_del.

          s_teven-stokz = 'X'.
          APPEND s_teven TO t_teven_ins.

          s_teven_more-stokz = 'X'.
          APPEND s_teven_more TO t_teven_more_ins.

FM: HR_TMW_DB_UPDATE_TEVENT


  IF sy-subrc = 0.
    COMMIT WORK AND WAIT.
  ELSE.
    ROLLBACK WORK.
    EXIT.
  ENDIF.

FM: HR_EMPLOYEE_DEQUEUE

Tried also seting STOKZ = 'X' to all internal tables as well, but getting the same error. Are there some other parameters that need to be filed or is there anything else we need to take into account while running this FM?

Thank you,

Matevž

Edited by: Matevz Babnik on Jan 19, 2012 9:39 AM

Edited by: Matevz Babnik on Jan 19, 2012 10:38 AM

0 Kudos

Hello Matev,

seems like i'm unable to drive my point home,

> Preparing tables:

>


>           MOVE-CORRESPONDING s_teven TO s_teven_more.
> 
>           APPEND s_teven TO t_teven_del.
>           APPEND s_teven_more TO t_teven_more_del.
{quote}

the deletion part(above) is fine, the program is not supposed to set the values of 'STOKZ' to 'X',  the FM will that for you as a mark of deleting the records( instead of deleting them physically from the database.

{quote:title=Matevz Babnik wrote:}
> 

> s_teven-stokz = 'X'.

> APPEND s_teven TO t_teven_ins.

>

> s_teven_more-stokz = 'X'.

> APPEND s_teven_more TO t_teven_more_ins.

>


{quote}

not sure at what you are trying to achieve in ther insertion part above,  if you want to insert a new record in TEVEN, you have to generate the value of the key field 'PDSNR' of the table 'TEVEN', this can be done by calling the FM 'NUMBER_GET_NEXT', then you can build the remaining fields of the TEVEN structure in your program as shown below:

  

DATA: w_pdsnr TYPE teven-pdsnr.

CALL FUNCTION 'NUMBER_GET_NEXT'

EXPORTING

nr_range_nr = '01'

object = 'PD_SEQ_NR'

IMPORTING

number = w_pdsnr

EXCEPTIONS

interval_not_found = 1

number_range_not_intern = 2

object_not_found = 3

quantity_is_0 = 4

quantity_is_not_1 = 5

interval_overflow = 6

buffer_overflow = 7

OTHERS = 8.

IF sy-subrc IS INITIAL.

s_teven-pdsnr = w_pdsnr.

  • build the rest of the fields in s_teven structure

APPEND s_teven TO t_teven_ins.

ENDIF.

As you are trying to insert duplicate records you are currently receiving an update error, remember, PDSNR is the only key field in TEVEN table, debugging the update FM should be straight forward and easy, just in case if you run into errors.

-Rajesh

0 Kudos

Hello Rajesh,

I had tried it this way as well, but get the same result. So it was first, get data from TEVEN table, get next seq. number (pdsnr) with the FM you've written, fan FM for updating TEVEN and got the same result. The current (old) value was set for deletion, but the new one was not created. Exception was again no. 2 (Update failed).

So what I have done to resolve this was, that I use FM HR_TMW_DB_UPDATE_TEVENT to set deletion status to the existing record, and

FM HR_INFOTYPE_OPERATION to create the next (new) record. Doing that I've got the change I wanted.

I will be still testing FM HR_TMW_DB_UPDATE_TEVENT, to learn how to create the change with it, but for now this will do.

Thank you for all your help and if you have some update, please paste it.

Kind regards,

Matevž

0 Kudos

> I had tried it this way as well, but get the same result. So it was first, get data from TEVEN table, get next seq. number (pdsnr) with the FM you've written, fan FM for updating TEVEN and got the same result. The current (old) value was set for deletion, but the new one was not created. Exception was again no. 2 (Update failed).

Hello Matevž,

Can you please paste the relevant part of the code where-in you are building the internal tables for deletion and inserttion?

-Rajesh.

0 Kudos

Hello Rajesh,

the code goes:


* get original data:
    CALL FUNCTION 'HR_TMW_DB_READ_TEVENT'
      EXPORTING
        pernr    = iv_pernr
        fromdate = iv_begda
        todate   = iv_endda
      IMPORTING
        result   = result_tmw.

* get next seq. nr.:
CALL FUNCTION 'NUMBER_GET_NEXT'
  EXPORTING
    nr_range_nr                   = lv_ragne
    object                        = lv_object
 IMPORTING
   NUMBER                        = lv_number
 EXCEPTIONS
   INTERVAL_NOT_FOUND            = 1
   NUMBER_RANGE_NOT_INTERN       = 2
   OBJECT_NOT_FOUND              = 3
   QUANTITY_IS_0                 = 4
   QUANTITY_IS_NOT_1             = 5
   INTERVAL_OVERFLOW             = 6
   BUFFER_OVERFLOW               = 7
   OTHERS                        = 8.

      LOOP AT result_tmw INTO s_result_tmw.
        s_teven = s_result_tmw-teven.
        IF s_teven-ldate = iv_ldate AND s_teven-ltime = iv_ltime AND s_teven-satza = iv_satza.
          "set TEVEN_DEL tables for reading
          APPEND s_teven TO t_teven_del.
          APPEND s_teven_more TO t_teven_more_del.

          "set status for change to TEVEN_INS tables
          s_teven-pdsnr = lv_number.
          s_teven-ldate = iv_ldate.
          s_teven-ltime = iv_ltime.     
          s_teven-satza = iv_satza.
          APPEND s_teven TO t_teven_ins.
          MOVE-CORRESPONDING s_teven TO s_teven_more.
          APPEND s_teven_more TO t_teven_more_ins.

          EXIT.
        ENDIF.
      ENDLOOP.

* execute deletion of current record:
      CALL FUNCTION 'HR_TMW_DB_UPDATE_TEVENT'
        TABLES
          del_teven      = t_teven_del
          ins_teven      = t_teven_ins
          del_teven_more = t_teven_more_del
          ins_teven_more = t_teven_more_ins
        EXCEPTIONS
          insert_failed  = 1
          update_failed  = 2
          OTHERS         = 3.
      COMMIT WORK.

Now I am using the following code, that is working:


* get original data:
    CALL FUNCTION 'HR_TMW_DB_READ_TEVENT'
      EXPORTING
        pernr    = iv_pernr
        fromdate = iv_begda
        todate   = iv_endda
      IMPORTING
        result   = result_tmw.

********************************************************************** modification
* CODE :                            MODIFY CLOCK IN/OUT
    IF iv_operation = 'MOD'.

      LOOP AT result_tmw INTO s_result_tmw.
        s_teven = s_result_tmw-teven.
        IF s_teven-ldate = iv_ldate AND s_teven-ltime = iv_ltime AND s_teven-satza = iv_satza.
          "set TEVEN_DEL tables for reading
          APPEND s_teven TO t_teven_del.
          APPEND s_teven_more TO t_teven_more_del.

          "set status for change to TEVEN_INS tables
          APPEND s_teven TO t_teven_ins.
          MOVE-CORRESPONDING s_teven TO s_teven_more.
          APPEND s_teven_more TO t_teven_more_ins.

          EXIT.
        ENDIF.
      ENDLOOP.

* execute deletion of current record:
      CALL FUNCTION 'HR_TMW_DB_UPDATE_TEVENT'
        TABLES
          del_teven      = t_teven_del
          ins_teven      = t_teven_ins
          del_teven_more = t_teven_more_del
          ins_teven_more = t_teven_more_ins
        EXCEPTIONS
          insert_failed  = 1
          update_failed  = 2
          OTHERS         = 3.
      COMMIT WORK.

* insert new (updated) record of clock registration:
      s_p2011-pernr = iv_pernr.
      s_p2011-infty = '2011'.
      s_p2011-ldate = iv_ldate_new.
      s_p2011-ltime = iv_ltime_new.
      s_p2011-erdat = sy-datum.
      s_p2011-ertim = sy-uzeit.
      s_p2011-satza = iv_satza_new.
      s_p2011-origf = 'E'.

      s_p2011-begda = iv_ldate.
      s_p2011-endda = iv_ldate.

      CALL FUNCTION 'HR_INFOTYPE_OPERATION'
        EXPORTING
          infty            = '2011'
          number           = iv_pernr
*         SUBTYPE          =
*         OBJECTID         =
*         LOCKINDICATOR    =
          validityend      = iv_begda
          validitybegin    = iv_endda
          recordnumber     = f_recordnumber
          record           = s_p2011
          operation        = 'INS'                        
          tclas            = 'A'
          dialog_mode      = '0'
*         NOCOMMIT         =
*         VIEW_IDENTIFIER  =
*         SECONDARY_RECORD =
        IMPORTING
          return           = fm_return
          key              = personaldatakey.
      COMMIT WORK.

ENDIF.

Kind regards,

Matevž

0 Kudos
LOOP AT result_tmw INTO s_result_tmw.
        s_teven = s_result_tmw-teven.
        IF s_teven-ldate = iv_ldate AND s_teven-ltime = iv_ltime AND s_teven-satza = iv_satza.
          "set TEVEN_DEL tables for reading
          APPEND s_teven TO t_teven_del.
          APPEND s_teven_more TO t_teven_more_del.
 
          "set status for change to TEVEN_INS tables
          s_teven-pdsnr = lv_number.
          s_teven-ldate = iv_ldate.
          s_teven-ltime = iv_ltime.     
          s_teven-satza = iv_satza.
          APPEND s_teven TO t_teven_ins.
          MOVE-CORRESPONDING s_teven TO s_teven_more.
          APPEND s_teven_more TO t_teven_more_ins.
 
          EXIT.
        ENDIF.
      ENDLOOP.

Hello Matevž,

In the above code, it seems like you are using the same variable lv_number for building all the entries in the internal table t_teven_ins, however, it is expected that a new pdsnr should be generated for each entry in the insertion internal table, as already explained, pdsnr is the only key field in the db table TEVEN and key fields should not be duplicated...

-Rajesh.

0 Kudos

Hi Rajesh,

HR_TMW_DB_UPDATE_TEVENT

This one is not update logged change of STOKZ into PCL4.

Is there any solution that i can logged who is the one delete records?

Cause ask i test, when i delete record record in PA30, a record logged generate in PCL4, and i can get it

Former Member
0 Kudos

Hello Rajesh,

Even i have the same requirment i need to modify the existing record.

i used fm  'HR_INFOTYPE_OPERATION' but getting an error No data stored for info type 2011

please help me