Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Aashish28
Contributor

Introduction :

For consuming HANA data on UI we usually develop XSJS , XSODATA depends on situation. As you know in every release of HANA , SAP is increasing XSODATA features. In this blog will give you basic idea how can you use XSJSLIB based modification exit for updating and returning value in XSODATA response.

Scenario :

Let's consider a scenario we've created employee table which contain empid , first name , department , email ...etc. For performing CRUD operation I've created XSODATA service. we can pass each and every information from UI except employee id because it should be generated at server side with the help of sequence / custom logic and should return at UI side after successful creation . I've seen many threads in which many Native Hana developer faced issue to get newly created value in XSODATA .

Objects :

TABLE : 

XSODATA : EMS.xsodata


service  {
    "EMS"."EMS.Employee.HANATABLE::EmpPersInfo" as "Pinfo"
     create events ( before "EMS.Employee.XSJSLIB:emp_oprtn.xsjslib::usersCreate" ) //before create operation this exit will be trigger
     }



SEQUENCE: EMS.hdbsequence


schema= "EMS";
increment_by = 1;      //  -1 for descending
start_with = 100;
maxvalue= 99999999;
cycles= false;         // when reaching max/min value
depends_on_table = "EMS.Employee.HANATABLE::EmpPersInfo";



XSJSLIB: emp_oprtn.xsjslib


function usersCreate(param){
       $.trace.debug('entered function');
       let after = param.afterTableName; // temporary table
       // Updating Employee Id Before Create operation via sequence
       let pStmt = param.connection.prepareStatement('update "' + after + '" set EID = "EMS.Employee.SEQUENCE::EMS".NEXTVAL' );
       pStmt.executeUpdate();
       pStmt.close();
}



UI5 code -


var oModel= new sap.ui.model.odata.ODataModel('/EMS/Employee/XSODATA/EMS.xsodata', false);
var inputData={};
inputData.EID= '';
inputData.FNAME='AB';
inputData.LNAME='Moy';
inputData.MNAME='Toy';
inputData.GEN='MALE';
inputData.MSTS='SINGLE';
inputData.DOB='1991/08/07';
oModel.create('/Pinfo',inputData,null, function(odata,oResponse){
  alert("Creation successful");
});



Testing : Everything is ready we can check it now -

see below screenshot of debugger we've send just dummy EID = 1 but in response our newly created Employee id is available :smile:

           

   

4 Comments
Labels in this area