메뉴 건너뛰기

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;


}


}

번호 제목 글쓴이 날짜 조회 수
670 <b>easy abap 소스 전체 파일 입니다. [188] file sapjoy 2008.05.01 10124
669 REPORT z18_033 [47] sapjoy 2008.10.13 9031
668 REPORT Z15_003 [49] sapjoy 2008.04.15 7498
667 report zunicode_027. [4] sapjoy 2008.11.21 6262
666 REPORT Z20_01. sapjoy 2012.08.01 5062
665 REPORT z18_03. sapjoy 2012.08.01 4557
664 Z01_012 [9] sapjoy 2006.12.02 4546
663 Z_EXPORT_GRAPHIC_FROM_SE78 [1] sapjoy 2011.03.28 4443
662 report zsapdoi_002. sapjoy 2008.12.26 4405
661 REPORT zsmw0010 sapjoy 2010.10.11 4313
660 REPORT z18_028 sapjoy 2007.04.09 4278
659 report zsalv_045 . sapjoy 2010.08.20 4262
658 Dynamic Table Maintenance [1] sapjoy 2006.12.04 4094
657 REPORT ZTABLE_UTIL sapjoy 2010.10.09 4010
656 REPORT Z19_02. sapjoy 2012.08.01 3926
655 report zsaptip_009 [1] sapjoy 2010.12.10 3852
654 INCLUDE ZXF04U01 sapjoy 2008.12.15 3695
653 REPORT ZTEST_ABAPTPDF sapjoy 2010.10.09 3691
652 REPORT Z_3DGRAPH. [1] sapjoy 2010.10.17 3659
651 REPORT zfalv_011. sapjoy 2011.02.16 3624