cancel
Showing results for 
Search instead for 
Did you mean: 

JCo3 - How to parse the metadata of the structure of a function?

Former Member
0 Kudos

Hi,

when converting our JCo2 based interface to JCo3 I encounter this problem: In JCo2 I could easily parse structures of ImportParameterList of TableParameterList by fields() and getString():

Pseudocode:

  input= function.getImportParameterList()

  kopf = input.getStructure("KOPF")

  fi   = kopf.fields()

  while fi.hasMoreElements()

    fld = fi.nextField()

    System.out.println(fld.getName()+" "+fld.getString())

  wend

 
  tables = function.getTableParameterList()

  pos    = tables.getTable("POSITION")

  for pp=0 to pos.getNumRows()-1

      pos.setRow(pp)

      fi = pos.fields()

      jcoServer.printlog("Position:"+pp)

      while fi.hasMoreElements()

            fld = fi.nextField()

            System.out.println(fld.getName()+" "+fld.getString())

      wend

   next pp

My attempts, to do similar with JCo3 showed the problem:

Pseudo code 1:

  input= function.getImportParameterList()

  kopf = input.getStructure("KOPF")

  fields = kopf.getMetaData().getFieldCount()

  for feld=0 to fields-1

      System.out.println(kopf.getMetaData().getName(feld)+" "+kopf.getMetaData().getString(feld))

      // results in: No match for method com.sap.conn.jco.rt.DefaultRecordMetaData.getString(java.lang.Integer)

  next

Pseudo code 2:

  tables = function.getTableParameterList()

  pos    = tables.getTable("POSITION")

  rows = pos.getNumRows()

  for row=0 to rows-1

      pos.setRow(row)

      row=new java.lang.Integer(row)

      System.out.println(pos.getMetaData().getName(row)+" "+pos.getMetaData().getString(row))

      // results in: java.lang.IndexOutOfBoundsException: Index [32] out of bounds.The metadata 'ZJMM_KMK_GM_POS' contains 26 fields

  next

(I know it looks like I run out of bounds, but I attempt to take care of them by looping only for existing rows rows = pos.getNumRows())

Maybe some expert can assist here?

Many thanks for all help

Stephan

Accepted Solutions (0)

Answers (1)

Answers (1)

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

What is the function ?


I cannot see any "KOPF" structure on our machine.

Regards.

Former Member
0 Kudos

Thanks for your answer, Eitan.

The function is a user defined procedure created to provide an interface to a 3rd party software. So it's not likely, that you will find such a structure anywhere on your system.

The KOPF structure provides a set of fields which I would like to dynamically parse to scan for all data it provides. Of course I can scan for all known pairs of each FIELD and its value, but I'd prefer a dynamic routine. This was possible in JCo 2 so I'd like to learn to do it in JCo 3, too.

Best regards.

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

I am sending you a piece of code that I wrote.

 

Give it a go. maybe you will find it useful.

Regards.

package metadata;

import java.text.MessageFormat;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoMetaData;
import com.sap.conn.jco.JCoParameterList;

public class MyDumper {

public static void dumpFunction(final JCoFunction function) {
  dumpParameterList(function.getImportParameterList());
  dumpParameterList(function.getExportParameterList());
  dumpParameterList(function.getChangingParameterList());
  dumpParameterList(function.getTableParameterList());
}

public static void dumpParameterList(final JCoParameterList parameterList) {

  if (parameterList == null) {
   return;
  }

  final JCoMetaData metaData = parameterList.getMetaData();

  for (int index = 0; index < parameterList.getFieldCount(); index++) {

   final String newline = metaData.isStructure(index)
     || metaData.isTable(index) ? "\n" : "";

   println("{0}: {1}{2}", metaData.getName(index), newline,
     parameterList.getValue(index));

  }

}

private static void println(final String pattern, final Object... arguments) {
  System.out.println(MessageFormat.format(pattern + "\n", arguments));
}

private MyDumper() {
}

}