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: 

Modify / Insert/ Delete a Infotype using Class / Methods

marcosch
Explorer
0 Kudos

Hi Experts

We need to update several infotypes and we tried it with FM HR_INFOTYPE_OPERSTION. But this FM is not working properly and its not released for customers. So we have to do it via the Classes. We found many Classes, but no one has a example within SAP and all the threads I found are not really helpful for me.

So can somebody give me a good example to do a action on a infotype with Classes? I tried it with if_hrpa_plain_infotype_access and cl_hrpa_infotype_ nnnn, both are not working. An error occures releated to grpval CP. CP is not used in this system.

I tried it with cl_hrpa_infotype_container and this is also not working. I have to change the keys, and the method modify_primary_record throws a dump when I want to change the begda.

It would be really great if somebody can give me a helping hand.

Many Thanks

Marco

1 ACCEPTED SOLUTION

enric101
Active Contributor
0 Kudos

Hi,

If you wold use OO for operations with infotypes please check this example:

In your message commends that you try to modify primary record using OO. check configuration of time constrains in transaccion SM30 -> table: V_T582A.

If error persist, paste your dump.

Regards

Enric

4 REPLIES 4

enric101
Active Contributor
0 Kudos

Hi,

If you wold use OO for operations with infotypes please check this example:

In your message commends that you try to modify primary record using OO. check configuration of time constrains in transaccion SM30 -> table: V_T582A.

If error persist, paste your dump.

Regards

Enric

0 Kudos

Hi Enric

Thank you for your reply. I will take a look at your example.

Yes, The Infotype 0002 has constraint 1. Can I not modify the Infty the it will be delimited? Like in HR_INFOTYPE_OPERATON or Batch Input? Updating a Infty in this old way was never a problem. I.e. I have a record 01.01.2014 - 31.12.9999. Now I want to update with a new record 01.01.2016 - 31.12.9999. How can I do this that the old record will be delimited? Do I have to use the secondary record? And where I have to change the fields?

Unfortunately the expample has lack of data declaration..

enric101
Active Contributor
0 Kudos

Hi,

The complete example with all declarations is this:

DATA infotype_container_tab TYPE hrpad_infotype_container_tab.

DATA: lo_0002 TYPE REF TO cl_hrpa_infotype_0002,

      ls_pskey       TYPE pskey,

      lt_old_container TYPE hrpad_infty_container_tab,

      lw_pernr TYPE p_pernr,

      lw_ok    TYPE boole_d,

      ls_container     TYPE  hrpad_infty_container_ref.



DATA lw_message     TYPE char50.

DATA      ls_exp TYPE REF TO cx_hrpa_violated_assertion.

DATA :    lr_message_list TYPE REF TO cl_hrpa_message_list.

DATA :    fr_msg_handler TYPE REF TO if_hrpa_message_handler.

DATA:    lw_update_mode  TYPE hrpad_update_mode.

DATA :    fr_keyref  TYPE REF TO data.



DATA: lw_masterdata_buffer TYPE REF TO if_hrpa_masterdata_bl.



FIELD-SYMBOLS : <lfs_0002> TYPE P0002.

DATA :    lr_container_temp_0002 TYPE REF TO cl_hrpa_infotype_container.





**-----Create Object for Message handling-----**

CREATE OBJECT lr_message_list.

fr_msg_handler  = lr_message_list.

lw_pernr       '00000008'.

ls_pskey-pernr '00000008'.     "Personnel Number

ls_pskey-infty '0002'.

ls_pskey-begda '19000101'.

ls_pskey-endda '99991231'.



*Create instance

TRY.

    CREATE OBJECT lo_0002

      EXPORTING

        tclas = 'A'

        infty = '0002'.





    lo_0002->if_hrpa_infty_bl~read(

     EXPORTING

       tclas           = 'A'

       pernr           = lw_pernr

       infty           = '0002'

       subty           = space

       begda           = ls_pskey-begda

       endda           = ls_pskey-endda

       no_auth_check   = ' '

       message_handler = fr_msg_handler

       mode            = '2'

     IMPORTING

       container_tab       = lt_old_container  "Infty container

       is_ok               = lw_ok         "OK flag

       ).

  CATCH cx_hrpa_violated_assertion INTO ls_exp.

    lw_message = ls_exp->get_text( ).

ENDTRY.



READ TABLE lt_old_container INTO ls_container INDEX 1.



CHECK sy-subrc = 0.



**Move container to temparary container

lr_container_temp_0002 ?= ls_container."*get primary record reference

TRY.

  lr_container_temp_0002->primary_record_ref(

  IMPORTING

    pnnnn_ref = fr_keyref "Primary record reference variable

    ).

ENDTRY.

**Assign key refernce to 0194 work area

ASSIGN fr_keyref->* TO <lfs_0002>.



**Change the status to 4 –Example we can change any field here

<lfs_0002>-NACH2 = 'TESTCLASS'.



**--Modify Primary record and get the updated container reference back

ls_container ?=

lr_container_temp_0002->modify_primary_record( <lfs_0002> ).





* *modify the record -after this  method check pa0194  for specific record itxex should be 'X'

TRY.

    lo_0002->if_hrpa_infty_bl~modify(

     EXPORTING

       old_container   = lr_container_temp_0002

       massn           = space

       massg           = space

       update_mode     = lw_update_mode

       no_auth_check   = 'X'

       message_handler = fr_msg_handler "Message handler

    IMPORTING

     is_ok           = lw_ok        "Ok flag

    CHANGING

      container       = ls_container )."Infty Container.

  CATCH cx_hrpa_violated_assertion INTO ls_exp.

    lw_message = ls_exp->get_text( ).

ENDTRY.

IF lw_ok NE 'X' AND lw_message IS NOT INITIAL.







  TRY.

      cl_hrpa_masterdata_bl=>get_instance(

      IMPORTING

    masterdata_bl = lw_masterdata_buffer ).



    CATCH cx_hrpa_violated_assertion INTO ls_exp.

  ENDTRY.



ENDIF.

0 Kudos

Hi


I am calling as like you if_hrpa_infty_bl~modify but it is not updating in database 😞 do you have any idea.