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 : 

Capture.JPG

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 🙂

           

   

return.JPG

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Wolfgang Röckelein

    Hi Ashish,

    thanks for the valuable blog!

    In the documentation regarding hdbsequence I found “The target table or view specified in the depends_on keyword must be mentioned in the SELECT query that defines the reset condition”. So isn’t using depends_on_table without a reset_by incorrect?

    Also it seems that depends_on_table was replaced with depends_on…

    Regards,

    Wolfgang

    (0) 

Leave a Reply