Dear experts,
Am using BAPI_FIXEDASSET_CREATE1 in JCo. BAPI_TRANSACTION_COMMIT is not working. Since asset not being created. Here my sample code.
public static void createDestinationDataFile(String destinationName, Properties connectProperties) {
File destCfg = new File(destinationName + ".jcoDestination");
try {
FileOutputStream fos = new FileOutputStream(destCfg, false);
connectProperties.store(fos, "for tests only !");
fos.close();
} catch (Exception e) {
System.out.println(e);
throw new RuntimeException("Unable to create the destination files", e);
}
}
public static void insertCustomerData() throws JCoException {
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
JCoFunction function = destination.getRepository().getFunction("BAPI_FIXEDASSET_CREATE1");
String tid = destination.createTID();
System.out.println("TID======="+tid);
if (function == null)
throw new RuntimeException("BAPI_FIXEDASSET_CREATE1" + " not found in SAP.");
System.out.println("BAPI_FIXEDASSET_CREATE1 Name from function object: " + function.getName());
JCoStructure codes = function.getImportParameterList().getStructure("KEY");
codes.setValue("COMPANYCODE", "1000");
codes = function.getImportParameterList().getStructure("GENERALDATA");
codes.setValue("ASSETCLASS", "1000");
codes.setValue("DESCRIPT", "Sample");
codes.setValue("DESCRIPT2", "Sample new Asset Main description");
codes.setValue("QUANTITY", "0");
codes = function.getImportParameterList().getStructure("GENERALDATAX");
codes.setValue("ASSETCLASS", "X");
codes.setValue("DESCRIPT", "X");
codes.setValue("DESCRIPT2", "X");
codes.setValue("QUANTITY", "X");
codes = function.getImportParameterList().getStructure("TIMEDEPENDENTDATA");
codes.setValue("COSTCENTER", "1000");
codes = function.getImportParameterList().getStructure("TIMEDEPENDENTDATAX");
codes.setValue("COSTCENTER", "X");
function.execute(destination,tid);
JCoFunction commitfunction = destination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT");
commitfunction.getImportParameterList().setValue("WAIT","X");
System.out.println("COmmit function=========="+commitfunction);
commitfunction.execute(destination,tid);
destination.confirmTID(tid);
System.out.println("Function BAPI_TRANSACTION_COMMIT executed .");
String assetnumber = function.getExportParameterList().getString("ASSET");
System.out.println("The generated Asset number is" + assetnumber);
String subnumber = function.getExportParameterList().getString("SUBNUMBER");
System.out.println("The generated Asset sub number is" + subnumber);
}
public static void main(String[] args) throws Exception {
AssetCreation.insertCustomerData();
}
}