设为首页 收藏本站
查看: 1771|回复: 0

[经验分享] Delphi 连接SAP

[复制链接]

尚未签到

发表于 2015-9-18 08:25:56 | 显示全部楼层 |阅读模式
  本人对DELPHI开发工具熟悉,所以测试连接的时候用DELHI来做例子,其它JAVA. DotNet估计原理应该是一样的,先说下要做的例子;
  1. 如何将ACTIVEX控件注册到DELPHI, 以便利用SAP这些控件;
2. 利用SAP自动的FUNCTION:BAPI_PO_CREATE ,测试如何通过DELPHI去调用这个函数,创建采购订单
  例子很简单,但是通过这个例子可以知道SAP于其它开发工具交互的一种方式(RFC:远程调用),整个例子不需要在SAP做什么配置(原以为需要在DBCO中建立
连接,看来那个跟此没有关系),开始做下,按此步骤:
1。安装sap客户端,安装SAPGui和SAP SDK (如果你是SAP使用者,估计这部都做过了,没有安装在DELPHI中找不到相应的控件的)
2. Delphi中安装ActiveX部件
   2.1 SAPLogonControl, SAPBapiControl 安装
        component --> ActiveX import   (imported components: TSAPLogonControl, TSAPBapiControl)
  

   2.2 SAP remote Function call control安装
        project --> type library import (imported components: TSAPFunctions, TFunction, TParameter, TExports, TImports, TStructure)
  

     系统会自动建立一个文件:TSAPFunctionsOCX_TLB.pas
   做完这两步骤后,可以在DELPHI中看到控件如下:
  

  3.开始写DELPHI代码,测试连接
    3.1 新建一个DELPHI PROJECT,将SAPLogonControl1控件和SAPFunctions1控件拖到界面上;
3.2 再放两个按钮:一个是建立SAP连接,一个是调用SAP FUNCTION
     Connection :variant;(全局变量)
3.3 建立SAP连接:
       Connection                    := SAPLogoncontrol1.newConnection;
    Connection.User               := Ansiuppercase('wangnz');
    Connection.System             := 'IDS';
    Connection.Client             := '800';
    Connection.ApplicationServer := '192.168.5.112';
    Connection.SystemNumber       := '00';
    Connection.Password           := '321';
    //Connection.Language           := 'DE' ; //注意这个语言的,填DE还登录不上
    SAPLogonControl1.Enabled      := false;
  if Connection.LogOn(0,true) = True then
    begin
    ShowMessage('Logon O.K.');
    btn_CreatePO.Enabled:= true;
    SapBapiControl1.Connection:=Connection;
    sapFunctions1.Connection := Connection;
    end
    else
    begin
    ShowMessage('Error on logon :-(((');
    end;
    3.4 调用SAP FUNCTION:BAPI_PO_CREATE
     var MLDText : String;
    Funct,Header,POItems,Schedules,ItemsRow,
     SchedulesRow: Variant;
   begin
    (* 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' ;
  Header.Value[5] := '1000' ; //公司代码
    (* purcasing organisation 采购组织 *)
    Header.Value[5] := '1000' ;
  (* purcasing group *)
    Header.Value[6] := '026' ;
  (* forget the leading zeroes!!!                     *)
    Header.Value[8] := '111';   //供应商
  (*** 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]:='100-210';
  (* storage location *)
    ItemsRow.Value[11]:='0001';
  (* plant *)
    ItemsRow.Value[17]:='1000';
  (* netprice in purcasing document, *)
    (* in document currency              *)
    ItemsRow.Value[21]:='10000';
  (*** 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]:='20000523';
  (* 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;
  如此就将SAP连接起来,具体的实现SAP的功能都在SAP SE37中写功能而已;

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-115154-1-1.html 上篇帖子: SAP Control framework 下篇帖子: SAP中V1和V2的区别及各功能
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表