cancel
Showing results for 
Search instead for 
Did you mean: 

problem while executing BAPI_PRODORD_GET_DETAIL through JAVA using JCo

Former Member
0 Kudos

Hi All,

I am trying to get Production Order details in JAVA program using JCo. Following is the code I have written.

JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS); 

JCoFunction function = destination.getRepository().getFunction("BAPI_PRODORD_GET_DETAIL"); 
if(function == null) 
throw new RuntimeException("BAPI_PRODORD_GET_DETAIL not found in SAP."); 

function.getImportParameterList().setValue("NUMBER", 1067831); 

JCoStructure struct = com.sap.conn.jco.JCo.createStructure(destination.getRepository().getStructureDefinition("BAPI_PP_ORDER_OBJECTS")); 

struct.setValue("HEADER", 'Y'); 
struct.setValue("POSITIONS", 'Y'); 
struct.setValue("SEQUENCES", 'Y'); 
struct.setValue("OPERATIONS", 'Y'); 
struct.setValue("COMPONENTS", 'Y'); 
struct.setValue("PROD_REL_TOOLS", 'Y'); 
struct.setValue("TRIGGER_POINTS", 'Y'); 

function.getImportParameterList().setValue("ORDER_OBJECTS", struct); 
function.getImportParameterList().setValue("COLLECTIVE_ORDER",'Y'); 


try 
{ 
function.execute(destination); 
} 
catch(AbapException e) 
{ 
System.out.println(e.toString()); 
return; 
} 
JCoStructure returnStructure = function.getExportParameterList().getStructure("RETURN"); 
if (! (returnStructure.getString("TYPE").equals("") || 
   returnStructure.getString("TYPE").equals("S") || 
   returnStructure.getString("TYPE").equals("W")) ) 
{ 
System.out.println(returnStructure.getString("MESSAGE")); 

} 

JCoTable codes = function.getTableParameterList().getTable("HEADER"); 
int iCnt = codes.getNumRows(); 
System.out.println("No Of Rows " + iCnt); 
int iFldCnt = codes.getNumColumns(); 
JCoMetaData codesMD = codes.getMetaData(); 
for (int i = 0; i < codes.getNumRows(); i++) 
{ 
codes.setRow(i); 

// Display the data 

}

The number which I am passing is a valid production order. When I test this BAPI in SAP gui with same input, it gives back the data but when I try to run this through java I always get the return message as this production order does not exist. Is there anything wrong I am doing?

I am using JCo 3.0

I have tried passing various values to ORDER_HEADER structure. I have tried getting the structure from import parameter list and then setting the values on that itself. Nothing has worked for me.

Thanks,

Dayanand

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

The problem is solved. I just set the order number as string and added 0s before the order number to complete the required length. Also I changed the setting import structure for order header. Each field in the structure should have value as 'X' or ' '

JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS); 
 
JCoFunction function = destination.getRepository().getFunction("BAPI_PRODORD_GET_DETAIL"); 
if(function == null) 
throw new RuntimeException("BAPI_PRODORD_GET_DETAIL not found in SAP."); 
 
function.getImportParameterList().setValue("NUMBER", "000001067831"); 
 
JCoStructure struct = com.sap.conn.jco.JCo.createStructure(destination.getRepository().getStructureDefinition("BAPI_PP_ORDER_OBJECTS")); 
 
struct.setValue("HEADER", 'X'); 
struct.setValue("POSITIONS", 'X'); 
struct.setValue("SEQUENCES", 'X'); 
struct.setValue("OPERATIONS", 'X'); 
struct.setValue("COMPONENTS", 'X'); 
struct.setValue("PROD_REL_TOOLS", 'X'); 
struct.setValue("TRIGGER_POINTS", 'X'); 
 
function.getImportParameterList().setValue("ORDER_OBJECTS", struct); 
function.getImportParameterList().setValue("COLLECTIVE_ORDER",'X'); 
 
 
try 
{ 
function.execute(destination); 
} 
catch(AbapException e) 
{ 
System.out.println(e.toString()); 
return; 
} 
JCoStructure returnStructure = function.getExportParameterList().getStructure("RETURN"); 
if (! (returnStructure.getString("TYPE").equals("") || 
   returnStructure.getString("TYPE").equals("S") || 
   returnStructure.getString("TYPE").equals("W")) ) 
{ 
System.out.println(returnStructure.getString("MESSAGE")); 
 
} 
 
JCoTable codes = function.getTableParameterList().getTable("HEADER"); 
int iCnt = codes.getNumRows(); 
System.out.println("No Of Rows " + iCnt); 
int iFldCnt = codes.getNumColumns(); 
JCoMetaData codesMD = codes.getMetaData(); 
for (int i = 0; i < codes.getNumRows(); i++) 
{ 
codes.setRow(i); 
 
// Display the data 
 
}

Regards,

Dayanand