cancel
Showing results for 
Search instead for 
Did you mean: 

passing date to BAPI

Former Member
0 Kudos

Hi,

I am getting date from the frontend in mm-dd-yyyy format.But BAPI accepts date only in yyyymmdd format.How should I pass date to BAPI in required format. Can I use Date Object to pass date to BAPI and how?

Regards,

Samir

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi samir,

Declare Date dateObject={pass your value here} Then while passing value to BAPI follow the code given below.

new Date(dateObject.getYear(),dateObject.getMonth(),dateObject.getDay());

regards

sukanta

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Samir,

otherwise if you want to pass to the BAPI the date in Date Format (instead of String format as Venkatesh suggested) another way is this:

//dat is your string MMddyyyy

datDate = easyDateFormat("MMddyyyy",dat);

//easyDateFormat give you date in Date Format, pass datDate to the BAPI

public Date easyDateFormat (String format, String actualDate) {

Date datenewformat = null;

SimpleDateFormat formatter = new SimpleDateFormat(format);

try {

datenewformat = formatter.parse(actualDate);

} catch(ParseException e) {

return null;

}

return datenewformat;

}

Hope thsi help.

Regards,

Vito

Former Member
0 Kudos

Hi Samir,

Use the following steps

1. Use SimpleDateFormat to convert mm-dd-yyyy to util.date object

2. Convert util.Date object to String of form yyyymmdd again using SimpleDateFormat

3. BAPI uses Sql.Date... So convert the string (yyyymmdd) to sql.date using Date.valueOf(String) function

Regards

Smruti

*Reward if found useful

Former Member
0 Kudos

Hi Samir,

You can convert the frondend date as your wish. Create a object for SimpleDateFormat and parse the date as you want and send pass the required format to the BAPI.

For Example:

SimpleDateFormat isdf = new SimpleDateFormat("MM-dd-yyyy"); // For input format

Date dt=sdf.parse(strDate); // strDate is input from the frontend

Through this, you have converted the string(ie. strDate) into normal date format. From this you can get the required format as the following,

String result = null;

int dd=dt.getDate();

int MM=dt.getMonth()+1;

int year = dt.getYear()+1900;

result = yearMMdd+"";

Now, you have got the required format.

Regards,

Venkatesh. K

/* Consider Points if it is useful */