//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;
}
}
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
590 | REPORT Z12_20. | sapjoy | 2012.07.30 | 926 |
589 | REPORT z12_10. | sapjoy | 2012.07.30 | 927 |
588 | REPORT z05_05. | sapjoy | 2012.07.30 | 931 |
587 | REPORT Z12_19 | sapjoy | 2012.07.30 | 931 |
586 | REPORT z12_12. | sapjoy | 2012.07.30 | 932 |
585 | REPORT z14_04. | sapjoy | 2012.08.01 | 932 |
584 | REPORT z17_11 . | sapjoy | 2012.08.01 | 934 |
583 | REPORT z15_11. | sapjoy | 2012.08.01 | 937 |
582 | REPORT Z16_02. | sapjoy | 2012.08.01 | 939 |
581 | REPORT Z07_05. | sapjoy | 2012.07.30 | 943 |
580 | REPORT z05_13. | sapjoy | 2012.07.30 | 945 |
579 | REPORT z15_27. | sapjoy | 2012.08.01 | 946 |
578 | REPORT z05_15. | sapjoy | 2012.07.30 | 948 |
577 | REPORT z15_19. | sapjoy | 2012.08.01 | 952 |
576 | REPORT Z12_02 | sapjoy | 2012.07.30 | 954 |
575 | REPORT z17_09 . | sapjoy | 2012.08.01 | 955 |
574 | REPORT z12_09. | sapjoy | 2012.07.30 | 960 |
573 | REPORT z17_12 . | sapjoy | 2012.08.01 | 962 |
572 | REPORT Z12_18. | sapjoy | 2012.07.30 | 967 |
571 | REPORT z15_09. | sapjoy | 2012.08.01 | 967 |