• BAPI / RFC with Delphi(系列之三)--TSAPLogonControl使用(无对话框的登录sap的delphi源代码)


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

    Component Function
    SAPLogOnControl1 SAP ActiveX-Component to logon to the system
    Button1 Button to start the procedure

    2、源代码如下
     

    unit s_logon;

    interface

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

    type
      TForm1 = class(TForm)
      SAPLogonControl1: TSAPLogonControl;
      Panel1: TPanel;
      Edit1: TEdit;
      Edit2: TEdit;
      Label1: TLabel;
      Label2: TLabel;
      StaticText1: TStaticText;
      Button1: TButton;
      procedure SAPLogonControl1Click(Sender: TObject);
      procedure Button1Click(Sender: TObject);
    private
    { Private-Deklarationen }
    public
    { Public-Deklarationen }
    end;

    var
    Form1: TForm1;
    Connection :variant;

    implementation

    {$R *.DFM}

    procedure TForm1.SAPLogonControl1Click(Sender: TObject);
    begin

      (* define connection and it's parameters *)
      Connection := SAPLogoncontrol1.newConnection;

      (* In some GUI-versions the username *)
      (* must be written in uppercase !!!  *)
     
    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
      (* parameter "true" : SilentLogOn *)

      begin
        ShowMessage('Logon O.K.');
        Button1.Enabled:= true;
      end
      else
      begin
        ShowMessage('Error on logon :-(((');
        SAPLogonControl1.Enabled:=true;
      end;
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin

      (* cut connection *)
      Connection.LogOff;

      ShowMessage('System LogOff...');
      SAPLogonControl1.Enabled:=true;
      Button1.Enabled :=false;
    end;
    end.

    wdtfuncs   SAP data type not supported
    
    error on line:
    Set i_TABNAME = Func.Exports("TABNAME")
    

    Here is my VB code:

    Option Explicit
    
    Public Functions As SAPFunctionsOCX.SAPFunctions
    Private LogonControl As SAPLogonCtrl.SAPLogonControl
    Private R3Connection As SAPLogonCtrl.Connection
    Private TableFactory As SAPTableFactory
    
    Dim Func As SAPFunctionsOCX.Function
    
    Public i_TABNAME  As SAPFunctionsOCX.Parameter
    
    Public i_FIELD  As SAPFunctionsOCX.Parameter
    Public i_LANGU  As SAPFunctionsOCX.Parameter
    
    Public strLabel  As SAPFunctionsOCX.Parameter
    
    'Public tENTRIES  As SAPTableFactoryCtrl.Table
    
    Public Sub Main()
        Dim ix As Integer
        Dim retcd As Boolean
        Dim SilentLogon As Boolean
        Set LogonControl = CreateObject("SAP.LogonControl.1")
        Set Functions = CreateObject("SAP.Functions")
        Set TableFactory = CreateObject("SAP.TableFactory.1")
        Set R3Connection = LogonControl.NewConnection
        R3Connection.client = "000"
        R3Connection.ApplicationServer = "A1KGNB09"
        R3Connection.language = "DE"
        R3Connection.User = "BCUSER"
        R3Connection.Password = "minisap"
        R3Connection.System = "A1 SAP 620 09"
        R3Connection.SystemID = "000"
        R3Connection.SystemNumber = "00"
        R3Connection.UseSAPLogonIni = False
        SilentLogon = False
       
        retcd = R3Connection.Logon(0, SilentLogon)
        If retcd <> True Then MsgBox "Logon failed": Exit Sub
       
        Functions.Connection = R3Connection
        Set Func = Functions.Add("DDIF_FIELDLABEL_GET")
        Set i_TABNAME = Func.Exports("TABNAME")
        Set i_FIELD = Func.Exports("FIELDNAME")
        Set i_LANGU = Func.Exports("LANGU")
        Set strLabel = Func.Imports("LABEL")
        i_TABNAME.Value = "USR02"
        i_FIELD.Value = "BNAME"
        i_LANGU.Value = "DE"
        Func.Call  
        MsgBox strLabel
    '    Debug.Print eNUMBER_OF_ENTRIES
    '    For ix = 1 To tENTRIES.RowCount
    '        Debug.Print tENTRIES(ix, 1)
    '    Next
        R3Connection.Logoff
    End Sub
    
  • 相关阅读:
    Effective Java:Ch4_Class:Item14_在public类中应该使用访问方法而不是public域
    [置顶] 学习JDK源码:可进一步优化的代码
    [置顶] 学习JDK源码:编程习惯和设计模式
    如何开展软件架构之概念架构
    POJ 3667 & 1823 Hotel (线段树区间合并)
    CF 161D Distance in Tree【树DP】
    BroadcastReceiver基础总结
    OSI七层模型具体解释
    习惯的力量之四理直气壮的借口?
    堆(stack) 之 c 和 c++模板实现(空类默认成员函数 初谈引用 内联函数)
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157382.html
Copyright © 2020-2023  润新知