Technical Articles
How to Create Your First SAP Business One Loosely Coupled Solution in the SAP Cloud Platform
Update 20/01/20
As part of the strategy of SAP Cloud Platform. Several standard services like the ones used in this tutorial were deprecated. I adapted the code and update the tutorial so it stills relevant.
If you want to implement an application that makes use of a persistence layer (Postgres) and a Cache mechanism (Redis). Please check this other hands-on exercise, that leverage Azure services. This hands-on was offered as part of the Intelligent Enterprise Webinar Series.
The paradigm for SAP Business One solutions have completely changed (you probably notice that if you were not hiding in a cave). It started with small steps when we first adopted SAP HANA as our platform. The main drive was the push the add-ons’ business logic from the legacy fat client to the server and, by the usage of Service Layer, leveraging standard protocols such as Odata we opened SAP Business One to countless possibilities. With Social Media integration, IoT and Voice Interfaces, just to name a few
In a more recent wave. We have digital transformation happening in the cloud and all the benefits that comes with it. Much further than a simplistic idea of porting your logic to the server. It gives your solution an amazing flexibility You can choose the technology, the services, when to implement new features and which customer will have access to it. And of course, hence you will be untangled from SAP Business One, you can create “multiple erp” solutions, like the SMB Marketplace or simply plug your B1 app to other system, like we did with the Amazon Echo and ByD.
With that mindset, I developed a tutorial repository to go trough some features of a cloud application. Such as deployment, scalability and persistence.
In this blog I am going to teach you how to get start and create your first SAP Business One loosely coupled solution. So get your git installed (shame on you if didn’t have it) and let’s do some code!
Get your free SAP Cloud Platform trial Account with Cloud Foundry
This is all you need to get started and It’s quite easy to do it. Just follow this great tutorial and you will be all set
Do I need a SAP Business One System?
Not at all! The app supports the B1 APIs available in the SAP API Business Hub so we can play with B1 data in a sandbox without having a system.
You will need an API Key which you can get by clicking in the button in the details page
In case you want to use your own system. Make sure the B1 Service Layer port is exposed to the public internet, otherwise your loosely coupled app won’t be able to fetch data from it. If you don’t have a valid SSL certificate (which is the case for most dev environments). You can use the http port 50001.
Step 1 – Clone the Git Repository and deploy the app on Cloud Foundry
This is really basic, we first clone the GitHub repository executing
$ git clone https://github.com/B1SA/scp-b1.git
You should have a directory with all the files from the master branch in it. Navigate to this new directory and change it for the first step of our exercise with:
$ git checkout step_1
Time to send the app to the cloud!
If you followed the SAP Cloud Platform tutorial (the last step) mentioned before, you are already logged into the Cloud Foundry environment so in this case, create your cloud app is simple as:
$ cf push --random-route
–random-route will avoid name collisions with others that deploy this same app on SCP. You can choose your own app name by changing the manifest.yml file.
By the end of the process, your terminal should show something like this:
You can clearly see the route where your app is running and check it from your browser
Ok, but this is an empty HTML page. Where are the B1 Items?
Hold your horses, cowboy! We’ve just deployed the app, now we need to configure the environment. We could hard-code routes and credentials in the codebase. But this is not a Cloud development best practice. Instead, you should always use environment variables.
Set an environment variable for one app on cloud foundry is easy as:
$ cf set-env <appname> <env variable Name> <value>
The app require the following environment variables:
//Basic Variables
$ cf set-env scp-b1 B1_SERVER_ENV http://<your b1 server> or API HUb
$ cf set-env scp-b1 B1_SLPORT_ENV <Service Layer Port> or "" if API HUB
$ cf set-env scp-b1 B1_SLPATH_ENV <Service Layer path> or API HUB path
$ cf set-env scp-b1 B1_COMP_ENV <B1 Company DB>
//When using your own environment
$ cf set-env scp-b1 B1_USER_ENV <B1 User Name>
$ cf set-env scp-b1 B1_PASS_ENV <B1 User Password>
//When using the SAP API HUB
$ cf set-env scp-b1 APIKey <Your API Hub Key>
$ cf set-env scp-b1 APIHUB true
In my case, using the API HUB the variables would be like:
$ cf set-env scp-b1 B1_SERVER_ENV https://sandbox.api.sap.com
$ cf set-env scp-b1 B1_SLPORT_ENV ""
$ cf set-env scp-b1 B1_SLPATH_ENV /sapb1/b1s/v2/
$ cf set-env scp-b1 B1_COMP_ENV SBODEMOUS
$ cf set-env scp-b1 APIHUB true
$ cf set-env scp-b1 APIKey iamnotshowingyoumykey
time to restart the app and check it once again
$ cf restart scp-b1
TADA!!
Step 2 – Monitoring and Scaling
Let’s assume your solution that lists B1 Items is a huge success. A lot of users are accessing it. First thing you do is to monitor the app’s usage with:
$ cf app cfdemosummit18
Now it’s time to scale our application to support more users. Let’s do a scale out, that will create more instances of our application to support a high traffic, for example.
//Then we can create, lets say, 3 instances of the app with
$ cf scale scp-b1 -i 3
Checking how the app looks like now you will see the multiple instances:
The Cloud Foundry Environment variable CF_INSTANCE_INDEX returns the number of the instance which your app is running. You can see my implementation here.
If you access your app from the web browser and refresh the page fast enough, you can check that the web page is provided by different servers. The load balancing it’s done automatically so you don’t have to worry about that.
Step 3 – Cloud Foundry Services (Persistence)
The SAP Cloud Platform offers a great amount of services to support and enhance your application. Many of those are available in the Cloud Foundry environment. To check what services are assigned to your trial account
$ cf markeplace
There are two steps to have a service in your application, first you need to create it and then bind it to one or many apps. Like this:
$ cf create-service <Service> <Plan> <service_instance_name>
$ cf bind-service <app name> <service_instance_name>
In our case we want to create a PostgreSQL DB Service named itemdb. There are 2 plans available, we gonna use the V9.4-dev. Then we will bind it to the cfdemosummit18 app
You can check the services and bounds in your account by executing $ cf services. Once a service is bound, the connection parameters are availabe in the VCAP_SERVICES environment variable. You can see my implementation here.
To check the Environment Variables of your app:
$ cf env scp-b1
As in the previous step, checkout the step_3 branch and push it to the cloud. You will be able to interact with your new DB:
Step 4 – Create B1 Items from Cloud DB
Last step is just to close the cycle and synchronize the items created in the PostgreSQL db in the cloud to your B1 environment using Service Layer. It doesn’t use any additional cloud feature but you can check the code here
That’s it!
Hope you find this tutorial useful and get start developing cloud applications. You can also find a .Net version for the same app. Ithe Cloud is all about choice, so choose your runtime, tools and platforms and let us know if you have any questions. Just ping me on twitter @Ralphive
I can share this information to spanish audience from Latin América?
Thank you so much!
Claro que sí?
Hi Ralph,
I tried the link https://www.sap.com/developer/tutorials/hcp-cf-getting-started.html referenced in this blog but it did not work.
Is there a new link. Not sure how to proceed without it.
Please let me know if you have any ideas because this is stopping me from working through the blog.
Thank you,
Mel Dodd
Thank you for the heads up, Mel. It seems that tutorial was deprecated.
I linked a new one that should work the same.
Bear in mind the last update of this how-to (first paragraph) if you want to implement the persistence layer.
Hi Ralph,
Thanks for your response. Now it seems that what I really need is to create an odatav4 service on my on-premise HANA server to act as a data service/source for my smartform on the client. Does that make sense?
I have tried searching in sap.answers.com and googling and looked through the blogs and tutorials for this but I have not yet found a good example. There are many examples using the cloud and apihub etc. but in my case I think I need to create the odata service on my B1 HANA server.
Can you point my to some resources that would help with this?
Also, I am currently on B1 9.3PL08 HANA 100.122.21... Does that support odatav4 or do we need to upgrade first.
Thanks for any help.
Regards,
Mel
Thanks.
Regards,
Mel
Hi, Ralph. Nice to meet you.
I'm Macarena from Argentina, I don't speak English very well but I need your help.
Following all the steps to assemble the SMBMKT, in the section where I have to consume the SAP Leonardo endpoints, for example, "Inference Service for Customizable Image Feature Extraction" it says they were decommissioned. Do you know if I could consume of another similar one? Or if there is a way to enable them?
I appreciate your response.
Greetings
Good morning community, nice to greet you
I would like to know if anyone could give me a hand regarding the SAP Leonardo Similarity Scoring API. It is disabled and therefore I cannot use it. Researching on the subject, I found that this API could be consumed from "Data Intelligence" which was then merged. Do you know if it is useful for me to pay for data intelligence services to continue with the assembly? Do you have any documentation that you can recommend me to know how to use it?
Thank you in advance.
Hi Ralph,
---Never Mind!-- I ran cf push scp-b1 -b https://github.com/cloudfoundry/nodejs-buildpack and that resolved the issue. Apparently the version of buildpack had a bug.
I will leave this comment here in case it can help someone.--
Original comment:
I am trying to work through this example using the new “SAP Business Application Studio.” I was able to clone the app from https://github.com/B1SA/scp-b1.git and then cf push it.
I was also able to set the environment variables.
Then I tried cf restart scp-b1 which failed as follows.
user: scp-b1 $ cf restart scp-b1
Restarting app scp-b1 in org ec6af04btrial / space dev as mel@johnscreeksolutions.com…
Stopping app…
Waiting for app to start…
Start unsuccessful
TIP: use ‘cf logs scp-b1 –recent’ for more information
FAILED
user: scp-b1 $
I ran cf logs scp-b1 –recent
It seems that the app is looking for package.json in a folder that does not exist /home/vcap/app/package.json.
Ralph, do you know where this folder reference is set?
I cannot find it in any of the files in the project.
Any help you can give is appreciated.
Thanks,
Mel
hello Ralph,
I'm learning Service Layer and practicing it with this code.
It works with Postman, like the screenshot bellow.
and when i try to see the result through the code you wrote, it fails.
then wrote $ cf restart scp-b1 on the terminal.
the route link (scp-b1-empathic-roan-ch.cfapps.us10.hana.ondemand.com) shows only this empty page
please let me know if there is a mistake
thank you