cancel
Showing results for 
Search instead for 
Did you mean: 

Can I dynamically change the date format of a simple type?

Former Member
0 Kudos

Hi,

I have created A Web Dynpro Table Called 'Arrivals'.

One of the Field in my table is 'Arrival Dateu2019 - Which is of type u201CDateu201D (I have created a simple type giving the representation format as "DD/MM/YYYY" and assigned this simple type to the 'Arrival Date').

When I run this Web Dynpro application.I am getting the output as expected, as shown below

"DD/MM/YYYY"

31/10/2008

05/11/2008

23/10/2008

10/11/2008

My requirement is :

In the applicaiton I have a radio button to choose the Dateformat between "European Format(DD/MM/YYYY)" and "US format", i.e, "MM/DD/YYYY". so that the output now will be

"MM/DD/YYYY"

10/31/2008

11/05/2008

10/23/2008

11/10/2008

So when I select the US format radio button I want to dynamically change the format representation of the simple type to "MM/DD/YYYY"

I cannot use date formatter as Arrival Date is of type 'Date' and more over I have implemented sorting to my table, So if I change it to String , it will sort date as String..

And also I cannot use different value attribute(Say Arrival Date1) which is assigned to another simple type with US format as this will increase the complexity.

Kindly let me know if there is any possible solution for this.

Regards,

Shilpa B.V

Accepted Solutions (1)

Accepted Solutions (1)

former_member185086
Active Contributor
0 Kudos

Hi

1.You can achieve this during runtime only thing is that based on the selection of the the RadioButton you have finally populate the values from enumerations. like this

IWDNodeInfo nodeinfo_dist = wdContext.nodeRegionDetails().getNodeInfo();

IWDAttributeInfo attributeInfo = nodeinfo_dist

.getAttribute(IPublicAdminComp.IRegionDetailsElement.DISTRICTCODE);

ISimpleTypeModifiable districtYype = attributeInfo.getModifiableSimpleType();

IModifiableSimpleValueSet valueSet_dist = districtYype.getSVServices().getModifiableSimpleValueSet();

valueSet_dist.clear();

for (int i = 0; i < wdContext.nodeReturnGetAllDistrict().size(); i++)

{

if(RadioButton Option)

{

districtYype.setFormat(arg0)

}

else if(RadioButton Option)

{

districtYype.setFormat(arg0)

}

district = wdContext.nodeReturnGetAllDistrict().getReturnGetAllDistrictElementAt(i);

valueSet_dist.put(district.getSalesOrgCode(), district.getSalesOrgName());

}

2. You can escape the populate all the data other than date and then format it ,Just it require understanding of the previous code.

Best Regards

Satish Kumar

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Try this code.

DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
Date dateString = new java.util.Date();
Date today = df.parse(dateString);
java.sql.Date datepass = new java.sql.Date(today.getTime());
wdContext.currentPersonalDataElement().setdate(datepass );

By using this you can convert date format to any type.

Regards,

H.V.Swathi

Former Member
0 Kudos
pravesh_verma
Active Contributor
0 Kudos

Hi Shilpa,

You can use the format function of the modifiable simple value set to achieve this.

modifbale_object.setFormat(Define your format);

Please check this link:

This will be definitely of your help:

http://help.sap.com/javadocs/NW04S/SPS09/dr/com/sap/dictionary/runtime/ISimpleTypeModifiable.html

I hope this solves your issue!

Thanks and Reagrds,

Pravesh