Posted: Sat Jan 31, 2009 3:57 pm Post subject: Scramble sensitive HR data in test-environments
Author: Michael Arnold
In the event of a restore of production data into your Test / QA environment, you need scramble your sensitive HR data. This program will scramble the employees SSN, date of birth, salaries, bonuses, etc.
The code was written in R/3 4.6B.
Code:
REPORT zhrqaprv.
************************************************************************
* Program Name : ZHRQAPRV *
* Interface ID : N/A *
* Create Date : 09/26/2003 *
* Application : HR *
* Author : Mike Arnold *
* Logical DB : PNP *
* Description : This program will scramble confidential data in *
* a NON-production environment *
* *
* Infotype *
* 0002 Change DOB and SSN *
* 0006 Change BEGDA if it equals DOB *
* 0077 Change BEGDA if it equals DOB *
* 0008 Change Salary
*
* 0014 Change Recurring payments & deductions *
* 0015 Change one-time payments *
* *
* Inputs : N/A *
* Includes : N/A *
* Functions : N/A *
* Modifications: *
* DATE PROGRAMMER CORR# DESCRIPTION *
* 09/26/03 Mike Arnold DV2K906063 New Program *
************************************************************************
DATA: g_gbdat_real TYPE d,
g_gbdat_fake TYPE d,
g_mode TYPE pspar-actio,
g_multiplier TYPE bseg-wrbtr,
g_gbdat_adj TYPE p,
g_salpct_adj TYPE p.
DATA: wa_return TYPE bapireturn1,
wa_record_key TYPE bapipakey,
wa_pskey TYPE pskey.
START-OF-SELECTION.
* Prevent this program from accidentally being run in PRD.
IF sy-sysid = 'PRD'.
MESSAGE a001(z1) WITH 'Program cannot be run in ' sy-sysid.
ENDIF.
GET pernr.
CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
EXPORTING
number = pernr-pernr
IMPORTING
return = wa_return.
IF NOT wa_return IS INITIAL.
WRITE:/ wa_return-message.
EXIT.
ENDIF.
rp-provide-from-last p0002 space pn-begda pn-endda.
MOVE p0002-gbdat TO g_gbdat_real.
PERFORM change_dob USING g_gbdat_real
CHANGING g_gbdat_fake.
* Change the DOB and SSN.
LOOP AT p0002.
MOVE g_gbdat_fake TO p0002-gbdat.
CONCATENATE '999' pernr-pernr+2(6) INTO p0002-perid.
IF p0002-begda = g_gbdat_real.
MOVE g_gbdat_fake TO p0002-begda.
MOVE 'INS' TO g_mode.
ELSE.
MOVE 'MOD' TO g_mode.
ENDIF.
MOVE-CORRESPONDING p0002 TO wa_pskey.
PERFORM update_infotype USING p0002 g_mode wa_pskey.
* If the begin date is later than the original, then the
* old one will be delimited. This must be deleted.
IF g_gbdat_fake > g_gbdat_real.
MOVE g_gbdat_real TO: wa_pskey-begda, p0002-begda.
wa_pskey-endda = g_gbdat_fake - 1.
MOVE wa_pskey-endda TO p0002-endda.
MOVE 'DEL' TO g_mode.
PERFORM update_infotype USING p0002 g_mode wa_pskey.
ENDIF.
ENDLOOP.
* Since BEGDA on 0006 and 0077 is the same as the DOB,
* these need to be changed as well.
LOOP AT p0006
WHERE begda = g_gbdat_real.
MOVE g_gbdat_fake TO p0006-begda.
MOVE 'INS' TO g_mode.
MOVE-CORRESPONDING p0006 TO wa_pskey.
PERFORM update_infotype USING p0006 g_mode wa_pskey.
* If the begin date is later than the original, then the
* old one will be delimited. This must be deleted.
IF g_gbdat_fake > g_gbdat_real.
MOVE g_gbdat_real TO: wa_pskey-begda, p0006-begda.
wa_pskey-endda = g_gbdat_fake - 1.
MOVE wa_pskey-endda TO p0006-endda.
MOVE 'DEL' TO g_mode.
PERFORM update_infotype USING p0006 g_mode wa_pskey.
ENDIF.
ENDLOOP.
LOOP AT p0077
WHERE begda = g_gbdat_real.
MOVE g_gbdat_fake TO p0077-begda.
MOVE 'INS' TO g_mode.
MOVE-CORRESPONDING p0077 TO wa_pskey.
PERFORM update_infotype USING p0077 g_mode wa_pskey.
* If the begin date is later than the original, then the
* old one will be delimited. This must be deleted.
IF g_gbdat_fake > g_gbdat_real.
MOVE g_gbdat_real TO: wa_pskey-begda, p0077-begda.
wa_pskey-endda = g_gbdat_fake - 1.
MOVE wa_pskey-endda TO p0077-endda.
MOVE 'DEL' TO g_mode.
PERFORM update_infotype USING p0077 g_mode wa_pskey.
ENDIF.
ENDLOOP.
* Scramble each salary
LOOP AT p0008.
PERFORM get_random_number CHANGING g_multiplier.
MULTIPLY p0008-ansal BY g_multiplier.
MOVE 'MOD' TO g_mode.
MOVE-CORRESPONDING p0008 TO wa_pskey.
PERFORM update_infotype USING p0008 g_mode wa_pskey.
ENDLOOP.
* Scramble each recurring payment
LOOP AT p0014.
PERFORM get_random_number CHANGING g_multiplier.
MULTIPLY p0014-betrg BY g_multiplier.
MOVE 'MOD' TO g_mode.
MOVE-CORRESPONDING p0014 TO wa_pskey.
PERFORM update_infotype USING p0014 g_mode wa_pskey.
ENDLOOP.
* Scramble each additional payment
LOOP AT p0015.
PERFORM get_random_number CHANGING g_multiplier.
MULTIPLY p0015-betrg BY g_multiplier.
MOVE 'MOD' TO g_mode.
MOVE-CORRESPONDING p0015 TO wa_pskey.
PERFORM update_infotype USING p0015 g_mode wa_pskey.
ENDLOOP.
CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE'
EXPORTING
number = pernr-pernr
IMPORTING
return = wa_return.
END-OF-SELECTION.
WRITE:/ 'Employee data has been scrambled'.
*&---------------------------------------------------------------------*
*& Form CHANGE_DOB
*&---------------------------------------------------------------------*
* Scramble date of birth
*----------------------------------------------------------------------*
* -->P_GBDAT_REAL Real DOB
* <--P_GBDAT_FAKE Fake DOB
*----------------------------------------------------------------------*
FORM change_dob USING p_gbdat_real
CHANGING p_gbdat_fake.
DATA: l_value TYPE bseg-wrbtr,
l_abs_value TYPE bseg-wrbtr.
* This will adjust the persons DOB by at least 90 days
l_abs_value = abs( l_value ).
IF l_abs_value > 90.
EXIT.
ENDIF.
ENDDO.
* Adjust the employee's age by +/- 10 years
p_gbdat_fake = p_gbdat_real + l_value.
ENDFORM. " CHANGE_DOB
*&---------------------------------------------------------------------*
*& Form UPDATE_INFOTYPE
*&---------------------------------------------------------------------*
* Use the BAPI to update the infotypes
*----------------------------------------------------------------------*
* -->P_nnnn Infotype Data
* -->P_MODE Operation (INS, MOD, or DEL)
* -->P_PSKEY Infotype keys
*----------------------------------------------------------------------*
FORM update_infotype USING p_nnnn p_mode p_pskey STRUCTURE pskey.
*&---------------------------------------------------------------------*
*& Form GET_RANDOM_NUMBER
*&---------------------------------------------------------------------*
* Get a random number to multiply by the person's
* salary, bonus, etc...
*----------------------------------------------------------------------*
* <--P_MULTIPLIER Random number
*----------------------------------------------------------------------*
FORM get_random_number CHANGING p_multiplier.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.