zoukankan      html  css  js  c++  java
  • BAPI / RFC with Delphi(系列之八)--TBAPIControl使用BUS2012建立PO(Delphi源代码)

     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.

  • 相关阅读:
    OpenCV4学习笔记(1.0)换一种方式从源码编译、安装 | OpenCV4.3.0以及Contrib | Win10 | CMakeGUI | VS2019 | HTTP代理
    Dapr初体验之服务调用
    Dapr初体验之Hello World
    adb shell input text 中文输入方法
    记一次Mongodb数据库查询之包含所有指定元素的数组或者都在指定元素的数组中 du
    CentOS 7.2 内核3升级到4或者5
    pv
    静态 pv 和动态 pv
    k8s 编写 yaml 文件格式
    把刚升级完成的内核设置成默认启动
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157377.html
Copyright © 2011-2022 走看看