Skip to Content
avatar image
Former Member

sap hana remove colum values

I have .hdbtable with ID column. I need remove this column and add new with autoincrement. How can i do this?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Nov 04, 2016 at 09:13 PM

    Autoincrement is not supported in the .hdbtable syntax. A workaround would be to use a sequence when inserting data.

    Regards,
    Florian

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 05, 2016 at 05:21 PM

    Ok! I read about this. How can I apply sequence to existing column? and add data using xsodata in sapui5?

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 05, 2016 at 06:11 PM

    You have to create a sequence (Create a Sequence) and determine the next value of the sequence before you insert the data. The next value can be determined using <sequence_name>.NEXTVAL.

    If you wanna apply that in a xsodata service, then you have to implement a Custom Exit for Write Requests to be able to apply the logic.

    Add comment
    10|10000 characters needed characters exceeded

    • I would recommend to read the documentation about custom exits linked in the answer.

      Following an example from the SHINE content using an XSJS function in the create before event. The XSJS function determines the next value from the sequence and sets it in the data set to be inserted.

      OData service calling:

      service namespace "sap.hana.democontent.epm"  { 
         "sap.hana.democontent.epm.data::User.Details" as "Users"
          create events(before "sap.hana.democontent.epm.services:userBefore.xsjslib::create_before_exit");
      }
      

      XSJS function:

      function create_before_exit(param) {
      
      
          var after = param.afterTableName;
          var pStmt = null;
          //Get Input New Record Values
      
      
          try {
      
      
              pStmt = param.connection
                  .prepareStatement('select "sap.hana.democontent.epm.data::userSeqId".NEXTVAL from dummy');
              var rs = pStmt.executeQuery();
              var PersNo = '';
              while (rs.next()) {
                  PersNo = rs.getString(1);
              }
              pStmt.close();
              pStmt = param.connection.prepareStatement("update\"" + after + "\"set PERS_NO = ?");
              pStmt.setString(1, PersNo);
              pStmt.execute();
              pStmt.close();
      
      
          } catch (e) {
              pStmt.close();
          }
      
      
      }