Treeview for SAP data??

Questions and answers on developing, deploying and using plugins and JavaBeans

Treeview for SAP data??

Postby abeermann » Tue May 20, 2014 12:22 pm

Hello Servoy Gurus

I use the dbtreeview with a table xxx that has an id and a parentid in each record.
I have a relation id_to_parentid
xxx.id = xxx.parentid

I do:
var v_binding = elements.treeview.createBinding('database','xxx');
v_binding.setNRelationName("id_to_parentid");

Everything works as expected!

But now i need to show structured parts-lists from our SAP System.

SAP has a table mast (= material master) with column matnr and column stlnr
and a table stpo (= components for material master) with stlnr and idnrk

The mast record with matnr=xxx and stlnr=yyy points to n stpo records with stlnr=yyy.
These stpo records have a idnrk ( containing a matnr which can be found in mast)

So the treeview has to show:
first level = wanted matnr from mast
second level = all stpo records with stlnr eq to stlnr in mast record.
third level = get mast record with matnr = stpo.idnrk , get the stlnr of the mast record and show all stpo records for this stlnr
fourth level = get mast record with matnr = stpo.idnrk , get the stlnr of the mast record and show all stpo records for this stlnr
...

I have no idear what i need as "binding" and how the setNrelation has to be ??
Can this be done with Servoy ??
Any help welcomed

Best regards
Albert
abeermann
 
Posts: 106
Joined: Fri Nov 26, 2010 12:46 pm

Re: Treeview for SAP data??

Postby HEKUCH » Tue May 20, 2014 3:31 pm

Hi Albert,

We use the "SAP-Java-Connector" to read and write Date from SAP. You can download this software from the SAP-Service-Marketplace (https://websmp102.sap-ag.de/support) Put the files (sapjco3.jar, sapjco3.pdb, sapjco3.dll, sapjcomanifist.mf) to your Servoy-beens-Folder.

To access Date from SAP you need also a valid SAP-User /pw and the connection-Datas (Systemid, etc.). To read date from SAP you need a SAP-RFC-Function. With SAP-Transaction SE37 you'l find given functions or build own RFC-function's.

My sample connect to sap and read a list from Companys.

Hendrick Kurland
DataBit GmbH

Code: Select all
* Enthält True wenn Java-Klassen geladen wurden
* @type {Boolean}
* @properties={typeid:35,uuid:"055804CC-6A27-4CC3-A5EB-2A47FB5C9B59",variableType:-4}
*/
var ApiIsLoaded = false ;


/**
* Enthält True wenn das Verbindungsfile erstellt wurde
* @type {Boolean}
* @properties={typeid:35,uuid:"176FD4E7-0F51-435B-A308-2B470D4ECBA4",variableType:-4}
*/
var VerbFileCreated = false ;


/**
* Lädt JAVA und ABAB-Klassen
* @author Kurland
* @SuppressWarnings(undeclared)
* @properties={typeid:24,uuid:"1CDCEE3A-1BC9-4D61-A0E9-2BB229299129"}
*/
function load_api(){
   if (ApiIsLoaded == false){
      
      importClass(Packages.java.io.File);
      importClass(Packages.java.io.FileOutputStream);
      importClass(Packages.java.util.Properties);
      importClass(Packages.java.util.concurrent.CountDownLatch);
      
      importClass(Packages.com.sap.conn.jco.AbapException);      
      importClass(Packages.com.sap.conn.jco.JCoContext);      
      importClass(Packages.com.sap.conn.jco.JCoDestination);
      importClass(Packages.com.sap.conn.jco.JCoDestinationManager);
      importClass(Packages.com.sap.conn.jco.JCoException);
      importClass(Packages.com.sap.conn.jco.JCoField);
      importClass(Packages.com.sap.conn.jco.JCoFunction);
      importClass(Packages.com.sap.conn.jco.JCoFunctionTemplate);
      importClass(Packages.com.sap.conn.jco.JCoStructure);
      importClass(Packages.com.sap.conn.jco.JCoTable);
      importClass(Packages.com.sap.conn.jco.ext.DestinationDataProvider);
      
      ApiIsLoaded = true
   }
}



/**
* Erstellt ein Verbindungsfile und gibt TRUE zurück wenn erfolgreich
* @author Kurland
* @properties={typeid:24,uuid:"FA77097A-3CFF-40DF-8A14-85ED9151E754"}
*/
function create_verbindungsfile() {

   if  (VerbFileCreated == true){
      return true ; // Verbindungsfile besteht bereits
   }
   
   
   connectProperties = new java.util.Properties;
   connectProperties.setProperty(Packages.com.sap.conn.jco.ext.DestinationDataProvider.JCO_ASHOST, lcHostName);
   connectProperties.setProperty(Packages.com.sap.conn.jco.ext.DestinationDataProvider.JCO_SYSNR, lcSysNr);
   connectProperties.setProperty(Packages.com.sap.conn.jco.ext.DestinationDataProvider.JCO_CLIENT, lcMandant);
   connectProperties.setProperty(Packages.com.sap.conn.jco.ext.DestinationDataProvider.JCO_USER, lcUserName);
   connectProperties.setProperty(Packages.com.sap.conn.jco.ext.DestinationDataProvider.JCO_PASSWD, lcPasswd);
   connectProperties.setProperty(Packages.com.sap.conn.jco.ext.DestinationDataProvider.JCO_LANG, lcSprache);
   //connectProperties.setProperty(Packages.com.sap.conn.jco.ext.DestinationDataProvider.JCO_R3NAME, lcSystemId);


   var cfg = new java.io.File(lcConnectName + "." + "jcoDestination" );
   try {
      var fos = new java.io.FileOutputStream(cfg, false);
      connectProperties.store(fos, "jcoDestination");
      fos.close();
      VerbFileCreated = true ;
      
   } catch (e) {
      VerbFileCreated = false ;
      application.output('Fehler: Verbindungsdatei kann nicht angelegt werden')
   }
   
   return VerbFileCreated  ;
   
}


/**
* Baut Verbindung zum SAP auf
* @return {Boolean}
* @properties={typeid:24,uuid:"B17D545F-B4CB-4BEC-BADC-75322E34808D"}
*/
function logon_sap() {

   if (loSap != null){
      return true ; // Verbindung ist bereits initialisiert
   }
   
   //... API laden
   load_api() ;
   
   //... Verbindungsfile erzeugen
   create_verbindungsfile() ;
   
   
   
   var loDM = Packages.com.sap.conn.jco.JCoDestinationManager ;
   loSap = Packages.com.sap.conn.jco.JCoDestination  ;
   
   loSap = loDM.getDestination(lcConnectName); // throws JCoException) ;   
   
    if (loSap == null){
       application.output('Login SAP gescheitert')
       return false ; // Fehler bei Verbindungsaufbau
    }

    loSap.getDestinationName()
    application.output('*** Login SAP-System: '+loSap.getDestinationName()+' erfolgreich aufgebaut ! ****')
    return true ;
}


   
/**
* Diese Funktion ruft die Buchungskreise ab 
* @properties={typeid:24,uuid:"8A901F15-9355-4586-B587-D509F1F395BE"}
*/
function test_sap(){
   
   var llRetval = logon_sap() ;
   if (llRetval == false){
      return ; // Kein Logon möglich
   }
   
   
    //... Lesen Buchungskreise
   var loFunc = loSap.getRepository().getFunction("BAPI_COMPANYCODE_GETLIST");
    loSap.getRepository().getRecordMetaData('COMP_NAME')
   //application.output(loSap.getRepository().getFunctionInterface('BAPI_COMPANYCODE_GETLIST')) ;
   
   
    llRetval = loFunc.execute(loSap);
   
    //... Tabelle
   var loTable = loFunc.getTableParameterList().getTable('COMPANYCODE_LIST');    //Referenz auf SAP-Tabelle

   //... Abfrage Spalten in SAP-Tabelle
   application.output('*** Feldnamen SAP-Tabelle ****')  ;
   var laFields = getSapTableColToArray(loTable) ;
   for (var i2 = 0; i2 < laFields.length;i2++ ){
      application.output(laFields[i2]);
   }
   application.output(' ')  ;
   

   //... Umwandeln SAP-Tabelle in DataSet
   application.output('*** Datensätze in SAP-Tabelle ****')  ;
    var loDs = getSapTable_to_Ds(loTable,[]);
    for (var i = 0 ; i < loDs.getMaxRowIndex(); i++){
      application.output(loDs.getValue(i+1,1)+' '+ loDs.getValue(i+1,2)) ;
   }
   
   logoff_sap() ;   
   

   

/**
* @properties={typeid:24,uuid:"9400AE24-F86F-4BA7-B231-2F66EF883F2D"}
*/
function logoff_sap(){
        application.output('*** Logout SAP-System: '+loSap.getDestinationName()+' ****')
      loSap.getRepository().clear()
      loSap = null ;
}
Hendrick Kurland

DataBit GmbH
CH-9217 Neukirch an der Thur
HEKUCH
 
Posts: 13
Joined: Thu May 05, 2011 8:02 am


Return to Plugins and Beans

Who is online

Users browsing this forum: Bing [Bot] and 4 guests