cancel
Showing results for 
Search instead for 
Did you mean: 

Problems passing a table to BAPI using JCO

Former Member
0 Kudos

Hello,

I have problems to store information in a table of a bapi.

The bapi works in the following way:

You define one import parameter.

You store ranges for certain values in some of the tables of the bapi (selection criterias).

You execute the bapi and it stores the result in the "EMMA_HDR_TAB" table according to your selection.

Defining the import values works and getting the result table works as well. But, the bapi does not take the selection critierias into account. The result is as if the tables (i.e. BUSINESSPROCESSCODE table) were empty.

If I insert the values and execute it in the se80, everything works fine.

So the problem must be that the bapi does not get the selection criterias. But the table BUSIESSPROCESSCODE has one row with correct values.

Does anybody know this problem and can help me with it?

Any help highly appreciated!

Daniel

ps:

The table with the selection criteria is "BUSINESSPROCESSCODE".

The result table is "EMMA_HDR_TAB".

Here is my code and the output in the console:


import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.JCO;
import com.sap.mw.jco.JCO.ParameterList;

public class SapPlug2 extends Object {
	JCO.Client mConnection;
	JCO.Repository mRepository;

	public SapPlug2() {
		try {
						mConnection =
				JCO.createClient(
					"***",
					"*****",
					"*****",
					null,
					"*****",
					"**");

			mConnection.connect();
			mRepository = new JCO.Repository("mRepo", mConnection);

		
	JCO.Function function = null;

	function = this.createFunction("BAPI_EMMA_HDR_READ");

			
	//	Import Parameters
	JCO.ParameterList input = function.getImportParameterList();
	input.setValue("1", "XPREP");

	ParameterList tables = function.getTableParameterList();
	
        //Inserting the selection criteria in the table		
	JCO.Table bpcode = tables.getTable("BUSINESSPROCESSCODE");
	bpcode.appendRow();
	bpcode.setValue("I", "SIGN");
	bpcode.setValue("EQ", "OPTION");
	bpcode.setValue("EBI00001", "LOW");
	
        //Check whether one row has been appended	
	System.out.println(
			"The table BUSINESSPROCESSCODE has:"
					+ bpcode.getNumRows()
					+ " row(s)");
			
			
	JCO.Table emma_tab = function.getTableParameterList().getTable("EMMA_HDR_TAB");
        
        mConnection.execute(function);
        
        //Check how many rows are in the result table
        //I expect about 390 if the selection has been taken into account and around 4300 if the selection tables are empty
	
        System.out.println("Number of rows in the table EMMA_HDR_TAB:"+ emma_tab.getNumRows());
						mConnection.disconnect();

	} catch (Exception ex) {
		ex.printStackTrace();
			System.exit(1);
	}
	}

	public JCO.Function createFunction(String name) throws Exception {
		try {
			IFunctionTemplate ft =
				mRepository.getFunctionTemplate(name.toUpperCase());
			if (ft == null)
				return null;
			return ft.getFunction();
		} catch (Exception ex) {
			throw new Exception("Problem retrieving JCO.Function object.");
		}
	}

	public static void main(String args[]) {
		SapPlug2 app = new SapPlug2();
	}
}

The console:


The table BUSINESSPROCESSCODE has:1 row(s)
Number of rows in the table EMMA_HDR_TAB:0
Number of rows in the table EMMA_HDR_TAB:4341

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Hi Daniel,

Try to call JCO.Table emma_tab = function.getTableParameterList().getTable("EMMA_HDR_TAB");

after mConnection.execute(function);.

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Hi Maksim,

thank you for your reply.

However, I tried it, but it does not work.


...
System.out.println("Number of rows in the table EMMA_HDR_TAB:" + emma_tab.getNumRows());
			
mConnection.execute(function);

System.out.println("Number of rows in the table EMMA_HDR_TAB:" + emma_tab.getNumRows());
...

result on the console:


Number of rows in the table EMMA_HDR_TAB:0
Number of rows in the table EMMA_HDR_TAB:4341

I expect about 390 rows with the selection and these 4341 if no selection is taken into account.

Any other ideas?

former_member182372
Active Contributor
0 Kudos

Hi Daniel,

Can you debug BAPI? Set a break point and check what BUSINESSPROCESSCODE table contains after JCo call.

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

How can I check what a table contains when the bapi as been called from remote?

So, no I don't know how to debug it in this way.

former_member182372
Active Contributor
0 Kudos

Hi Daniel,

Set breakpoint (ctrlshiftf12) and mark it is external.

Best regards, Maksim Rashhcynski.

Former Member
0 Kudos

Thank you, this hint helped to solve the problem!

Apparently, JCo does not have an equivalent to the ABAP command "move-corresponding". Replacing this command solved the problem. The code above works fine now

Answers (0)