Using Field Transformations…
SAP Cloud development has lot of interesting and undocumented features. One for such example is Field Transformation.
This document gives you an idea on how to use it and where to use it.
Using field transformations, you can avoid lot of extra fields which are basically calculated. Calculation can mean anything here based on your operation.
Let us take a small example to see how it works.
Example: To display logon language of user, you don’t need to write an absl script always. If you want to render it on the UI, then UI layer can do the same job as absl does.
With the assumption that you’ve defined your BO and opened your QAF/OIF screen in UI Designer and switched to Data Model, follow these steps:
Step 1: Create a new field in your DataModel and set the DedicatedField (LogonLanguage) property to true.
Ste 2: Switch to Controller tab and create a New FieldTransformation.
Step 3: In the next screen that you see, set the field values as shown in the below screenshot (where TargetField is the one which you created in Step1)
Step 4: That’s it. It just works with what you’ve done till now. Bring the DedicatedField (LogonLanguage) on to the screen where ever you want and preview the screen.
If you ask me, ” Okay. We are done with SimpleExample. Now what? How complex can this thing go? “, my answer would be ” I am here to help you to make a good start. There are lot of other reusable functions which might help your use case which you’ll have to dig it out yourself buddy. “
- Just toggle through namespaces in Step 3.
- Make sure that you have these properties of the DedicatedField in your DataModel filled properly right after TargetField assignment in Step 3.
- You might encounter dumps for some FieldTransformations as it totally depends on the DataType of the DedicatedField most of the times. Each FieldTransformation returns values of a particular DataType. Some may not be even PSM released. If there’s nothing you can do and you tried your best already, then do raise an incident to know the exact reason why it didn’t work in your case.
It is just not the case that you need to use the UI layer functions always. If you want to bring up something on to the screen which is an outcome of your absl code, even that is possible.
- Create a new Reusable library and create a New Function with the UI Designer indicator checked as shown in the below screenshot.
- In this case, as we are writing a simple code to return Current User’s LoggedIn language, we just need a return parameter. But, make sure that the data type you use is available in the list of released GDT datatypes as you’re gonna have to assign the same data type to the DedicatedField later on in UI Deisgner. Review and Finish the function creation screen.
- Prepare your absl code with something like as shown in the below screenshot.
- Okay. Now, we are done with what has to be done on absl side. Going back to UI Designer part, we just need to make one change in method which we already followed that is at Step 3. Select your solution Namespace in the Namespace field.
- You know about the rest of the Process. Good luck with it.
Is this the only advantage of such a useful feature? Well, fortunately, NO!
As the title of this document talks about using Field Transformation but not in UI Designer alone. So, here you go with another way where you can make a good use of Field Transformations.
- Consider a general requirement that you have a Date field in your Custom BO and user stores date when creating instances but wants to see just the Month while viewing Report so that he can sort the Business Data based on ‘Month’.
- So, when you create DataSource on your Custom BO, stop at Stage 3/6 and have a look at what that screen provides you. Select your Date field and look at the right pane for what all you can do with that. You should something like below:
- In this example, you will have new field in your Report with name “Month” which gives you only Month values from the custom field “FinalDate”. You don’t have to store ‘Month’ as a separate field in your Custom BO to show it for reporting purposes. Isn’t this good?
- There are few such DataTypes with which you can play in this screen like Duration. You can get this info from Documentation. Have fun with it.
End of story pal! Let me know if this could be done in a better way or something needs to be added. Thanks for going through.