Skip to Content
Author's profile photo Former Member

Currency/Number formatting in HCM forms

Things get bit challenging and also quite interesting with new requirements that drop in, a recent one was to have all the numeric fields formatted in the same way as how SAP does in the R/3, and now that made me to sit in the “Thinking Man” posture.

Well, my first reaction was..ooops! this thing cannot be done, let us follow a universal format, why worry over the commas and the dots which is of not much significance to me, well, if not to me, it was to others who use it.

Why not give this a shot, and I just started off researching on this topic, sooner I realized that it can be achieved with much lesser effort and impact than I had initially thought.

To make things clear…this is what was required, if the user maintains a format like 1,234,567.89 then the form also should display in the same manner and also the decimals should be as per the currency(that is another challenge). Before I go ahead explain the trick of making this happen….I want to mention a small finding..this formatting can be carried out only if the field is declared Numeric, this does not work on text fields, so no use sweating on that.

A little bit of ABAP and Java scripting is all it takes, and this is how you do it.

1. Have a hidden field in the form which stores the decimal notation of the R/3 user, and on the form launch fetch the notation from table USR02.

2. Once you know his notation and the currency he is going to enter, here is the scripting you need to do. But before that, there are two events you need to trigger your script from, it can be your form ready or the exit event or both.

Based on the user decimal notation set the locale of the field. Usually, there are only three locales you need to set and they are en, be, and de.

so set the locale by using this script

if (DecNot == “X”)
 {
  strField.locale = “en”;
 }

 Now that you have set the locale, you need to make sure the formatting does take care of the decimal places of the currency. So you need to set the format as per the currency decimals by using the script given below

this is for 3 decimal places
switch (decplaces)
 {
  case 3: strField.format.picture.value = “z,zzz,zzz,zz9.999”; break;
}

And yes, that is it, this should do your work of formatting as well as the currency decimals. Hope this was useful.

 

Cheers!

Raghavendra

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.