if (window.name != "content")
document.write("
");
<!-- !chm2web! -->
SAP Java Connector - Example 2: CompanyCode_GetList
This example shows how to use the BAPI CompanyCode_GetList to retrieve a list of company codes from SAP and display them in a listbox..
//-------------------------------------------------------------
// GetCompanycodeList CLASS
//-------------------------------------------------------------
import com.sap.mw.jco.*; //The JCO
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.border.*;
public class GetCompanycodeList extends JFrame implements ActionListener
{
private JCO.Client mConnection = null;
private JTextField returnValues;
private IRepository mRepository;
private JCO.Function myFunction;
private JList companyCodeList;
public GetCompanycodeList()
{ //------------------------------------------------------------
//Set size of window and center it on the screen
//------------------------------------------------------------
setSizeAndPosition();
//------------------------------------------------------------
// Windows listener
//------------------------------------------------------------
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ if (mConnection != null)
JCO.releaseClient(mConnection);
System.exit(0);
}
} );
//------------------------------------------------------------
// Add Logon and Cancel button
//------------------------------------------------------------
Container myContentPane = getContentPane();
JPanel buttonPanel = new JPanel();
Border bevel1 = BorderFactory.createBevelBorder(0);
buttonPanel.setBorder(bevel1);
myContentPane.add(buttonPanel,BorderLayout.SOUTH);
JButton logonButton = new JButton("Logon");
JButton cancelButton = new JButton("Cancel");
logonButton.setActionCommand("logon_action");
cancelButton.setActionCommand("cancel_action");
logonButton.addActionListener(this);
cancelButton.addActionListener(this);
buttonPanel.add(logonButton);
buttonPanel.add(cancelButton);
//------------------------------------------------------------
// Add textfield for system messages
//------------------------------------------------------------
returnValues = new JTextField(50);
myContentPane.add(returnValues,BorderLayout.NORTH);
//------------------------------------------------------------
// Add a listbox for Company codes
//------------------------------------------------------------
companyCodeList = new JList();
JScrollPane scrollPane = new JScrollPane(companyCodeList );
myContentPane.add(scrollPane,BorderLayout.CENTER);
}
//---------------------------------------------------------
// Action listener for push buttons
//---------------------------------------------------------
public void actionPerformed(ActionEvent evt)
{ Object mySource = evt.getSource();
String command = evt.getActionCommand();
if (command == "logon_action")
ConnectToSap();
else if (command == "cancel_action")
if (mConnection != null)
JCO.releaseClient(mConnection);
// System.exit(0);
}
//------------------------------------------------------------
// Logon and display Company Code list
//------------------------------------------------------------
private void ConnectToSap()
{
//--------------------------------------------------------
// Logon to SAP
//--------------------------------------------------------
try
{
mConnection = JCO.createClient("800", //SAP client
"WMHEFRN", //User ID
"SLUPPERT3", //Password
"EN", //Language
"172.29.80.207", //Host
"00"); //System
mConnection.connect();
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(this,"Error in logon");
System.exit(0);
}
JOptionPane.showMessageDialog(this, "Logon ok");
//---------------------------------------------------------
// Create metadata with JCO Repository
//---------------------------------------------------------
try
{ mRepository = new JCO.Repository("Henrik",mConnection);
}
catch (Exception ex)
{ JOptionPane.showMessageDialog(this,"Error reading meta data");
System.exit(0);
}
//---------------------------------------------------------
// Get a function template from the repository, create a
// function from it and and execute the function
//---------------------------------------------------------
try
{
// Get a function template from the repository
IFunctionTemplate ftemplate = mRepository.getFunctionTemplate("BAPI_COMPANYCODE_GETLIST");
// Create a function from the template
myFunction = new JCO.Function(ftemplate);
//Execute function
mConnection.execute(myFunction);
}
catch (Exception ex)
{ JOptionPane.showMessageDialog(this,"Error executing function");
System.exit(0);
}
//---------------------------------------------------------
// Handle return data
//---------------------------------------------------------
// Check return parameter.
JCO.Structure vReturn = myFunction.getExportParameterList().getStructure("RETURN");
if (vReturn.getString("TYPE").equals("") ||
vReturn.getString("TYPE").equals("S") )
returnValues.setText("OK");
else
returnValues.setText("Returnvalues: " + vReturn.getString("MESSAGE"));
// Get companycode list
JCO.Table company_codes = myFunction.getTableParameterList().getTable("COMPANYCODE_LIST");
// Create vector an store Company code data in it
Vector listElements = new Vector(0,1);
for (int i = 0; i < company_codes.getNumRows();i++)
{ company_codes.setRow(i);
listElements.setSize( i + 1);
listElements.addElement( company_codes.getString("COMP_CODE") + " " +
company_codes.getString("COMP_NAME"));
}
// Use vector as listbox source
companyCodeList.setListData(listElements);
// Release the client into the pool
JCO.releaseClient(mConnection);
JOptionPane.showMessageDialog(this,"Ended without errors");
}
//---------------------------------------------------------
//Set window properties and center the frame on the screen
//---------------------------------------------------------
private void setSizeAndPosition()
{
setSize(300,400);
setTitle("Event handling");
setResizable(false);
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
//Change look and feel to Windows
try
{ //Call the static setLookAndFeel method and give it the name of the
//look and feel you want
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//Refresh components
SwingUtilities.updateComponentTreeUI(this);
}
catch(Exception e) {}
}
}
//-----------------------------------------------------------------
// Run CLASS - Runs the application
//-----------------------------------------------------------------
public class Run
{ public static void main(String[] args)
{ GetCompanycodeList GetCompanycodeList1 = new GetCompanycodeList();
GetCompanycodeList1.show();
}
}
Preparations
The application consists of two classes stored in the two files Run.java and and GetCompanycodeList.java. We are using a directory name d:\javatest for the classes.
For our convinience we also copy the SAP/Java connector class and the jRFC12.dll to the same directory, so we easily can include them in the CLASSPATH.
Copy: jCO.jar and jRFC12.dll to d:\javatest
Compiling:
We now compile the two classes. Remember to use the classpath statement
d:\javatest>javac *.java -classpath d:\javatest;d:\javatest\jCO.jar
Running the application from a DOS prompt:
Aalso here remember the classpath (-cp)
d:\javatest>java -cp d:\javatest;d:\javatest\jCO.jar Run
Making a JAR file
Make a manifest file in notepad and name it mainclass. In the manifest write:
Main-Class: Run
Make the JAR file:
jar cvmf mainclass sap.jar *.class jCO.jar
Important: When you compile the java claases a file named GetCompanycodeList$1.class is automatically generated. This file must be included in the JAR file.
Running the JAR file from a DOS prompt:
java -jar sap.jar
分享到:
相关推荐
夹板剪刀 :police_officer_light_skin_tone:检测长调用链/嵌套表达式 :scissors: :person_raising_hand: 向“ NullPointerError”说再见 :bomb:介绍名为“嵌套表达式”的规则将使then/catch方法中的... getList ( )
表的普通字段 一对多字段 多对多字段 插入数据 ... G_authors_list=request.POST.getlist('authors')#-------值为:[3,7] publish_obj=Publish.objects.get(id=G_publish)#查找Publish表对应id的obj authors_obj_li
一 Jeecms安装过程 ...<id name="id" type="java.lang.Integer" column="id"><generator class="identity"/></id> <property name="title" column="title" type="java.lang.String" not-null="true" /> ...
创建一个支持选举的Java IDL应用。服务器有两个方法:1)getList; 2)castVote
变更日志 --- 2.1.1 --- [Add] Windows::getSystemDrive() Migrate to jppm --- 2.1 --- [Add] Windows::reboot() [Add] Windows::shutdown() [Add] Windows::pressKey() ...[Fix] Startup::getList()
使用 Java SAX 的基本 Java RSS 阅读器 只是 SAX 的 DefaultHandler 的基本实现,用于解析 RSS 2 提要。 不依赖于任何外部库,它只使用 SAX(自 Java 5 起包含在 JavaSE 中,也在 Android 上)。 使用示例 ...
ENVI/IDL程序,需要通过Java来调用,拓展了IDL的应用场景。Java调用IDL程序需要通过 IDL bridge来完成这一目的,该文件包括对IDL程序编写的规范格式示范,以及提供了本人编写的参考例子,提到在实现调用IDL过程中...
重装java隐藏源码Jinx - 用于 Java 的 Flickr API Jinx 是 Flickr API 的 Java 接口。 项目目标是: 使用简单明了 完整覆盖 Flickr API 最低的图书馆要求 使用金克斯 首先,转到并熟悉 Flickr API。 包 ...
图标素材下载工具系统结构:GetList,mysub, ======窗口程序集1 || ||------__启动窗口_创建完毕 || ||------GetList || ||------_按钮1_被单击 || ||------mysub
字体真棒v5图标 返回Font Awesome v5图标的实际列表(纯... getList ( ) . then ( icons => console . log ( icons . length ) ) ; //=> 875 faIcons . getList ( ) . then ( icons => console . log ( icons [ 0 ] )
NodeJS的odoo JSON-RPC客户端 概要 var odoo = require ( './lib/odoo.js' ) ; var opts = { login : 'admin' , ... database_getlist ( callback ) ; // get model function callback ( err , res
代码如下:/* 日期:2009-03-19 功能:根据各种条件获取 游戏国家任务 列表数据 */ Create procedure [dbo].[PrGs_Nation_Task_GetList] @PageSize int = 100, — 每页显示记录条数,默认为100 @PageIndex int = 1, ...
字体真棒图标 返回Font Awesome图标的实际... getList ( ) . then ( icons => console . log ( icons . length ) ) ; //=> 675 faIcons . getList ( ) . then ( icons => console . log ( icons [ 0 ] ) ) ; /*=> {
fields : [ "field1" , "field2" , "field_x0020_three" , "etc." ] , completefunc : function ( raw ) { // raw contains 4 parameters: changeToken, data, mapping, deletedIds var jsonData = raw . data ;...
getList(选项,回调) 获取使用此API密钥上传的所有文档的列表。 options (object) : limit (int) -要返回的文档数(默认= 10,最大= 50) created_before (Date) -返回的文档创建时间戳的上限(默认=现在) ...
2.输入聊天昵称 3.输入"-quit"会自动退出聊天 4.输入"-getList"会得到在线用户的名称 5.输入"-to <用户名称> <聊天信息>"会把信息发送到指定的用户处,他人看不到 6.输入"-help"会得到...
getList GET http://my.api.url/posts?order=title.asc&offset=0&limit=24&filterField=eq.value getOne GET http://my.api.url/posts?id=eq.123 getMany GET http://my.api.url/posts?id=in.(123,4
getList GET http://my.api.url/records/posts?order=title,ASC&page=1,25 getOne GET http://my.api.url/records/posts/123 getMany GET http://my.api.url/records/posts?id=123,456,789 getManyReference ...
统一变更集获取/列出Unity编辑器更改集用作节点模块安装npm install unity-changeset例子const { getUnityChangeset , scrapeArchivedChangesets , scrapeBetaChangesets } = require ( 'unity-changeset' ) ;...
list(model, id, params) - 类似于在 Retangular 资源上调用 getList() get(model, id, params) - 类似于在 Restangular 资源上调用 get() store(id, obj) - 手动存储数据 onCacheInvalid(callback) - 每当服务器...