cancel
Showing results for 
Search instead for 
Did you mean: 

JCO3 - execute BAPI but nothing got changed in crm

Former Member
0 Kudos

Hello,

I have a problem with using a BAPI with the JCO adapter.

We would like to trigger the BAPI ZCRM_MKTBP_CHANGE_BP. The BAPI is only an extention of CRM_MKTBP_CHANGE_BP to make it work with remote access. I can start this BAPI at the CRM manually without problems and the marketing attributes we would like to change got also changed.

Now I tried to trigger it with JCO.

The code looks like this:

Initialization:


context.tableOrViewName = "TM1_IMPORT_RETAILSALES";

context.tableOrViewSchema = "TM1_MEMCLUSTERING";

context.sapProgramm = "ZCRM_MKTBP_CHANGE_BP";

//context for table

JCoRecordMetaData rmd = com.sap.conn.jco.JCo.createRecordMetaData("RecordMetaData");

context.recordMetaData = rmd;

String nameForDestination = "ABAP_AS_WITHOUT_POOL";

context.destinationName = nameForDestination;

//create connection information

        ...

//create destination file

File destCfg = new File(nameForDestination+".jcoDestination");

            try{

                    FileOutputStream fos = new FileOutputStream(destCfg, false);

                    connectProperties.store(fos, "for tests only !");

JCoDestination destination = JCoDestinationManager.getDestination(context.destinationName);

//context for table

JCoRecordMetaData rmd = com.sap.conn.jco.JCo.createRecordMetaData("RecordMetaData");

rmd.add("ATNAME", 29, 10, 10, 20, 20);

rmd.add("ATFLV", 29, 20, 20, 30, 30);

rmd.add("ATWRT", 29, 30, 30, 40, 40);

rmd.lock();

context.recordMetaData = rmd;

                    fos.close();

            } catch (Exception e){

                throw new RuntimeException("Unable to create the destination files", e);

            }

Execute BAPI and Transaction Commit:


JCoDestination destination = JCoDestinationManager.getDestination(context.destinationName);

JCoFunction function = destination.getRepository().getFunction(context.sapProgramm);

      

if(function == null)

    throw new RuntimeException(context.sapProgramm + " not found in SAP.");

       

//create table for parameter

JCoTable table = com.sap.conn.jco.JCo.createTable((JCoRecordMetaData)context.recordMetaData);

table.appendRow();

table.setValue("ATNAME", input_row.ATNAME);

table.setValue("ATFLV", input_row.UMS);

table.setValue("ATWRT", input_row.UMS);

       

       

//Set parameters for function

function.getImportParameterList().setValue("IV_PROFILE_TEMPLATE_ID", "UMSATZ");

function.getImportParameterList().setValue("IV_BP_GUID", input_row.PARTNER_GUID);

function.getImportParameterList().setValue("IV_PARTNER", input_row.BUSINESSPARTNER);

function.getTableParameterList().setValue("IT_IMP_SELTAB", table);

//Execute function     

try {

    function.execute(destination);

} catch(AbapException e) {

     System.out.println(e.toString());

     return;

}

//Transaction Commit

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

try {

    commit.execute(destination);

} catch(AbapException e) {

     System.out.println(e.toString());

     return;

}

With executing the BAPI BAPI_TRANSACTION_COMMIT the other BAPI should be executed at the CRM and the marketing attributes should be changed. But nothing happened. I also don't get any error message.

Does I have to do any additionally or is anything wrong with my code?

Thanks in advance.

Best Regards

Stefan

Accepted Solutions (1)

Accepted Solutions (1)

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Stefan,

if you have a call sequence where the follow-up calls rely on the RFC context and LUW of a previous call, you have to create a stateful context and nest your RFC call sequence between a JCoContext.begin(destination) and a JCoContext.end(destination) statement.

Please see the JCo JavaDoc at class JCoContext for further details.

Best regards,
Stefan

Former Member
0 Kudos

Hi Stefan,

I added the statements JCoContext.begin(destination) and JCoContext.end(destination) before and after my sequence of functions. But unfortunally it doesn't change anything. Again, I don't get any error messages and the data are not changed.


It now looks like this:

//Execute function

try {

    JCoContext.begin(destination);

function.execute(destination);
commit.execute(destination);

} catch(AbapException abapE) {

System.out.println(abapE.toString());
return;

} catch (JCoException jcoE){

     System.out.println(jcoE.toString());

return;

} catch (Exception ex){

     System.out.println(ex.toString());

return;

} finally {

     JCoContext.end(destination);

}


Any other ideas what the problem can be?


Best Regards

Stefan

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

To eliminate further possible errors, I recommend to remove most of your initialization stuff. Do not try to define static RFC metadata on your own, in most cases the self-made definitions are wrong!

So don't create JCoRecordMetaData objects and don't create JCoTable objects.

Just use what the standard dynamic JCoRepository returns, e.g. if you call JCoRepository.getFunction("ZCRM_MKTBP_CHANGE_BP") the RFC metadata is queried from the ABAP back-end and all parameter and table objects are already there in the returned JCoFunction object. Just use them, For example you can get the empty table with JCoFunction.getTableParameterList().getTable("IT_IMP_SELTAB") and work with it.

Best regards,

Stefan

Former Member
0 Kudos

Thank you :-). I eliminatet the JCoRecordMetaData part and now it works fine.

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Stefan,

I'm glad to hear that.

thanks for your feedback.

Best regards,

Stefan

Answers (0)