‘Formatting in WebDynpro Java ‘
How have been handling this in WebDynpro til now?
Some methods we have been following are…
We create a simple type , of base type Integer.. and in its external representation we give the format that is required.
External Representation: “##,###.000#”
What does it do ?
It takes the integer value and formats it to the particular format for display. This method can be used when we need percentage displays or if we have format decimals in a specific way.
One other commonly used method is usage of modifiable simple types.
A handicap with these methods being , we cannot implement them in instances when we use a single value attribute to display different currencies each having a different format.
One quick fix would be to utilize the calculated attribute feature in WebDynpro. We can determine the currency used in the accessor and format the amount accordingly. This is not a neat solution as we need to hard-code the format for each currency. Taking into account all the currencies and formatting them accordingly would make the solution untidy.
To facilitate this process, SAP has introduced “setR3NormalizingFormattingService”.Unfortunately the catch is , its usage isn’t straightforward.
It’s usage is defined in the following section.
ITELO customer needs an application to keep track of their monthly telephone usage in their administrative offices.
They have 32 offices across the world in different regions. They need a report which displaysthe monthly telephone expenditure in their local currency and the equivalent amount in euros.
Two S/w developers are working on it.Dev 1 needs to provide the solution. Dev 2 is the other developer in the team.
Dev 1 : Hi Dev2. I am facing an issue on this ITELO customer requirement. Could you help me on this ?
Dev 2 : Yes Sure. What is the issue?
Dev 1 : I need to format amounts based on the currency they belong to. I am not able to find out a generic solution to implement it. The customer does not want us to hard code any values.
Dev 2 : Haven’t you worked on”setR3NormalizingFormattingService”. This was introduced for this exact requirement.
Dev 1 : Oh that’s cool ! How do i use? Any documentation?
Dev 2 : It is a function listed under interface IWDAttributeInfo.
void setR3NormalizingFormattingService (boolean formatting)
When set to true , values are sent to Adaptive RFC in a normalized fashion i.e. with 2 decimal places. But on display an appropriate formatting function is invoked and the currency value is formatted.
Dev 1: Thanks a lot for the information.. I will work on it..
After a while….
Dev 1 : oh oh !This thing is not working.. Its throwing me an error “The attribute is not based on a structure field.”. Why should it be a part of a structure. What nonsense!
Dev 2 : There is a sound logic behind it..it does have point.. I should have explained its working better..
This is how. !
Navigate to Dictionary -> Structures
1. Create an a structure with element of type CURR Simple type.
2. Create another element.. “Cost”of type decimal and in its reference element select the CURR element we have created in step 1.
This definition is used by WebDynpro at run time to determine the type of currency the amount belongs to.
For example ,in a value node..(created based on our structure) there is one element whose “Cost” is 100.00 and “Currency” is INR.
When displaying this amount, the webdynpro runtime does the following activities.
1. Read the “Cost” attribute’s attribute info
2. Find its parent structure
3. Read the reference currency attribute, if any. i.e. “Currency”.
4. Obtain currency Key stored in this currency value attribute, for the particular node element
5. Each currency has an equivalent simple type (an xml file)defined. Read the appropriate currency simple type from the dictionary .
6. Parse the simple type file and obtain the corresponding format.
6. Apply this format to the value stored in “Cost” for the corresponding currency key.
Pretty Simple, Isn’t it.
A structure is hence mandatory.
The following shows the value”100.00″ formatted based on the currency selected.
And thus the”ITELO Development” story ended. .. !
I hope this information was interesting and useful.
Many thanks to Bertram Ganz and Uwe Reeder for elucidating on the intricacies of this function.