My experience with HXE2 SP3 – Part2
Thank you again for reading my blog on part 2 of my experiences while installing HXE2 SP3.
on my previous blog – i mentioned how to the installation, and create a sapui5 basic module. In this blog, I will explain how to add a database module into the same project. I believe this was the easiest of all the modules I created in my project.
Here are the steps:
- Right click on the project
- Add new DB module – provide a name
Next on the wizard, provide a schema name if you have one already (I did not)
As the db module was built… (since we checked the checkbox on the last step in the wizard). We can see the dbm module added and reflected on the mta.yaml file.
Again, please try to see it in the UI form, rather than trying to update the code editor. I have made the mistake of trying to edit it manually and Mike Howles can agree with me from his early days in the XSA world.
Well, now that we added a web module, then what… well, so far we have only added a “container”.. we have not added any tables, or data models… so let’s try creating a few entities and models (based on CDS).
Provide a name for the HDB CDS artifact – once the name is provided, we can see the following.
Now it is time to add some entities (Tables) by clicking on the table icon and then in the blank space to create an entity. Click on the name to change the name. Then, double click on the entity little rectangle to add some columns, data types, etc as follows
Well where is the physical table… we don’t have one yet… let’s look into the and see if we can create a database.
Since this is the first time for me to use this HXE, I need to create one.
Remember we are in an HDI container – and this Is a schema less world… below we see the unique identifier for our container.
After clicking on ok , we can see the newly created HDI container DB
Notice, our hdbcds file is not saved… and when we selected the tables section, there were no tables selected… so if we save the hdbcds file… then, we have to go back to the dbm module and build, and run…. Everytime we make a modification in our tables or data models, we must build and run in order to reflect the changes done in our module content.
After successfully building the dbm module, we can see
Now it is time to add some data into it — keep in mind, we use the webide to create our code… and we use the DB explorer ( 2nd icon from the top on the left nav) to interact w tables, views, etc.
- Double click on the table name (bottom right corner)
- Then click on the open table button to add some records manually
After adding a few records, save table
it gave me an error because the date format should be YYYYMMDD
So now I did it right ?
And we can query the table now from the sql console. (drag table name, type select * from… then run and see the output on the bottom of the screen. Voila!!!
Back in the hdbcds file, let’s add a CDS view.. double click on it… give it a name and let’s add an active object
Then add the columns needed – in my case I want to add all 3 columns, however, I want to add a where clause for my view. I want to display who was born after 1/1/2000. Save, Build, Run
Wait.. there is an error.. look at the red dot…
After a few back and forths, I decided to open the code editor, instead of the graphical editor…
and yep.. there was an issue that did not reflect what I saw on the screenshot above. I corrected the code editor… saved the file and re-built it. No issue after that.
Now, selecting this from the sql console, we can see those people who were born after 1/1/2000
So far so good…. So if we have a table, and a view…
My learning on this step while adding a db module:
- the hdi-container and schema less world
- the new(ish) HANA database explorer tool
- the CDS graphical editor – make sure the errors you see are not due to the editor… like in my case
- make sure you use proper data and data types
On my next blog, I will expose this table and view via odata in the nodejs module
Again, please share you experiences, issues and successes with the community. Look forward to hearing from you all.