cancel
Showing results for 
Search instead for 
Did you mean: 

XSJS file without db.Getconnexion ?

Former Member
0 Kudos

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

pfefferf
Active Contributor

As long as you have access to HANA in your local network, you do not need internet access.

Can you share your code example and how you try to call the service?

Regards,
Florian

PS: The tutorial your link refers too is already a bit outdated. If you are using XS Classic there is a newer $.hdb database interface available. Did you also consider to use an OData service (if you just wanna read the data w/o any further "formatting" of the data)?

Former Member
0 Kudos

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&supplierCountry=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

pfefferf
Active Contributor
0 Kudos

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
0 Kudos

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.

Accepted Solutions (0)

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>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.

Former Member
0 Kudos

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