BAPI_PERSDATA_CHANGE to update user data using SAP JCo 3

927 views Asked by At

I'm using the following code snippet. The goal is to update the user lastname firstname and co using the BAPI_PERSDATA_CHANGE bapi. But somehow it's not working, I tried a lot of possibilities but it's not working. The message to the function related to BAPI_PERSDATA_CHANGE is:

No data stored for 0002 in the selected period

I'm using the following code

public boolean writeData(long id, HashMap<String, String>  userData) throws Exception{
    String DST1 = "ABAP_AS";
    JCoDestination dest = JCoDestinationManager.getDestination(DST1);
    JCoFunctionTemplate template = dest.getRepository().getFunctionTemplate("BAPI_PERSDATA_CHANGE");
    JCoFunction jcoFunction = template.getFunction();
    jcoFunction.getImportParameterList().setValue("EMPLOYEENUMBER", id);
    //jcoFunction.getImportParameterList().setValue("SUBTYPE", "002");
    //jcoFunction.getImportParameterList().setValue("OBJECTID", "");
    //jcoFunction.getImportParameterList().setValue("LOCKINDICATOR", "");
    jcoFunction.getImportParameterList().setValue("VALIDITYBEGIN", "19570101"); //"1994-04-24");
    jcoFunction.getImportParameterList().setValue("VALIDITYEND", "99991231");
    jcoFunction.getImportParameterList().setValue("RECORDNUMBER", "000");
    jcoFunction.getImportParameterList().setValue("FIRSTNAME", "FOfie modifier");
    JCoFunction jCoFunction1 = dest.getRepository().getFunctionTemplate("BAPI_TRANSACTION_COMMIT").getFunction();
    JCoFunction BAPI_EMPLOYEE_DEQUEUE = dest.getRepository().getFunction("BAPI_EMPLOYEE_DEQUEUE");
    BAPI_EMPLOYEE_DEQUEUE.getImportParameterList().setValue("NUMBER", id);
    jcoFunction.execute(dest);
    jCoFunction1.execute(dest);
    BAPI_EMPLOYEE_DEQUEUE.execute(dest);
    JCoContext.end(dest);
    return false;
}

Am I missing something ? Or doing something wrong ?

2

There are 2 answers

0
Jagger On

The problem is exactly described in the error message.

No data stored for 0002 in the selected period

means that there is no data for the infotype 0002 for the period given in the parameters VALIDITYBEGIN and VALIDITYEND hence there is nothing to be updated.

Ensure that the data for the aforementioned infotype is provided for the EMPLOYEENUMBER in the requested period of time.

0
Lanzelot On

The line

JCoContext.begin(dest);

is missing. Therefore the execution of BAPI_PERSDATA_CHANGE and of BAPI_TRANSACTION_COMMIT will happen in two different ABAP sessions...