cancel
Showing results for 
Search instead for 
Did you mean: 

How to update last name , email , phone etc of an employee using BAPI in SAP HCM?

former_member213644
Participant
0 Kudos

Hi SAP Community,

I am trying to update last name, email , phone etc of an employee using the BAPI (BAPI_PERSDATA_CHANGE). But this Bapi is asking for some mandatory value

like 1) Employee number - I am providing a  valid value

       2) SUBTYPE - What can be the possible value for this?  I am giving 002

      3) OBJECTID - What can be the possible value for this? I am giving O

      4) LOCKINDICATOR - What can be the possible value for this? I am giving X

      

I am not aware what value I need to provide in these arguments, So i am getting an exception "009No data stroed for 002 in the selected period".

I dont want to update employee record using Transaction PA30. I only want to use BAPI.

The reason to use BAPI is , I want to call the same from JAVA code to update records.

Any help is highly appreciated.

Thanks

Riju Bhasker

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

please check the below links.. Make sure of Enqueue/Dequeue of Emp. no. and BAPI_Commit_Transaction.

former_member213644
Participant
0 Kudos

Hi Soumyasanto,

Thanks for your reply. Actually i had gone through all these links already, but was of no help to me.

As the values are not getting changed, and I am getting error.

Is there a way to directly update records in database of hr? Or if you have any sample java code changing lastname, email , phone of records present in HR then it will be great help to me.

Thanks

Riju Bhasker

Former Member
0 Kudos

Hi Riju,

BAPI_PERSDATA_CHANGE is used for changing the infotype 002, where subtype parameter is used for any subtype used in 002 and may that's the reason you are getting that error. Also I think you store email, phone etc in 105 not in 002 but first you may try the below solution.

use BAPI_EMPLOYEE_GETDATA to first fetch the data and using those parameters then use your FM to update.

Reg

Soumya

former_member213644
Participant
0 Kudos

Hi Soumya,

Thanks for your reply.

I will share my java code with you, I tried to change only last name of an employee.

Even the the things are not working.

In case of BAPI_PERSDATA_CHANGE the infotype is 0002 which dont have any subtype. Is my understnanding correct?

Also I am not providing any values for "OBJECTID","LOCKINDICATOR". Do we need to provide any value to them?

In the code below i tried to use 4 bapis in sequence

BAPI_EMPLOYEE_ENQUEUE

BAPI_PERSDATA_CHANGE

BAPI_TRANSACTION_COMMIT

BAPI_EMPLOYEE_DEQUEUE


This is giving no exceptions, even then the values are not getting changed on server.

My code below

/*****************************************************************************************************/

public void modifyRecordLastnameUsingBapiPersDataChange()  throws Exception

    {

    System.out.println("inside bapi pers data change");
    JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME1);
    JCoFunction bloqFunction = destination.getRepository().getFunction("BAPI_EMPLOYEE_ENQUEUE");
    bloqFunction.getImportParameterList().setValue("NUMBER", "00000003");
 
   
   

JCoFunction cambFunction = destination.getRepository().getFunction("BAPI_PERSDATA_CHANGE");

System.out.println(cambFunction.getImportParameterList());

cambFunction.getImportParameterList().setValue("EMPLOYEENUMBER", "00000003");//EMPLOYEENUMBER//VALIDITYBEGIN//VALIDITYEND//LASTNAME

cambFunction.getImportParameterList().setValue("SUBTYPE", "");

cambFunction.getImportParameterList().setValue("OBJECTID", "");

cambFunction.getImportParameterList().setValue("LOCKINDICATOR", "");

cambFunction.getImportParameterList().setValue("VALIDITYBEGIN", "19830429");//ENDDA//BEGDA//PERNR//NACHN

cambFunction.getImportParameterList().setValue("VALIDITYEND", "99991231");

cambFunction.getImportParameterList().setValue("RECORDNUMBER", "000");

cambFunction.getImportParameterList().setValue("LASTNAME", "KURAANE");

JCoFunction transctFunction = destination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT");

//transctFunction.execute(destination);

JCoFunction desbFunction = destination.getRepository().getFunction("BAPI_EMPLOYEE_DEQUEUE");

desbFunction.getImportParameterList().setValue("NUMBER", "00000003");

//desbFunction.execute(destination);

   

try {

    JCoContext.begin(destination);

         if (JCoContext.isStateful(destination))

             System.out.println("doing commits");

              bloqFunction.execute(destination);

              cambFunction.execute(destination);

              transctFunction.execute(destination);

              desbFunction.execute(destination);

              System.out.println("done commits");

    } finally {

    JCoContext.end(destination);

    }

    System.out.println("done changes");

    }

//****************************************************************************************

Thanks

Riju Bhasker

GirieshM
Active Contributor
0 Kudos

Hi Vikas,

Can you set a external debugger inside the BAPI and try to find out what went wrong. As you said, there is no need of Object ID hence it is time constraint 1 and no sub types. No need of lock indicator if you havent locked the personnel number for the infotype.

With Regards,

Giriesh M