Tip

Scramble sensitive HR data in test-environments

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.
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                   *
*    

    Requires Free Membership to View

* * Inputs : N/A * * Includes : N/A * * Functions : N/A * * Modifications: * * DATE PROGRAMMER CORR# DESCRIPTION * * 09/26/03 Mike Arnold DV2K906063 New Program * ************************************************************************ TABLES: pernr. INFOTYPES: 0002, 0006, 0008, 0014, 0015, 0025, 0077. 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. DO. CALL FUNCTION 'RANDOM_P' EXPORTING rnd_min = -3650 rnd_max = 3650 IMPORTING rnd_value = l_value. * 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. CALL FUNCTION 'HR_INFOTYPE_OPERATION' EXPORTING infty = p_pskey-infty number = p_pskey-pernr subtype = p_pskey-subty objectid = p_pskey-objps lockindicator = p_pskey-sprps validityend = p_pskey-endda validitybegin = p_pskey-begda recordnumber = p_pskey-seqnr record = p_nnnn operation = p_mode * TCLAS = 'A' * DIALOG_MODE = '0' * NOCOMMIT = * VIEW_IDENTIFIER = * SECONDARY_RECORD = IMPORTING return = wa_return key = wa_record_key. IF wa_return-type = 'E'. WRITE:/ p_pskey, wa_return-message. ENDIF. ENDFORM. " UPDATE_INFOTYPE *&---------------------------------------------------------------------* *& 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. DO. CALL FUNCTION 'RANDOM_P' EXPORTING rnd_min = '0.80' rnd_max = '1.20' IMPORTING rnd_value = p_multiplier. * Adjust the number by at least 3% IF p_multiplier < '0.97' OR p_multiplier > '1.03'. EXIT. ENDIF. ENDDO. ENDFORM. " GET_RANDOM_NUMBER

This was first published in October 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.