JCO调用BAPI_DOCUMENT_CHECKOUTVIEW2

ABAP文档检查出视图
本文介绍了一个用于从ABAP系统中检查并导出文档视图到指定输出流的方法_checkoutView2Table。该方法通过定义和执行特定的ABAP功能模块来实现,涉及参数设置、表格填充及内容读取等步骤。
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);
    }

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值