Start of Content Area

Procedure documentation Replacing JCo Classes  Locate the document in its SAP Library structure

Use

To standardize access to the API for platform-specific use as well, the new JCo API replaces the previous JCo classes (for example, JCO.Function, JCO.Table and so on) with interfaces .

In addition to this interfaces enable the use of the Java Development Infrastructure (JDI) for Java development as it makes it possible to assign functionality to different development components.

The naming of the newly-defined interfaces is very similar to that of the former JCo classes. Like the former classes, all the important interfaces have the same prefix, not in the form of an outer class, but simply as a naming convention. "JCO.~“ becomes "JCo~“.

Procedure

Replace all the former JCo classes with the corresponding interface.

Example

The following example shows JCo classes being replaced by interfaces:

 

Example JCo 2.x

 

IRepository repository = JCO.createRepository(“REPO”, “SAP”);

IFunctionTemplate template = repository.getFunctionTemplate("FUNCTION_MOCULE");

IMetaData structureDefinition = repository.getStructureDefinition("MY_STRUCT");

 

JCO.Structure structure=JCO.createStructure(structureDefinition);

structure.setValue(“Hello World”,  “TITLE”);

structure.setValue(“Good Morning”, 1);

 

JCO.FieldIterator iterator=new JCO.FieldIterator(structure);

while(iterator.hasNextFields())

{

    JCO.Field field=iterator.nextField();

    System.out.println(“FieldValue: ”+field.getString());

}

  

JCO.Function function = template.getFunction();

JCO.ParameterList tables=function.getTablesParameterList();

  

JCO.Table tracks = tables.getTable("TRACKS");

if (!tracks.isEmpty())

{

    for (int i=0; i<tracks.getNumRows(); i++)

    {

        tracks.setRow(i);

        System.out.println(tracks.getString("ARTIST")+

                                        ":  "+ tracks.getString("SONG"));

    }

}

 

JCO.AbapException[] exceptions=function.getExceptionList();

if (exceptions!=null)

for (int i=0; i<exceptions.length(); i++)

System.out.println(“ExceptionName: ”+exceptions[i].getKey());

 

 

Example JCo 3.0

 

JCoRepository repository = destination.getRepository();

JCoFunctionTemplate template = repository.getFunctionTemplate("FUNCTION_MOCULE");

JCoRecordMetaData structureDefinition = repository.getStructureDefinition("MY_STRUCT");

 

JCoStructure structure=JCo.createStructure(structureDefinition);

structure.setValue(“TITLE”,  “Hello World”);

structure.setValue(1, “Good Morning”);

 

JCoFieldIterator iterator=structure.getFieldIterator();

while(iterator.hasNextField())

{

    JCoField field=iterator.nextField();

    System.out.println(“FieldValue: ”+field.getString());

}

  

JCoFunction function = template.getFunction();

JCoParameterList tables=function.getTablesParameterList();

  

JCoTable tracks = tables.getTable("TRACKS");

if (!tracks.isEmpty())

{

    for (int i=0; i<tracks.getNumRows(); i++)

    {

        tracks.setRow(i);

        System.out.println(tracks.getString("ARTIST")+

                                        ":  "+ tracks.getString("SONG"));

    }

}

 

AbapException[] exceptions=function.getExceptionList();

if (exceptions!=null)

    for (int i=0; i<exceptions.length(); i++)

        System.out.println(“ExceptionName: ”+exceptions[i].getKey());

 

 

 

 

End of Content Area