Skip to Content
Author's profile photo Former Member

SAP Web IDE Ninja #4: Develop Full-Stack To-Do app in SAP Web IDE – Part 1 – Database

This blog post is part 1 of a series of blogs on how to develop full-stack To-Do application in SAP Web IDE Full-Stack.

 

Prerequisites

Before reading this blog please make sure that you have read, understood and implemented part 0 of this series there I have shown how to setup the environment for developing full-stack applications in SAP Web IDE Full-Stack.

 

Let’s Get Started!

 

Create your database module

The database module will allow you to create and provision HANA database tables and views, following the SAP HANA programming model.

To create a new database module, follow these steps:

  • In SAP Web IDE select your todo project
  • Right click it and select New > SAP HANA Database Module 
  • Enter db as the module name and click Next
  • Remove the namespace (only for the sake of this blog) and make sure that SAP HANA Database Version is 1.0 SPS12. Then click Finish
  • SAP Web IDE creates a new db folder in your todo app that contains all the artifacts of your database module. Also the mta.yaml file is updated accordingly.

Now let’s create the HANA data model:

  • Expand the db folder, right-click the src folder and select New > HDB CDS Artifact*HDB CDS stands for SAP HANA Core Data Services and it is the approach to transform design time resource into a HANA database objects defined in the CDS document. In simple words: you model your entities and their properties in a simple syntax and all the relevant database artifacts are dynamically generated during deployment.
  • Name it todo and click Create
  • Expand the src folder and double click on todo.hdbcds file for editing it
  • You will immediately notice that SAP Web IDE opens the HDBCDS graphical editor for you. This editor allows you to easily create or change your HANA data model.
  • Inside the graphical editor, create a new DB Entity by clicking on the entity icon. Then position it somewhere in the white area and name it Task
  • Double-click the entity title and click on the + icon to create the following property:
    • Name: id
    • Type: Primitive Type
    • Data Type: String
    • Length: 10
    • Key: true
    • Not Null: true

 

  • Following above step, continue to create the below properties:
    • Name: title
    • Type: Primitive Type
    • Data Type: String
    • Length: 100
    • Key: false
    • Non Null: true
    • Name: note
    • Type: Primitive Type
    • Data Type: String
    • Length: 250
    • Key: false
    • Non Null: false
    • Name: status
    • Type: Primitive Type
    • Data Type: Integer
    • Key: false
    • Non Null: false
    • Default: 0
  • After creating all the properties of the Task entity, it should look like the below:
  • Save your changes and click on the back button to navigate back to the previous screen
  • In this screen you should be able to see the new properties you added to the entity.
  • Now create another entity and name it SubTask
  • Double-click it and add the following properties:
    • id – String length 10, mark as key and not null
    • taskId – String length 10, mark also as key (it is a foreign key for the Task entity) and not null
    • content – String 100, not null for holding the sub task content
    • status – Integer, default value is 0
  • Now create a relationship between Task and SubTask. We will create 1 to n relationship because each task can have several subtasks:
    • Click on the Task entity to select it
    • Click on the Association button 
    • Drag and drop a line from the Task entity to the taskId property of the SubTask entity
    • In the dialog enter FromTaskToSubTask as the Name of the association
    • Under Source Cardinality select 1
    • Under Target Cardinality select [0..*]
    • Make sure that Managed is selected under Type and taskId is the Association Key
    • Click OK

  • Now that you have your HANA data model ready, it’s time to build your db module. Building MTA modules requires CF runtime so you must make sure that your project is connected to a SAP Cloud Platform, Cloud Foundry Org and Space:
    • In SAP Web IDE, select your project folder (todo)
    • Right click it and select Project Settings
    • Select Space from the left side menu
    • Select your Cloud Foundry API Endpoint – SAP Web IDE will show you a popup dialog for entering your CF credentials. Make sure you use your email address as username.
    • Select your CF Org and Space – If you are using your trial account, you will see only one org and one space and SAP Web IDE will auto select them for you.
    • Next, install the builder by clicking on the Install Builder button – Notice that installing a builder can take several minutes and you will not be able to build your modules until it is finished.
    • Click Save and wait for the builder to be installed in your SAP Cloud Foundry environment.
  • Now that your CF builder is installed it’s time to use it to build your db module. Right-click the db folder and click Build
  • SAP Web IDE will now send a request to build your project. You will be able to see the build logs and status in SAP Web IDE runtime console. If you see “Build of /todo/db completed successfully” it means that everything went well and your database module has been built!

 

 

Test your database module

In the previous section you created your HANA database module and built it. In order to test the outcome of the build process you need to connect to your HANA database instance, search for the scheme and check if the build process has created 2 tables: one for the Task and another for the SubTask with all of their properties.

In order to connect to your SAP HANA database instance you need to do the following:

  1. Download and install Eclipse
  2. Install SAP HANA Database Eclipse plugin
  3. Go to your Cloud Foundry account and search for the SAP HANA connection string under VCAP SERVICES
  4. Grab the scheme id, username and password from there
  5. ….
  6. ….

Looks exhausting right? Don’t worry, it’s only a joke 🙂  

Lucky for you, SAP Web IDE Full-Stack has the HANA Database Explorer plugin integrated in it,  and it provides an easy and intuitive way to connect, test and provision your SAP HANA database instance on Cloud Foundry!

  • In SAP Web IDE Full-Stack, click on the Database Explorer icon which is located on the left side pane
  • Click the Connect button
  • Click on the + button to add a new database to the database explorer
  • Search for your database by typing todo inside the text field. The Database Explorer will show you all schemes that contain the word todo 
  • Select your scheme and click OK 

  • After clicking OK you should notice that the new database has been added to the list of databases
  • Now, you can execute any query to this database, check the data and metadata of your tables, views and more.
  • Let’s verify our tables were created. Click on Tables (located under your database scheme) and check that both tables exist
  • To verify the tables metadata, double-click each table tto see the list of fields and their type
  • Please verify that the field types are equivalent to how you modeled them in your hdbcds file 

Congrats! You have created a database module and generated HANA tables on SAP Cloud Foundry!

Bonus! Create or load data

What’s a table without data? 🙂
In order to create some data (without having an app) we can do one of the following:

  • Create some data in SAP Web IDE using the HANA Database Explorer
  • Load initial data to the tables during build by creating hdbtabledata & csv files.

Creating data using the HANA Database Explorer

  • In SAP Web IDE, open the HANA Database Explorer
  • Click on Tables under your scheme
  • Select the table you want to create data in
  • Right click it and choose Open Data 
  • The table data will be opened in a new tab (at first you will not see any data)
  • To create a new entry, simply click on the + button, enter task id, task title, note and status and click the Save button

Load initial data during the build process

To load initial data during the build process you will need to create the following files:

  • todo.hdbtabledata – contains the information on the table fields and the CSV files that will fill them with data
    { 
      "format_version": 1, 
      "imports": 
      [ { 
    		"target_table": "todo.Task", 
    		"source_data" : { "data_type" : "CSV", "file_name" : "tasks.csv", "has_header" : true }, 
    		"import_settings" : { "import_columns" : [ "id", "title","note" ] }, 
    		"column_mappings" : { "id" : 1, "title" : 2, "note" : 3 	} 
    	},
    	{ 
    		"target_table": "todo.SubTask", 
    		"source_data" : { "data_type" : "CSV", "file_name" : "subtask.csv", "has_header" : true }, 
    		"import_settings" : { "import_columns" : [ "id","taskId","content"] }, 
    		"column_mappings" : { "id" : 1, "taskId" : 2, "content" : 3 	} 
    	}
      ] 
    }​
  • tasks.csv – contains initial data for the Task table
    id,title,note
    1,my first task, this is my first task
    2,my second task,my second task​
  • subtask.csv – contains initial data for the SubTask table
    id,taskId,content
    1,1,First task subtask
    2,1,First task second sub task
    3,2,Second task subtask​

These files should be created under the src folder of your db module. After creating these files your project structure should look like the below:

 

When everything is ready you can build your project again, and go to the HANA Database Explorer to see the data from the CSV files in the Task and SubTask tables.

Now you can continue to the server-side development, in part 2.

 

 

Assigned Tags

      34 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Henrik Damhøj Andersen
      Henrik Damhøj Andersen

      Hi Ran,

      Great post!

      I'm curious why SAP HANA Database Version has to be version 1.0 SPS12. Why not 2.0?

      By the way when should we expect to get part 3. Can't wait 🙂

      Best regards,

      Henrik

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Henrik,

      Thanks for reading my blog!

      The version of SAP HANA is the version that installed on your CF env. If you will change it to HANA 2.0 it will work for you as well. I choose the SPS12 because its the most "safe" one  (if you have a newer release it will still work), but it is recommended to choose the latest one.

      I am planning to post part 3 of this series on Thursday (2.11) there i will show how to create a simple UI5 app on top of it.

       

      Thanks,

      Ran.

      Author's profile photo Michal Keidar
      Michal Keidar

      Hi Henrik,

      Part 3 is now available:
      https://blogs.sap.com/2017/11/07/sap-web-ide-ninja-4-develop-full-stack-to-do-app-in-sap-web-ide-part-3-ui/

      Happy coding 🙂
      Michal.

       

      Author's profile photo Sameer Shirole
      Sameer Shirole

      Getting an error on building the db module. Tried starting/stopping the builder app in the dev space. Also deleted and reinstalled the builder app. Keep getting the same message -

      2:13:01 PM (Builder) Build of /todo/db started.
      2:13:08 PM (DIBuild) Build of /todo/db in progress
      2:13:09 PM (DIBuild) [INFO] Injecting source code into builder...
      [INFO] Source code injection finished
      [INFO] ------------------------------------------------------------------------
      2:13:12 PM (Builder) Internal server error
      2:13:12 PM (Builder) Build of /todo/db failed.
      Does a HANA database service need to be active in the dev space? User id has the space developer role.
      Any ideas of what to check next?
      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi,

      Yes, you must have an active HANA database instance on your CF space in order to build the HANA database module.

       

      Ran.

      Author's profile photo Sameer Shirole
      Sameer Shirole

      Thanks for the confirmation. I assume this can be done on a cloud foundry trial account (That is what I am using). There are multiple HANA database services available to choose from. Which one is needed for the purpose of this tutorial? Does the instance be named specifically as 'hanatrial' or anything else?

      The documentation I found has instructions to create bind the service to a deployed application. Which is different from the steps outlined in this tutorial.

      Thanks!

       

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      If you’re using the trial you can only have the hanatrial database there which is a shared instance. You don’t need to have a specific name, only to create a service and that’s it

       

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Actually you just need to make sure that hanatrial service is there. Moreover, you need to verify that you have enough quota in your account for running these services

      Author's profile photo Sameer Shirole
      Sameer Shirole

      I was able to build the db module successfully. Updating the build tool (app) in WebIDE fixed the issue. Not sure why it did not work previously.

      Data Explorer shows no data. It must be because it expects to always connect to a cloud foundry instance in the Europe region. I don't see a way to switch it to North America region URL. Must be a limitation in the trial account.

      Author's profile photo Julio Alberto Martinez Real
      Julio Alberto Martinez Real

      Getting this error on building bd:

       

      Build of db failed. Cannot provision services due to Cloud Foundry error: 'No Hana Service broker available for current user'

       

      Any ideas of resolve this?

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi, are you trying to run it on trial ?  Because if you are not running it on the trial you must make sure that you HANA instance available in your CF account.

      In hanatrial there is the hanatrial service so when you build your DB for the first time it auto create it.

       

       

      Author's profile photo Julio Alberto Martinez Real
      Julio Alberto Martinez Real

      Hi Thanks for your reply.

       

      Yes im running it on trial but i dont see this service (hannatrial)

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Are you trying to search this service on cloud foundry or in Neo?

      Author's profile photo Julio Alberto Martinez Real
      Julio Alberto Martinez Real

      Cloud foundry.

       

      Did i miss some point??

       

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Can you check if you see HANATRIAL in your service marketplace ?

       

      Author's profile photo Julio Alberto Martinez Real
      Julio Alberto Martinez Real

      no i dont see it

       

       

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      If you use cloud foundry trial you should have it there...that’s strange.

      When you created this trial account ?

       

      Author's profile photo Sushant Nath
      Sushant Nath

       

      Dear Henrik,

      Hope you are doing good.

      While maintaining space, in the project settings, the organisation and the space field are coming blank.

      Hence not allowing me to proceed ahead.

      PFA a screenshot of the same.

      Can you please, help me out on this?

       

      Best Regards,

      Sushant

      Author's profile photo Michal Keidar
      Michal Keidar

      Hi,

      If you don't have a productive Cloud Foundry environment you can use the Trial one.
      Login to SAP Cloud Platform and click on the "Cloud Foundry Trial" button, This will create a trial org and space for you. Then, in Web IDE, after selecting the CF endpoint, you will see your trial org and space.

      Regards,
      Michal.

       

      Author's profile photo Kim Seong-Woong
      Kim Seong-Woong

      Hi Ran,

      Thanks for the nicely prepared contents.

       

      For the following steps of

      • Now that you have your HANA data model ready, it’s time to build your db module. Building MTA modules requires CF runtime so you must make sure that your project is connected to a SAP Cloud Platform, Cloud Foundry Org and Space:
        • Next, install the builder by clicking on the Install Builder button – Notice that installing a builder can take several minutes and you will not be able to build your modules until it is finished.

      I am experiencing this error

      6:47:47 (Project Space) Workspace settings set successfully

      6:47:47 (Project Space Builder) Builder push triggered

      6:48:02 (Project Space Builder) Builder installation failed: CF-OrgQuotaTotalRoutesExceeded(310006): You have exceeded the total routes for your organization’s quota.

       

      Can you help me out of this? Thanks in advance,

       

      Regards,

      Kim

       

       

      Author's profile photo Jerry Wang
      Jerry Wang

      Hi Kim,

      I am not sure whether you have already resolved this issue.  In my case I have created two sub accounts in Cloud Foundry Trial, and meet with error message:

      Builder installation failed: CF-OrgQuotaTotalRoutesExceeded(310006): You have exceeded the total routes for your organization's quota.

      When I remove one sub account, the builder installation could be done successfully.

      Best regards,

      Jerry

       

      Author's profile photo Sushant Nath
      Sushant Nath

       

      Dear Henrik,

       

      Hope you are doing good.

       

      I am not getting, the Database explorer, in my SAP Web IDE Full Stack.

      I am using, the trial account(cloud foundry).

      PFA a screenshot for the same.

       

      Can you please, help me out on this?

       

      Best Regards,

      Sushant

       

       

      Author's profile photo Former Member
      Former Member

      Dear Henrik,

      Thanks for your sharing.It's really helpful.

      I followed your guide step by step but it didn't work:

      If you are convenient,would you like to help me to solve this problem?

      Thanks
      Lucy

      Author's profile photo Ivan Mirisola
      Ivan Mirisola

      Hi,

      My empirical conclusion regarding the CSV file is that it *must* be stored at the src folder.

      If you structure your HDI module with something like:

      --src
      --|-data
      --|-|-hdbtabledata
      --employee.csv

      It will silently fail to insert the initial data if the csv file is stored at the data folder.

      Maybe there is a way to specify the data folder for builder to look for this file. As of now, it simply doesn't build the import file manually. It tells me that it cannot find the csv file.

      Error: The file requires "tabledata.source://employee.csv" which is not provided by any file [8212001]      at "src/data/load.hdbtabledata" (0:0)

      Regards,
      Ivan

       

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Can you  try to put the csv file inside the data folder and retry?

       

      thanks,

      ran.

      Author's profile photo Ivan Mirisola
      Ivan Mirisola

      Hi Ran,

      It was there initially. But the builder was not picking it from that location. Anyway, now I cannot reproduce the issue because CF Trial landscape is offline for everyone. Guess major changes as coming...

      Regards,
      Ivan

      Author's profile photo Former Member
      Former Member

      Hi, Ran,

      I am using Cloud Foundry on official cloud platform (Europe - Canary), and I have access to the official Hana service. When I tried to build the db module, I got the following error in log:

      (DIBuild) Cannot provision services due to Cloud Foundry error: 'CF-ServiceBrokerBadResponse(10001): The service broker returned an invalid response for the request to https://hana-broker.cfapps.sap.hana.ondemand.com/v2/service_instances/e87b09dc-39b2-4cde-b48c-40915a7bffae?accepts_incomplete=true. Status Code: 500 Internal Server Error, Body: {"message":"Failed to lookup database, because of: Multiple databases are available, exact id needs to be specified. ([aca1808e-7f50-41df-896b-3a2f53f6f0da:sharingtest, aca1808e-7f50-41df-896b-3a2f53f6f0da:statisticsdb3, aca1808e-7f50-41df-896b-3a2f53f6f0da:mobilehanadb])"}'

      In my CF space ,there are 3 tenant database, which are listed in the above log. Looks like this is the root of the problem. Here is what I did:

      1. Created an instance of the Hana service, and provide the following parameters:
        {"database_id":"aca1808e-7f50-41df-896b-3a2f53f6f0da:mobilehanadb"}​

        I suppose this helps to specify the database I intend to use.

      2. Bind the this instance with the builder app.
      3. Restart the builder app.
      4. Build the db module from Web IDE.

      Then I got the error message shown above.

      What else should I do the fix the problem? Or should I specify the database id somewhere else?

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Former Member

      Since you are running on Canary and not on the productive landscape it's very hard to know why you see this error so I cannot really help here. Please try to open an internal ticket on that issue.

       

      Thanks,

      Ran,

      Author's profile photo Tapishnu Sengupta
      Tapishnu Sengupta

      Hi Steven ,

       

      Were you able to solve this problem?

      I am also facing a similar issue.

       

      Regards,

      Tapishnu

      Author's profile photo Oliver Merk
      Oliver Merk

      Hi Ran,

      I really like your well described tutorials!

       

      Currently I am struggling a bit with the build of step “Load initial data during the build process”.

      This is my model:

      And I have put all the files directly into the src-folder.

       

      At build, I receive the following message:

       

      Making…
      Preparing…
      Preparing the make transaction…
      Adding “src/subtask.csv” for deploy…
      Adding “src/subtask.csv” for deploy… ok
      Adding “src/tasks.csv” for deploy…
      Adding “src/tasks.csv” for deploy… ok
      Adding “src/todo.hdbtabledata” for deploy…
      Adding “src/todo.hdbtabledata” for deploy… ok
      Preparing… ok
      Preparing the make transaction… ok
      Checking the uniqueness of the catalog objects in the schema “TODO_HDI_DB_16″…
      Checking the uniqueness of the catalog objects in the schema “TODO_HDI_DB_16″… ok
      Calculating dependencies…
      Expanding…
      Expanding… ok
      Precompiling…
      Precompiling “src/subtask.csv”…
      Precompiling “src/tasks.csv”…
      Precompiling “src/todo.hdbtabledata”…
      Precompiling “src/subtask.csv”… ok
      Precompiling “src/tasks.csv”… ok
      Precompiling “src/todo.hdbtabledata”… ok
      Precompiling… ok
      Merging…
      Merging… ok
      Error: The file requires “db://todo.SubTask” which is not provided by any file [8212001]
      at “src/todo.hdbtabledata” (0:0)
      Error: The file requires “db://todo.Task” which is not provided by any file [8212001]
      at “src/todo.hdbtabledata” (0:0)
      Error: The file requires “tabledata.source://subtask.csv” which is not provided by any file [8212001]
      at “src/todo.hdbtabledata” (0:0)
      Error: The file requires “tabledata.source://tasks.csv” which is not provided by any file [8212001]
      at “src/todo.hdbtabledata” (0:0)
      Error: Calculating dependencies… failed [8212108]
      Error: Could not compose a consistent make graph [8212012]

       

      Kind regards

      Oliver

       

       

      EDIT: I could fix it. It was a matter of namespaces which must match between namespace of attribute "target_table" in todo.hdbtabledata and namespace declaration of todo.hdbcds.

      Author's profile photo Vishesh Agrawal
      Vishesh Agrawal

      Hi Ran,

      Really nice tutorial..!!

      I am facing issue when going to DB view. I did Build on the DB folder and it was successful.

      Now when i go the DB view to add HDI container search is not giving me any result.

       

      I checked i have HanaTrial instance in Trial CF account

       

       

      Can you please help me on how can i solve the problem.?

       

      Thanks,

      Vishesh.

       

       

       

      Author's profile photo Sven Hoffmann
      Sven Hoffmann

      Hello all,

      I’m also using the CF trial account and encounter the issue that in the context menu of the src folder in the HANA module there is no entry for the HDB CDS Artifact:

       

      The version of the FullStack WebIDE is 180524.

      Any idea what’s wrong?

       

      Thanks and best regards,

      Sven.

       

      Update: I found the solution: a WebIDE plugin was not enabled in my trial account

      Author's profile photo Dmitrii Iudin
      Dmitrii Iudin

      Hello.

      I am also facing this issue. could you please elaborate where exactly do you need to enable the WEbIDE plugin?

       

      Regards,

      Dmitrii Iudin

       

      Author's profile photo Victor Carmona Pale
      Victor Carmona Pale

      Hi everyone

      I think this is excellent post (step-by-step).

      This is my first contact with SAP Web IDE Full-Stack.

      I tried to follow the steps but, I'm facing some issues.

      There is a step where you need create your db module, the specific sentence tell us "Select Space from the left side menu".

      I open "Project Settings", I can't see the option "Space"

      I am doing something wrong?

      Do I need to enable Cloud Foundry?

      Best regards,

      Victor Carmona.