powerbuilder 调用BAPI_PO_CREATE创建po订单
oleobject saprfc,connection2,funct
oleobject poheader,poitems,poitemschedule,it_RETURN
oleobject ItemsRow,SchedulesRow
ANY PO_NO
long ll_status
saprfc = create oleobject
ll_status = saprfc.connecttonewobject("sap.functions") //sap.functions
/********************************************************/
//连接到SAP
/********************************************************/
connection2 = saprfc.connection
connection2.applicationserver = "192.168.0.71" //服务器IP
connection2.system = 'DEV' //系统标识
connection2.systemnumber = '00'
connection2.client = '110'
connection2.user = ''
connection2.password = ''
connection2.language = 'EN'
if connection2.logon(0,true) = false then //登录
messagebox('连接到sap','连接失败')
return
end if
SETPOINTER( HourGlass! )
/********************************************************/
//指定要呼叫SAP的哪个函数,并取得该函数的各对象
/********************************************************/
funct = saprfc.add("BAPI_PO_CREATE")
poheader = funct.exports.Item("PO_HEADER")
poitems = funct.tables.Item("PO_ITEMS")
poitemschedule = funct.tables.Item("PO_ITEM_SCHEDULES")
//it_RETURN = funct.tables.Item("RETURN")
/********************************************************/
//给wa对象赋值
/********************************************************/
poheader.Value[2] = 'NB' //采购凭证类型
poheader.Value[3] = 'F' //采购凭证类别
poheader.Value[5] = '1001' //采购组织
poheader.Value[6] = 'A01' //采购组
poheader.Value[8] = '0000100024' //供应商帐户号
/********************************************************/
//给itab对象赋值
/********************************************************/
//00010
ItemsRow = poitems.Rows.Add()
ItemsRow.Value[2] = '00010'//采购凭证的项目编号
ItemsRow.Value[5] = '000000001101010006'//物料号
ItemsRow.Value[11] = '1000'//库存地点
ItemsRow.Value[17] ='1001'//工厂
ItemsRow.Value[21] ='5'//采购凭证中的净价格(以凭证货币计)
SchedulesRow = poitemschedule.rows.add( )
SchedulesRow.Value[1] = '00010'//采购凭证的项目编号
SchedulesRow.Value[3] = '1'//日期类型 (日,周,月,间隔)
SchedulesRow.Value[4] = '20100531'//项目交货日期
SchedulesRow.Value[6] = '100'//已计划数量
//00020
ItemsRow = poitems.Rows.Add()
ItemsRow.Value[2] = '00020'//采购凭证的项目编号
ItemsRow.Value[5] = '000000001101010007'//物料号
ItemsRow.Value[11] = '1000'//库存地点
ItemsRow.Value[17] ='1001'//工厂
ItemsRow.Value[21] ='6'//采购凭证中的净价格(以凭证货币计)
SchedulesRow = poitemschedule.rows.add( )
SchedulesRow.Value[1] = '00020'//采购凭证的项目编号
SchedulesRow.Value[3] = '1'//日期类型 (日,周,月,间隔)
SchedulesRow.Value[4] = '20100531'//项目交货日期
SchedulesRow.Value[6] = '99'//已计划数量
/********************************************************/
//开始呼叫SAP的函数
/********************************************************/
BOOLEAN lb_call
lb_call = funct.call()
/********************************************************/
//取返回wa值
/********************************************************/
PO_NO = funct.imports.ITEM('PURCHASEORDER')
//MESSAGEBOX('新订单号',STRING(PO_NO))
/********************************************************/
//取返回itab值
/********************************************************/
it_return = funct.tables("RETURN")
string ls_aa,ls_bb
Long ll_r,i
ll_r = it_return.rowcount()
mle_1.text = ''
if ll_r > 0 then
for i = 1 to ll_r
ls_aa = it_return.value(i,'TYPE')
ls_bb = it_return.value(i,'MESSAGE')
mle_1.text += '符号:' + ls_aa +space(32) + ' 描述: ('+ ls_bb + ')~r~n'
next
end if
//MESSAGEBOX('新订单号',STRING(PO_NO))
//commit
funct = saprfc.add("BAPI_TRANSACTION_COMMIT")
lb_call = funct.call()
/********************************************************/
//释放对象,
/********************************************************/
connection2.LogOff()
destroy connection2
saprfc.disconnectobject()
destroy saprfc
oleobject poheader,poitems,poitemschedule,it_RETURN
oleobject ItemsRow,SchedulesRow
ANY PO_NO
long ll_status
saprfc = create oleobject
ll_status = saprfc.connecttonewobject("sap.functions") //sap.functions
/********************************************************/
//连接到SAP
/********************************************************/
connection2 = saprfc.connection
connection2.applicationserver = "192.168.0.71" //服务器IP
connection2.system = 'DEV' //系统标识
connection2.systemnumber = '00'
connection2.client = '110'
connection2.user = ''
connection2.password = ''
connection2.language = 'EN'
if connection2.logon(0,true) = false then //登录
messagebox('连接到sap','连接失败')
return
end if
SETPOINTER( HourGlass! )
/********************************************************/
//指定要呼叫SAP的哪个函数,并取得该函数的各对象
/********************************************************/
funct = saprfc.add("BAPI_PO_CREATE")
poheader = funct.exports.Item("PO_HEADER")
poitems = funct.tables.Item("PO_ITEMS")
poitemschedule = funct.tables.Item("PO_ITEM_SCHEDULES")
//it_RETURN = funct.tables.Item("RETURN")
/********************************************************/
//给wa对象赋值
/********************************************************/
poheader.Value[2] = 'NB' //采购凭证类型
poheader.Value[3] = 'F' //采购凭证类别
poheader.Value[5] = '1001' //采购组织
poheader.Value[6] = 'A01' //采购组
poheader.Value[8] = '0000100024' //供应商帐户号
/********************************************************/
//给itab对象赋值
/********************************************************/
//00010
ItemsRow = poitems.Rows.Add()
ItemsRow.Value[2] = '00010'//采购凭证的项目编号
ItemsRow.Value[5] = '000000001101010006'//物料号
ItemsRow.Value[11] = '1000'//库存地点
ItemsRow.Value[17] ='1001'//工厂
ItemsRow.Value[21] ='5'//采购凭证中的净价格(以凭证货币计)
SchedulesRow = poitemschedule.rows.add( )
SchedulesRow.Value[1] = '00010'//采购凭证的项目编号
SchedulesRow.Value[3] = '1'//日期类型 (日,周,月,间隔)
SchedulesRow.Value[4] = '20100531'//项目交货日期
SchedulesRow.Value[6] = '100'//已计划数量
//00020
ItemsRow = poitems.Rows.Add()
ItemsRow.Value[2] = '00020'//采购凭证的项目编号
ItemsRow.Value[5] = '000000001101010007'//物料号
ItemsRow.Value[11] = '1000'//库存地点
ItemsRow.Value[17] ='1001'//工厂
ItemsRow.Value[21] ='6'//采购凭证中的净价格(以凭证货币计)
SchedulesRow = poitemschedule.rows.add( )
SchedulesRow.Value[1] = '00020'//采购凭证的项目编号
SchedulesRow.Value[3] = '1'//日期类型 (日,周,月,间隔)
SchedulesRow.Value[4] = '20100531'//项目交货日期
SchedulesRow.Value[6] = '99'//已计划数量
/********************************************************/
//开始呼叫SAP的函数
/********************************************************/
BOOLEAN lb_call
lb_call = funct.call()
/********************************************************/
//取返回wa值
/********************************************************/
PO_NO = funct.imports.ITEM('PURCHASEORDER')
//MESSAGEBOX('新订单号',STRING(PO_NO))
/********************************************************/
//取返回itab值
/********************************************************/
it_return = funct.tables("RETURN")
string ls_aa,ls_bb
Long ll_r,i
ll_r = it_return.rowcount()
mle_1.text = ''
if ll_r > 0 then
for i = 1 to ll_r
ls_aa = it_return.value(i,'TYPE')
ls_bb = it_return.value(i,'MESSAGE')
mle_1.text += '符号:' + ls_aa +space(32) + ' 描述: ('+ ls_bb + ')~r~n'
next
end if
//MESSAGEBOX('新订单号',STRING(PO_NO))
//commit
funct = saprfc.add("BAPI_TRANSACTION_COMMIT")
lb_call = funct.call()
/********************************************************/
//释放对象,
/********************************************************/
connection2.LogOff()
destroy connection2
saprfc.disconnectobject()
destroy saprfc
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/139677/viewspace-664851/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/139677/viewspace-664851/