Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
raeijpe
Contributor
In my previous blog I describe why we created the EDMX Label Builder. In this blog we will look how we can use the EDMX Label Builder.



 

The OData Metadata File


First we need to have a metadata file (EDMX file) of our OData Service. If we don’t have this file we easily can create on putting $metadata just behind the service url of the odata service in your browser and save the file. For this blog we use the metadata of S/4Hana OData service for Technical Users, but you can use any type of OData service
https://<s4hana hostname>/sap/opu/odata/sap/APS_IAM_TUSR_SRV/$metadata

The VDM Generator


After saving this metadata in directory called ‘input’, we can try to generate our java classes using the VDM Generator of the S/4HANA Cloud SDK with the command:
java -jar odata-generator-cli-1.10.0.jar -i input -o target 
-p com.nl4b.sap.cloud.sdk

This statement will generate a 'serviceNameMappings.properties' file that generates properties for the classname and package, which will be used by the generator to create the java package names. These names are properly not the names you want to use and you need to modify them and run the statement again.

But before we will do this, we will see that the generation goes into an error:
java.lang.IllegalArgumentException: 
trying to create the same field twice: userGroup

Beside this error, you can expect errors when sap:label aren’t available, when they don’t have a value and when the values contains none-(alpha)numeric characters like dots and commas. This means that this metadata file cannot be used unless we will modify this file. This is where the EDMX Label Builder will come into the game.

The EDMX Label Builder


The EDMX Label Builder can be used to generate a template and properties files out of OData EDMX file using the command
java -jar edmx-sap-label-builder-1.0.4.jar --generate
--edmx-file ./input/APS_IAM_TUSR_SRV.edmx
--edmx-template ./template/APS_IAM_TUSR_SRV_TEMPLATE.txt
--edmx-properties ./template/APS_IAM_TUSR_SRV_PROPS.txt

This will generate 2 new files in the template directory:

  • The argument --edmx-template will be use to generate a template file. This template file contains the EDMX tags with placeholders which can be used to rebuild the EDMX

  • The argument --edmx-properties will be use to generate a properties file which will contains all needed sap:label fields and values in a key/value pair.


This properties file needs to be repaired, so both files can be used for rebuilding a fixed EDMX file.

So to fix the properties file, we need to found out what is wrong. For this we can ask the EDMX Label Builder again using the followings statement:
java -jar edmx-sap-label-builder-1.0.4.jar --check
--edmx-template ./template/APS_IAM_TUSR_SRV_TEMPLATE.txt
--edmx-properties ./template/APS_IAM_TUSR_SRV_PROPS.txt

This will tell us that we have to fix the following issues:
Property PasswordData_0_EntityTypeLabel is empty
Property TechnicalUser_0_EntityTypeLabel is empty
Properties TechnicalUser_1_UserGroup and TechnicalUser_1_UserGroupText have both the same value 'UserGroup'
Property UserGroup_0_EntityTypeLabel is empty
Property UserGroup_1_Description is empty
Property UserGroup_1_GroupCode is empty

After each fix you should run the check command until the message that the properties file is consistent.

Now you will have a consistent properties file we are able to create a fixed EDMX file using the command:
java -jar edmx-sap-label-builder-1.0.4.jar -v --build
--edmx-file ./input/APS_IAM_TUSR_SRV.edmx
--edmx-template ./template/APS_IAM_TUSR_SRV_TEMPLATE.txt
--edmx-properties ./template/APS_IAM_TUSR_SRV_PROPS.txt

This will rename the original EDMX file. Will check if the template and properties files are consistent. And finally combine the template and properties file to generate a consistent EDMX file.

The end result


Now you can run the VDM Generator of the S/4HANA Cloud SDK and it will create the java classes, its methods and properties with the names you specified properties file:
java -jar odata-generator-cli-1.10.0.jar -i input 
-o target -p com.nl4b.sap.cloud.sdk

And if you are not happy with these names, you can easily modify the properties file again, build a new EDMX file with the EDMX Label Builder and generate the java classes again with the OData Generator Client VDM Generator of the S/4HANA Cloud SDK.

We share, Try it out


If you want to try it out yourself, you can download the EDMX Label Builder tool. The binary code is licensed under the Apache license 2.0. After downloading you can use the command: java -jar edmx-sap-label-builder-1.0.4.jar -h -v -r to get more information.

If you want to know more about SAP S/4HANA Cloud SDK you can go to this community page. On the release tab you can go to the release notes where you can find the latest version of the VDM Generator.

Remarks


Remark 1:

The EDMX Label Builder will add missing sap:label in the original EDMX to the template and properties file. This makes it possible that you can also use the VDM Generator of the S/4HANA Cloud SDK for non-sap odata service with meaningful names instead of using the --use-odata-names alternative. When a missing sap:label is added to the property file, this value will initially always be empty and you need to modify the properties file.
Remark 2:

The original files for template and properties by default will be renamed, when the files already exists. If you don’t want to rename but want to override them, you can specify the argument --override.
Remark 3.

By default you don’t loose work, if you already modified a previous properties file. If you use this file as the argument, it will not create a new file but but the EDMX Label Builder will only append the missing sap:label to properties file. If you want the original values of the EDMX file, you can specify the argument --ignore-properties. With this argument the EDMX Label Builder will ignore the existing properties file and build it from scratch. This will also the default when the specified properties file does not exist.
Remark 4

Beside empty labels and duplicate value, the EDMX Label Builder will check on forbidden characters for java class names like dot and comma. And before compare values, it will capitalize words and remove space in between.
Remark 5

When a property is missing in the properties file, but needed in the template, you will be informed by running the check command. In this case you need to add these missing properties yourself.

 

 
Labels in this area