Skip to Content
avatar image
Former Member

XSJS file without db.Getconnexion ?

Hello

I'm a newbie on sap xsjs file so sorry if my question sound silly.

I need to create a xsjs file which get data from hana table (CDATA on SYS.REPO) and return information.

So I need to execute a sql query in my file

I try to execute the exemple here: http://saphanatutorial.com/sap-hana-xsjs-database-connectivity/

But where I work I don't have internet's connexion . So I get the error: Code 13: User account denied for Internet access

I don't understand why I need internet.

Is there an other way to do it ?

Kind Regards

Add comment
10|10000 characters needed characters exceeded

  • Former Member Florian Pfeffer

    Thank for your answer and your time.

    I followed the tutorial

    The code is :

     function getDataFromTable(){  
      var supplierCountry = $.request.parameters.get('supplierCountry');    
    var conn = $.db.getConnection();   
     var pstmt;    
    var rs;   
     var query;    
    var output = {results: [] };   
     try {       
     query = 'SELECT PRODUCT_ID, PRODUCT_NAME, SUPPLIER_COUNTRY FROM \"SAP_HANA_TUTORIAL\".\"PRODUCT_INFO\" WHERE SUPPLIER_COUNTRY = ?';   
         pstmt = conn.prepareStatement(query);       
     pstmt.setString(1, supplierCountry);     
       rs = pstmt.executeQuery();       
     while (rs.next()) {              
     var record = {};               
     record.productId = rs.getString(1);        
            record.productName = rs.getString(2);       
             record.supplierCountry = rs.getString(3);       
             output.results.push(record);        }  
          rs.close();        
    pstmt.close();      
      conn.close();              
      }   
      catch (e) {  
          $.response.status = $.net.http.INTERNAL_SERVER_ERROR;       
     $.response.setBody(e.message);      
      return;    }   
     var body = JSON.stringify(output);    
    $.response.contentType = 'application/json'; 
       $.response.setBody(body);  
      $.response.status = $.net.http.OK;}
    
    var aCmd = $.request.parameters.get('cmd');
    switch (aCmd) 
    {    case "select":    
        getDataFromTable();  
          break;   
     default:     
       $.response.status = $.net.http.INTERNAL_SERVER_ERROR;  
          $.response.setBody('Invalid Command: ', aCmd);}
    
    

    I activate, then Run As -> XS service

    I add ?cmd=select⊃plierCountry=India

    to the page.

    Do you have a reliable link about how to use xsjs file and sql in xsjs ?

    My goal is to extract information of xml calculation view, you think OData can be a solution ?

    I hope you can help me.

    Thanks a lot

    Etienne

  • Question: Do you have the data used in the tutorial available in your DB (e.g. the Schema SAP_HANA_TUTORIAL)?

    As a starting point I would check the XS Classic JavaScript API Reference (here the link to the ResulSet of the $.hdb db interface with a simple example: https://help.sap.com/http.svc/rc/3de842783af24336b6305a3c0223a369/2.0.01/en-US/$.hdb.ResultSet.html).

  • Former Member Florian Pfeffer

    Yes I created the data and replace SAP_HANA_TUTORIAL with my schema.

    CREATE COLUMN TABLE "SAP_HANA_TUTORIAL"."PRODUCT_INFO"(   
    
    "PRODUCT_ID" INTEGER NULL PRIMARY KEY,      "PRODUCT_NAME" VARCHAR (100),"SUPPLIER_COUNTRY" VARCHAR(50));
    
    INSERT INTO "SAP_HANA_TUTORIAL"."PRODUCT_INFO" VALUES(1,'Shirts','India');
    
    INSERT INTO "SAP_HANA_TUTORIAL"."PRODUCT_INFO" VALUES(2,'Jackets', 'India');
    
    INSERT INTO "SAP_HANA_TUTORIAL"."PRODUCT_INFO" VALUES(3,'Watches', 'Japan');
    
    INSERT INTO "SAP_HANA_TUTORIAL"."PRODUCT_INFO" VALUES(4,'Mobile','USA');
    
    INSERT INTO "SAP_HANA_TUTORIAL"."PRODUCT_INFO" VALUES(5,'Purse', 'India');

    Thanks for the link, I will read it.

  • Get RSS Feed

1 Answer

  • Jul 06, 2017 at 01:56 PM

    >But where I work I don't have internet's connexion . So I get the error: Code 13: User account denied for Internet access

    Where do you get this error? When you try to connect to the HANA system with a browser? I think you will have to talk to your company's admins about that if they are the ones blocking you from accessing the HANA system.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I got this error after I did run as -> XS Services

      I can read this data with sql console but it's not working on my xsjs file