Show TOC

Procedure documentationChanges to the Metadata Model Locate this document in the navigation structure

 

Some changes have also been made with the new JCo API in the area of the metadata model.

Separating Metadata Types

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.

Enhancement of Metadata Objects

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 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.

End of the note.
Reducing Metadata Objects in the Memory

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.

Consequences
  • 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.

Prerequisites

The following activities are only relevant if you want to use an application with static metadata or with metadata-relevant APIs.

Procedure

Perform the required changes in your code to adapt the metadata model.

Example

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

Retrieving Metadata

Syntax Syntax

JCo 2.x

  1. JCO.Function function = template.getFunction();
  2. JCO.ParameterList exports=function.getExportParameterList();
  3. for (int i=0; i<exports.getFieldCount(); i++)
  4.     System.out.println("Parameter: " + exports.getName(i) + 
  5.                        " length " + exports.getLength(i) +
  6.                        " is " + (exports.isOptional(i)?"":"not ") + "optional");
  7. JCO.ParameterList tables=function.getTableParameterList();
  8. JCO.Table theTable = tables.getTable("THE_TABLE");
  9. for (int i=0; i<theTable.getFieldCount(); i++)
  10.     System.out.println("Field: " + theTable.getName(i) + 
  11.                        " length " + theTable.getLength(i) +
  12.                        " offset " + theTable.getOffset(i));
  13. System.out.println("Table length: " + theTable.getTabLength());
End of the code.

Syntax Syntax

JCo 3.0

  1. JCoFunction function = template.getFunction();
  2. JCoParameterList exports=function.getExportParameterList();
  3. JCoListMetaData listMetaData=exports.getListMetaData();
  4. for (int i=0; i< listMetaData.getFieldCount(); i++)
  5.     System.out.println("Parameter: " + listMetaData.getName(i) + 
  6.                        " length " + listMetaData.getByteLength(i) +
  7.                        " is " + (listMetaData.isOptional(i)?"":"not ") + "optional");
  8. JCoParameterList tables=function.getTableParameterList();
  9. JCoTable theTable = tables.getTable("THE_TABLE");
  10. JCoRecordMetaData recordMetaData = theTable.getRecordMetaData();
  11. for (int i=0; i< recordMetaData.getFieldCount(); i++)
  12.     System.out.println("Field: " + recordMetaData.getName(i) + 
  13.                        " length " + recordMetaData.getByteLength(i) +
  14.                        " offset " + recordMetaData.getByteOffset(i));
  15. System.out.println("Table length: " + recordMetaData.getRecordLength());
End of the code.
ParameterList on the fly

Syntax 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!");

End of the code.

Syntax Syntax

JCo 3.0

  1. JCoListMetaData importsMeta = JCo.createParameterList();
  2. importsMeta.add("PARAM", JCoMetaData.TYPE_CHAR, 30, 60, 0, null, null, 0, null, null);
  3. importsMeta.lock();
  4. //no exports, changings, tables and exceptions for this function
  5. JCoFunction function = JCo.createFunctionTemplate("JCO_HELLO_WORLD", imports, null,
  6.                                                    null, null, null).getFunction();
  7. JCoParameterList imports = function.getImportParameterList();
  8. imports.setValue("PARAM", "Hello World!");
End of the code.
Static Metadata

Syntax Syntax

JCo 2.x

  1. JCO.MetaData bapiReturnUC = new JCO.MetaData("BAPIRETURN", 9);
  2. JCO.MetaData bapiReturn = new JCO.MetaData("BAPIRETURN", 9);
  3. JCO.MetaData companyListUC = new JCO.MetaData("BAPI0014_1", 2);
  4. JCO.MetaData companyList = new JCO.MetaData("BAPI0014_1", 2);
  5. bapiReturnUC.addInfo("TYPE",       IMetaData.TYPE_CHAR,   1,   2,   0, 0, null, null, 0, 
  6.                      null, null);
  7. bapiReturnUC.addInfo("CODE",       IMetaData.TYPE_CHAR,   5,  10,   2, 0, null, null, 0, 
  8.                      null, null);
  9. bapiReturnUC.addInfo("MESSAGE",    IMetaData.TYPE_CHAR, 220, 440,  12, 0, null, null, 0,
  10.                      null, null);
  11. bapiReturnUC.addInfo("LOG_NO",     IMetaData.TYPE_NUM,   20,  40, 452, 0, null, null, 0, 
  12.                      null, null);
  13. bapiReturnUC.addInfo("LOG_MSG_NO", IMetaData.TYPE_CHAR,   6,  12, 492, 0, null, null, 0, 
  14.                      null, null);
  15. bapiReturnUC.addInfo("MESSAGE_V1", IMetaData.TYPE_CHAR,  50, 100, 504, 0, null, null, 0, 
  16.                      null, null);
  17. bapiReturnUC.addInfo("MESSAGE_V2", IMetaData.TYPE_CHAR,  50, 100, 604, 0, null, null, 0, 
  18.                      null, null);
  19. bapiReturnUC.addInfo("MESSAGE_V3", IMetaData.TYPE_CHAR,  50, 100, 704, 0, null, null, 0, 
  20.                      null, null);
  21. bapiReturnUC.addInfo("MESSAGE_V4", IMetaData.TYPE_CHAR,  50, 100, 804, 0, null, null, 0, 
  22.                      null, null);
  23. bapiReturnUC.setTabLength(904);  
  24. bapiReturn.addInfo("TYPE",       IMetaData.TYPE_CHAR,   1,   1,   0, 0, null, null, 0, 
  25.                    null, null);
  26. bapiReturn.addInfo("CODE",       IMetaData.TYPE_CHAR,   5,   5,   1, 0, null, null, 0, 
  27.                    null, null);
  28. bapiReturn.addInfo("MESSAGE",    IMetaData.TYPE_CHAR, 220, 220,   6, 0, null, null, 0, 
  29.                    null, null);
  30. bapiReturn.addInfo("LOG_NO",     IMetaData.TYPE_NUM,   20,  20, 226, 0, null, null, 0, 
  31.                    null, null);
  32. bapiReturn.addInfo("LOG_MSG_NO", IMetaData.TYPE_CHAR,   6,   6, 246, 0, null, null, 0, 
  33.                    null, null);
  34. bapiReturn.addInfo("MESSAGE_V1", IMetaData.TYPE_CHAR,  50,  50, 252, 0, null, null, 0, 
  35.                    null, null);
  36. bapiReturn.addInfo("MESSAGE_V2", IMetaData.TYPE_CHAR,  50,  50, 302, 0, null, null, 0, 
  37.                    null, null);
  38. bapiReturn.addInfo("MESSAGE_V3", IMetaData.TYPE_CHAR,  50,  50, 352, 0, null, null, 0, 
  39.                    null, null);
  40. bapiReturn.addInfo("MESSAGE_V4", IMetaData.TYPE_CHAR,  50,  50, 402, 0, null, null, 0, 
  41.                    null, null);
  42. bapiReturn.setTabLength(452);
  43. companyListUC.addInfo("COMPANY", IMetaData.TYPE_CHAR,  6, 12,  0, 0, null, null, 0, 
  44.                       null, null);
  45. companyListUC.addInfo("NAME1",   IMetaData.TYPE_CHAR, 30, 60, 12, 0, null, null, 0, 
  46.                       null, null);
  47. companyListUC.setTabLength(72);
  48. companyList.addInfo("COMPANY", IMetaData.TYPE_CHAR,  6,  6, 0, 0, null, null, 0, null,
  49.                      null);
  50. companyList.addInfo("NAME1",   IMetaData.TYPE_CHAR, 30, 30, 6, 0, null, null, 0, null, 
  51.                      null);
  52. companyList.setTabLength(36);
  53. JCO.MetaData exportsMetaUC=new JCO.MetaData("EXPORTS", 1);
  54. exportsMetaUC.addInfo("RETURN", IMetaData.TYPE_STRUCTURE, 452, 904, 0, 0, null, null, 0,
  55.                       bapiReturnUC, null);
  56. JCO.MetaData exportsMeta=new JCO.MetaData("EXPORTS", 1);
  57. exportsMeta.addInfo("RETURN", IMetaData.TYPE_STRUCTURE, 452, 452, 0, 0, null, null, 0,
  58.                     bapiReturn, null);
  59. JCO.MetaData tablesMetaUC=new JCO.MetaData("TABLES", 1);
  60. tablesMetaUC.addInfo("COMPANY_LIST", IMetaData.TYPE_TABLE, 36, 72, 0, 0, null, null, 0, 
  61.                      companyListUC, null);
  62. JCO.MetaData tablesMeta=new JCO.MetaData("TABLES", 1);
  63. tablesMeta.addInfo("COMPANY_LIST", IMetaData.TYPE_TABLE, 36, 36, 0, 0, null, null, 0,
  64.                    companyList, null);
  65. JCO.Client client = JCO.getClient("FOO");
  66. try
  67. {
  68.     client.connect();
  69.     boolean isUnicode = client.getAttributes().getPartnerBytesPerChar()==2;
  70.     JCO.Function bapiCompanyGetList=null;
  71.     if (isUnicode)
  72.         bapiCompanyGetList=JCO.createFunction("BAPI_COMPANY_GETLIST", null,
  73.                                               JCO.createParameterList(exportsMetaUC), 
  74.                                               JCO.createParameterList(tablesMetaUC));
  75.     else 
  76.         bapiCompanyGetList=JCO.createFunction("BAPI_COMPANY_GETLIST", null,
  77.                                               JCO.createParameterList(exportsMeta), 
  78.                                               JCO.createParameterList(tablesMeta));
  79.     client.execute(bapiCompanyGetList);
  80.     JCO.ParameterList tables= bapiCompanyGetList.getTableParameterList();
  81.     JCO.Table companies=tables.getTable("COMPANY_LIST");
  82.     for (int i=0; i<companies.getNumRows(); i++)
  83.     {
  84.         companies.setRow(i);
  85.         System.out.println(companies.getString("COMPANY")+
  86.                            ":  "+companies.getString("NAME1"));
  87.     }
  88. }
  89. catch(Exception e)
  90. {
  91.     System.err.println("Exception occured: "+e.toString());
  92. }
  93. finally 
  94. {
  95.     JCO.releaseClient(client);
  96. }
End of the code.

Syntax Syntax

JCo 3.0

  1. JCoRecordMetaData bapiReturn = JCo.createRecordMetaData("BAPIRETURN", 9);
  2. JCoRecordMetaData companyList = JCo.createRecordMetaData("BAPI0014_1", 2);
  3. bapiReturn.add("TYPE",       JCoMetaData.TYPE_CHAR,   1,   0,   2,   0, 0, null, null,
  4.                null);
  5. bapiReturn.add("CODE",       JCoMetaData.TYPE_CHAR,   5,   1,  10,   2, 0, null, null,
  6.                null);
  7. bapiReturn.add("MESSAGE",    JCoMetaData.TYPE_CHAR, 220,   6, 440,  12, 0, null, null,
  8.                null);
  9. bapiReturn.add("LOG_NO",     JCoMetaData.TYPE_NUM,   20, 226,  40, 452, 0, null, null,
  10.                null);
  11. bapiReturn.add("LOG_MSG_NO", JCoMetaData.TYPE_CHAR,   6, 246,  12, 492, 0, null, null,
  12.                null);
  13. bapiReturn.add("MESSAGE_V1", JCoMetaData.TYPE_CHAR,  50, 252, 100, 504, 0, null, null,
  14.                null);
  15. bapiReturn.add("MESSAGE_V2", JCoMetaData.TYPE_CHAR,  50, 302, 100, 604, 0, null, null,
  16.                null);
  17. bapiReturn.add("MESSAGE_V3", JCoMetaData.TYPE_CHAR,  50, 352, 100, 704, 0, null, null,
  18.                null);
  19. bapiReturn.add("MESSAGE_V4", JCoMetaData.TYPE_CHAR,  50, 402, 100, 804, 0, null, null,
  20.                null);
  21. bapiReturn.setRecordLength(452, 904);
  22. bapiReturn.lock();  
  23. companyList.add("COMPANY", IMetaData.TYPE_CHAR,  6,  0, 12,  0, 0, null, null, 0, null,
  24.                 null);
  25. companyList.add("NAME1",   IMetaData.TYPE_CHAR, 30,  6, 60, 12, 0, null, null, 0, null,
  26.                 null);
  27. companyList.setRecordLength(36, 72);
  28. companyList.lock();
  29. JCoListMetaData exportsMeta=JCo.createListMetaData("EXPORTS", 1);
  30. exportsMeta.add("RETURN", JCoMetaData.TYPE_STRUCTURE, 452, 904, 0, null, null, 0,
  31.                 bapiReturn, null);
  32. JCoListMetaData tablesMeta=JCo.createListMetaData("TABLES", 1);
  33. tablesMeta.add("COMPANY_LIST", JCoMetaData.TYPE_TABLE, 36, 72, 0, null, null, 0,
  34.                companyList, null);
  35. JCoFunctionTemplate bapiCompanyGetListTemplate=JCo.createFunctionTemplate("BAPI_COMPANY_GETLIST", 
  36.               null, exportsMeta, null, tablesMeta, null);
  37. try
  38. {
  39.     JCoDestination foo=JCoDestinationManager.getDestination("FOO");
  40.     JCO.Function bapiCompanyGetList=bapiCompanyGetListTemplate.getFunction();
  41.     bapiCompanyGetList.execute(foo);
  42.     JCoParameterList tables= bapiCompanyGetList.getTableParameterList();
  43.     JCoTable companies=tables.getTable("COMPANY_LIST");
  44.     for (int i=0; i<companies.getNumRows(); i++)
  45.     {
  46.         conmpanies.setRow(i)
  47.         System.out.println(companies.getString("COMPANY")+
  48.                            ":  "+companies.getString("NAME1"));
  49.     }
  50. }
  51. catch(Exception e)
  52. {
  53.     System.err.println("Exception occured: "+e.toString());
  54. }
End of the code.