cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with the Date format and sending it to R/3

dhruv_shah3
Active Contributor
0 Kudos

Hi all,

I have an Adaptive RFC application which fetches the data from the R/3 and displays the Employee's Personal Data.

I am using a ZFM which is customised as per the requirement from the Standard BAPI_EMPLOYEE_GETDATA.

Now the Problem i am facing is Date is default and Optional Parameter in RFC.

If i execute the RFC in R/3 without Date it is not filling the Internal Tables. And if i pass the Date it is filling the Internal Table and fetches the Records.

So in WD application i am inputing Employee FirstName, LastName or the Employee ID.

User can give any of the above input or combination of FirstName and LastName Or only the Employee ID.

Now the Main Problem is of Date which is of type Date.

I have also tried the SimpleDateFormat Class, but i am not able to achieve the result.

I have also seen the Links and threads on SDN, but unable to solve the problem.

So pls help me out asap.

Thanks & Regards,

Dhruv Shah

Accepted Solutions (0)

Answers (4)

Answers (4)

dhruv_shah3
Active Contributor
0 Kudos

Hi,

Can anybody help me out?

Thanks & Regards,

Dhruv Shah

Former Member
0 Kudos

Hi ,

By default , RFC accept date format of SQL date (yyyy-mm-dd) . If you are using a date picker from WD, it directly set the date in SQL date format. Incase if you are trying to pass date to RFC in some other way you have to convert that into SQL date format before passing.

if you are passing String date of format dd-mm-yyyy , you try this method to convert that to SQL date and pass to your RFC.

**************************************************************************************************************

public java.sql.Date sqlDateConvert( String date) {

//@@begin sqlDateConvert()

java.sql.Date dateObj=null;

try{

StringTokenizer tempStringTokenizer = new StringTokenizer(""+date,"-"); int dd=Integer.parseInt(tempStringTokenizer.nextToken().trim());

int mm=Integer.parseInt(tempStringTokenizer.nextToken().trim());

mm=mm-1;

int yyyy=Integer.parseInt(tempStringTokenizer.nextToken().trim());

Calendar cal =Calendar.getInstance();

cal.set(yyyy,mm,dd);

dateObj = new java.sql.Date( cal.getTime().getTime());

}catch(Exception e)

{

}

return dateObj;

}

****************************************************************************************************************

Hope this will help you.

nikhil_bose
Active Contributor
0 Kudos

Go to Dictionary, find the date in the model dictionary and make an attribute of that type.

nikhiL

snehal_kendre
Active Contributor
0 Kudos

Hi Dhruv,

did you tried sql.date...?

dhruv_shah3
Active Contributor
0 Kudos

Hi,

Yes i have tried that tooo...

Former Member
0 Kudos

Hi Dhruv,

r u using date picker or context variable of type date (that is of SQL date format) to pass into the RFC ?

ur RFC field input field is of date type or not ?

Thanks ,

Tony .

dhruv_shah3
Active Contributor
0 Kudos

HI,

I am using the context variable of type type

com.ani.wd.model.types.Datum

and in RFC its Date.

My code is :



Date currdate = new Date(System.currentTimeMillis());
	
	SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
	
	String out_date = formatter.format(currdate);
		   
    Zbapi_Employee_Getdata_Com_New_Input inp = new Zbapi_Employee_Getdata_Com_New_Input();
    
    wdContext.nodeZbapi_Employee_Getdata_Com_New_Input().bind(inp);
    
    inp.setFstname_M(wdContext.currentZbapi_Employee_Getdata_Com_New_InputElement().getFstname_M());
    
    inp.setLastname_M(wdContext.currentZbapi_Employee_Getdata_Com_New_InputElement().getLastname_M());
    
    inp.setEmployee_Id(wdContext.currentZbapi_Employee_Getdata_Com_New_InputElement().getEmployee_Id());
    
    inp.setDate(out_date);

but now i amgetting error cannot convert String to Date.

Thanks & Regards,

Dhruv Shah

Former Member
0 Kudos

Hi,

As you said the value of the date in RFC is date. Now in the last line of the code you are setting string to an attribute which accepts a date.

inp.setDate(out_date);

In this line you need to set Date and not String.

Hope this will solve your problem.

thanks & regards,

Manoj

dhruv_shah3
Active Contributor
0 Kudos

Hi Manoj,

Following is my code:

Also in R/3 the date format is dd.MM.yyyy



Date currdate = new Date(System.currentTimeMillis());
	
	SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
	
	String out_date = formatter.format(currdate);
		   
    Zbapi_Employee_Getdata_Com_New_Input inp = new Zbapi_Employee_Getdata_Com_New_Input();
    
    wdContext.nodeZbapi_Employee_Getdata_Com_New_Input().bind(inp);
    
    inp.setFstname_M(wdContext.currentZbapi_Employee_Getdata_Com_New_InputElement().getFstname_M());
    
    inp.setLastname_M(wdContext.currentZbapi_Employee_Getdata_Com_New_InputElement().getLastname_M());
    
    inp.setEmployee_Id(wdContext.currentZbapi_Employee_Getdata_Com_New_InputElement().getEmployee_Id());
    
//    inp.setDate(out_date);

	wdContext.currentContextElement().setIn_Date(out_date);

Thanks & Regards,

Dhruv Shah

Former Member
0 Kudos

Hi,

Ok. Now what is the problem. What i mean to say in my previous reply is that the variable out_date is a String and as you said that the attribute in RFC accepts Date.

Then how can you set the attribute which accepts Date with a String.

What type of parameter does inp.setDate() takes?

thanks & regards,

Manoj

dhruv_shah3
Active Contributor
0 Kudos

Hi,

In_Date parameter is of type Date which i created in the context as value attribute.

and i am assigning this to my RFC attribute.

Regards,

Dhruv Shah

Former Member
0 Kudos

Hi Dhruv,

Try this ways:

Create a context attribute say "JoiningDate" of type "com.ani.wd.model.types.Datum" and bind it to the input field.

While passing the date to back end get the value from input field and set it to the input field.

Zbapi_Employee_Getdata_Com_New_Input inp = new Zbapi_Employee_Getdata_Com_New_Input();

inp.setEmployee_Id(wdContext.currentContextElement().getJoiningDate());

Thanks n Regards,

Jhansi Miryala

Former Member
0 Kudos

Hi,

There is something seriously wrong somewhere. As you said that In_Date is a value attribute of type Date. And out_date is a String then if you use the code:

wdContext.currentContextElement().setIn_Date(out_date);

it will give the error at the compile time only. No idea how you are getting through this line.

thanks & regards,

Manoj

dhruv_shah3
Active Contributor
0 Kudos

Hi,

I have done that but the problemis with the format of the Date.

In R/3 the format is dd.MM.yyyy

where in WD its MM/dd/yyyy.

So i want to change that and then pass to the backend.

Please read my other replies it will give you more idea.

Thanks & regards,

Dhruv Shah

Former Member
0 Kudos

Hi Dhruv,

Try following:

Date currdate = new Date(System.currentTimeMillis());
	
    Zbapi_Employee_Getdata_Com_New_Input inp = new Zbapi_Employee_Getdata_Com_New_Input();
    
    wdContext.nodeZbapi_Employee_Getdata_Com_New_Input().bind(inp);
    
    inp.setFstname_M(wdContext.currentZbapi_Employee_Getdata_Com_New_InputElement().getFstname_M());
    
    inp.setLastname_M(wdContext.currentZbapi_Employee_Getdata_Com_New_InputElement().getLastname_M());
    
    inp.setEmployee_Id(wdContext.currentZbapi_Employee_Getdata_Com_New_InputElement().getEmployee_Id());
    
    inp.setDate(currdate);

Regards,

Gopal

dhruv_shah3
Active Contributor
0 Kudos

Hi Gopal,

But my problem is with the Format of the Date.

CurrentTimeMills is giving the format in MM/dd/yyyy.

but i want in the format of dd/MM/yyyy.

So pls can you help me out.

Thanks & Regards,

Dhruv Shah

Former Member
0 Kudos

Hi Dhruv,

Just try the code. At ABAP side you will see the date in your desired format.

Regards,

Gopal

dhruv_shah3
Active Contributor
0 Kudos

Hi Gopal,

I tried it out, but unable to pass the formatted date to RFC.

Thanks & Regards,

Dhruv Shah

Former Member
0 Kudos

Hi Dhruv,

By writing code,

inp.setDate(currdate);

you don't have to care any thing about the formatting of the date. Automatically you will see in ABAP table date values in dd.mm.yyyy format.

Regards,

Gopal

dhruv_shah3
Active Contributor
0 Kudos

HI Gopal,

As you said:

you don't have to care any thing about the formatting of the date. Automatically you will see in ABAP table date values in dd.mm.yyyy format.

My problem is that in WD its returning as String but i want it as Date.

Also if i am taking as Date then i have then again prblem for the Format.

I want dd.MM.yyyy format.

Thanks & REgards,

Dhruv Shah