Technology Blog Posts by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
5,609


In SAP Newtown Square there is a place called the D-Shop (Developers Workshop). The D-Shop is a place to meet and collaborate, to explore and learn, to play and, of course, to invent and build. My first project at SAP was to create an inventory app for the D-Shop (Developer Workshop), and I was responsible for implementing the backend system for the project on HCP.

 

It was a new challenge for me to get started on SAP’s new HANA Web-based Development Workbench, since I just started programming. However, I realized that knowing only how to code doesn’t always solve the problem, you also need to understand the tools that you are using. I had about 3 days of HANA training when I started my internship earlier this year at SAP. The training was focused on using HANA Studio, but my mentor gave me the opportunity to work on the new HANA SPS11 to create XS application. In HANA SPS11 I can not only do Data Modeling but I can also do frontend design. With that said, I decided to share my experience on how I learned to create an XS application.

 

 

Pre-Requisites: Getting Access to the right system!

http://go.sap.com/developer.html

If you don’t have access:

https://account.hanatrial.ondemand.com/register

Helpful tutorial: https://thewebide.hana.ondemand.com/tutorials/hcptrial/

 

                                                                 STEP 1

 

In the blank package or application created, create a database SCHEMA with your new package that you have created.

**Remember it is very important that your SCHEMA name looks exactly the same as the file you have created since it’s case sensitive**



schema_name=”Your Schema name”;







 

                                                                    STEP 2

Next, create three new files within your XS package. The first file will be called ".xsprivileges".This file defines the privileges required to access an application.



{
"privileges": [{
"name": "Basic",
"description": "Basic usage privilege"
}]
}







The second file will be called .xsaccess. This file determines whether or not package content can be exposed and specifies the authentication method to be used to grant access.



1. {
2. "exposed": true,
3. "authentication": [{
4. "method": "Basic"
5. }],
6. "authorization": ["YourSchemaName"::Basic"]
7. }

 

The third file will be called ".xsapp". This file marks the root point in the package hierarchy from which content can be served. There should only be curly brackets {} within this file. You can also click on "insert snippet", button which is located to the right of the save button.

(This was one of the challenges that I faced because I kept on getting a 404 error.
This file is a must!)


 

 



{}







                                                                 STEP 3

Create a sub package within the original package. Name it roles.
(Creating a new package with roles is not required, but I like to do it because it organizes my files). Now create a file under the package “roles” and name it  <your-file-name>.hdbrole. This file contains the defined application privileges.




role thedshop.roles::user {
sql object thedshop.data::inventory.ShopItems: SELECT, INSERT, UPDATE, DELETE;
sql object thedshop.procedures::createItems: EXECUTE;
sql object thedshop.data:items.hdbsequence: SELECT;
application privilege: thedshop::Basic;
}







                                                                                          STEP 4

 

Then, under the SCHEMA created, create <file-name>.hdbdd file. HDBDD stands for Hana Data Base Data Dictionary. HDBDD contains all of your Data Base tables and table types.



namespace thedshop.data;
@Schema: 'THEDSHOP'
context inventory {
type myKeyType: String(60);
@Catalog.tableType:
#COLUMN
Entity ShopItems {
key itemId: Integer;
name: String(50);
description: String(140);
serialNumber: String(100);
quantity: Integer;
images: CLOB;
};
context procedures{
type items {
itemId: Integer;
name: String(50);
description: String(140);
serialNumber: String(100);
quantity: Integer;
images: CLOB;
};
type errors {
HTTP_STATUS_CODE : Integer;
ERROR_MESSAGE : String(100);
DETAIL : String(100);
};
};







 

                                                             STEP 5


It is good to create CSV file if you are providing mass data from your backend system. CSV stands for Comma Separated Value. Also it is better to create a new package under your original package for .hdbti, .hdbdd, and .csv files so your files are organized.



                                                             STEP 6


 


Create file <your-file-name>.hbdti. This file will represent the Hana Data Base Table Import.


(In the table-import configuration, the table, cdstable, and hdbtable, the keywords can allow us to specify the name of the target table into which the table-import operation must insert data.)


The target table specified in the table-import configuration can be a runtime table in the catalog or a design-time table definition, for example, a table defined using either the .hdbtable or the .hdbdd (Core Data Services) syntax.


 





import = [
{
table = "thedshop.data::inventory.ShopItems";
schema = "THEDSHOP";
file = "thedshop.data.loads:shopItems.csv";
header = false;
}
];







                                                                 STEP 7

Create Stored Procedure.
(**Recommendation: Create a separate package under original package for procedures to allow the creation of multiple procedure files under the package "procedure"**)


A stored procedure is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database in compiled form, so that it can be shared by a number of programs.

 



PROCEDURE "THEDSHOP"."thedshop.procedures::createItems"(
IN intab "THEDSHOP"."thedshop.data::inventory.procedures.items",
OUT outtab "THEDSHOP"."thedshop.data::inventory.procedures.errors"
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
BEGIN
DECLARE lv_itemId INTEGER;
DECLARE lv_name STRING;
DECLARE lv_description STRING;
DECLARE lv_serialNumber STRING;
DECLARE lv_quantity INTEGER;
DECLARE lv_images NCLOB;
SELECT "itemId",
"name",
"description",
"serialNumber",
"quantity"
"images"
INTO lv_itemId,
lv_name,
lv_description,
lv_serialNumber,
lv_quantity,
lv_images
FROM :intab;
IF (:lv_name = '') THEN
outtab = SELECT 500 AS http_status_code,

i. 'Invalid name ' || lv_name AS error_message,
ii. 'No Way! Item name must not be empty' AS detail
iii. FROM dummy;
ELSE
INSERT INTO "thedshop.data::inventory.ShopItems" VALUES("thedshop.data::items".NEXTVAL, lv_name, lv_description, lv_serialNumber, lv_quantity,lv_images);
END IF;
END;







                         STEP 8


                      (Recommendation: Create a .hdbsequence file. This will auto generate your primary key.



schema= "THEDSHOP";
start_with= 24;
maxvalue= 1000000000;
nomaxvalue=false;
minvalue= 24;
nominvalue=true;
cycles= false;
depends_on_table= "thedshop.data::inventory.ShopItems";







                                                  Final Step


 

The final step is to create an XSODATA service. Again, it is better to create a separate package for all the XSODATA services. The OData service definition is the mechanism you use to define what data to expose with OData, how, and to whom.



service {
"YourSchemaName::NameOfYourhdbddFile.TableName" as "Contact"
create using "YourSchemaName.procedures::tableName";
}




Thanks for reading!

4 Comments