Managing the Lifecycle of a Modeling Project

Performing Practical Exercises

Objective

After completing this lesson, you will be able to performing practical exercises

Create a New Project and an HDB Module

Exercise Objectives

After completing this exercise, you will be able to:

  • Create a new project (MTA Application)

  • Create a HDB module

  • Deploy the project

Business Example

You have been working on an SAP HANA project as a modeler in SAP Business Application Studio for some time, and will soon work on a new project. Before that, you want to put into practice key concepts of MTA application, SAP HANA Database module, and namespace configuration, by creating a simple project and reviewing its key properties.

Note

The scope of this course is restricted to the HDB Module, which means we cover only a part of what MTA projects encompass. To use the best project template for this need, we will use the SAP HANA Database Project project template.

Overview of Exercise Tasks

  • Task 1: Create the Project and Database Module
  • Task 2: Finalize the Project and Deploy the HDB Module

Note

In this exercise, when values include A####, replace the characters with the user number assigned to you (one letter and four digits).

Prerequisites

Prerequisites

Your SAP Business Application Studio development environment should have been set up.

Task 1: Create the Project and Database Module

Steps

  1. If needed, launch SAP Business Application Studio and start your HCMOD_A#### development space.

  2. In the Explorer pane, create a new project based on the SAP HANA Database Project template, with the following properties:

    FieldValue
    Project NameMyProject_A####
    Module Namedb
    Namespacemyproj.db
    Schema NameMYSCHEMA_A####
    SAP HANA Database VersionSAP HANA Cloud
    Bind the database module to a run-time environment service instance?Yes
    Create a new HDI service instance?Yes
    Service instance name[Keep the default]
    Use the default database instance of the selected Cloud Foundry space?Yes
    1. Choose View→Command Palette

    2. Enter project in the search field.

    3. Choose SAP Business Application Studio : New Project from Template.

      As an alternative to the sub-steps above, you can also choose File→New Project from Template.

    4. Select the SAP HANA Database Project template and choose Start.

    5. Enter the project properties according to the table and choose Next to navigate to each subsequent screens.

    6. Confirm the project creation by choosing Finish.

  3. Open the project in a new workspace.

    After a little while, a dialog box Leave Siteshows up to allow SAP Business Application Studio to leave the current HC300_A#### project/workspace, and open the new project in a new workspace. invites you to open .

    1. Choose Leave Site.

      Result

      The new project opens in a new workspace.

Task 2: Finalize the Project and Deploy the HDB Module

Steps

  1. Review the content of the mta.yaml located at the root of your project.

    1. Click the file mta.yaml.

      Note

      You can also righ-click the mta.yaml file and choose Open with→MTA Editor, which opens the file with a dedicated user interface.
    2. Note that the file contains the project ID and version, the list of modules (only one HDB module), and a resource used by this module, called hdi_db, of type com.sap.xs.hdi-container.

  2. In the project, create the following sub-folders within the src folder to organize the design-time content of your HDB module:

    • data

    • models

    • synonyms

    • test

    1. Right-click the db→src folder and choose New Folder.

    2. Enter the folder name data and press Enter.

    3. Repeat the previous steps for the other folders.

  3. Deploy the HDB Module db.

    1. In the SAP HANA Projects sub-pane, choose the Deploy icon for your MyProject_A####/db module.

    2. Check the deployment status in the Console.

  4. Close all the open tabs in SAP Business Application Studio.

    1. Right-click any open tab and choose Close All.

Set Up a Project to Access an External Schema

Exercise Objectives

After completing this exercise, you will be able to:

  • Reference a service to access data outside of the application container
  • Define synonyms for external objects and set up the relevant security

Business Example

In your project, you need to access data that is not managed within your application container. You will set up the application so that it can consume data from external schemas.

Overview of Exercise Tasks

  • Task 1: Bind the User Provided Service to your Project
  • Task 2: Define Synonyms and Authorization to the External Schema
  • Task 3: Check That Your Synonyms are Correctly Defined

Prerequisites

Prerequisites

  • Your SAP Business Application Studio development environment should have been set up.
  • The previous exercise on creating a new project should have been completed.

Task 1: Bind the User Provided Service to your Project

To access data outside of your HDI container, you need a user provided service that will connect to the external database. This user provided service has already been created and is called EXT_SCHEMA_SERVICE. It uses a technical user that has the relevant privileges to access your data, and you will need to transfer those rights to the Object Owner and Application User in your project.

Steps

  1. If needed, launch SAP Business Application Studio and start your HCMOD development space.

  2. If needed, open your project MyProject_A####

    1. You can open your project by using the File→Open Folder menu.

  3. Bind the user-provided service to your MyProject_A#### project with the following information:

    FieldValue
    Connection typeExisting user-provided service instance
    Service instance nameEXT_SCHEMA_SERVICE
    1. Go back to the Explorer view.

    2. In the SAP HANA PROJECTS pane, expand the MyProject_A####/db module.

    3. Hover the Database Connections folder and choose the +(Add database connection) icon on the right.

    4. Enter the information provided in the above table and choose Add.

  4. Check the mta.yaml file.

    1. Select the mta.yaml file in your project and open it in the Text Editor.

    Result

    Your file should look like the following :
    Code Snippet
    123456789101112131415161718192021222324252627282930
    ID: MyProject_A#### version: 0.0.1 modules: - name: db type: hdb path: db requires: - name: hdi_db properties: TARGET_CONTAINER: ~{hdi-container-name} - name: cross-container-service-1 group: SERVICE_REPLACEMENTS properties: key: ServiceName_1 service: ~{the-service-name} resources: - name: hdi_db type: com.sap.xs.hdi-container parameters: config: schema: MYSCHEMA_A#### properties: hdi-container-name: ${service-name} - name: cross-container-service-1 type: org.cloudfoundry.existing-service parameters: service-name: EXT_SCHEMA_SERVICE properties: the-service-name: ${service-name}

Task 2: Define Synonyms and Authorization to the External Schema

You must configure synonyms and authorization in order to access the data from any schema outside of your container.

Steps

  1. Check your project environment.

  2. Create a new .hdinamespace file in your synonyms folder, with the following content:

    Code Snippet
    1234
    { "name": "", "subfolder": "ignore" }

    Hint

    To save time, you can copy/paste the .hdinamespace file from the src folder to the synonyms folder, and then open it and adjust its content.
    1. Select the src→.hdinamespace file and press Ctrl+C(copy).

    2. Select the src→synonyms folder and press Ctrl+V(paste).

    3. Open the new .hdinamespace file and adjust its content.

  3. Define the authorizations you want to grant to both the object owner and to the application user on objects.

    A design-time file, ExternalAccessService.hdbgrants, is located in your exercise folder, HC300→New Project Files, and ready for import into the synonyms folder.

    1. Right-click the synonyms folder and choose Upload.

    2. Select the file HC300→New Project Files→ExternalAccessService.hdbgrants, and choose Open.

  4. Deploy the entire synonyms folder and check the deployment status.

    1. Choose the Deploy icon for the synonyms folder.

    2. In the Console pane, check that the deployment completes successfully.

  5. In your db→src→synonym folder, create a design-time TRAINING.hdbsynonym file that will store synonyms for tables located in the TRAINING schema.

    1. Right-click the synonyms folder and choose New File.

    2. Enter the file name TRAINING.hdbsynonym and press Enter.

      Result

      The new .hdbsynonym file opens.
  6. Add a synonym for the table ORDERS in the TRAINING schema with the following properties:

    Synonym Definition

    ColumnValue
    Synonym NameORDERS
    Object NameORDERS
    Schema NameTRAINING

    Hint

    When using the Find Data Sources utility, you need to add the external schema access service you created earlier in the Services list.
    1. In the synonym editor, choose <Click to Add>.

    2. Enter the synonym name.

    3. Choose the … icon on the right of the Object Name field.

    4. In the Find Data Sources dialog box, select the service EXT_SCHEMA_SERVICE.

    5. In the Search field, enter ord and press Enter.

    6. Select the ORDERS table from TRAINING schema.

      Note

      If you receive an error message Fail to update request header, you might need to sign out and log in back to Cloud Foundry. Choose View→Command Palette, enter login and choose CF: Login to Cloud Foundry. Then sign out and log back in as you did in the first exercises.
    7. Choose Finish.

  7. Deploy the TRAINING.hdbsynonym file and check the deployment status.

    1. Choose the Deploy icon for the TRAINING.hdbsynonym file.

    2. In the Console pane, check that the deployment completes successfully.

Task 3: Check That Your Synonyms are Correctly Defined

To check that your settings for the external schemas access are correct, create a view using the ORDERS table, which is now referenced by a synonym. You will create a simple calculation view of the type CUBE, and output all the columns.

Steps

  1. In your models folder, create a new calculation view with the following properties:

    FieldValue
    NameCVC_ORDERS
    LabelOrders
    Data CategoryCUBE
    With Star Join[Not selected]
    1. In the Explorer view, right-click the db→src→models folder and choose New File.

    2. Enter CVC_ORDERS.hdbcalculationview as file name and press Enter.

    3. Enter the calculation view label as specified in the table.

    4. Choose Create.

  2. Add the ORDERS table to the Aggregation node.

    Note

    Because the synonym is already defined in your project (inside the Target Container Service, you do not need to include the external schema access service in the Find Data Sources dialog box. The object you add as a data source is the existing synonym, but you can also see/check the type and name of the actual target object.

    In other scenarios, you might want to create the synonym on-the-fly while adding a data source to a calculation view, in which case you need to include the external schema access service to the Services list.

    1. Select the new Aggregation node and click the + sign on the right of the node.

    2. In the Find Data Sources window, click the search field and enter ORD.

    3. In the search results, select the ORDERS table.

    4. Choose Finish.

  3. Add all the columns to the output

    1. Double-click the Aggregation node to expand the details panel.

    2. In the Mapping tab, drag the ORDERS Data Source to the Output Columns area.

  4. Deploy the CVC_ORDERS calculation view.

    Check the deployment status.

    1. Choose the Deploy icon for your CVC_ORDERS calculation view.

    2. In the Console pane, check that the deployment completes successfully.

  5. Check your Calculation View has been created in your HDI container. You first need to add the HDI container of your deployed modeling project to the SAP HANA Database Explorer.

    The HDI container can be added automatically by launching the SAP HANA Database Explorer from SAP Business Application Studio (SAP HANA Projects sub-pane).

    1. In the Explorer view of SAP Business Application Studio, expand the SAP HANA Projects sub-pane.

    2. On the right of the MyProject_A####/db element, choose the Open HDI Container icon.

    3. If a dialog box about opening an external website shows up, choose Open.

      Note

      You will not do this very often as part of this learning journey, so just choosing Open is fine. Otherwise, you can add hana-cockpit (wherein SAP HANA Database Explorer is exposed) as a trusted domain.
  6. Modify the display name of your HDI Container connection to make it simpler.

    Use the following pattern: <project_name>_A####_HDI_CONTAINER, where A#### is your assigned user number

    1. In the database list, locate your HDI Container connection, which has the pattern SharedDevKey@MyProject_A####-hdidb-ws-xxxxx.

    2. Right-click the connection name and choose Properties.

    3. Replace the Display Name with MyProject_A####_HDI_CONTAINER (A#### is your assigned user number) and choose OK.

  7. Look for your calculation view.

    1. Choose Column Views.

    2. Check that your CVC_ORDERS calculation view is present.

  8. Preview the data of the CVC_ORDERS calculation view in Data Preview.

    1. Back in the workspace, right-click the CVC_ORDERS calculation view and choose Data Preview.

    2. Check that the raw data tab contains data.

  9. Close all the open tabs in Business Application Studio.

    1. Right-click any open tab and choose Close All.

Use Git for Version Control in Your Local Workspace

Exercise Objectives

After completing this exercise, you will be able to:

  • Activate the Git functionality in a local project

  • Version your modeling objects with commits

  • Work with branches to manage the lifecycle of your project features and versions

Business Example

You are working on a modeling project in SAP Business Application Studio, and would like to understand how the native Git integration within SAP Business Application Studio can help you better support your development cycle. You must first finalize version 2.1.0 of your project, then you will implement changes and new features that will be released in upcoming version 2.2.0.

Note

Git is a tool that supports collaboration on a project. But a number of Git features are also suitable to support version control requirements even for a developer working alone on a project. This "single developer" use case is a good starting point to understand most of the concepts and benefits of Git.

Overview of Exercise Tasks

  • Task 1: Import a Project and Initialize your Project for Git

  • Task 2: Modify the Project Content and Commit your Changes

  • Task 3: Start the Development of Next Release

  • Task 4: Create an Urgent Hotfix (optional task)

Prerequisites

Prerequisites

Your SAP Business Application Studio development environment should have been set up.

Task 1: Import a Project and Initialize your Project for Git

Git is not activated by default when you create a project in your workspace or import a project, but it’s very straightforward, because you basically declare that the folder of your SAP Business Application Studio project will be managed as a local Git repository from now on. No content is moved or duplicated. The only change is the creation of a .git folder in the project.

Steps

  1. In the Explorer view, import the project archive MyGitProject.zip from your course files folder HC300→Git Project Files. The target folder in the Explorer tree is the /projects/. Give the imported project the name MyGitProject_A#### (A#### is your student number).

    Note

    The project name contains "Git", which makes it easier to identify during this course. In real life, you would probably NOT include "Git" in the project name.
    1. In the Explorer view, to open the /projects folder, choose File→Open Folder, select /home/user/projects/ and choose OK.

    2. Choose File→Import Project.

    3. In the dialog box, choose the HC300/Git Project Files/MyGitProject.zip and choose Open.

      Result

      The imported .zip archive is added to the /projects folder and the project is automatically unzipped.
    4. If the project was opened in a new workspace, reopen the /projects folder (choose File→Open Folder and choose the /projects folder.

    5. To change the imported project name to MyGitProject_A####, right-click the project name and choose Rename.

    6. Delete the .zip archive from the Explorer tree.

  2. Enable the Git functionality in your new project MyGitProject_A####.

    1. Choose View→Command Palette and enter Git ini.

    2. Choose Git: Initialize Local Repository.

      Caution

      Make sure you do NOT select the entire projects folder.
    3. Click Choose Folder.

    4. Select the project MyGitProject_A####.

    5. Choose OK.

    6. Close the dialog box without choosing any option.

      Result

      The project folder is initialized and stays open in the Explorer view.
  3. Observe the changes in the way the project now displays in the workspace.

    1. Expand the project structure in the workspace tree.

  4. Open the Source control view.

    1. On the activity bar at the left of the screen, choose the Source Control icon.

    2. In the Changes area, observe the Status of the files.

  5. Stage all your project content and commit the changes with description Import V2.1.0 project (in progress).

    1. In the Source Control view, below the Commit button, hover the Changes node and, on the right, choose Stage All Changes.

    2. Check that all the listed files are now in the Staged Changes node.

    3. In the Commit Message field, enter Import V2.1.0 project (in progress).

    4. Choose Commit.

  6. Display the Git History pane and observe the information that is stored for each commit.

    1. At the top of the Source Control view, choose Git: View History (git log).

    2. Note that the git history can be filtered by author, branch, and so on. It also enable quick reset, branching, and others, in relation to a given commit.

    3. Close the Git History tab.

Task 2: Modify the Project Content and Commit your Changes

You will now create some objects and modify them, applying your changes step by step, and observe the changes in the history. To save time on object creation and modification, you will use basic text files in which you will add a row of text to simulate file modification.

File1 requires a modification, and you must create a new model File3.

Steps

  1. Modify File1.

    Add a row of text: Change to finalize Model 1 V2.1.0

    1. Open the Explorer view.

    2. In your project MyGitProject_A####, expand the folder dbmodule→src→models.

    3. Click File1.

    4. Add the text provided in the step.

    5. Choose Save if Auto Save is off.

  2. Create a new model File3.

    Add a row of text: Model 3 for V2.1.0

    1. Right-click the models folder and choose New→File.

    2. Enter the file name File3 and press Enter.

    3. Add the text provided in the step.

    4. If needed, choose Save.

  3. Stage all the new/modified files and commit the changes with description Finalize V2.1.0 project. Then check that the commit is listed in the Git History pane.

    Note

    The commit history displays only for the selected file, or all the files of a selected folder. If you want to display the commit history of all your files, you must select, for example, the models folder.
    1. In the Source Control view, make sure that both File1 and File3 are listed and choose Stage All.

      Note

      If needed, to display the modified files in the Changes list, choose Refresh.
    2. In the Message field, add the text provided in the step.

    3. Choose Commit.

    4. At the top of the Source Control view, choose Git: View History (git log).

    5. Check that your last commit is listed.

    6. Observe how the bottom part of the Git History tab changes depending on which commit you select in the top part.

      If you want to see the history of a specific file, choose the corresponding History icon at the right of the file list.

  4. Observe the commit history of your project.

    1. Check that the entire commit history for all your files is listed.

    2. Select the last commit (the top one in the list) and check the status of each of the affected files.

  5. You’ve just realized that there is a small error in File3. Make the correction.

    Add a row of text: Small change to Model 3 for V2.1.0

    1. If File3 is not open, in the project tree, click File3.

    2. Add the text provided in the step.

    3. If needed, choose Save.

  6. Amend the previous commit (you think that there is no need for an additional/distinct commit for this small change) and keep the original description.

    Hint

    Select the Amend checkbox.
    1. In the Source Control view, choose Refresh..

    2. At the right of File3, select the +(Stage) checkbox.

    3. In the dropdown list at the right of the Message field, choose Commit (Amend).

    4. In the Commit_EditMsg that shows up with commit details, keep the previous description.

    5. Close the Commit_EditMsg file to let the commit (amend) terminate.Commit.

  7. Close all the open tabs in SAP Business Application Studio.

    1. Right-click any open tab and choose Close All.

Task 3: Start the Development of Next Release

The version 2.1.0 of your application has been released, and you want to start developing the new features for the upcoming minor release (V2.2.0).

To clearly separate this new development from the existing version, you will create a dedicated branch.

Steps

  1. Create a new branch, V220, in order to isolate the new features development from the main branch.

    1. In the Source Control view, click the ... icon and choose Branch→Create Branch.

    2. In the New Branch Name dialog box, field, enter V220 and press Enter.

      Result

      The new branch is created and automatically selected (which, in Git terminology, is known as "checked out"). This is visible in the "prompt" in the Message field.
  2. Perform the following modifications to the models in your project:

    • Create a new model File4, with text content New Model 4 for V2.2.0.

    • Modify File2 by adding a row of text: Change to Model 2 for V2.2.0.

    1. In the Explorer view, right-click the models folder and choose New File.

    2. Enter the file name File4 and choose OK.

    3. Add the text provided in the step for File4.

    4. If needed, click Save.

    5. Choose File2.

    6. Add the text provided in the step.

    7. Click Save.

  3. Stage all the new/modified files and commit these changes into branch V220 with description Development of V2.2.0 features phase 1.

    1. In the Source Code view, choose Refresh, then at the right of the Changes node, choose Stage All Changes.

    2. In the Commit Description field, add the text provided in the step.

    3. Choose Commit.

  4. Close all the open tabs in the SAP Business Application Studio.

    1. Right-click any open tab and choose Close All.

  5. In the Source Control view, select the main branch.

    1. At the top of the Source Control view, select the ... icon and choose Checkout To.

    2. Notice that the main and V220 branches have a different commit hash (because V220 is now ahead of main).

    3. Choose the main branch.

    4. Open the Explorer view.

  6. Open File2 and switch back to branch V220.

    1. In your models folder, click File2.

    2. In the Source Control window, click the ... icon and choose Checkout To and select the branchV220.

  7. Close the File2 tab.

    1. Click the x(close) icon next to the tab name.

Task 4: Create an Urgent Hotfix (optional task)

Your development work for the upcoming version V220 is not finished yet, but you’ve just received an e-mail from support requesting an urgent hotfix for a bug identified in V2.1.0. As a first step, you will create a new branch V211 to develop the hotfix.

Steps

  1. Create the new branch V211 from main.

    1. In the Source Control view, choose the ... icon and choose Branch→Create Branch From.

      Note

      Alternatively, because the branch main is currently checked out, you could just use the Branch→Create Branch menu item as you did in a previous task.
    2. In the ref to create branch from, choose main.

    3. In the New Branch Name field, enter V211 and press Enter.

    4. Choose OK.

  2. Perform the hotfix, which consists of a modification to File1.

    Add a row of text: Change to Model 1 for hotfix V2.1.1.

    1. In the Explorer view, double-click File1.

    2. Add the text provided in the step.

    3. Click Save.

  3. Update the MTA version to 2.1.1 in the mta.yaml file. Then save and close this file.

    1. In the workspace tree of MyGitProject_A####, double-click the mta.yaml file.

      Result

      The file opens in the MTA Editor or the Text Editor depending on your preferences.
    2. In the Basic Information tab, update the Application Version to 2.1.1.

    3. Choose Save.

    4. Click the x(close) icon next to the tab name.

  4. Stage the modified files File1 and mta.yaml, and commit the changes into branch V211 with description Implement Hotfix V2.1.1

    1. In the Source Control view, check that the two modified files are listed in the changes and choose Stage All Changes.

    2. In the Message field, add the text provided in the step.

    3. Choose Commit.

  5. Close all the open tabs in SAP Business Application Studio

    1. Right-click any open tab and choose Close All.

  6. The hotfix has been tested and released. You will now merge the V211 branch into the main branch.

    Hint

    You must check out the main branch first.
    1. In the Source Control view, click the ... icon and choose Checkout to.

    2. Choose the main branch.

    3. Click the ... icon again and choose Branch→Merge.

    4. In the dialog box, select the V211 branch.

  7. Check that the main branch now contains the hotfix.

    1. At the top of the Source Control view, choose Git: View History.

    2. In the open tab, check that the branch is main and, in the Git "timeline", check that the commit Implement Hotfix V2.1.1 is listed.

    3. Close the Git History tab.

  8. Delete the V211 branch.

    Note

    Depending on your tracking requirements, you might prefer to keep the V211 branch as is, because it is a good way to visualize the details of the hotfix, especially after additional changes are made to the main branch.
    1. Make sure the V211 branch is not checked out. If it is, check out any other branch, for example, main.

      Note

      This is mandatory because you cannot delete a branch that is currently checked out.
    2. In the Source Control view, click the ... icon and choose Branch→Delete Branch.

    3. Select the V211 branch.