메뉴 건너뛰기

SAP 한국 커뮤니티

zbapi_java

sapjoy 2009.02.02 11:54 조회 수 : 2693

//Importing the required classes:


import com.sap.rfc.*;
import com.sap.rfc.exception.*;
import com.ibm.sap.bapi.*;
import com.ibm.sap.bapi.generated.*;


//Connecting to the R/3 System:


static private IRfcConnection establishConnection(MiddlewareInfo aMiddlewareInfo)


throws JRfcRemoteException


{


IRfcConnection aConnection = null ;


ConnectInfo aConnectInfo = null ;


UserInfo aUserInfo = null ;


String orbServerName = aMiddlewareInfo.getOrbServerName() ;


boolean bAdjusted = true;


if (!bAdjusted) {


throw (new JRfcRfcConnectionException (


"Please adjust the Connection-Parameters to your
needs! (See method "establishConnection")"));


}


//Connection information:
//SAP  시스템 정보 세팅


aConnectInfo = new ConnectInfo (


3, // int aRfcMode 3=R/3 or 2=R/2  => SAP R3 세팅.


null, // String aDestination


"9.7.12.7", // String aHostName YOUR HOSTNAME (e.g. IP-
//address) => IP 주소


0, // int aSystemNo YOUR SYSTEM-NUMBER = >시스템 번호


null, // String aGatewayHost


null, // String aGatewayService


null, // String aSystemName


null, // String aGroupName


null, // String aMsgServer


false, // Boolean isLoadBalancing


true); // Boolean isCheckAuthorization


//User information:
//사용자정보 세팅


aUserInfo = new UserInfo (


"MUSTER", // String aUserName, YOUR USERID => 사용자ID


"IDES", // String aPassword, YOUR PASSWORD => 비밀번호


"800", // String aClient, YOUR CLIENT NUMBER => 클라이언트


"e", // String aLanguage, YOUR PREFERRED  => 로그온 언어
//LANGUAGE


1103); // int aCodePage YOUR REQUIRED CODEPAGE


//Technical conversion for the selected middleware;
// Open connection:


IRfcConnectionFactory aConnectionFactory = FactoryManager.getSingleInstance().getRfcConnectionFactory() ;


aConnection = aConnectionFactory.createRfcConnection(aConnectInfo, aUserInfo) ;


aConnection.open() ;


//Returning the connection:


return aConnection ;


}


//Calling the main method:


public static void main (java.lang.String[] args)


//Setting up the connection using the selected middleware:


{


MiddlewareInfo aMiddlewareInfo = new MiddlewareInfo(args) ;


FactoryManager aFactoryManager = FactoryManager.getSingleInstance() ;


aFactoryManager.setMiddlewareInfo(aMiddlewareInfo) ;


//Initializing the connection object:


IRfcConnection aConnection = null ;


try


{


aConnection = establishConnection(aMiddlewareInfo) ;


}


catch (Exception ex)


{


System.out.println("ERROR : Could not create connection : " + ex) ;


System.exit(-1) ;


}


System.out.println("Connection established.");


// --- TEST CODE (start) --------------------------------------


try


{


printList(aConnection) ;


//Calling the BAPI:


//Declare an empty Object ID for the Business Object
//CompanyCode:
// [그림 6-5-2]에서 본 BAPI Object를 사용 Object name = CompanyCode


objectId = CompanyCode.getEmptyObjectId() ;


//Entering a value in the object ID:
//[그림 6-5-3]에서 본 Key 필드 COMPANYCODEID에 기본값 1000을 세팅함


objectId.getKeyField("COMPANYCODEID").setString("1000") ;


//Instantiate the object CompanyCode with the object ID:


companyCode = new CompanyCode(objectId) ; // Create 2nd
CompanyCode


System.out.println ("Successfully created new CompanyCode : '" + companyCode + "'") ;


printDetails(companyCode, aConnection) ;


}


// --- TEST CODE (end) ----------------------------------------


catch (Exception ex)


{


System.out.println ("Unexpected exception occurred:");


System.out.println (ex);


}


}


private static void printDetails(CompanyCode companyCode, IRfcConnection connection)


{


try


{


//Declare the parameters of the BAPI CompanyCode.GetDetail:
//[그림 6-5-2]에서 본 CompanyCode Object에 속해 있는 GetDetail Method 선언


CompanyCodeGetdetailParams aCompanyCodeGetdetailParams =


new CompanyCodeGetdetailParams() ;


//Aufruf des BAPI CompanyCode.GetDetail auf die Objektinstanz:


companyCode.getdetail(connection, aCompanyCodeGetdetailParams);


//Splitting the parameter object into its separate components
// 결과값 Bapi0002_2 구조체를 선언하고 값을 받아온다.


Bapi0002_2Structure struct = aCompanyCodeGetdetailParams.getCompanycodeDetail() ;


System.out.println ("The details of the companycode are : ") ;


//Splitting the structure into individual fields:


System.out.println ("CompCode : '" + struct.getCompCode() + "'");


System.out.println ("CompName : '" + struct.getCompName() + "'");


System.out.println ("City1 : '" + struct.getCity() + "'");


System.out.println ("Country1 : '" + struct.getCountry() + "'");


System.out.println ("Currency : '" + struct.getCurrency() + "'");


System.out.println ("Langu1 : '" + struct.getLangu() + "'");


System.out.println ("ChrtAccts : '" + struct.getChrtAccts() + "'");


System.out.println ("FyVariant : '" + struct.getFyVariant() + "'");


System.out.println ("VatRegNo : '" + struct.getVatRegNo() + "'");


System.out.println ("Company : '" + struct.getCompany() + "'");


System.out.println ("AddrNo : '" + struct.getAddrNo() + "'");


System.out.println() ;


}


catch (Exception ex)


{


System.out.println("Exception in printDetails() : " + ex) ;


}


return;


}


private static void printList(IRfcConnection connection)


{


try


{


//Declaring the parameter object:
// CompanyCode Object에 속해 있는 Getlist Method 선언


CompanyCodeGetlistParams aCompanyCodeGetlistParams =


new CompanyCodeGetlistParams() ;


//Actual BAPI call:
// getlist BAPI Method 호출


CompanyCode.getlist(connection, aCompanyCodeGetlistParams);


//Splitting the parameter objects into its separate components
// 결과값 Bapi0002_1 테이블을 선언하고 값을 받아온다.


Bapi0002_1Table table = aCompanyCodeGetlistParams.getCompanycodeList();


int rowCount = table.getRowCount() ;


System.out.println ("Returned table has " + rowCount + " lines.");


//Evaluating the table row by row:


for (int i = 0; i < rowCount; i++)


{


Bapi0002_1TableRow row = table.getRow(i) ;


System.out.println("t" + row.getCompCode() + "t" + row.getCompName()) ;


}


System.out.println() ;


}


catch (Exception ex)


{


System.out.println("Exception in printList() : " + ex) ;


}


return;


}


}

번호 제목 글쓴이 날짜 조회 수
589 REPORT ZDYNAMIC_ITAB_08. sapjoy 2009.02.16 2760
588 REPORT Z15_026 sapjoy 2007.01.31 2758
587 REPORT Z07_002 . sapjoy 2006.12.06 2755
586 REPORT Z17_019 [1] sapjoy 2007.02.14 2748
585 REPORT Z03_021 [5] sapjoy 2007.05.15 2737
584 REPORT Z03_005 [1] sapjoy 2006.12.02 2735
583 report zunicode_034. [1] sapjoy 2008.11.21 2734
582 REPORT z18_037 [3] sapjoy 2008.04.21 2728
581 REPORT zBADI_FIND sapjoy 2009.01.15 2724
580 REPORT Z15_027 . sapjoy 2007.02.01 2715
579 REPORT z18_032 sapjoy 2008.04.21 2710
578 TYPE-POOL ztgrp [1] sapjoy 2007.05.14 2699
577 REPORT Z07_007 sapjoy 2006.12.07 2698
» zbapi_java sapjoy 2009.02.02 2693
575 Z01_019 [2] sapjoy 2006.12.02 2688
574 report zunicode_031. sapjoy 2008.11.21 2684
573 TOTAL sapjoy 2009.02.19 2683
572 REPORT Z15_007 eabap 2007.01.23 2677
571 REPORT z18_017 sapjoy 2007.03.11 2672
570 REPORT z_userexit_01 sapjoy 2008.12.14 2655