BAPI / RFC with Delphi(系列之八)--TBAPIControl使用BUS2012建立PO(Delphi源代码)

本文介绍了一个使用 SAP BAPI 控件创建采购订单 (PO) 的 Delphi 示例程序。该程序通过定义采购订单头信息及明细项来创建两个不同物料的 PO,并设置交货计划。

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

Component Function SAPLogonControl1 SAP ActiveX-Component to logon to the system SAPBAPIControl1 SAP ActiveX-Component to connect to BAPI Button1 Button to start the procedure Button2 Button to logon Panel1-3 Elements to display messages

2、源代码如下(BUS2012建立PO)

unit best;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, SAPBAPIControlLib_TLB, ExtCtrls, Grids,
SAPLogonCtrl_TLB;

type
TForm1 = class(TForm)
SAPBAPIControl1: TSAPBAPIControl;
Button1: TButton;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Button2: TButton;
SAPLogonControl1: TSAPLogonControl;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;

var
Form1: TForm1;
Connection,Mat,Header,Ret,Schedul,Item : Variant;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin

(* select BusinessObject *)
Mat:= SAPBapiControl1.GetSAPObject('BUS2012');

(* define structures *)
Header := SAPBapiCcontrol1.dimAs (Mat,'CreateFromData','PoHeader');
Schedul:= SAPBapiCcontrol1.dimAs (Mat,'CreateFromData','PoItemSchedules');
Item := SAPBapiCcontrol1.dimAs (Mat,'CreateFromData','PoItems');
Ret := SAPBapiCcontrol1.dimAs (Mat,'CreateFromData','Return');

(* purchaseorder header data's *)
Header.value ('DOC_TYPE') := 'NB';
Header.value ('DOC_CAT') := 'F';
Header.value ('PURCH_ORG'):= '10';
Header.value ('PUR_GROUP'):= '10';
Header.value ('VENDOR') := '0010000999';

(* data for position 00010 *)
Item.Rows.Add;
Item.Value (1,'PO_ITEM') := '00010';
Item.Value (1,'PUR_MAT') := '000000000000000017';
Item.Value (1,'STORE_LOC') := '100';
Item.Value (1,'PLANT') := '1000';
Item.Value (1,'NET_PRICE') := '10,00';

(* schedules for position 00010 *)
Schedul.Rows.Add;
Schedul.Value (1,'PO_ITEM') := '00010';
Schedul.Value (1,'DEL_DATCAT') := '1';
Schedul.Value (1,'DELIV_DATE') := '20.09.2000';
Schedul.Value (1,'QUANTITY') := '10';

(* data for position 00020 *)
Item.Rows.Add;
Item.value (2,'PO_ITEM') := '00020';
Item.value (2,'PUR_MAT') := '000000000000001161';
Item.value (2,'STORE_LOC') := '100';
Item.value (2,'PLANT') := '1000';
Item.value (2,'NET_PRICE') := '10,00';

(* schedules for position 00020 *)
Schedul.Rows.Add;
Schedul.Value (2,'PO_ITEM') := '00020';
Schedul.Value (2,'DEL_DATCAT') := '1';
Schedul.Value (2,'DELIV_DATE') := '20.09.2000';
Schedul.Value (2,'QUANTITY') := '10';

(* call the method CreateFromData *)
Mat.CreateFromData (PoHeader := Header,
SkipItemsWithError := ' ',
PoItems := Item,
PoItemSchedules := Schedul,
Return := Ret);

(* Errors are saved in the structure Ret *)
if Ret.RowCount > 0 then
begin
Panel1.Caption:= Ret.Value (1,'TYPE');
Panel2.Caption:= Ret.Value (1,'MESSAGE');
end

(* If the method was calles without errors, *)
(* display the number of the purchaseorder *)

else Panel2.Caption:= Mat.PurchaseOrder;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin

(* Logon to the system *)
Connection := SAPLogoncontrol1.newConnection;
Connection.User := Ansiuppercase(Edit1.text);
Connection.System := 'IDS';
Connection.Client := '800';
Connection.ApplicationServer := 'SAPIDES';
Connection.SystemNumber := '00';
Connection.Password := Edit2.text;
Connection.Language := 'DE' ;
SAPLogonControl1.Enabled := false;

if Connection.LogOn(0,true) = True then
begin
ShowMessage('Logon O.K.');
Button1.Enabled:= true;

(* assign the existing connection to the *)
(* component SAPBapiControl1 *)

SapBapiControl1.Connection:=Connection;
end
else
begin
ShowMessage('Error on logon :-(((');
end;
end;
end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值