zoukankan      html  css  js  c++  java
  • BAPI / RFC with Delphi(系列之四)--TSAPFunctions使用(有登录对话框的delphi源代码)

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

    Component function
    SAPFunctions1 SAP ActiveX-component to connect RFC/BAPI
    Grid Stringgrid to show the data's in the form
    Button1 Button to start the procedure

    2、源代码如下(使用RFC_READ_TABLE函数读取成本中心)
     unit logon1;

    interface

    uses

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

    type
    TForm1 = class(TForm)
      SAPFunctions1: TSAPFunctions;
      Button1: TButton;
      Grid: TStringGrid;
      procedure Button1Click(Sender: TObject);
    private
    { }
    public
    { }
    end;

    var
    Form1 : TForm1 ;
    Table,Funct : VARIANT ;

    implementation
    {$R *.DFM}

    procedure TForm1.Button1Click(Sender: TObject);
    var txt : string  ;
        r   : integer ;
    begin

      (* define function *)
      Funct := SAPFunctions1.add('RFC_READ_TABLE');

      (* tell the function what table should be read *)
      Funct.exports('QUERY_TABLE').value := 'CSKT';

      (* call the function *)
      if not Funct.call then

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

      else begin

        (* select table with the data's *)
        Table := Funct.tables.item('DATA');

        (* addjust the StringGrid *)
        grid.rowCount := Table.rowcount + 1;
        grid.cells[0,0] := 'Client';
        grid.cells[1,0] := 'Cost Number';
        grid.cells[2,0] := 'CostCenter Description';
        for r := 1 to grid.rowCount -1 do begin

          (* select first dataset *)
          txt := Table.value(r,1);

          (* Because the RCF-function returns only one    *)
          (* string whitch contains all data's, the       *)
          (* string must be cut to different parts        *)

          grid.cells[0,r] := copy(txt,0,3);  
    (* Client                *)
          grid.cells[1,r] := copy(txt,9,10); 
    (* CostCent-number     *)
          grid.cells[2,r] := copy(txt,27,20);
    (* CostCent-description*)
        end;
        grid.visible := True;
      end;
    end;
    end.

  • 相关阅读:
    Laravel模型间关系设置分表方法详解
    11个PHP程序员最常犯的MySQL错误
    教你使用swoole监听redis数据
    使用 Docker 环境来开发 PHP,Laradock 系列 1
    tp5 workerman安装不上解决方法
    一种颗粒度很小的 Laravel 路由文件划分方式
    VT 调试环境搭建
    masm32基本配置与写出第一个汇编程序
    [debug] 解决pycharm中无法import自己建立的模块问题
    《Windows内核安全与驱动开发》 7.1&7.2&7.3 串口的过滤
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157381.html
Copyright © 2011-2022 走看看