메뉴 건너뛰기

SAP 한국 커뮤니티

zbapi_java

sapjoy 2009.02.02 20:54 조회 수 : 2699

//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;


}


}

번호 제목 글쓴이 날짜 조회 수
331 REPORT zsapgos_002. sapjoy 2009.02.12 2458
330 REPORT ZSAPGOS_001. sapjoy 2009.02.12 2477
329 FUNCTION Z_BAPIALE_SEND. sapjoy 2009.02.10 2420
328 REPORT zale_001 . sapjoy 2009.02.10 2471
327 REPORT ZBAPI_002. sapjoy 2009.02.10 2590
326 FUNCTION Z_BAPI_REQ_FUNCLOC. sapjoy 2009.02.05 2421
325 REPORT ZBAPI_ALE sapjoy 2009.02.05 2334
» zbapi_java sapjoy 2009.02.02 2699
323 FUNCTION Z_BAPI_ASSETNAME_SEARCH sapjoy 2009.01.31 2898
322 REPORT z18_003 sapjoy 2007.03.06 3281
321 REPORT ZSMARTFORMS_07. sapjoy 2009.01.22 2389
320 REPORT zBADI_FIND sapjoy 2009.01.16 2732
319 REPORT ZBADI_003. sapjoy 2009.01.15 2403
318 REPORT zbadi_002. sapjoy 2009.01.10 2545
317 REPORT zbadi_001 sapjoy 2009.01.07 2527
316 doi_excel.xls file sapjoy 2008.12.26 2177
315 report zsapdoi_005. sapjoy 2008.12.26 2978
314 report zsapdoi_004. sapjoy 2008.12.26 2932
313 report zsapdoi_003. sapjoy 2008.12.26 2570
312 report zsapdoi_002. sapjoy 2008.12.26 4405