BAPI / RFC with Delphi(系列之六)--TSAPFunctions使用BAPI创建PO(有登录对话框的delphi源代码)...

本文介绍如何使用 Delphi 和 SAP BAPI_PO_CREATE 函数创建采购订单。通过定义 SAP 功能、设置采购订单头部信息、添加采购订单项及交货计划,最终调用 SAP 函数创建采购订单并显示订单号。

1、新建一个Form,并在form上添加下列控件

Component

Function

SAPFunctions1 SAP ActiveX-component to connect RFC/BAPI Button1 Button to start the procedure Panel1 not relevant!

2、源代码如下(使用BAPI_PO_CREATE函数创建PO)

unit PO_Create;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, OleCtrls, SAPFunctionsOCX_TLB, ExtCtrls;

type
TForm1 = class(TForm)
SAPFunctions1: TSAPFunctions;
Button1: TButton;
Panel1: TPanel;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;

var
Form1: TForm1;
Funct,
Header,
POItems,
Schedules,
ItemsRow,
SchedulesRow: Variant;

implementation
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var MLDText : String;
begin
Button1.Enabled:=false;
Panel1.Caption := 'RFC ist running, please wait.....';
(* define function *)
Funct := sapFunctions1.add('BAPI_PO_CREATE');

(*** define tables, use structures of the dictionary ***)

(* table for the purcaseorder header *)
Header := funct.exports('PO_HEADER');

(* table of the purcaseorder items *)
POItems := funct.tables.item('PO_ITEMS');

(* table of the schedules *)
Schedules := funct.tables.item('PO_ITEM_SCHEDULES');

(*** filling the PO_Header-table ***)

(* purcasing document type *)
Header.Value[2] := 'NB ' ;

(* purcasing document category *)
Header.Value[3] := 'F' ;

(* purcasing organisation *)
Header.Value[5] := '600' ;

(* purcasing group *)
Header.Value[6] := '610' ;

(* vendor account number, on numeric values don't *)
(* forget the leading zeroes!!! *)
Header.Value[8] := '0099000123';

(*** filling the PO_Items-table ***)

(* add new row to the table *)
ItemsRow := POItems.rows.add;

(* item number of purcasing document *)
ItemsRow.Value[2]:='00010';

(* material-number, on numeric values don't forget *)
(* the leading zeros !!! *)
ItemsRow.Value[5]:='000000000000001161';

(* storage location *)
ItemsRow.Value[11]:='100';

(* plant *)
ItemsRow.Value[17]:='0001';

(* netprice in purcasing document, *)
(* in document currency *)
ItemsRow.Value[21]:='10,00';

(*** filling the PO_Items_Schedules-table ***)

(* add new row to the table *)
SchedulesRow := Schedules.rows.add;

(* item number of purcasing document *)
SchedulesRow.Value[1]:='00010';

(* category of delivery date *)
SchedulesRow.Value[3]:='1';

(* item delivery date *)
SchedulesRow.Value[4]:='30.05.2000';

(* scheduled quantity *)
SchedulesRow.Value[6]:='10';

(*** call function ***)

if not funct.call then

(* on error show message *)
showMessage(funct.exception)

else
begin

(* show number of the purcaseorder *)
MLDText:= funct.imports('PURCHASEORDER');
MessageDlg('purcaseorder '+MLDText+' created.',
MTInformation,[mbOK],0);
end;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值