SAP Java Connector - Excample 1: Simple RFC call

本文介绍如何使用SAP Java Connector调用简单的RFC功能模块ZNAS_HIE1_GET_MEMBER_FARM,该模块根据农场编号返回拥有过该农场的成员列表。通过示例代码展示了连接SAP系统、设置输入参数、执行RFC调用并处理返回结果的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

if (window.name != "content") document.write("

Click here to show toolbars of the Web Online Help System: show toolbars

"); <!-- !chm2web! -->

SAP Java Connector - Excample 1: Simple RFC call

Scenario

We will call the RFC function module ZNAS_HIE1_GET_MEMBER_FARM.that returns members that have owned a farm. Input to the function is a farm number, and output is a table of members that have owned the farm and Owner number (Sequence number of owners).

  • Class testJCO is excuted and calls class GetMemberFarm method GetMemberFarmFromSap. Input parameters to GetMemberFarm are Farm and Owner number.
  • GetMemberFarmFromSap executes RFC ZNAS_HIE1_GET_MEMBER_FARM, that returns a table of members that have owned the farm from the input parameters.
  • GetMemberFarmFromSap loops through the table and finds the member where ZZCHCODE (Owner numer), is equal owner number from the input-parameters. and returns the member.

Code

Class testJCO

 testJco
{   
         main(String[] args)
        {   
                GetMemberFarm testGetMemberFarm = new GetMemberFarm();
                String memberFarm= testGetMemberFarm.GetMemberFarmFromSap("0111020155","02");
                System.out.println("Memberfarm: " + memberFarm);
        }

}

Class GetMemberFram

 com.sap.mw.jco.*;  //The JCO
 


 GetMemberFarm {
        
 String GetMemberFarmFromSap(String farm, String OwnerNumber)    
  {  String zzmemb ="";
         String memberFarm = "";
     JCO.Repository mRepository;
     JCO.Client mConnection = null;
     JCO.Function myFunction = null;
          try
          { 
                mConnection = JCO.createClient("800",           //SAP client
                                           "HFR",       //User ID
                                           "vimmer3",     //Password
                                           "EN",            //Language
                                           "53.205.22.71", //Host
                                           "03");           //System
        
        
            mConnection.connect();
            System.out.println("Connection OK");
          }
          catch (Exception ex)
          {     
                System.out.println(ex);
          }

      try
          {
        //Create repository
        mRepository = new JCO.Repository( "GetMember", mConnection );
        
        //Get a function template from the repository
        IFunctionTemplate ftemplate = mRepository.getFunctionTemplate("ZNAS_HIE1_GET_MEMBER_FARM");
        
        //Create function
        myFunction = new JCO.Function(ftemplate);
        System.out.println("Function created");
        
        //Set import parameter
        JCO.Field zzfarm = myFunction.getImportParameterList().getField("ZZFARM");
        zzfarm.setValue(farm);
       
        
        System.out.println("Parameters ok");
        
        
          } 
     catch (Exception ex)          
         {               
        System.out.println(ex);
         }
     try
         { 
        mConnection.execute(myFunction);
        System.out.println("RFC Call OK");            
         }
     
     catch (Exception ex)         
         {  System.out.println(ex); //Exception from function            
        
         }      
     

     JCO.Table gt_HIERARCHY = null;
     try
         {  
        gt_HIERARCHY=myFunction.getTableParameterList().getTable("GT_HIERARCHY");
        
        //Loop thhrough table and return the member that has
        // changecode (ZZCHCODE) = 02
        for (int i = 0; i < gt_HIERARCHY.getNumRows(); i++)
        {   gt_HIERARCHY.setRow(i);
            String zzchcode = gt_HIERARCHY.getString("ZZCHCODE");
            if (zzchcode.equals(OwnerNumber))                           
            {
                zzmemb = gt_HIERARCHY.getString("ZZMEMB");                    
            }   
                
        }
        
         }
     
     catch (Exception ex)         
         {  System.out.println(ex);              
        
         }      
     
     
     
     try
           {
            mConnection.disconnect();   
            System.out.println("Disconnected from SAP");
           }
      catch (Exception ex)
          { 
        System.out.println(ex);
          }  
          
      return zzmemb;
  }  
        
} //public class GetMemberFarm

var fe = FindFrame("toc", top); if ((fe != null) && (chmtop.c2wtopf.jstree != null)) { if (chmtop.c2wtopf.FITEMS[chmtop.c2wtopf.pagenum] != chmtop.c2wtopf.pageid) chmtop.c2wtopf.jstree.OpenTreeNode("" + chmtop.c2wtopf.pageid); } <!-- CHM2WEB --><!-- DO NOT DELETE OR MODIFY THIS CODE WITHOUT WRITTEN PERMISSION OF A!K RESEARCH LABS -->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值