Some changes have also been made with the new JCo API in the area of the metadata model.
The most important new feature is based on separating the data container classes for structures and tables. JCo structure und JCo table were previously assigned to a common parent class. In the new API, structure and table metadata is assigned to two different metadata type to avoid any confusion. As a result of this separation, each Record
and every ParameterList
has a reference to a metadata object of its own.
With the new JCo API, metadata objects contains both Unicode and non-Unicode information. This helps to avoid any errors when configuring the Repository.
Note
It is of coruse still forbidden for the general configuration of the Repository, for example, it shoul dbe strictly avoided that different functions have the same name in different systems.
Only one object is stored in the memory for a specific metadata layout, this object references the corresponding tables and structures. This reduces the memory consumption, particularly for nested tables.
A consequence of these changes is that specific metadata operations (for example, addinfo()
) for record and list objects are no longer possible.
The method ParameterList.appendValue()
also no longer exists.
However, it is still possible to create JCoFunction
and its JcoParameterLists
on the fly.
Additionally, it is now possible to lock a metadata object after you have created it to avoid any unwanted changes.
The following activities are only relevant if you want to use an application with static metadata or with metadata-relevant APIs.
Perform the required changes in your code to adapt the metadata model.
The following examples show the differences between JCo 2.x and 3.0 in three different areas:
Retrieving metadata when only the data container is available
Creating a ParameterList
on the fly.
Setting Up Static Metadata
Syntax
JCo 2.x
JCO.Function function = template.getFunction();
JCO.ParameterList exports=function.getExportParameterList();
for (int i=0; i<exports.getFieldCount(); i++)
System.out.println("Parameter: " + exports.getName(i) +
" length " + exports.getLength(i) +
" is " + (exports.isOptional(i)?"":"not ") + "optional");
JCO.ParameterList tables=function.getTableParameterList();
JCO.Table theTable = tables.getTable("THE_TABLE");
for (int i=0; i<theTable.getFieldCount(); i++)
System.out.println("Field: " + theTable.getName(i) +
" length " + theTable.getLength(i) +
" offset " + theTable.getOffset(i));
System.out.println("Table length: " + theTable.getTabLength());
Syntax
JCo 3.0
JCoFunction function = template.getFunction();
JCoParameterList exports=function.getExportParameterList();
JCoListMetaData listMetaData=exports.getListMetaData();
for (int i=0; i< listMetaData.getFieldCount(); i++)
System.out.println("Parameter: " + listMetaData.getName(i) +
" length " + listMetaData.getByteLength(i) +
" is " + (listMetaData.isOptional(i)?"":"not ") + "optional");
JCoParameterList tables=function.getTableParameterList();
JCoTable theTable = tables.getTable("THE_TABLE");
JCoRecordMetaData recordMetaData = theTable.getRecordMetaData();
for (int i=0; i< recordMetaData.getFieldCount(); i++)
System.out.println("Field: " + recordMetaData.getName(i) +
" length " + recordMetaData.getByteLength(i) +
" offset " + recordMetaData.getByteOffset(i));
System.out.println("Table length: " + recordMetaData.getRecordLength());
Syntax
JCo 2.x
JCO.ParameterList imports = new JCO.ParameterList();
//no exports, tables and exceptions for this function
JCO.Function function = new JCO.Function("JCO_HELLO_WORLD", imports, null, null);
imports.appendValue("PARAM", JCO.TYPE_CHAR, 30, "Hello World!");
Syntax
JCo 3.0
JCoListMetaData importsMeta = JCo.createParameterList();
importsMeta.add("PARAM", JCoMetaData.TYPE_CHAR, 30, 60, 0, null, null, 0, null, null);
importsMeta.lock();
//no exports, changings, tables and exceptions for this function
JCoFunction function = JCo.createFunctionTemplate("JCO_HELLO_WORLD", imports, null,
null, null, null).getFunction();
JCoParameterList imports = function.getImportParameterList();
imports.setValue("PARAM", "Hello World!");
Syntax
JCo 2.x
JCO.MetaData bapiReturnUC = new JCO.MetaData("BAPIRETURN", 9);
JCO.MetaData bapiReturn = new JCO.MetaData("BAPIRETURN", 9);
JCO.MetaData companyListUC = new JCO.MetaData("BAPI0014_1", 2);
JCO.MetaData companyList = new JCO.MetaData("BAPI0014_1", 2);
bapiReturnUC.addInfo("TYPE", IMetaData.TYPE_CHAR, 1, 2, 0, 0, null, null, 0,
null, null);
bapiReturnUC.addInfo("CODE", IMetaData.TYPE_CHAR, 5, 10, 2, 0, null, null, 0,
null, null);
bapiReturnUC.addInfo("MESSAGE", IMetaData.TYPE_CHAR, 220, 440, 12, 0, null, null, 0,
null, null);
bapiReturnUC.addInfo("LOG_NO", IMetaData.TYPE_NUM, 20, 40, 452, 0, null, null, 0,
null, null);
bapiReturnUC.addInfo("LOG_MSG_NO", IMetaData.TYPE_CHAR, 6, 12, 492, 0, null, null, 0,
null, null);
bapiReturnUC.addInfo("MESSAGE_V1", IMetaData.TYPE_CHAR, 50, 100, 504, 0, null, null, 0,
null, null);
bapiReturnUC.addInfo("MESSAGE_V2", IMetaData.TYPE_CHAR, 50, 100, 604, 0, null, null, 0,
null, null);
bapiReturnUC.addInfo("MESSAGE_V3", IMetaData.TYPE_CHAR, 50, 100, 704, 0, null, null, 0,
null, null);
bapiReturnUC.addInfo("MESSAGE_V4", IMetaData.TYPE_CHAR, 50, 100, 804, 0, null, null, 0,
null, null);
bapiReturnUC.setTabLength(904);
bapiReturn.addInfo("TYPE", IMetaData.TYPE_CHAR, 1, 1, 0, 0, null, null, 0,
null, null);
bapiReturn.addInfo("CODE", IMetaData.TYPE_CHAR, 5, 5, 1, 0, null, null, 0,
null, null);
bapiReturn.addInfo("MESSAGE", IMetaData.TYPE_CHAR, 220, 220, 6, 0, null, null, 0,
null, null);
bapiReturn.addInfo("LOG_NO", IMetaData.TYPE_NUM, 20, 20, 226, 0, null, null, 0,
null, null);
bapiReturn.addInfo("LOG_MSG_NO", IMetaData.TYPE_CHAR, 6, 6, 246, 0, null, null, 0,
null, null);
bapiReturn.addInfo("MESSAGE_V1", IMetaData.TYPE_CHAR, 50, 50, 252, 0, null, null, 0,
null, null);
bapiReturn.addInfo("MESSAGE_V2", IMetaData.TYPE_CHAR, 50, 50, 302, 0, null, null, 0,
null, null);
bapiReturn.addInfo("MESSAGE_V3", IMetaData.TYPE_CHAR, 50, 50, 352, 0, null, null, 0,
null, null);
bapiReturn.addInfo("MESSAGE_V4", IMetaData.TYPE_CHAR, 50, 50, 402, 0, null, null, 0,
null, null);
bapiReturn.setTabLength(452);
companyListUC.addInfo("COMPANY", IMetaData.TYPE_CHAR, 6, 12, 0, 0, null, null, 0,
null, null);
companyListUC.addInfo("NAME1", IMetaData.TYPE_CHAR, 30, 60, 12, 0, null, null, 0,
null, null);
companyListUC.setTabLength(72);
companyList.addInfo("COMPANY", IMetaData.TYPE_CHAR, 6, 6, 0, 0, null, null, 0, null,
null);
companyList.addInfo("NAME1", IMetaData.TYPE_CHAR, 30, 30, 6, 0, null, null, 0, null,
null);
companyList.setTabLength(36);
JCO.MetaData exportsMetaUC=new JCO.MetaData("EXPORTS", 1);
exportsMetaUC.addInfo("RETURN", IMetaData.TYPE_STRUCTURE, 452, 904, 0, 0, null, null, 0,
bapiReturnUC, null);
JCO.MetaData exportsMeta=new JCO.MetaData("EXPORTS", 1);
exportsMeta.addInfo("RETURN", IMetaData.TYPE_STRUCTURE, 452, 452, 0, 0, null, null, 0,
bapiReturn, null);
JCO.MetaData tablesMetaUC=new JCO.MetaData("TABLES", 1);
tablesMetaUC.addInfo("COMPANY_LIST", IMetaData.TYPE_TABLE, 36, 72, 0, 0, null, null, 0,
companyListUC, null);
JCO.MetaData tablesMeta=new JCO.MetaData("TABLES", 1);
tablesMeta.addInfo("COMPANY_LIST", IMetaData.TYPE_TABLE, 36, 36, 0, 0, null, null, 0,
companyList, null);
JCO.Client client = JCO.getClient("FOO");
try
{
client.connect();
boolean isUnicode = client.getAttributes().getPartnerBytesPerChar()==2;
JCO.Function bapiCompanyGetList=null;
if (isUnicode)
bapiCompanyGetList=JCO.createFunction("BAPI_COMPANY_GETLIST", null,
JCO.createParameterList(exportsMetaUC),
JCO.createParameterList(tablesMetaUC));
else
bapiCompanyGetList=JCO.createFunction("BAPI_COMPANY_GETLIST", null,
JCO.createParameterList(exportsMeta),
JCO.createParameterList(tablesMeta));
client.execute(bapiCompanyGetList);
JCO.ParameterList tables= bapiCompanyGetList.getTableParameterList();
JCO.Table companies=tables.getTable("COMPANY_LIST");
for (int i=0; i<companies.getNumRows(); i++)
{
companies.setRow(i);
System.out.println(companies.getString("COMPANY")+
": "+companies.getString("NAME1"));
}
}
catch(Exception e)
{
System.err.println("Exception occured: "+e.toString());
}
finally
{
JCO.releaseClient(client);
}
Syntax
JCo 3.0
JCoRecordMetaData bapiReturn = JCo.createRecordMetaData("BAPIRETURN", 9);
JCoRecordMetaData companyList = JCo.createRecordMetaData("BAPI0014_1", 2);
bapiReturn.add("TYPE", JCoMetaData.TYPE_CHAR, 1, 0, 2, 0, 0, null, null,
null);
bapiReturn.add("CODE", JCoMetaData.TYPE_CHAR, 5, 1, 10, 2, 0, null, null,
null);
bapiReturn.add("MESSAGE", JCoMetaData.TYPE_CHAR, 220, 6, 440, 12, 0, null, null,
null);
bapiReturn.add("LOG_NO", JCoMetaData.TYPE_NUM, 20, 226, 40, 452, 0, null, null,
null);
bapiReturn.add("LOG_MSG_NO", JCoMetaData.TYPE_CHAR, 6, 246, 12, 492, 0, null, null,
null);
bapiReturn.add("MESSAGE_V1", JCoMetaData.TYPE_CHAR, 50, 252, 100, 504, 0, null, null,
null);
bapiReturn.add("MESSAGE_V2", JCoMetaData.TYPE_CHAR, 50, 302, 100, 604, 0, null, null,
null);
bapiReturn.add("MESSAGE_V3", JCoMetaData.TYPE_CHAR, 50, 352, 100, 704, 0, null, null,
null);
bapiReturn.add("MESSAGE_V4", JCoMetaData.TYPE_CHAR, 50, 402, 100, 804, 0, null, null,
null);
bapiReturn.setRecordLength(452, 904);
bapiReturn.lock();
companyList.add("COMPANY", IMetaData.TYPE_CHAR, 6, 0, 12, 0, 0, null, null, 0, null,
null);
companyList.add("NAME1", IMetaData.TYPE_CHAR, 30, 6, 60, 12, 0, null, null, 0, null,
null);
companyList.setRecordLength(36, 72);
companyList.lock();
JCoListMetaData exportsMeta=JCo.createListMetaData("EXPORTS", 1);
exportsMeta.add("RETURN", JCoMetaData.TYPE_STRUCTURE, 452, 904, 0, null, null, 0,
bapiReturn, null);
JCoListMetaData tablesMeta=JCo.createListMetaData("TABLES", 1);
tablesMeta.add("COMPANY_LIST", JCoMetaData.TYPE_TABLE, 36, 72, 0, null, null, 0,
companyList, null);
JCoFunctionTemplate bapiCompanyGetListTemplate=JCo.createFunctionTemplate("BAPI_COMPANY_GETLIST",
null, exportsMeta, null, tablesMeta, null);
try
{
JCoDestination foo=JCoDestinationManager.getDestination("FOO");
JCO.Function bapiCompanyGetList=bapiCompanyGetListTemplate.getFunction();
bapiCompanyGetList.execute(foo);
JCoParameterList tables= bapiCompanyGetList.getTableParameterList();
JCoTable companies=tables.getTable("COMPANY_LIST");
for (int i=0; i<companies.getNumRows(); i++)
{
conmpanies.setRow(i)
System.out.println(companies.getString("COMPANY")+
": "+companies.getString("NAME1"));
}
}
catch(Exception e)
{
System.err.println("Exception occured: "+e.toString());
}