Following is the case when you open the create travel request application and click on “+” symbol to create a new request. There is a currency field in the create form which is after the input field for Estimated Cost.

1.JPG

Requirement was to fill the default currency applicable to the user as shown in the below image

2.JPG

Next thing was to look into the code of this application. View corresponding to this was DetailForm View.

Code corresponding to the view was

              <Input

id=“Trc_SC_Currency”

value=“{EstimatedCost/Currency}”

showValueHelp=“true”

editable=“{ parts:[{path:’UserInfo>/GlobalSettings>/FixedCurrency’}] , formatter : ‘.checkGlobalSettingsFixedCurrency’}”                

showSuggestion=“true”             

suggestionItems=“{Currencies>/result}”

valueHelpRequest=“onCurrencyValueHelpRequest”>

               <suggestionItems>

                <core:Item text=“{Currencies>Id}”></core:Item>

               </suggestionItems>

              </Input>                             

As we can see the editable property if already having mapping to some value. We map it to the field which will be filled by us in the backend using our own logic for the user and also we need to change the logic in function for formatter (checkGlobalSettingsFixedCurrency).

So extended view will have the currency field as below

              <Input

id=“Trc_SC_Currency”

value=“{EstimatedCost/Currency}”

showValueHelp=“true”

editable=“{ parts:[{paxth:’UserInfo>/Currency’}] , formatter : ‘.checkGlobalSettingsFixedCurrency’}”                

showSuggestion=“true”             

suggestionItems=“{Currencies>/result}”

valueHelpRequest=“onCurrencyValueHelpRequest”>

               <suggestionItems>

                <core:Item text=“{Currencies>Id}”></core:Item>

               </suggestionItems>

              </Input>

Changing the formatter function also as below

       checkGlobalSettingsFixedCurrency : function() {

         

            var UserInfo = this.getUserInfo();  

            if(UserInfo.Currency) 

             {

                    return false;

          

             }

            else

             {

             return true;

             }

                                                       },

The above should be enough for the UI side. Now we need to fill the default currency in the placeholder for the user info.

For fetching the default currency for the employee using odata, we used the Enhancement Spot SRA004_MY_TRAVEL_REQUEST.

Its implementation will provide you a

method (“IF_SRA004_BADI_MY_TRAVEL_REQ~CHANGE_EMPLOYEE”)

for changing the user profile. We will fetch the default currency for the user’s assigned cost center and send it in the currency field for the Employee.

Following is the code we used.

METHOD if_sra004_badi_my_travel_req~change_employee.

data: lt_return type bapireturn,
lt_return2
type bapiret1,
ls_return
type bapiret2,
ls_org_assignement
type bapip0001b,
lt_org_assignment
like table of ls_org_assignement,
ls_personal_data
type bapip0002b,
lt_personal_data
like table of ls_personal_data,
ls_internal_control
type bapip0032b,
lt_internal_control
like table of ls_internal_control,
lt_return3
type standard table of bapiret2,
ls_costcenterdetails
type bapi0012_ccoutputlist.

CALL FUNCTION ‘BAPI_EMPLOYEE_GETDATA’
EXPORTING
employee_id     
= is_employeeid
IMPORTING
return           = lt_return
TABLES
org_assignment  
= lt_org_assignment
personal_data   
= lt_personal_data
internal_control
= lt_internal_control.

READ TABLE lt_org_assignment INDEX 1 INTO ls_org_assignement.

IF sysubrc EQ 0.
is_employee
costcenter = ls_org_assignementcostcenter.
is_employee
companycode = ls_org_assignementcomp_code.

CALL FUNCTION ‘BAPI_COSTCENTER_GETDETAIL1’
EXPORTING
controllingarea 
= ls_org_assignementco_area
costcenter      
= is_employeecostcenter        
IMPORTING
costcenterdetail
= ls_costcenterdetails
TABLES
return           = lt_return3.

is_employeecostcentername = ls_costcenterdetailsname.

CALL FUNCTION ‘HRCA_COMPANYCODE_GETDETAIL’
EXPORTING
companycode
= is_employeecompanycode
IMPORTING
currency    = is_employeecurrency.
IF sysubrc <> 0.

ENDIF.
ENDIF.

ENDMETHOD.

This provides us the required default currency and it is passed through the odata service to the UI screen.

Hope it will be useful for someone.

Regards,

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply