cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with java.sql.Date

Former Member
0 Kudos

Hi

I use 2 adaptive RFC function with a r3 backend system:

1- Search

2- Update

The first works fine, I show the data, one of the fields is a date (with r3 Date format) binded and in the web dynpro is showed in inputfield, with a little calendar icon on the right.

I have problem with the second one. Cause I use the same inputfield for both RFC. I bind in design time with the Search RFC and for the update I pass the changed values to the 2nd RFC trought coding:

java.sql.Date date_ini = wdContext.current_OutputElement().getDate();

wdContext.currentZcx_Lo_Ingresofactura_Of_01_InputElement().setDate(date_ini);

The problem is in the value of send to R/3. For example, if the value of date in Webdynpro is "10/04/2007", R/3 get value "2007-04-" (the type of the var in R/3 is DATUM).

How to implement the code for R/3 get date like YYYYMMDD?

Regards,

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member751941
Active Contributor
0 Kudos

Hi,

Here is the code to convert String in to Date Format.You can use the valid format as you want inside the SimpleDateFormat constructor.

import java.sql.Date;

import java.text.ParseException;

import java.text.SimpleDateFormat;

for(int i =0; i<n;i++)

{

try {

prodElem = wdContext.createProductDetailsElement();

String validFr="";

String validTo="";

validFr = wdContext.nodeProduct_Dtl().getElementAt(i).getAttributeValue("Validfr").toString();

prodElem.setValidFrom(new Date(smpdtFormat.parse(validFr).getTime()));

validTo = wdContext.nodeProduct_Dtl().getElementAt(i).getAttributeValue ("Validto").toString();

prodElem.setValidTo(new Date(smpdtFormat.parse(validTo).getTime()));

wdContext.nodeProductDetails().addElement(prodElem);

}

catch(ParseException e)

{

}

}

//@@begin others

SimpleDateFormat smpdtFormat =new SimpleDateFormat("yyyy-MM-dd");

//@@end

Regards,

Mithu

abhijeet_mukkawar
Active Contributor
0 Kudos

Rodolfo,

here is exactly what you want: add following things to your code,


SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
//add above line to your code, the string passed is case sensetive 
java.sql.Date date_ini = wdContext.current_OutputElement().getDate();

wdContext.currentZcx_Lo_Ingresofactura_Of_01_InputElement().setDate(formatter.format(date_ini);
//notice the change in the parameter passed to rfc, formatter is used

i am sure that this will solve your prblem

let me know if you face some issues

regards

Former Member
0 Kudos

Abhijeet,

Your solution apparently can serve, but your code returns a STRING, and my parameter of entry is of type DATUM .

Can you help me with that?

Regards.

abhijeet_mukkawar
Active Contributor
0 Kudos

Rodolfo,

can you tell me which format Datum needs the date,

if it is yyyymmdd, then the same i have given in formatter. If it is throwing error tell me in which format it wants the date?

regards

Former Member
0 Kudos

Abhijeet,

The format is java.sql.Date

Regards.

abhijeet_mukkawar
Active Contributor
0 Kudos

Rodolfo,

I wanted to know , which is the format the r3 needs date in ?

okay have you tried the solution earlier i had given (have you tried adding those lines that also sends date in yyyymmdd format), is it throwing any error?

I have tried just now for DATUM in backend and same code has worked , it should work for you too, just give it a try . i have tried just now.

regards

Message was edited by:

Abhijeet

Former Member
0 Kudos

Abhijeet,

This is my code

SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");

java.sql.Date date_ini = wdContext.current_OutputElement().getFecha();

wdContext.currentZcx_Lo_Ingresofactura_Of_01_InputElement().setFecha(formatter.format(date_ini));

This code returns a string and my parameter of entry is of the type date(java.sql.Date).

Regards.

Former Member
0 Kudos

Rodolfo,

Interesting, does this code compiles or not:


java.sql.Date date_ini = wdContext.current_OutputElement().getFecha();
wdContext.currentZcx_Lo_Ingresofactura_Of_01_InputElement().setFecha(date_ini);

I.e. no formatting at all.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

abhijeet_mukkawar
Active Contributor
0 Kudos

Rodolfo,

then it should work:

java.sql.Date date_ini = wdContext.current_OutputElement().getFecha();

wdContext.currentZcx_Lo_Ingresofactura_Of_01_InputElement().setFecha(date_ini);

regards

abhijeet_mukkawar
Active Contributor
0 Kudos

Rodolfo,

if it is still not working , then i will suggest that dont directly bind the model attributes to Ui elements, when we do it for tables thats fine since we hardly give them editable option. When we want to give edit option that time we generally dont go for binding directly model Attrib to UI element.

I will suggest you to , take different Input Field for input to BAPI, bind this inputfield to context attribute whose datatype is date and then directly you can pass this date without any formatting.(just like what i mentioned in immediate above post).

see this for more:

hope it helps

let me know if you face any problem

regards

former_member189631
Active Contributor
0 Kudos

RodolFo,

One way is ,

  • Create Adaptive RFC function Module in R/3.

  • The input to this FM can be YYYYMMDD format.

  • You can pass this date as String.

  • Write the code to change the date format.

  • In the same function module itself you can use your Standard FM/BAPI

Regards,

<b>Ramganesan K</b>