Use
Sometimes the call of DMS BAPIs in the JAVA environment causes problems with SAPHTTP or RFC connection.
Reason
In case that BAPI functions should be used in JAVA environment or within some background action the API function modules are much better and flexible. The document BAPIs always require a SAPGUI or an open RFC connection, because this channel is required to start the program SAPHTTP (or SAPFTP) on the client for the check-in. When the BAPI is used in background, the system doesn't know where to get the original files from.
Solution
Generally please use the API function modules instead of BAPIs. For further information see the SAP note 504692 which contains special sample programs to create documents and check in originals in background.
Regarding the call of the API modules in JAVA environment please see the following sample coding, which might be useful to create the correct call for it:
private boolean _checkoutView2Table (DVSDocumentFile docFile, OutputStream oStream) { JCO.Function function; JCO.ParameterList pList; JCO.Structure sDraw; JCO.Structure sReturn; JCO.Table tblFiles; JCO.Table tblContent; String strFunction; byte[] contentBytes; int fileSize; int len, offset; // ----------------------------------------------------------------------------- // Create function strFunction = new String ("CVAPI_DOC_CHECKOUTVIEW"); function = this.createFunction(strFunction); // Define import-parameter function.getImportParameterList().setValue(this.m_docType, "PF_DOKAR"); function.getImportParameterList().setValue(this.m_docNumber, "PF_DOKNR"); function.getImportParameterList().setValue(this.m_docVersion, "PF_DOKVR"); function.getImportParameterList().setValue(this.m_docPart, "PF_DOKTL"); // Get content as table function.getImportParameterList().setValue("TBL", "PF_CONTENT_PROVIDE"); // Fill files tblFiles = function.getTableParameterList().getTable("PT_FILES"); tblFiles.appendRow(); tblFiles.setValue(docFile.getStorageCat(), "STORAGE_CAT"); tblFiles.setValue(docFile.getApplication(), "DAPPL"); tblFiles.setValue(docFile.getAppNr(), "APPNR"); tblFiles.setValue(docFile.getFileName(), "FILENAME"); tblFiles.setValue(docFile.getLoio(), "LO_OBJID"); tblFiles.setValue(docFile.getPhio(), "PH_OBJID"); tblFiles.nextRow(); // ----------------------------------------------------------------------------- // Execute function // ----------------------------------------------------------------------------- try { this.m_client.execute(function); } catch(JCO.AbapException ae) { System.err.println("JCO.AbapException: <" + strFunction + "> " + ae); ae.printStackTrace(); return(false); } catch(JCO.Exception e) { System.err.println("JCO.Exception: <" + strFunction + "> " + e); e.printStackTrace(); return (false); } // Get export-parameter & tables sDraw = function.getExportParameterList().getStructure("PSX_DRAW"); sReturn = function.getExportParameterList().getStructure("PSX_MESSAGE"); tblContent = function.getTableParameterList().getTable("PTX_CONTENT"); // Do we have content if (tblContent.getNumRows() < 0) { System.err.println ("No Content"); return (false); } contentBytes = new byte[2550]; offset = 0; fileSize = docFile.getFileSize(); // ----------------------------------------------------------------------------- // Write the output to the given Stream // ----------------------------------------------------------------------------- try { do { if (fileSize == 0) { fileSize = tblContent.getInt ("ORLN"); docFile.setFileSize (fileSize); } contentBytes = tblContent.getByteArray("ORBLK"); if ((offset + 2550) <= fileSize) len = 2550; else len = fileSize - offset; if (len > 0) { oStream.write(contentBytes, 0, len); offset = offset + len; } } while(tblContent.nextRow()); oStream.close(); } catch (IOException e) { System.err.println ("Error writing to the given Stream " + e); e.printStackTrace(); return (false); } return (true); }
Please keep in mind that this is just a sample for CVAPI_DOC_CHECKOUTVIEW function module. So if you want to call another one you have to modify this sample.