cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert the date format from R3 to webdynpro

Former Member
0 Kudos

Hi all,

I want to retrieve the date from R3 and insert it in to the dropdownbykey UI Element. In R3 the date format is dd.mm.yyyy .

When i try to retrieve it retrieves the null value. how can i get date from R3 to dropdown.

If anyone fo you knnow please tell me.

thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Krishnaveni,

You can use dropdown by index for the return values from R3.

Create a nodeValue and Value attribute

I<ViewName>.I<DropName>Node node = wdContext.node<DropName>();

int len=wdContext.node<BAPIList>().size();

for(int l=0;l<len;l++) {

dropCount=dropCount+1;

String returndate=String.valueOf(((IPrivate<viewname>.I<BAPIList>Element)(wdContext.node<BAPIList>().getElementAt(l))).get<Parameter>());

//or element can be a Date type

java.sql.Date returnDate=((IPrivate<viewname>.I<BAPIList>Element)(wdContext.node<BAPIList>().getElementAt(l))).get<Parameter>()

I<ViewName>.I<DropName>Element element = wdContext.create<DropName>Element();

element.set<Param>(returndate);

node.addElement(element);

}

kind Regards

Mukesh

Former Member
0 Kudos

Hi Mukesh,

As you told i used dropdownindex and get date from r3. In the r3 table i have 2 rows with separate field for date and time.

when i retrieve i want to combine the date and time and set it to dropdown by index.

when i directly assign the date & time it will assign and print in the format as Fri Sep 08 00:00:00 GMT+05:30 200613:02:30

but what i want is i want to convert this date in to 08.09.2006 as in r3 table.

what i did is i format the date to as said above format in inputfield and assign it to dropdownbyindex. the result is it override the firstdate.

Is there any other format to directly gett the r3 date. If you know plz tell me.It's in urgent.

thanks a lot for your time and code.

Former Member
0 Kudos

Hi Krishnaveni,

U can parse the given date into string and use it.

String chDate=String.valueOf(Date from R/3);

int yy=Integer.parseInt(chDate.substring(0,chDate.indexOf(".")));

String balda=chDate.substring(chDate.indexOf(".")+1);

int mm=Integer.parseInt(balda.substring(0,balda.indexOf(".")));

int dd=Integer.parseInt(balda.substring(balda.indexOf(".")+1));

String date=(dd"."mm"."yy);

I used "." delimiter from r/3 u can use the . or - wat you get from R/3.

And you merge the time with it.

P.S:For util /sql date u can use ddob= new Date(yy-1900,mm-1,dd);

Kind Regards,

Saravanan K

Answers (1)

Answers (1)

sridhar_k2
Active Contributor
0 Kudos

Hi,

Hope the below code is help full for you. User your context element in the place of "contextElement.date".

IContextElement contextElement = wdContext.currentContextElement();

IWDNodeInfo nodeInfo = wdContext.getNodeInfo();

IWDAttributeInfo dateAttributeInfo = nodeInfo.getAttribute(contextElement.date);

IModifiableSimpleValueSet dropValueSet = dateAttributeInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

String dateText=null;

java.sql.Date dateVal=null;

int nodeLength = wdContext.node<BAPIList>().size();

for (int i = 0; i < nodeLength; i++) {

dateText=String.valueOf(((IPrivate<viewname>.I<BAPIList>Element)(wdContext.node<BAPIList>().getElementAt(l))).get<Parameter>());

dateVal=((IPrivate<viewname>.I<BAPIList>Element)(wdContext.node<BAPIList>().getElementAt(l))).get<Parameter>();

dropValueSet.put(dateVal, dateText);

}

Regards,

Sridhar

Former Member
0 Kudos

Hi

Thanks a lot for your quick response.

Now my issue is when i try to get a date from r3 and assign to one date variable, it accpts only util format not the sql format.

I use the following code to get date from r3 and convert it to sql and display in inputfield.

java.util.Date date1=table.getDate("<field name>");

java.sql.Date value8 = new java.sql.Date(date1.getDate());

now value8 contain the sqldate.

when i try to print the date, it prints 1/1/1970.

i tried to get the individual values, the date comes properly, but the month value is 3 less than the actual(It does not accpt the month 1,2,3), and the year value is 106 for all the year.

String date_cur=date1.getDate()+"";

String date_year=date1.getYear()+"";

String date_mon1=date1.getMonth()+";//its value is 106

wdContext.currentContextElement().setTxt1(date_cur"."date_mon"."date_year));//itprints17.10.106

I believe that i told the issue correctly.If not able to follow plz let me know. I

Former Member
0 Kudos

Hi Krishnaveni,

This is occording to the java.util.Date date

You add the Year with 1900

and Month with 1

otherwise you can directly get the date as String from the BAPI like

String datevalue=String.valueOf(table.getDate("<field name>"));

datevalue=datevalue.replaceAll("/",".");

and set to the input element

otherwise you can bind the attribute as date and directly assign the value to the Element as.

wdContext.currentContextElement().setTxt1(table.getDate("<field name>"));

Kind Regards

Mukesh

Former Member
0 Kudos

Hi,

From the javadocs:

<i>In all methods of class Date that accept or return year, month, date, hours, minutes, and seconds values, the following representations are used:

A year y is represented by the integer y - 1900.

A month is represented by an integer from 0 to 11; 0 is January, 1 is February, and so forth; thus 11 is December.

A date (day of month) is represented by an integer from 1 to 31 in the usual manner.

An hour is represented by an integer from 0 to 23. Thus, the hour from midnight to 1 a.m. is hour 0, and the hour from noon to 1 p.m. is hour 12.

A minute is represented by an integer from 0 to 59 in the usual manner.

A second is represented by an integer from 0 to 61; the values 60 and 61 occur only for leap seconds and even then only in Java implementations that actually track leap seconds correctly. Because of the manner in which leap seconds are currently introduced, it is extremely unlikely that two leap seconds will occur in the same minute, but this specification follows the date and time conventions for ISO C.

In all cases, arguments given to methods for these purposes need not fall within the indicated ranges; for example, a date may be specified as January 32 and is interpreted as meaning February 1.

</i>

Regards,

Satyajit.

sridhar_k2
Active Contributor
0 Kudos

Hi,

If you are trying for individual values. Try this code.

String dataObject= iStringDate.toString();

String[] data = dataObject.split("/");

in data[0] - you have first element and data[1] - second element data[3] - will have year.

Reagrds,

Sridhar