Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
kamesh_g
Contributor
0 Kudos

This Article is about ‘How to update the garnishment infotypes in Simulation/Test mode using standard Classes and update infotype text.

Business Scenario

You may come across requisite to update  the infotypes in Simulation/Test mode. Means when you run the program ,actual system update should not happen in the Database but we should able to know the update is successful or failure.

Below is the code to update infotypes 194 and 195 (Garnishment infotypes) in Simulation mode.  Below code can be used in the loop of internal table of infotype 194 data or in the loop of GET PERNR if LDB is used.

***********************************************************************************************************

*DATA  DECLARATION

***********************************************************************************************************

DATA : lo_0194 type ref to cl_hrpa_infotype_0194, " Object creation of IT1094

       lo_0195 type ref to cl_hrpa_infotype_0195. " Object creation of IT1095

DATA :  fr_msg_handler  type ref to if_hrpa_message_handler,"Message handler

        fr_keyref       type ref to data,

        lr_message_list type ref to cl_hrpa_message_list,   "Msg reference
        ls_container   
type  hrpad_infty_container_ref,    "Infty container

        lr_container_temp_0194 type ref to cl_hrpa_infotype_container,
        lr_container_temp_0195
type ref to cl_hrpa_infotype_container.
DATA  :   lt_text     type         hrpad_text_tab,
          ls_text    
type line of hrpad_text_tab.

DATA:     lw_ok            type boole_d,      "OK flag
          lw_update_mode  
type hrpad_update_mode ,
          lw_message      
type char1.
DATA :    ls_0194_fill    
type p0194,

          ls_0195          type p0195.

       

DATA :    ls_pskey type pskey.

DATA :    ls_exp   type ref to cx_hrpa_violated_assertion.

***Buffer variables declaration

DATA:     lw_masterdata_buffer type ref to if_hrpa_masterdata_bl,
          lw_exp              
type ref to cx_root,

          lw_pgmid             type old_prog value sy-repid,

          lr_upd_cluster       type ref to cl_hrpa_text_cluster.

FIELD-SYMBOLS: <lfs_0194> type p0194,         "For IT0194 data

               <lfs_0195> type p0195.         "For IT0195 data

***********************************************************************************************************

*CODE TO UPDATE INFOTYPES IN SIMULATION MODE

***********************************************************************************************************

**------Get reference to Buffer management class-------**
 
try.
      cl_hrpa_masterdata_bl=>get_instance(
        
importing
           masterdata_bl = lw_masterdata_buffer ).

   
catch cx_hrpa_violated_assertion into lw_exp.
    lw_message = ls_exp->get_text( ).
   
endtry.

**--------Move buffer contents to Infotype Database---------**
  lw_masterdata_buffer->if_hrpa_buffer_control~initialize( ).

*Create objects for 194 and 185
 
try.
     
create object lo_0194
       
exporting
          tclas =
'A'
          infty =
'0194'.

    catch cx_hrpa_violated_assertion into ls_exp.
      lw_message = ls_exp->get_text( ).
   
endtry.

  Try.
     
Create object lo_0195
       
exporting
          tclas =
'A'
          infty =
'0195'.

    Catch cx_hrpa_violated_assertion into ls_exp.
      lw_message = ls_exp->get_text( ).
 
Endtry.

**-----Create Object for Message handling-----**
 
create object lr_message_list.
  fr_msg_handler  = lr_message_list.

**-----Fill PSKEY -----**
        ls_pskey-pernr = ls_0194_fill-pernr.    
"Personnel Number
        ls_pskey-infty = ls_0194_fill-infty.
        ls_pskey-begda = ls_0194_fill-begda.    
"Begin date
        ls_pskey-endda = ls_0194_fill-endda.    
"End date

**-----------Create Infotype Container for IT0194--------**
       
clear :lw_ok.
       
Try.
            lo_0194->if_hrpa_infty_bl~get_infty_container(
            
exporting
               tclas           =
'A'
               pskey           = ls_pskey
               no_auth_check   = space
               message_handler = fr_msg_handler
"Message handler
            
importing
               container       = ls_container 
"Infty container
               is_ok           = lw_ok        
"OK flag
               ).
         
catch cx_hrpa_violated_assertion into ls_exp.
            lw_message = ls_exp->get_text( ).
         
endtry.

If lw_ok eq abap_true and

lw_message  is initial  . "Container built successfully**Move container to temporary container
          lr_container_temp_0194 ?= ls_container.*get primary record reference
         
try.
            lr_container_temp_0194->primary_record_ref(
           
importing
              pnnnn_ref = fr_keyref
"Primary record reference variable
              ).
         
endtry.**Assign key reference to 0194 work area-Enough if we pass only mandatory *fields also
         
assign fr_keyref->* to <lfs_0194>.
          <lfs_0194>-schid = ls_0194_fill-schid.
          <lfs_0194>-rulnr = ls_0194_fill-rulnr.
          <lfs_0194>-lifnr = ls_0194_fill-lifnr.
          <lfs_0194>-orign = ls_0194_fill-orign.
          <lfs_0194>-orcod = ls_0194_fill-orcod.
          <lfs_0194>-ornam = ls_0194_fill-ornam.
          <lfs_0194>-orstr = ls_0194_fill-orstr.
          <lfs_0194>-orort = ls_0194_fill-orort.
          <lfs_0194>-orreg = ls_0194_fill-orreg.
          <lfs_0194>-orcnt = ls_0194_fill-orcnt.
          <lfs_0194>-orplz = ls_0194_fill-orplz.
          <lfs_0194>-gcase = ls_0194_fill-gcase.
          <lfs_0194>-gprio = ls_0194_fill-gprio.
          <lfs_0194>-gcate = ls_0194_fill-gcate.
          <lfs_0194>-gstat =  ls_0194_fill-gstat.
          <lfs_0194>-rcvdd =  ls_0194_fill-rcvdd.
          <lfs_0194>-fipsc =  ls_0194_fill-fipsc.
          <lfs_0194>-itxex =  ls_0194_fill-itxex.
         
try.**--Modify Primary record and get the updated container reference back
            ls_container ?=
            lr_container_temp_0194->modify_primary_record( <lfs_0194> ).
         
endtry.
         
clear :lw_ok.*Insert record
         
try.
              lo_0194->if_hrpa_infty_bl~
insert(
                
exporting
                  update_mode     = lw_update_mode
                  massn           = space
                  massg           = space
                  no_auth_check   =
' '     "Do Authority Check
                  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 abap_true or lw_message is not initial.

Clear : ls_pskey.

**Populate PSKEY of 195
   
    ls_pskey-pernr = ls_0195-pernr.    
"Personnel Number
    ls_pskey-infty = ls_0195-infty.
    ls_pskey-begda = ls_0195-begda.
    ls_pskey-endda = ls_0195-endda.

   
clear :lw_ok.*Get container of IT0195
   
try.
        lo_0195->if_hrpa_infty_bl~get_infty_container(
        
exporting
           tclas           =
'A'
           pskey           = ls_pskey
           no_auth_check   = space
           message_handler = fr_msg_handler
"Message handler
        
importing
           container       = ls_container 
"Infty container
           is_ok           = lw_ok        
"OK flag
           ).
     
catch cx_hrpa_violated_assertion into ls_exp.
        lw_message = ls_exp->get_text( ).
   
endtry.

if lw_ok ne abap_true or lw_message is not initial.

*Move container to temparary container
      lr_container_temp_0195 ?= ls_container.*get primary record reference
     
try.
        lr_container_temp_0195->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_0195>.*Populate internal table with IT0195 records

      <lfs_0195>-ordcd = ls_0195-ordcd.       
"Garnishment order type
      <lfs_0195>-rulid = ls_0195-rulid.
"Rule for calculating the non-“exempt amount
      <lfs_0195>-deduc = ls_0195-deduc.
"Garnishment order deduction
      <lfs_0195>-dedut = ls_0195-dedut.  
"Garnishment order deduction unit
      <lfs_0195>-itxex = ls_0195-itxex.

*Here when IT1094 update is successful GRNUM field will automatically create *by the system and same sequence *number should be used to update IT195.
      <lfs_0195>-grnum =  <lfs_0194>
-grnum.

     
try.**--Modify Primary record and get the updated container reference back
        ls_container ?=
        lr_container_temp_0195->modify_primary_record( <lfs_0195> ).

      Endtry.

     clear :lw_ok.*Insert record
     
try.
          lo_0195->if_hrpa_infty_bl~
insert(
            
exporting
              update_mode     = lw_update_mode
              massn           = space
              massg           = space
              no_auth_check   =
' '     "Do Authority Check
              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  abap_true  or lw_message is not initial.

      Endif.

Endif.

Endif.

*Commit or ‘No commit’ .If Infotypes to be updated in Simulation mode

*Do not use flush method below .if infotypes to be updated we can use flush *method .

if lw_ok ne  abap_true  or lw_message is not initial.

  lw_masterdata_buffer->if_hrpa_buffer_control~flush( space ).

Endif.

*Update infotype text .

*To update infotype text  pass PSKEY appropriately to update the text .And make sure ITXEX *field in infotype is checked ‘X’ otherwise not able to update infotype text. We could able to *update the cluster PCL1 but not able to see the text in infotype .

Ls_text  =  'TEXT'.

Append ls_text to lt_text.

*Create object

create object lr_upd_cluster.

*Call method to update text in infotype


 
try.
     
call method lr_upd_cluster->update
       
exporting
          tclas         =
'S'
          pskey         = ls_pskey
          histo         = abap_true          
"'X'
          uname         = sy-uname
          aedtm         = sy-datum
          pgmid         = lw_pgmid            
          text_tab      =
lt_text
          no_auth_check = space.            
"'X'
   
catch   cx_hrpa_violated_assertion.                 "#EC NO_HANDLER
 
endtry.