Chinaunix首页 | 论坛 | 博客
  • 博客访问: 668291
  • 博文数量: 194
  • 博客积分: 7067
  • 博客等级: 少将
  • 技术积分: 2008
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-09 14:48
个人简介

我很好

文章分类

全部博文(194)

文章存档

2019年(1)

2018年(1)

2017年(3)

2015年(2)

2012年(2)

2011年(1)

2010年(27)

2009年(15)

2008年(142)

分类:

2008-05-24 16:35:46

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, OleCtrls, SAPFunctionsOCX_TLB,
  SAPLogonCtrl_TLB;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Panel1: TPanel;
    Panel2: TPanel;
    SAPLogonControl1: TSAPLogonControl;
    SAPFunctions1: TSAPFunctions;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  Tab,Funct, Connection : VARIANT ;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
   Connection                  := SAPLogoncontrol1.newConnection;
   Connection.User             := 'if1';
   Connection.System           := '00';
   Connection.Client           := '300';
   Connection.ApplicationServer:= '172.16.98.20';
   Connection.SystemNumber     := '00';
   Connection.Password         := '801104';
   Connection.Language         := 'ZH' ;
  if Connection.LogOn(0,true) = true then
  begin
    SAPFunctions1.Connection := Connection;
    funct := sapFunctions1.add('BAPI_MATERIAL_GET_DETAIL');
    funct.exports('MATERIAL').value := '000000000013022256';
    if not funct.call then
    showMessage(funct.exception)
    else
    begin
     tab := funct.imports.item('MATERIAL_GENERAL_DATA');
     Panel1.caption := tab.value(1);
     Panel2.caption := tab.value(6);
    end;
  end;
end;
end.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
import com.sap.mw.jco.*;
public class SAP extends Object
{
 public static void main (String str[])
 {
  SAP app=new SAP();
 }
 int count;
 JCO.Client mConnection;
 JCO.Repository mRepository;
 String[] SAPInterfaces;
 
 public SAP()
 {
  try {
   // Logon info
    mConnection = JCO.createClient("300", // SAP client
                                       "if1", // userid
                                       "801104", // password
                                          null, // language
                                 "172.16.98.20", // application server host name
                                            "00"); // system number
   mConnection.connect();
   mRepository = new JCO.Repository("ARAsoft", mConnection);
   System.out.println("SAP连接成功");
  } catch (Exception ex) {
   ex.printStackTrace();
   System.exit(1);
  }
  JCO.Function function = null;
  JCO.Table codes = null;
  JCO.Table DATA=null;
  
  try
  {
   function=this.createFunction("ZRFC_READ_TABLE");
   if (function == null)
   {
    System.out.println(
     "BAPI_MATERIAL_GETLIST" + " not found in SAP.");
    System.exit(1);
   }
   codes = function.getTableParameterList().getTable("FIELDS");
   DATA =function.getTableParameterList().getTable("DATA");
   JCO.ParameterList input=function.getImportParameterList();
   input.setValue("MSEG", "QUERY_TABLE");
   input.setValue(20,"ROWCOUNT");
   mConnection.execute(function);
   System.out.println(Integer.toString(codes.getNumRows()));
    for (int i = 0; i < DATA.getNumRows();i++)
    {
     DATA.setRow(i);
     System.out.println(DATA.getString("WA"));
    }
  }
  catch (Exception ex)
  {
   ex.printStackTrace();
   System.exit(1);
  }
 }
 public JCO.Function createFunction(String name) throws Exception
 {
  try {
   IFunctionTemplate ft =
    mRepository.getFunctionTemplate(name.toUpperCase());
   if (ft == null)
    return null;
   return ft.getFunction();
  } catch (Exception ex)
  {
   throw new Exception("Problem retrieving JCO.Function object.");
  }
 }
}
 
 
阅读(1509) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~