Saturday, July 2, 2016

HANA sample coding

.xsaccess

{
 "exposed":true,
 "authentication":[{"method":"LogonTicket"},{"method":"Basic"}]

}



header.hdbtable

table.schemaName = "WorkshopA_00";
table.tableType = COLUMNSTORE ;
table.description = "workshop order header";
table.columns = [
{name = "orderID" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Createdby" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Createdat" ;sqlType = DATE ;nullable = false ;},
{name = "Currency" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Total" ;sqlType = DECIMAL ;nullable = false ;length = 10 ;
                                                   defaultValue = "0";}
];


table.primaryKey.pkcolumns = ["orderID"];


item.hdbtable

table.schemaName = "WorkshopG_00";
table.tableType = COLUMNSTORE ;
table.description = "workshop order item";
table.columns = [
{name = "orderID" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "OrderItem" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "ProductId" ;sqlType = NVARCHAR ;nullable = false ;length = 10 ;},
{name = "Quantity" ;sqlType = NVARCHAR ;nullable = false ;length = 5 ;},
{name = "QuantityUnit" ;sqlType = NVARCHAR ;nullable = false ;length = 5;}
];


table.primaryKey.pkcolumns = ["orderID"];


.hdbview
to join the tables

schema="WorkshopA_00";
query="select T0.\"orderID\",
              T1.\"OrderItem\",
              T0.\"Createdby\",
              T0.\"Createdat\",
              T1.\"ProductId\",
              T1.\"Quantity\",
              T1.\"QuantityUnit\"
        from \"WorkshopA_00\".\"<package>::header\" T0
        left outer join \"WorkshopA_00\".\"<package>::item\" T1
        on T0.\"orderID\" = T1.\"orderID\"
        order by T0.\"orderID\" ASC";
        depends_on_table =["<package>::header","<package>::item"];



header.hdbsequence

schema = "WorkshopA_00";
start_with = 1 ;

depends_on_table = "package::header";



.xsprivileges

{
    "privileges":[
        {
            "name": "Basic",
            "description":"Basic usage privileges"
        },
        {
            "name": "Admin",
            "description":"Administration privileges"
        }

             ]
}

workshopAdmin.hdbrole

role <package>::workshopAdmin
 extends role <package>::workshopUser
{
catalog schema "WorkshopA_00": SELECT ,INSERT ,UPDATE ,DELETE ,DROP ;
application privilege : <package>::Admin;
}

workshopUser.hdbrole 

role <package>::workshopUser {

catalog schema "WorkshopA_00": SELECT ;
application privilege : <package>::Basic;
}


To Activate role
call "_SYS_REPO"."GRANT_ACTIVATED_ROLE" ('package::workshopAdmin','uname');