package ru bdo rfc import com documentum fc client IDfSession import c

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package ru.bdo.rfc;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.common.DfException;
import com.sap.conn.jco.*;
import com.sap.conn.jco.ext.DestinationDataProvider;
import java.io.*;
import ru.bdo.methods.CommonMethod;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class TestJCO3Metod extends CommonMethod {
static String ABAP_AS = "ABAP_AS_WITHOUT_POOL";
static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
static String ABAP_MS = "ABAP_MS_WITHOUT_POOL";
static {
Properties p = new Properties();
try {
p.load(TestJCO3.class.getClassLoader().getResourceAsStream("r3d.properties"));
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, p.getProperty("jco.client.mshost"));
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, p.getProperty("jco.client.sysnr"));
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, p.getProperty("jco.client.client"));
connectProperties.setProperty(DestinationDataProvider.JCO_USER, p.getProperty("jco.client.user"));
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, p.getProperty("jco.client.passwd"));
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, p.getProperty("jco.client.lang"));
createDataFile(ABAP_AS, "jcoDestination", connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "5");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
connectProperties.clear();
connectProperties.setProperty(DestinationDataProvider.JCO_MSHOST, p.getProperty("jco.client.mshost"));
connectProperties.setProperty(DestinationDataProvider.JCO_R3NAME, p.getProperty("jco.client.r3name"));
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, p.getProperty("jco.client.client"));
connectProperties.setProperty(DestinationDataProvider.JCO_USER, p.getProperty("jco.client.user"));
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, p.getProperty("jco.client.passwd"));
connectProperties.setProperty(DestinationDataProvider.JCO_GROUP, p.getProperty("jco.client.group"));
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, p.getProperty("jco.client.lang"));
createDataFile(ABAP_MS, "jcoDestination", connectProperties);
}
static void createDataFile(String name, String suffix, Properties properties) {
File cfg = new File(name + "." + suffix);
try {
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "");
fos.close();
} catch (Exception e) {
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
}
}
static void deleteDataFile(String name, String suffix)
{
File cfg = new File(name+"."+suffix);
try {
if(cfg.exists()){
cfg.delete();
}
} catch (Exception e) {
throw new RuntimeException("Unable to delete the destination file " + cfg.getName(), e);
}
}
public TestJCO3Metod() {
super(TestJCO3Metod.class, TestJCO3Metod.class.getName().indexOf(".") > 0 ? TestJCO3Metod.class.getName().substring(TestJCO3Metod.class.getName().lastIndexOf(".") + 1) : TestJCO3Metod.class.getName());
}
protected void executeMethod(IDfSession dfSession, PrintWriter output) throws DfException {
try {
trace("Begin execution...");
JCoDestination destination = null;
destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
trace("Attributes{");
trace(destination.getAttributes().toString());
trace("}");
JCoFunction function = destination.getRepository().getFunction("ZEMC_KURATORS_GETLIST");
if (function == null)
throw new RuntimeException("BAPI_COMPANYCODE_GETLIST not found in SAP.");
try {
function.execute(destination);
} catch (AbapException e) {
trace(e.toString());
return;
}
JCoTable codes = function.getTableParameterList().getTable("KURATORS");
for (int i = 0; i < codes.getNumRows(); i++) {
codes.setRow(i);
trace(codes.getString("ATWRT") + " " + codes.getString("ATWTB"));
}
trace("Complete...");
} catch (JCoException e) {
trace(e.toString());
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}finally {
deleteDataFile(ABAP_AS, "jcoDestination");
deleteDataFile(ABAP_AS_POOLED, "jcoDestination");
deleteDataFile(ABAP_MS, "jcoDestination");
}
}
protected StringBuffer logSB = null;
protected void trace(String s) {
if (logSB == null) logSB = new StringBuffer();
logSB.append(s).append("\r\n");
super.trace(s);
}
public static void main(String[] args) throws DfException {
TestJCO3Metod aues = new TestJCO3Metod();
Map<String, String[]> hm = new HashMap<String, String[]>();
hm.put("docbase", new String[]{"kinef"});
hm.put("user", new String[]{"dmadmin"});
hm.put("ticket", new String[]{"dmadmin_3_kinef"});
hm.put("mode", new String[]{"0"});
try {
File file = new File("C:/file.txt");
PrintWriter printWriter = new PrintWriter("C:/file.txt");
try {
aues.execute(hm, printWriter);
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
} catch (FileNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}