Skip to Content
Technical Articles

Bulding a simple Web/Android App for Document-Management with Mendix Low-Code-Platform

Introduction

This blog examines how document management processes can be mapped in Mendix’s low-code platform when the actual document management functions are implemented via a backend in the form of the SAP ERP system using web-services.

Mendix offers the possibility to create applications without basic knowledge about the app or web programming. Besides the possibility to use Mendix to develop Fiori apps, you can also use it with its own UI layer. The background to Mendix is the increasing popularity and integration into the Hana Cloud platform.

The idea is to migrate partial aspects from the transactions CV01N, … CV03N to a Mendix frontend. Whether the use case is suitable for practical use must be checked on a case-by-case basis. It is much more important to show which possibilities there are in this area.

Business processes to be implemented:

Creation of document info records and simultaneous check-in of original files.

Steps to go through:

  1. Create SAP source code that can process Base64Files and import them into the SAP system DMS system
  2. Set up a Mendix application that represents the transactions CV01N…CV03N on the UI-layer (I will focus on partial aspects CV01N)
  3. Deploy the mendix Application as Web- and Android-App

Required SAP-components: 

  • SAP-ECC System with Application-Server 7.02 or higher. (Beware, the official development system will not be able to do this. Since we need to access business applications)
  • A Basic Understanding of Web Service Technologies within SAP(You should know how to create Web-services from a function module)
  • A running DMS system within SAP. With the Knowlede-Provider as administrator of the originals

Prerequisites

  • Access to a Mendix account can be created for free here
    • You should download an install the mendix Desktop-modeler
  • If you want to deploy the Mendix app as an Andorid app then create an account for Adbobe-Phone-Gap here

The SAP-Part

 

Some Basics for creating document info records using the SAP-GUI

(Can be skipped if you are already familiar with this)

  1. Go to Transaction CV01N here you can specify the primary key using Document, Document Type, Document Part, Document Version.

An original-file can be stored within the document info record. This file (which represents the real document) is loaded into the content server.

 

Creating the ABAP source code

The simplest way for me was to create a web-service that receives a BASE64 string, converts it into a PDF file, and then checks the file into the DMS system. Note: PDF is hardcoded in the source-code but this could also be generated dynamically.

We can use the following function modules:

  • SSFC_BASE64_DECODE
  • BAPI_DOCUMENT_CREATE2
  • BAPI_TRANSACTION_COMMIT

It is sufficient if the function module imports an IV_File as string value. (This will be a file, which we transfer in Base64 format). Additionally a data structure with the information for the document info record of type BAPI_DOC_DRAW2.

So that the interface does not become too confusing later, we limit the parameters to the mandatory fields of the document BAPIS(Type, Number, Version, Part), FILE-Content(IV_File), FILE-NAME(IV_FILENAME).

We simply write the file to the application server and load it from there into the DMS system.

A Web service is then generated from the function module.

FUNCTION Z_DOCUMENT_MANAGEMENT.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(IV_FILENAME) TYPE  STRING
*"     VALUE(IV_DOCUMENTTYPE) TYPE  DOKAR
*"     VALUE(IV_DOCUMENTNUMBER) TYPE  DOKNR
*"     VALUE(IV_DOCUMENTVERSION) TYPE  DOKVR
*"     VALUE(IV_DOCUMENTPART) TYPE  DOKTL_D
*"     VALUE(IV_FILE) TYPE  STRING
*"  EXPORTING
*"     VALUE(EV_RETURN) TYPE  BAPIRET2
*"----------------------------------------------------------------------

DATA: DOCUMENTDATA like BAPI_DOC_DRAW2,
      XSTRING TYPE XSTRING.

* Assign importparameter to structure

DOCUMENTDATA-DOCUMENTTYPE = IV_DOCUMENTTYPE.
DOCUMENTDATA-DOCUMENTNUMBER = IV_DOCUMENTNUMBER.
DOCUMENTDATA-DOCUMENTVERSION = IV_DOCUMENTVERSION.
DOCUMENTDATA-DOCUMENTPART = IV_DOCUMENTPART.


*Create filename for the application server
CONCATENATE '/tmp/' IV_FILENAME INTO IV_FILENAME.
* BASE64 Format in XString umwandeln.
CALL FUNCTION 'SSFC_BASE64_DECODE'
  EXPORTING
    B64DATA                        = IV_FILE
*   B64LENG                        =
*   B_CHECK                        =
  IMPORTING
    BINDATA                        = XSTRING
 EXCEPTIONS
   SSF_KRN_ERROR                  = 1
   SSF_KRN_NOOP                   = 2
   SSF_KRN_NOMEMORY               = 3
   SSF_KRN_OPINV                  = 4
   SSF_KRN_INPUT_DATA_ERROR       = 5
   SSF_KRN_INVALID_PAR            = 6
   SSF_KRN_INVALID_PARLEN         = 7
   OTHERS                         = 8
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

* Write the file to the applicationserver
* into /tmp/
OPEN DATASET IV_FILENAME FOR OUTPUT IN BINARY MODE.

  TRANSFER  XSTRING to IV_FILENAME.

CLOSE DATASET IV_FILENAME.

DATA: lt_files  TYPE TABLE OF bapi_doc_files2.
DATA: ls_files  LIKE LINE OF  lt_files .

CLEAR ls_files.
ls_files-originaltype = '1'.
ls_files-storagecategory = 'DMS_C1_ST'.
ls_files-docpath = ''.
ls_files-docfile = iv_Filename.
ls_files-wsapplication = 'PDF'.

*append structure to table
CLEAR lt_files.
APPEND ls_files TO lt_files.

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
  EXPORTING
    DOCUMENTDATA               = DOCUMENTDATA
*   HOSTNAME                   =
*   DOCBOMCHANGENUMBER         =
*   DOCBOMVALIDFROM            =
*   DOCBOMREVISIONLEVEL        =
*   CAD_MODE                   = ' '
    PF_FTP_DEST                = 'SAPFTPA'
    PF_HTTP_DEST               = 'SAPHTTPA'
*   DEFAULTCLASS               = 'X'
  IMPORTING
*   DOCUMENTTYPE               =
*   DOCUMENTNUMBER             =
*   DOCUMENTPART               =
*   DOCUMENTVERSION            =
    RETURN                     = EV_RETURN
  TABLES
*   CHARACTERISTICVALUES       =
*   CLASSALLOCATIONS           =
*   DOCUMENTDESCRIPTIONS       =
*   OBJECTLINKS                =
*   DOCUMENTSTRUCTURE          =
    DOCUMENTFILES              = lt_files
*   LONGTEXTS                  =
*   COMPONENTS                 =
          .


IF sy-subrc = 0.


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
          .


ENDIF.
ENDFUNCTION.

 

We have now performed all the steps required from the SAP side.

 

The Mendix-Part 

 

  1. Create a Mendix project
  2. Formulate data model
  3. Set up the UI layer
  4. Extend the data model with a file entity
  5. Define business logic
  6. Deployment as Android-App

 

Create a Mendix project

My recommendation is to start the Mendix project in the cloud and then migrate it to the local workstation. The easiest way to start is with a “blank app”.

In the Mendix Cloud environment.

  1. Step: Create a new “blank app” and choose a name.
  2. Select Edit in Mendix Studio (top right)

Formulate data model

We now create a very simple data model and front-end.The data model should represent a document info record and a file entity.

For creating the data model I recommend the official Mendix documentation.

Create Data Model in Mendix 

The minimum we need to add is the primary key for a document info record. The file entity can be added in a later step.We just want to map the SAP mask of transaction CV01n to the Mendix front end. You can, of course, add further attributes of the document info record to Mendix at this point. Then the web service has to be adapted accordingly. But at the moment it’s only about the minimum.

 

Set up the UI layer

The entity is now linked to the front-end so that the user can (later) enter data.

All further steps can now be performed in the Mendix Desktop Modeler. (The previous steps can also be executed there by the way.) Mendix will automatically import the project. Sometimes there are problems with the versions. If this is the case, just download the latest Mendix Modeler.

 

 

Extend the data model with a file entity

We now extend the data model with a file entity

In addition, an association must be established between the file entity and the document info record entity. You would expect a file entity to belong to exactly one InfoRecord. For reasons unknown so far, this has caused problems in the further process. Therefore, the method is chosen as shown in the screenshot. 1 Orginal_File to many Document_Data.

 

Furthermore, the Document-Data entity can be set to non-persistence.

We now have in Mendix the complete data model that we need for the web service call.

Define business logic

Mendix generally behaves very object-oriented. Therefore, in the next step, we have to define the object instantiation, which should be executed after starting the application. Instances must be created for all entities. These must then be connected to each other.

important: We will now create two individual microflows.

 

 

So far I couldn’t find another way to relate the two objects to each other. So we create two microflows to create an original and the document data objects. Within the original microflow, we use a parameter type Document-Data and set the association of the original file to the object of the Document-Data.

We now create the individual objects of the type document-data and original file within the microflow and then relate them via the Change_Object element. We then select Object as the return type of the microflow object and return the newly created Document_Data object.

 

Go to the Homepage (sidebar)

Within the document-data view we call another Dataview with the microflow to create the original file.

 

 

At this point you should have created 2 microflows and included them in 2 nested data views on your homepage.

 

Integrate the SAP-Service

 

All we have to do now is integrate the SAP-SOAP service. Extract the service-url from the SOA-Manager.

 

 

The Web-Service can now be used within a microflow. We will now create a microflow that transfers the Mendix data to the SAP Web Service.

 

Additional installation of Community Commons 

To convert the file to BAse64 we install an additional library from the Mendix app-Store. Install the Community Commons Function Library.

Choose a JAVA Action BASE64EncodeFile and include a java action call into the Microflow which

calls the Web-Service.

 

We could implement an export mapping but in our case simple parameter mapping is ok.

 

Now we bind the microflow to a front-end element and trigger the web service call at the push of a button.

 

We now place the button in the Data View and attach the Mircoflow with the Web Service Call to it.

 

 

Now we have everything we need to test the service.

 

Let’s run the Program locally and debug it from the SAP-side. (How to Debug Web-Service)

Keep in Mind to use a Documenttype which stores its original Files with the Kpro (You can do this in Customizing under the item Cross-Application Components->Document Management -> Control Data -> Define Documet Types)

As we can see in the debugger, the document interface works.

 

Create and deploy the Mendix-App as Android-Application

The simplest part of Mendix is really the creation of the Android App. With Apple devices, it is more complicated with the security requirements etc.

  1. Commit your app to the Mendix-Cloud.
  2. Go to your App.

 

Give the app the necessary permissions and deploy them afterward.

After the Build Process you can download the Andorid Package and install it to you Andorid device.

Note: Autorize Mendix access to your Phone-Gap-Account.

Conclusion

It could be shown that the Mendix low-code platform can be integrated with an existing SAP ERP system without much effort. In this case, the integration path via SOAP web services was chosen.

The idea can easily be transferred to simpler or more complex cases of backend services.

4 Comments
You must be Logged on to comment or reply to a post.
  • I like the SAP side of this.  It could be used with any outside document management system.  It also highlights the stress points of SAP’s document management functionality.  It isn’t the easiest app to use.   A long time ago we built some custom apps to upload our documentation to the database server.   The document management in SAP was just too much to try to use for what little we needed it.

    As always – the blog is appreciated,

    Michelle

    • xavier andres hi I’m facing the same problem. I’m guessing it’s somehow related to the connection between the Menidx Cloud and the emulator. The actual functionality runs in the Menidx cloud. Okay but I get the error “Cannot initialize app” so it seems to me that App is able to start but fails.