场景:
调用BAPI的时候不再是简单的传一个值,而是传递一个结构或者表。
第一步:创建工作流
第二步:编写脚本
// Describe functionality to be implemented in JavaScript later in the project.
var BAPI = new ActiveXObject("SAP.Functions");
var Connection = BAPI.Connection;
Connection.ApplicationServer = "dlwr-s4h-p8.dcsc.be";
Connection.SystemNumber = "00";
Connection.System = "F4P";
Connection.Client = "130";
Connection.User = "DLW_DCH_09";
Connection.Password = "0315Wanan";
Connection.Language = "ZH";
Connection.RfcWithDialog = true;
Connection.logon(0, true);
var RFC = BAPI.Add("BAPI_PO_CREATE1");
var ImportHeader = RFC.exports("POHEADER");
ImportHeader('PO_NUMBER').value = "1";
var ImportItemRow = RFC.tables("POITEM").Rows.Add;
ImportItemRow("PO_ITEM").value = "1";
RFC.Call();
//Read table parameter
var ResultTable = RFC.tables("RETURN");
ctx.log(ResultTable);
//Iterate through the tables parameter
for (var enumerator = new Enumerator(ResultTable.Rows); !enumerator.atEnd(); enumerator.moveNext()) {
var ResultTableRow = enumerator.item();
ctx.log("ResultTable= " + ResultTableRow("TYPE") + " " + ResultTableRow("MESSAGE") );
}
代码详解:
var ImportHeader = RFC.exports("POHEADER");
ImportHeader('PO_NUMBER').value = "1";
POHEADER是一个结构
var ImportItemRow = RFC.tables("POITEM").Rows.Add;
ImportItemRow("PO_ITEM").value = "1";
POITEM是一个内表
var ResultTable = RFC.tables("RETURN");
获取返回值,返回值也是一个内表
//Iterate through the tables parameter
for (var enumerator = new Enumerator(ResultTable.Rows); !enumerator.atEnd(); enumerator.moveNext()) {
var ResultTableRow = enumerator.item();
ctx.log("ResultTable= " + ResultTableRow("TYPE") + " " + ResultTableRow("MESSAGE") );
}
读取内表里的数据
上图可以看到我的输出。
至此,流程结束。