1.在SE37中创建z_get_scar.
FUNCTION z_get_scar.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(I_CARRID) LIKE SCARR-CARRID
*" EXPORTING
*" VALUE(E_CARRNAME) LIKE SCARR-CARRNAME
*"----------------------------------------------------------------------
SELECT SINGLE carrname
INTO e_carrname
FROM scarr
WHERE carrid = i_carrid.
IF sy-subrc IS NOT INITIAL.
RAISE carr_not_found.
ENDIF.
ENDFUNCTION.
特别注意点:
2.创建配置文件ABAP_AS.jcoDestionation
jco.client.lang=en ##语言设置
jco.client.client=001 ##客户端编码
jco.client.passwd=sapadmin2 ##登陆密码
jco.client.user=bcuser ##登陆账号
jco.client.sysnr=00 ##实例编号
jco.client.ashost=192.168.65.100 ##sap服务器ip
内容参考
3.Java编码
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
public class Programm {
public static void main(String[] args) throws JCoException {
JCoDestination destination = JCoDestinationManager.getDestination("ABAP_AS");
JCoFunction function = destination.getRepository().getFunction("Z_GET_SCAR");
function.getImportParameterList().setValue("I_CARRID","AC");
try {
function.execute(destination);
System.out.println(function.getExportParameterList().getString("E_CARRNAME"));
} catch (JCoException ex){
if(ex.getKey().equals("CARR_NOT_FOUND")){
System.out.println("Airline company not found with given id");
}
}
}
}
4.系统输出
Air Canada