Skip to Content
0

sap hana remove colum values

Nov 04, 2016 at 06:24 PM

62

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Florian Pfeffer
Nov 04, 2016 at 09:13 PM
0

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

Regards,
Florian

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Nov 05, 2016 at 05:21 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Florian Pfeffer
Nov 05, 2016 at 06:11 PM
0

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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0

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


}
0