1 package net.sf.sapjcosupport;
2
3 import com.sap.mw.jco.JCO;
4
5 /**
6 * @author Niki Driessen
7 * @since May 24, 2006 - 1:51:25 PM
8 */
9 public class SapDebuggingUtil {
10 public static void printInputParameters(JCO.Function function) {
11 JCO.FieldIterator iterator = function.getImportParameterList().fields();
12 prettyPrint(iterator);
13 }
14
15 public static void printOutputParameters(JCO.Function function) {
16 JCO.FieldIterator iterator = function.getExportParameterList().fields();
17 prettyPrint(iterator);
18 }
19
20 public static void printTableParameters(JCO.Function function) {
21 JCO.FieldIterator iterator = function.getTableParameterList().fields();
22 prettyPrint(iterator);
23 }
24
25 public static void printStructure(JCO.Structure structure) {
26 JCO.FieldIterator iterator = structure.fields();
27 while (iterator.hasNextFields()) {
28 JCO.Field field = iterator.nextField();
29 if (field.isStructure()) {
30 System.out.println(field.getName() + " [STRUCTURE]");
31 printStructure(field.getStructure());
32 }
33 if (field.isTable()) {
34 System.out.println(field.getName() + " [TABLE]");
35 printTable(field.getTable());
36 } else {
37 System.out.println(field.getName() + " [" + field.getTypeAsString() + "] = " + field.getValue());
38 }
39 }
40 }
41
42 public static void printTable(JCO.Table table) {
43 if (table.isEmpty()) {
44 System.out.println(table.getName() + " [TABLE] Contains no data");
45 return;
46 }
47 System.out.println("table.getNumRows() = " + table.getNumRows());
48 table.firstRow();
49 do {
50
51 System.out.println("--ROW " + table.getRow() + "----------------------");
52 JCO.FieldIterator iterator = table.fields();
53 while (iterator.hasNextFields()) {
54 JCO.Field field = iterator.nextField();
55 if (field.isTable()) {
56 System.out.println(field.getName() + " [TABLE]");
57 printTable(field.getTable());
58 }
59 if (field.isTable()) {
60 System.out.println(field.getName() + " [STRUCTURE]");
61 printStructure(field.getStructure());
62 } else {
63 System.out.println(field.getName() + " [" + field.getTypeAsString() + "][" + field.getDescription() + "] = " + field.getValue());
64 }
65 }
66 } while (table.nextRow());
67 }
68
69 private static void prettyPrint(JCO.FieldIterator iterator) {
70 while (iterator.hasNextFields()) {
71 JCO.Field field = iterator.nextField();
72 if (field.isStructure()) {
73 printStructure(field.getStructure());
74 } else if (field.isTable()) {
75 printTable(field.getTable());
76 } else {
77 StringBuffer sb = new StringBuffer();
78 sb.append(field.getName());
79 sb.append(" [");
80 sb.append(field.getTypeAsString());
81 sb.append("]");
82 sb.append("[");
83 sb.append(field.getDescription());
84 sb.append("] = ");
85 if (field.getValue() == null) {
86 sb.append("null");
87 } else {
88 sb.append(field.getValue());
89 }
90 System.out.println(sb.toString());
91 }
92 }
93 }
94 }