on 12-06-2012 11:36 AM
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
Hi,
What is the function ?
I cannot see any "KOPF" structure on our machine.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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() {
}
}
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.