cancel
Showing results for 
Search instead for 
Did you mean: 

How to Test JCO Connections

Former Member
0 Kudos

Hello,

I am trying to create a unit test class that can test if a JCO connection is established. How can I do this programmatically? Thanks.

Also, Can I also create a test for the BAPI's I get from the JCO connection?

regards,

arnold

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

May be this code snippet will help you.

/*

  • Created on Oct 29, 2007

*

  • To change the template for this generated file go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

package com.psft;

import com.sap.mw.jco.IRepository;

import com.sap.mw.jco.JCO;

/**

  • @author BALU

*

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

public class Test

{

static final String SID = "EC6"; //system ID used throughout the example

IRepository repository; //the repository we gonna be using

public Test() {

try{

// Add a connection pool for the specified system

JCO.addClientPool(SID, //alias for this pool

10, //max. number of connections

"800", //SAP client

"userid", //userid

"password", //password

"EN", //language

"host", //host name

"01" //system number

);

// Create a new repository

repository = JCO.createRepository("MYRepository", SID);

} catch(JCO.Exception ex) {

System.out.println("Caught an exception: \n" + ex);

}//try

}

public void salesOrders() {

JCO.Client client = null;

try{

// Get a function template from the repository

System.out.println("start");

JCO.Function function = repository.getFunctionTemplate(

"BAPI_SALESORDER_GETLIST").getFunction();

// Fill in input parameters

JCO.ParameterList input = function.getImportParameterList();

input.setValue("0000001200", "CUSTOMER_NUMBER" );

input.setValue("1000", "SALES_ORGANIZATION");

input.setValue("0", "TRANSACTION_GROUP" );

// Get a client from the pool

client = JCO.getClient(SID);

// Execute function the remote system

client.execute(function);

// Print return message

JCO.Structure ret=function.getExportParameterList().getStructure("RETURN");

System.out.println("RETURN MESSAGE: " + ret.getString("MESSAGE"));

// Get a reference to the table which contains the orders

JCO.Table orders=function.getTableParameterList().getTable("SALES_ORDERS");

// Print results

if(orders.getNumRows() > 0) {

// Loop over all rows

do{

// Loop over all columns in the current row

for(JCO.FieldIterator e = orders.fields(); e.hasMoreElements();) {

JCO.Field field = e.nextField();

System.out.println(field.getName() + ":\t" + field.getString());

}//for

} while(orders.nextRow());

} else{

System.out.println("No results found");

}//if

} catch(Exception ex) {

System.out.println("Caught an exception: " + ex);

} finally{

// Always release client !!!

JCO.releaseClient(client);

}//try

}

public static void main(String[] args)

{

Test quicky= new Test();

quicky.salesOrders();

}

}

Message was edited by:

Armin Reichert

Former Member
0 Kudos

Hello Bala,

This is great. Thanks.

regards,

arnold

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi arnold

Refer this blog for Dynamic Jco creation and testing.

/people/anilkumar.vippagunta2/blog/2007/02/06/dynamic-jco-creation

Regards

Ayyapparaj