on 08-06-2007 7:04 PM
Hi All
I am getting data from RFC and able to bind it into table. Now I want to format date and numbers into user logged in format. i.e. If user enters country as Germany while registration,date format should be European in table displayed otherwise it should be US format.
Can any one suggest me how to do it?
Hi Radhakrishna,
You need to do this ways:
- Create a new Attribute in the main node and assign the formatted value to new attibute.
//Assuming sap date is available in context attribute mysapdate;
Date sapDate = wdContext.current<nodeName>Element.getMysapdate();
IUser currentUser = WDClientUser.getCurrentUser().getSAPUser();
Locale userLocale = currentUser.getLocale();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, userLocale);
String newDateString = dateFormat.format(sapDate);
wdContext.current<nodeName>Element.setNewFormatDate(newDateString);
Regards
Abhilash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My code is given below. I am getting number format exception. My date format displayed in table is mm.dd.yyyy. In R3 date format is different and displaye ddate format is different . Can any one tell why they are different?
//Parsing String to date format
SimpleDateFormat sdf = new SimpleDateFormat("mm.dd.yyyy");
Date sqlDate =sdf.parse(ele.getSched_Date());
//Getting User Locale
IUser currentUser = WDClientUser.getCurrentUser().getSAPUser();
Locale userLocale = currentUser.getLocale();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, userLocale);
String newDateString = dateFormat.format(sqlDate);
//binding date string to context
ele3.setPlannedReceiptsDate(newDateString);
Couple of questions for you:
As per the below example I am sure ele.getSched_Date() is returning the String. As per my understanding if the data type is Date in RFC it should be SQL Date in WebDynpro data dictionary. So my doubt is are converting the date object to string some where?
Next, SQL date always returns the format MM/dd/yyyy. You can try this format in SimpleDateFormat. And also SimpleDateFormat always returns java.util.Date not java.sql.Date.
Regards
Abhilash
When I binded RFC to view controller it was string (not sql date). In above code using simpleDateformatter I converted into date. Next I used String newDateString = dateFormat.format(sqlDate);
for converting date to string again. After conversting into String I binded the value to table.
I used only java.util.Date not java.sql.Date but my naming convention was sqlDate.
Hi
You can see my whole code. I am getting expection in try catch field.
IPrivateDetailsView.IReceiptTableElement ele3 =
wdContext.createReceiptTableElement();
ele3.setMaterialName(ele.getMattext());
ele3.setReceiptQuantity(ele.getQuantity());
ele3.setUnit(ele.getSales_Unit());
try{
//Parsing String to date format
SimpleDateFormat sdf = new SimpleDateFormat("MM.dd.yyyy");
Date sqlDate =sdf.parse(ele.getSched_Date());
//Getting User Locale
IUser currentUser = WDClientUser.getCurrentUser().getSAPUser();
Locale userLocale = currentUser.getLocale();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, userLocale);
String newDateString = dateFormat.format(sqlDate);
// binding date string to context ele3.setPlannedReceiptsDate(newDateString);
}
catch(Exception e)
{
wdThis.wdGetAPI().getComponent().getMessageManager().reportException(
e.toString(),
false);}
Did you tried this format?
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
If this does not work, I have added few debug statements in the code: Can you tell the output of this?
IPrivateDetailsView.IReceiptTableElement ele3 =
wdContext.createReceiptTableElement();
ele3.setMaterialName(ele.getMattext());
ele3.setReceiptQuantity(ele.getQuantity());
ele3.setUnit(ele.getSales_Unit());
try{
//Parsing String to date format
SimpleDateFormat sdf = new SimpleDateFormat("MM.dd.yyyy");
Date sqlDate =sdf.parse(ele.getSched_Date());
<b>wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(" Date converted "+sqlDate);</b>
//Getting User Locale
IUser currentUser = WDClientUser.getCurrentUser().getSAPUser();
Locale userLocale = currentUser.getLocale();
<b>wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(" User Current Locale "+userLocale );</b>
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, userLocale);
<b>wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(" Formatting to user locale ");</b>
String newDateString = dateFormat.format(sqlDate);
// binding date string to context ele3.setPlannedReceiptsDate(newDateString);
}
catch(Exception e)
{
wdThis.wdGetAPI().getComponent().getMessageManager().reportException(
e.toString(),
false);}
Regards
Abhilash
Regards
Abhilash
Hi Radhakrishna,
Try this.
String st_Date = ele.getSched_Date().toString();
try {
Date sqlDate = new Date(smpdtFormat.parse(st_Date).getTime());
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//@@begin others
SimpleDateFormat smpdtFormat = new SimpleDateFormat("yyyy-MM-dd");
//@@end
Regards,
Mithu
Thanks for your your Help Abhilash. I slightly changed code and now its working. I think this is almost same thing that you discussed.You can see code below.
Can you help in working with Number format also? I am getting number format exception. String returned when RFC executed is in 10,000,00. I need to change according to user locale format. I tried doing it in java also. When I remove commas in above string its working fine.
public java.lang.String DisplayingDateFormat( java.lang.String date )
{
//@@begin DisplayingDateFormat()
// Current date Format in BW
SimpleDateFormat sdf = new SimpleDateFormat("MM.dd.yyyy");
String ChangedDateFormat=null;
try{
// sdf.setLenient(false);
//Parsing String to Date
Date sqlDate =sdf.parse(date);
// wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(" Source date"+ ele.getSched_Date());
//
// wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(" Date converted "+sqlDate);
// Getting User Locale
//Getting Locale Information form Current Session
Locale userLocale= WDResourceHandler.getCurrentSessionLocale();
//wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(" User Current Locale "+userLocale );
//Setting date format ie Short,default etc
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, userLocale);
//wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(" Formatting to user locale ");
//Converting Date to String
String newDateString = dateFormat.format(sqlDate);
//wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(" Changed Date Format "+newDateString);
//binding to Table UI element
ChangedDateFormat=newDateString;
}
catch(Exception e)
{
wdThis.wdGetAPI().getComponent().getMessageManager()
.reportException(
e.toString(),
false);
}
Thats cool.. but I did not see much difference in previous code and this code except number style DateFormat.SHORT.
Any ways here is the solution for you number formating:
String input = "10,000,00";
NumberFormat nFormat = NumberFormat.getNumberInstance(Locale.ENGLISH);
//replace locale with dynamic locale
try
{
Number localeNumber = nFormat.parse(input);
int newIntValue = localeNumber.intValue();
String newValue = localeNumber.toString();
}
catch (ParseException e)
{
e.printStackTrace();
}
Regards
Abhilash
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.