import com.sap.mw.jco.*;
import com.sap.mw.jco.JCO.ParameterList;
/** * 단순조회를 처리하는 소스 */
public class SAPJCOEx02 extends Object {
JCO.Client mConnection;
JCO.Repository mRepository;
public SAPJCOEx02() {
try {
// Change the logon information to your own system/user mConnection = JCO.createClient( "001", // SAP client "userid", // userid "1234", // password "EN", // language "hostname", // host name "00"); // system number
mConnection.connect();
mRepository = new JCO.Repository("ARAsoft", mConnection);
} catch (Exception ex) {
ex.printStackTrace(); System.exit(1); }
JCO.Function function = null;
try { function = this.createFunction("RFC FUNCTION NAME ");
if (function == null) {
System.out.println("FUC not found in SAP.");
System.exit(1);
}
//Funection에 Import값 설정 function.getImportParameterList().setValue("value", "name");
mConnection.execute(function);
//output의 내용을 출력한다. System.out.println("-----OUTPUT------------------");
JCO.ParameterList output = function.getExportParameterList();
for (int i = 0; i < output.getFieldCount(); i++) {
System.out.println(output.getName(i) + ": " + output.getString(output.getName(i)));
}
//table의 내용을 출력한다. System.out.println("\n-----TABLE-------------------");
JCO.ParameterList table = function.getTableParameterList();
for (int i = 0; i < table.getFieldCount(); i++) {
System.out.println("Table명: " + table.getName(i));
//column명 출력 JCO.Table codes = table.getTable(table.getName(i));
String[] colName = new String[codes.getNumColumns()];
for (int j = 0; j < codes.getNumColumns(); j++) {
colName[j] = codes.getName(j);
System.out.print(codes.getName(j) + " ");
}
System.out.println("\n-----------------------------------------------");
//row출력
for (int j = 0; j < codes.getNumRows(); j++) {
codes.setRow(j);
for (int k = 0; k < colName.length; k++) {
System.out.print(codes.getString(colName[k]) + " ");
}
System.out.println("\n");
}
System.out.println("\n");
} } catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
mConnection.disconnect();
}
public JCO.Function createFunction(String name) throws Exception {
try {
IFunctionTemplate ft = mRepository.getFunctionTemplate(name.toUpperCase());
if (ft == null)
return null;
return ft.getFunction();
} catch (Exception ex) {
throw new Exception("Problem retrieving JCO.Function object.");
} }
public static void main(String args[]) { SAPJCOEx02 app = new SAPJCOEx02(); }
}
|