cancel
Showing results for 
Search instead for 
Did you mean: 

sap hana remove colum values

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

pfefferf
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

I need add data using oData (.xsodata). For using this should I create procedure or just need specify ID column for sequence in (create using...)?

pfefferf
Active Contributor
0 Kudos

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();
    }


}
Former Member
0 Kudos

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

pfefferf
Active Contributor
0 Kudos

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

Regards,
Florian