SAP Cloud Platform & Cloud Foundry – test, feedback, tips and tricks

After you followed all the steps to setting up Cloud Foundry in your SAP Cloud Platform Cockpit, it’s time to dig into and like all new environment you are testing, you’ll face some problems.

In this article, I’ll quickly overview the activation/installation and talk about a simple NodeJS with a MongoDB scenario. I hope it will help you to be more familiar with the tools, to implement your own needs on the platform.

Quick CF activation/installation

Install CF on your machine and follow instructions detailed here. One it’s installed, you need to test the CF CLI by typing cf in your favorite terminal.

A quota was not automatically assigned for my account because I had several sub accounts. Then, when I deployed an application, I get an error message:

Activate MongoDB / PostgreSQL and other services

Follow the path: Cloud Foundry > Services > Service Marketplace and activate the services you want to use. You can directly map the service with your app if you have already deployed it.

Create and deploy a NodeJS

First, you need to create a skeleton NodeJS project using the Nodeclipse available for free on the Eclipse Market or create your own project from scratch using the framework your like. You can simply download this project from my Github account : js-app-for-sap-cloud-foundry.

If you are not using mongodb in the scenario, you can comment the line require(‘./server/db/mongo-connect.js’)(oAppEnv);. It simplifies the workflow, you can uncomment it later. When your project is ready, be sure it compiles by running the two following commands:

npm install
node app.js

If all is OK, your project is ready to be hosted on CF.

// Logon to Could Foundry
cf login
// Enter your credentials and navigate to the space you want to host the app
// Change directory and push it!
cd js-app-for-sap-cloud-foundry
cf push

The file manifest.yml is very important for your app deployment, to specify the app information: commands, name, buildpack, etc. Below, an example of manifest.yml file

---
applications:
- name: js-app
  memory: 512M
  host: js-app
  command: node app.js

Fields you need to know for the manifest.yml file:

Key Value
name The name of the application
buildpack The name of the Node.js buildpack determined before with command cf buildpacks. (by default an auto determination of the buildpack is done if the buildpack information is missing)
command For NodeJS apps, a start command is needed to start the application. Here for example, it’s “node app.js”.
memory RAM available for the application.
disk_quota Disk space available for the application.
host Host information used in the URL which makes the application accessible.

Connect with a MongoDB

The first step is to create a new MongoDB instance. You have to go to your SAP CP CF sub account > Services > Service Marketplace and select MongoDB. Now in your left panel you can select Instances and create a new one (see below)

Now you are able to map your instance with the app you deployed before. The manifest.yml will change a little bit and the service will be mapped like this:

---
applications:
- name: js-app
  memory: 512M
  host: js-app
  command: node app.js
  services:
  - mongodb-service 

/!\ “mongodb-service” is the name of you instance, you need to adapt /!\

Useful links

Github | SAP/hcp-cloud-foundry-tutorials
SAP CP | Cloud Foundry Tutorials
Github | Cloud Foundry CLI
Cloud Foundry CLI Reference Guide

Useful CLI commands

cf
cf apps
cf login
cf logout
cf push
cf buildpacks
cf marketplace
cf api api.cf.<host information>
cf create-service mongodb v3.0-dev mongo-service

SAP UI5 – Data binding without XML view for the sap.m.Table component

Here I’ll describe the best method I’ve found to bind data to the sap.m.Table component without using XML view, so only with JavaScript, programmatically.

Link to the sap.m.Table component in the SAP UI5 documentation.

First, you need to declare your dataset:

var oData = {
    'History': {
        'Entries': [
            {
                'Type': 'nonFolder',
                'Name': 'LCMCompare',
                'Time': 'Jan 9, 2017 2:01 PM',
                'modifiedCount': '1'
            },
            {
                'Type': 'nonFolder',
                'Name': 'Another one',
                'Time': 'Jan 2, 2017 5:55 PM',
                'modifiedCount': '9'
            },
            {
                'Type': 'nonFolder',
                'Name': 'First comparison',
                'Time': 'Jan 9, 2017 4:41 PM',
                'modifiedCount': '4'
            }
        ]
    }
};

After that, you need to declare your columns definitions:

var oTable = new UI5Table({
    headerText: 'Compared:',
    columns: [
        new UI5Column({
            header: new UI5Label({
                text: 'Type'
            })
        }),
        new UI5Column({
            header: new UI5Label({
                text: 'Comparison Name'
            })
        }),
        new UI5Column({
            header: new UI5Label({
                text: 'Date/Time'
            })
        }),
        new UI5Column({
            header: new UI5Label({
                text: 'Difference'
            })
        })
    ]
});

Now, it’s time to declare the table and to define the binding between the data and the columns: (in my case, I’m naming history as the root as my datasource)

var oModelTable = new sap.m.JSONModel(oData);
oTable.setModel(oModelTable, 'history');
var oTemplate = new UI5ColumnListItem({
    cells : [
        new UI5Text({
            text : '{history>Type}'
        }),
        new UI5Text({
            text : '{history>Name}'
        }),
        new UI5Text({
            text : '{history>Time}'
        }),
        new UI5Text({
            text : '{history>modifiedCount}'
        })
    ]
});
oTable.bindItems('history>/History/Entries', oTemplate);

The last line in this example will bind your data following the root > and the path to the array to iterate through. Your table will be rendered with the data in your oData object. I would suggest to attach this binding with an object in your store, so changes will appear automatically.

Preview of the result: sap-m-table_ui5_result

Application C# et SAP .NET Connector

Avant de pouvoir établir une connexion entre une application C# et un ERP comme SAP il va falloir vérifier que les quelques prérequis soient installés sur votre machine.

  • Microsoft Visual C# 2010
  • Microsoft .NET Framework 4.0

Téléchargement du SAP .NET Connector

Rendez-vous sur service.sap.com/connectors pour télécharger SAP .NET Connector 3.0 (disponible gratuitement)

Après avoir téléchargé et installé SAP .NET Connector, créez un nouveau projet dans Visual C# 2010, Application Console et nommez-la : “TestSAP”.

creer_projet_sap_csharp

Dans l’explorateur de solutions (à la droite de votre écran), faites un clic droit sur “Références”, puis “Ajouter une référence…”

Ajoutez maintenant les fichiers :

  • sapnco.dll
  • sapnco_utils.dll

Pour info, ces deux fichiers devraient normalement se trouver sous : C:\Programme Files\SAP\SAP_DotNetConnector3_x86\

ajouter_references_sap_csharp

Assurez-vous maintenant que votre projet cible bien sur le .NET Framework 4.0 (dans les propriétés de votre projet)

framework_sap_csharp

Place maintenant au code du fichier program.cs (remplacez l’intégralité du code par celui ci-dessous)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAP.Middleware.Connector;

namespace TestSAP
{

class Program
{
static void Main(string[] args)
{
RfcConfigParameters parameters = new RfcConfigParameters();

parameters[RfcConfigParameters.Name] = "VOTRE_NOM_DUTILISATEUR";
parameters[RfcConfigParameters.User] = "VOTRE_NOM_DUTILISATEUR";
parameters[RfcConfigParameters.Password] = "VOTRE_MOTDEPASSE";
parameters[RfcConfigParameters.Client] = "099"; // Remplacez par votre Client
parameters[RfcConfigParameters.Language] = "FR";
parameters[RfcConfigParameters.AppServerHost] = "127.0.0.1"; // Remplacez par l'adresse IP de votre hôte
parameters[RfcConfigParameters.SystemNumber] = "00";

RfcDestination destination = RfcDestinationManager.GetDestination(parameters);
RfcSessionManager.BeginContext(destination);
destination.Ping();

}

}
}

Si au lancement de l’application, vous voyez apparaitre une invite de commandes et qu’aucun message d’erreur ne survient, la connexion est alors bien établie.

Au contraire, en cas de message d’erreur, vérifiez vos ID + mot de passe ou simplement vos autorisations (votre compte SAP doit avoir les autorisations RFC)