Advertisement
rplantiko

Connect to SAP with Groovy

Aug 10th, 2011
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.59 KB | None | 0 0
  1. import com.sap.mw.jco.*
  2. import org.junit.*
  3.  
  4. // This is merely a run test which should pass for any successful SAP connection
  5.  
  6. // The idea is to retrieve the field system id by calling the function module TR_SYS_PARAMS
  7. // The result should of course be identical to the SystemID of the connection itself.
  8.  
  9. // When using SAP JCo with Groovy, you will need sapjco.jar and, beside it, also jdsr.jar !!!
  10. // The reason is an internal method lookup which needs to resolve such a reference:
  11. // It's precisely the problem reported here: http://jira.codehaus.org/browse/GROOVY-2980
  12.  
  13. // As always with JCo, the librfc32.dll must be available in one of the PATH directories
  14.  
  15. // You will find all these libraries in a SAP Frontend installation ( search in C:\Program Files\SAP )
  16.  
  17. class TestSapGroovyConnect {
  18.  
  19.   JCO.Client conn;
  20.   JCO.Repository repo;
  21.  
  22.   @Test void test() {      
  23.     JCO.Function getSysParams = repo.getFunctionTemplate( "TR_SYS_PARAMS" ).getFunction();      
  24.     conn.execute getSysParams    
  25.     assert getSysParams.getExportParameterList().getValue( "SYSTEMNAME" ) ==
  26.            conn.getAttributes().getSystemID()
  27.     }
  28.  
  29.   @Before
  30.   void setup() {
  31. // Maintain logon data in a Properties file, as documented in
  32. // http://help.sap.com/javadocs/NW04/current/jc/com/sap/mw/jco/JCO.html
  33.     def sys = new Properties()
  34.     sys.load( new FileInputStream( "h:\\Eigene Dateien\\groovy\\jco\\d12.properties" ) )
  35.     conn = JCO.createClient( sys )
  36.     conn.connect()
  37.     repo = new JCO.Repository( "repo", conn );
  38.    
  39.     }
  40.  
  41.   @After
  42.   void teardown() {
  43.     conn.disconnect()
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement