JAVA与SAP数据交互的方式总结_第1页
JAVA与SAP数据交互的方式总结_第2页
JAVA与SAP数据交互的方式总结_第3页
JAVA与SAP数据交互的方式总结_第4页
JAVA与SAP数据交互的方式总结_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、JAVA与SAP数据交互的方式总结日期:2009-12-09             1、RFC方式       Java程序直接通过RFC访问SAP的对象(或称函数,可能叫法不对)SAP提供了BAPI(Business Application Programming Interface),BAPI是SAP系统对外提供的一系列接口,主要是使第三方程序通过这些接口来使用SAP,从而方便客户定制某些程序.VB,Java,

2、C,C+等都可以通过BAPI来访问SAP.BAPI是通过R/3系统上的RFC(Remote function call)功能来实现的.因为BAPI的强大功能作为基础,SAP就完全可以选择Java在CRM上加强各种功能,比如可以用Java快速开发一个实现特定功能的客户端。针对Java,SAP也提供了一个API叫Java Connector(JCo),可以使用它方便的调用BAPI提供的接口。      举例说明 :在我们的某一个项目中,需要每个月从R3取出供应商的寄售和非寄售汇总结算数据和明细数据,展现在供应商信息平台上,供供应商开发票和财务部付款

3、进行结算,那么可以做一个定时器,通过RFC在每个月的一号0点将结算数据取出。private final static String FUNCTION_GET_NONVMI_DATA = 'ZPUR_DATA_GET_TMP1' /*  * 处理接口参数  */ private JCO.ParameterList getNonVmiTableParameterList(   JCO.Client aConnection, String bukr, String month, String start, 

4、;  String end, String lifnr)   IRepository aRepository = new JCO.Repository('SAPRep', aConnection);  IFunctionTemplate functionTemplate = aRepository    .getFunctionTemplate(FUNCTION_GET_NONVMI_DATA);  logger.debug('FunctionTemp

5、late=' + functionTemplate);  JCO.Function function = new JCO.Function(functionTemplate);  JCO.ParameterList input = function.getImportParameterList();  input.getField('BUKRS').setValue(bukr);  /input.getField('SPMON').setValue(month); 

6、 input.getField('LIFNR').setValue(lifnr);  input.getField('ZBUDATB').setValue(start);  input.getField('ZBUDATN').setValue(end);  logger.debug('ImportParameterList=' + input);  aConnection.execute(function);  JCO.P

7、arameterList tableParams = function.getTableParameterList();  return tableParams; 2、Idoc方式   适用于中间文件的IDoc定义格式,是SAP企业系统软件的应用程序之间或SAP应用程序与外部程序之间电子数据交换用的标准数据格式。IDoc是SAP的应用程序连接系统的数据转换工具。IDoc用于数据异步处理:每个IDoc生成独立的文本文件,无需连接中央数据库,就可以传送给要求数据的工作平台。SAP的另一个系统业务应用程序接口则用于数据同步处理。一个大公司的网络操作环

8、境很可能需要各地分公司的电脑都能与公司的主数据库连接。这些电脑很可能是用不同的硬件或操作系统平台。因为IDoc对数据进行了压缩,所以它无需变换格式就能在不同的操作系统上使用。       IDoc类型指定不同种类的数据,比如说购买订单或发票,它们可能被划分为更细小的数据种类,即信息类型。更详细的分类意味着一个IDoc类型只能储存某一特定交易所需的数据,这样既提高了工作效率又降低了资源损耗。在事务处理过程中,IDoc随时会生成。例如,在运货交易过程中,可能会产生打印货运清单所需数据的IDoc。客户在SAP系统执行完一项交易后,在数据传送

9、过程中和经过ALE通讯层时,一个或多个IDoc会生成。通讯层执行远程功能调用,使用由客户模式规定得端口定义和RFC介面定义。IDoc的接收者可能为R/3、R/2或一些外部系统。      在采用IDOC方式的时候,可以采用IDOC落地或不落地的方式,一般只有在跟踪测试或做传输记录的时候的采用IDOC落地的方式,一般其他情况基本上都是采用不落地的方式。public class JcoIdocServer extends JCoIDoc.Server   private final Log logger = LogFactory

10、.getLog(JcoIdocServer.class);  public JcoIdocServer(java.util.Properties properties,    IRepository jcoRepository, IDoc.Repository idocRepository)    super(properties, jcoRepository, idocRepository);  / constructor MyIDocServer  /*

11、0;  * Overridden method of JCoIDoc.Server. Function requests that do not   * contain IDocs will be handled here. These requests will be stored as   * XML the incoming path. No other action will be done. The   * return values won't be filled and no exception wil

12、l be thrown to the   * caller.   */  protected void handleRequest(JCO.Function function)    logger.error('error:incoming function request ''     + function.getName() + '',but this should be not happen.');&#

13、160; / method handleRequest  /*   * Overridden method of JCoIDoc.Server. Function requests that contain   * IDocs will be handled here. All IDocs will be stored as XML files in   * the incoming path. Additionally, IDocs that are part of an ORDERS 

14、60; * message will be processed specifically. Some relevant information is   * extracted from these IDocs and will be stored in a text the   * incoming path.   */  protected void handleRequest(IDoc.DocumentList documentList)    logger.debug('

15、;Incoming IDoc list request containing '     + documentList.getNumDocuments() + ' documents.');   IDoc.DocumentIterator iterator = documentList.iterator();   IDoc.Document doc = null;   while (iterator.hasNext()  

16、   doc = iterator.nextDocument();    logger.debug('Processing document no. ' + doc.getIDocNumber()      + '.');    JcoIdocAudit jcoIdocAudit = new JcoIdocAudit();    jcoIdocAudit.

17、setTabnam(doc.getTableStructureName();    jcoIdocAudit.setMandt(doc.getClient();    jcoIdocAudit.setDocnum(doc.getIDocNumber();    jcoIdocAudit.setDocrel(doc.getIDocSAPRelease();    jcoIdocAudit.setStatus(doc.getStatus()

18、;    jcoIdocAudit.setDirect(doc.getDirection();    jcoIdocAudit.setOutmod(doc.getOutputMode();    jcoIdocAudit.setExprss(doc.getExpressFlag();    jcoIdocAudit.setTest(doc.getTestFlag();    jcoIdocAudi

19、t.setIdoctyp(doc.getIDocType();    jcoIdocAudit.setCimtyp(doc.getIDocTypeExtension();    jcoIdocAudit.setMestyp(doc.getMessageType();    jcoIdocAudit.setMescod(doc.getMessageCode();    jcoIdocAudit.setMesfct(doc.getMessa

20、geFunction();    jcoIdocAudit.setStd(doc.getEDIStandardFlag();    jcoIdocAudit.setStdvrs(doc.getEDIStandardVersion();    jcoIdocAudit.setStdmes(doc.getEDIMessageType();    jcoIdocAudit.setSndpor(doc.getSenderPort(); 

21、;   jcoIdocAudit.setSndprt(doc.getSenderPartnerType();    jcoIdocAudit.setSndpfc(doc.getSenderPartnerFunction();    jcoIdocAudit.setSndprn(doc.getSenderPartnerNumber();    jcoIdocAudit.setSndsad(doc.getSenderAddress(); &

22、#160;  jcoIdocAudit.setSndlad(doc.getSenderLogicalAddress();    jcoIdocAudit.setRcvpor(doc.getRecipientPort();    jcoIdocAudit.setRcvprt(doc.getRecipientPartnerType();    jcoIdocAudit.setRcvpfc(doc.getRecipientPartnerFunction();&#

23、160;   jcoIdocAudit.setRcvprn(doc.getRecipientPartnerNumber();    jcoIdocAudit.setRcvsad(doc.getRecipientAddress();    jcoIdocAudit.setRcvlad(doc.getRecipientLogicalAddress();    jcoIdocAudit.setCredat(doc.getCreationDateAsSt

24、ring();    jcoIdocAudit.setCretim(doc.getCreationTimeAsString();    jcoIdocAudit.setRefint(doc.getEDITransmissionFile();    jcoIdocAudit.setRefgrp(doc.getEDIMessageGroup();    jcoIdocAudit.setRefmes(doc.getEDIMessage();&

25、#160;   jcoIdocAudit.setArckey(doc.getArchiveKey();    jcoIdocAudit.setSerial(doc.getSerialization();    jcoIdocAuditManager.create(jcoIdocAudit);    String result = new String       JcoIdocAudit

26、.OPERATION_FAILURE, '未知错误' ;    String msgType = doc.getMessageType();    logger.debug('Processing message of type '' + msgType + ''.');    if ('MATMAS'.equals(msgType)      l

27、ogger.debug('idocMcessMATMAS(doc),msgType='       + msgType);     logger.debug('idocManager=' + idocManager);     result = idocMcessMATMAS(doc);     else  

28、;    logger.debug('invalid msgType:' + msgType);     return;        jcoIdocAudit.setOpcod(result0);    jcoIdocAudit.setOpmsg(result1);    jcoIdocAuditManager.update(jc

29、oIdocAudit);     / method handleRequest  /*   * The following 4 methods for transaction management are not   * implemented here in this sample program. For a description on how to   * implement them in real production scenarios please see the JCo API   * specification for the JCO.Server class.   */  protected boolean onCheckTID(String tid)    return true;  / meth

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论