cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI_USER_CHANGE Error

Former Member
0 Kudos

Hi,

I'm calling BAPI_USER_CHANGE function for changing the Basis user details. I'm setting the values to the structures like ADDRESS. But I get this error :

"Trying to access row values in a table which does not have any rows yet"

Here is my code :

-


IFunctionTemplate ftemplate = connector_.getRepository().

getFunctionTemplate(

"BAPI_TRANSACTION_COMMIT");

JCO.Function jcoCommit = ftemplate.getFunction();

JCO.Field commitField = jcoCommit.getImportParameterList().getField(

"WAIT");

commitField.setValue("X");

String id = connector_.createID() ;

Function function = connector_.createFunction(

"BAPI_USER_CHANGE");

tableUser_.setRow(currentUser_);

function.getImportParameterList().

setValue(tableUser_.getString("USERNAME"), "USERNAME");

JCO.Structure detail =

function.getImportParameterList().getStructure("ADDRESSX");

detail.setValue("Mister", "TITLE_P");

detail.setValue("James", "FIRSTNAME");

detail.setValue("Bond", "LASTNAME");

detail.setValue("TEST ", "FUNCTION");

detail.setValue("007", "TEL1_NUMBR");

detail.setValue("james.bond@yahoo.com", "E_MAIL");

connector_.execute(function,id);

//System.out.println(jcoCommit.getExportParameterList().getStructure(

// "RETURN").getString("NUM"));

connector_.execute(jcoCommit,id);

System.out.println(function.getTableParameterList().getTable(

"RETURN").getString("MESSAGE"));

connector_.executeID(id);

-


Thanks in advance,

Mathieu.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

here is my current code :

---

try

{

IFunctionTemplate ftemplate = connector_.getRepository().

getFunctionTemplate(

"BAPI_TRANSACTION_COMMIT");

JCO.Function jcoCommit = ftemplate.getFunction();

JCO.Field commitField = jcoCommit.getImportParameterList().getField(

"WAIT");

commitField.setValue("X");

String id = connector_.createID();

Function function = connector_.createFunction(

"BAPI_USER_CHANGE");

tableUser_.setRow(currentUser_);

function.getImportParameterList().

setValue(tableUser_.getString("USERNAME"), "USERNAME");

IMetaData metaDetail = connector_.getRepository().

getStructureDefinition("BAPIADDR3");

JCO.Structure detail = JCO.createStructure(metaDetail);

function.getImportParameterList().setValue(detail, "ADDRESS");

detail.setValue("James", "FIRSTNAME");

detail.setValue("Bond", "LASTNAME");

connector_.execute(function,id);

connector_.execute(jcoCommit, id);

connector_.executeID(id);

connector_.disconnect();

}

catch (Exception err)

{

System.out.println("error " +err.getMessage());

}

---

There is no error,

but the table in the SAP System doesn't change

Thanks,

SV

Former Member
0 Kudos

Mathieu,

You misread my reply: you have to apdate <b>both</b> structures ADRESS (with values) and ADDRESSX (with flags that corresponding value updated).

Try this


try
{
  IFunctionTemplate ftemplate = 
    connector_
      .getRepository()
        .getFunctionTemplate("BAPI_TRANSACTION_COMMIT");
        
  JCO.Function jcoCommit = ftemplate.getFunction();
  JCO.Field commitField = 
    jcoCommit
      .getImportParameterList()
        .getField("WAIT");
        
  commitField.setValue("X");
  String id = connector_.createID();

  Function function = 
    connector_
      .createFunction("BAPI_USER_CHANGE");

  tableUser_.setRow(currentUser_);

  function
    .getImportParameterList()
      .setValue( tableUser_.getString("USERNAME"), "USERNAME" );

  /* SET ADDRESS VALUES */
  IMetaData metaDetail = connector_.getRepository().
  getStructureDefinition("BAPIADDR3");

  JCO.Structure detail = JCO.createStructure(metaDetail);
  function.getImportParameterList().setValue(detail, "ADDRESS");

  detail.setValue("James", "FIRSTNAME");
  detail.setValue("Bond", "LASTNAME");
  
  /* SET ADDRESS-X FLAGS */
  IMetaData metaDetailX = connector_.getRepository().
  getStructureDefinition("BAPIADDR3X");

  JCO.Structure detailX = JCO.createStructure(metaDetailX);
  function.getImportParameterList().setValue(detailX, "ADDRESSX");

  detailX.setValue('X', "FIRSTNAME");
  detailX.setValue('X', "LASTNAME");
  
  
  connector_.execute(function,id);
  connector_.execute(jcoCommit, id);

  connector_.executeID(id);
  connector_.disconnect();
}
catch (Exception err)
{
  System.out.println("error " +err.getMessage());
}

VS

Message was edited by: Valery Silaev

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Valery,

thank you for your help,

I have now undersanding the diffence between the 2 structures.

Mathieu

Former Member
0 Kudos

Hi Valery,

thank you for your help. I have tried but I have always this error message :

"Trying to access row values in a table which does not have any rows yet"

If I remove the CreateID method and the call to the function "BAPI_TRANSACTION_COMMIT" and put only this code : "connector_.execute(function);"

The message will become :

"Benutzer JAMESBOND wurde geändert."

The problem is that in SAP System (SU01 TCode) the user has not changed. There is no effect in the SAP Table !

Why ?

Thanks Mathieu

Former Member
0 Kudos

Mathieu,

Post your <b>current</b> code version (with my changes applied). Also tell at what line error occured.

VS

Former Member
0 Kudos

Mathieu,

Your code contains more erros than you expect

1. JCo programming error that you mentioned

instead of

JCO.Structure detail =
function.getImportParameterList().getStructure("ADDRESSX");

use this

IMetaData metaDetail 
  = connector_.getRepository().getStructureDefinition("BAPIADDR3X");
JCO.Structure detail = JCO.createStructure( metaDetail );
function.getImportParameterList().setValue( detail, "ADDRESSX");
/* the rest is same */

2. Logical error: you are udating ADDRESSX parameter with values, however according your code you need to update ADDRESS parameter instead (and getStructureDefinition("BAPIADDR3") correspondingly

). ADDRESSX, on other hand must be updated with flags rather then values!.

Use SAP GUI, run transaction SE37, enter BAPI_USER_CHANGE as funcion name and click "Display". Read related parameters description.

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com