您的位置:首页 > 编程语言 > Delphi

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

2007-03-26 12:10 471 查看
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;

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐