본문 바로가기

SAP ABAP

SAP JCO3 RFC 연동

1) JAVA->SAP RFC FUNTION호출

 

SAP Software DownloadCenter에서 jco라이브러리를 다운로드 받는다.

 

Wndows 기준

 

sapjco3.jar -> 이클립스 기준 lib 폴더 만들어서 넣는다.

sapjco3.dll -> /windows/system32 폴더에 넣는다.

 

gradle build 경로를 셋팅한다.

 

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation files("lib/sapjco3.jar")
	compileOnly 'org.projectlombok:lombok'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	runtimeOnly 'com.h2database:h2'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

 

SAP으로가서 RFC 구성을한다.

T-CODE : SM59

RFC USER Login을 하기 위한 통신id를 생성한다.

 

권한부여

 

 

SAP RFC 환경설정 끝.

 

SAP Funtion을 만든다. se37 이동

 

소스

 

import 영역

 

export영역

 

table영역

 

속성에서 remote function 체크를 한다.

 

다시 자바소스로 돌아간다.

JcoTest1.java

package kr.co.kblife;

import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoParameterList;
import com.sap.conn.jco.JCoTable;

public class JcoTest1 {
	
	public static void main(String[] args) throws JCoException {
		// step1Connect();
		// step2ConnectUsingPool();
		step3SimpleCall();
	}

	
	/**
	 * 부족자재 조회 관련 인터페이스 테스트
	 * @throws JCoException
	 */
	public static void step3SimpleCall() throws JCoException {
		try {
			JCoDestination destination = JCoDestinationManager.getDestination(DestinationConcept.SomeSampleDestinations.ABAP_AS1);
			JCoFunction function = destination.getRepository().getFunction("ZBC_GET_DATA");
			if (function == null) {
				System.out.println("function is null");
			}
			JCoParameterList listParam = function.getImportParameterList();

			listParam.setValue("I_BUKRS", "1000"); 
			listParam.setValue("I_GJAHR", "2024");
			listParam.setValue("I_BELNR", "101201");

			function.execute(destination);

//			String RESTAT = (String) function.getExportParameterList().getValue("O_RETURN1");
//			System.out.println(RESTAT);
//
//			String REMSG = (String) function.getExportParameterList().getValue("O_RETURN1");
//			System.out.println(REMSG);
			
			JCoTable codes = function.getTableParameterList().getTable("ET_LIST");

			//JCoTable tables = function.getTableParameterList().getTable("ZTMMC5030S");
			for (int i = 0; i < codes.getNumRows(); i++) {
	            // 테이블 로우 커서 세팅
	            codes.setRow(i);
	            // 테이블 로우 별 값 프린트
	            System.out.println("STD_DT => " + codes.getString("NUM1") );
	            System.out.println("WERKS => "  + codes.getString("NUM2") );
	            System.out.println("LIFNR => "  + codes.getString("NUM3") );
	            System.out.println("MATNR => "  + codes.getString("NUM4") );
//	            System.out.println("REVLV => "  + codes.getString("REVLV") );
//	            System.out.println("STD_TM => " + codes.getString("STD_TM") );
//	            System.out.println("WC_CHECK => " + codes.getString("WC_CHECK") );
//	            System.out.println("REQ_TY => " + codes.getString("REQ_TY") );
//	            System.out.println("ARBPL => "  + codes.getString("ARBPL") );
//	            System.out.println("MEINS => "  + codes.getString("MEINS") );
//	            System.out.println("PLAN_STOCK_QTY => " + codes.getString("PLAN_STOCK_QTY") );
//	            System.out.println("PLAN_VMI_STOCK_QTY => " + codes.getString("PLAN_VMI_STOCK_QTY") );
//	            for(int index = 1; index < 15; index++ ) {
//	            	
//		            System.out.println(String.format("D%02d_QTY1", index) + " => " + codes.getString(String.format("D%02d_QTY1", index)) );
//		            System.out.println(String.format("D%02d_QTY2", index) + " => " + codes.getString(String.format("D%02d_QTY2", index)) );
//		            System.out.println(String.format("D%02d_QTY3", index) + " => " + codes.getString(String.format("D%02d_QTY3", index)) );
//	            }
	             
	        }
			System.out.println(codes);

		} catch (

		JCoException e) {
			System.out.println(e.toString());
			return;
		}
	}
}

DestinationConcept.java

package kr.co.kblife;

import com.sap.conn.jco.ext.DestinationDataProvider;

/**
 * The application does not deal with single connections anymore. Instead it works with logical destinations like ABAP_AS1 and
 * ABAP_AS2 which separates the application logic from technical configuration. JCo retrieves destination information from the
 * registered {@link DestinationDataProvider}. See {@link CustomDestinationDataProvider} to understand how to implement your own
 * storage of destinations. For these test examples we use the jcoDestination files in this package. Those are interpreted by
 * the default {@link DestinationDataProvider} built-in to JCo and allow fast proof-of-concepts. Replace the dummy values and
 * put the files in the working directory. However, don't use them in a productive setup, refer to
 * {@link CustomDestinationDataProvider} how you have to implement {@link DestinationDataProvider} properly and make sure to use
 * an implementation with a secure storage. The properties that need to be supported by the implementation can be found in the
 * documentation of {@link DestinationDataProvider}.
 */
public class DestinationConcept
{

    public static class SomeSampleDestinations
    {

        public static final String ABAP_AS1="ABAP_AS1";
        public static final String ABAP_MS="ABAP_MS";
        public static final String ABAP_WS="ABAP_WS";

        // public static final String ABAP_AS2 = "<put any name for the destination here>";
    }
}

ABAP_AS1.jcoDestination

프로젝트 최상단위치에 파일을  놓는다.

 

이후 어플리케이션 실행.

 

SAP RFC 결과에 대한 데이타를 뽑아볼수 있다.

 

끝.