Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem with dates

Former Member
0 Likes
817

Hi,

Presently I am working in travel module and developing a RFC function module , the code is below mention ,the out put of this is that it will give the list of visa capacity for the present month & next 2 motnhs ahead.

My problem is that with respect to sy-datum i am getting data correctly.For the present month & next 2 months.

If i am passing furture date in the parameter i am not getting the data.

Please provide me with neccesary logic.

Thanks in Advance

Irfan Hussain

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

DATA:DATE1 LIKE SY-DATUM,

LINES LIKE SY-TABIX.

DATA: MON LIKE ZHTWPVERT_FCAST-CMONTH,

YER LIKE ZHTWPVERT_FCAST-CYEAR,

FMON LIKE ZHTWPVERT_FCAST-CMONTH,

FYER LIKE ZHTWPVERT_FCAST-CYEAR.

IF P_DATE IS INITIAL.

P_DATE = SY-DATUM.

ENDIF.

SELECT * FROM ZHTWPVERT_FCAST INTO CORRESPONDING

FIELDS OF TABLE IT_WPFCAST WHERE SVERT EQ SVERT

AND CNTRY EQ CNTRY

AND TVISA EQ TVISA.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

MONTHS = '2'

OLDDATE = P_DATE

IMPORTING

NEWDATE = DATE1.

MON = P_DATE+4(2).

YER = P_DATE+0(4).

FMON = DATE1+4(2).

FYER = DATE1+0(4).

LOOP AT IT_WPFCAST.

IF IT_WPFCAST-CYEAR NE YER AND IT_WPFCAST-CYEAR NE FYER.

DELETE IT_WPFCAST.

ENDIF.

ENDLOOP.

LOOP AT IT_WPFCAST.

IF IT_WPFCAST-CMONTH LT MON OR IT_WPFCAST-CMONTH GT FMON.

DELETE IT_WPFCAST.

ENDIF.

ENDLOOP.

DESCRIBE TABLE IT_WPFCAST LINES LINES.

IF LINES GT 0.

RETMSG = 'SUCCESS'.

ELSE.

RETMSG = 'FAILURE'.

ENDIF.

ENDFUNCTION.

6 REPLIES 6
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
790

Hi,

Just check your date format.

For example if it is p_date = '27/10/2005'.

data p_future type sy-datum.

data v type i.

v = p_date+2(2).

v = v + 2.

concatenate p_date0(3) v p_date4(5) to p_future.

Then use the future date as before you used present date.

Kindly reward points if it is helpful.

Read only

Former Member
0 Likes
790

as suggested, there could be a problem in the date format....

you are doing...

FMON = DATE1+4(2).

FYER = DATE1+0(4).

now if date1 = 27.10.2005 then FMON will hold '0.' while if date1 is 20051027 then it will hold '10'...this could be the problem...

u can use CONVERT_DATE_TO_INTERNAL to change date to internal format YYYYMMDD(if it is not already in that format)....check out the values in the debugger once to verify this...

rgds,

PJ

Read only

Former Member
0 Likes
790

hi,

u said u have a problem if you are using some other date then sy-datum.

i didn't find declaration part for p_date in your code,

but that should not be a problem.

but i tried with parameter where user can give any date

and it's functioning fine in my case.

below is the code given, i didnot used sy-datum.

parameter: date1 type d.

data: date2 type d.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

months = 2

olddate = date1

IMPORTING

NEWDATE = date2.

write:/ date1, 'date: ', date1+6(2) ,

' month:', date14(2), ' year:' ,date10(4).

write:/ date2, 'date: ', date2+6(2) ,

' month:', date24(2), ' year:', date20(4).

hope this could solve your problem

regards,

manohar

Read only

andreas_mann3
Active Contributor
0 Likes
790

Hi Ifran,

How have you defined p_date ?

Are there data with future date in your table ?

Andreas

Read only

0 Likes
790

Hi,

I have defined P_date to check for future cases,

If p_date is initial the p_date value will be equal to sy_datum.

Just to check whether my rfc is working fine for future dates also.

My problem is that up 10 month of the year the data is proper, the real problem starts in the month of nov an dec.

Because the year changes , i am taking data for the month of nov then jan 2006 will also will come into the

figure.

Regards,

Irfan

Read only

Former Member
0 Likes
790

Hi,

Try this -

I had made some changes in your code.

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

DATA:DATE1 LIKE SY-DATUM,

LINES LIKE SY-TABIX.

DATA: MON LIKE ZHTWPVERT_FCAST-CMONTH,

YER LIKE ZHTWPVERT_FCAST-CYEAR,

FMON LIKE ZHTWPVERT_FCAST-CMONTH,

FYER LIKE ZHTWPVERT_FCAST-CYEAR.

IF P_DATE IS INITIAL.

P_DATE = SY-DATUM.

ENDIF.

SELECT * FROM ZHTWPVERT_FCAST INTO CORRESPONDING

FIELDS OF TABLE IT_WPFCAST WHERE SVERT EQ SVERT

AND CNTRY EQ CNTRY

AND TVISA EQ TVISA.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

MONTHS = '2'

OLDDATE = P_DATE

IMPORTING

NEWDATE = DATE1.

MON = P_DATE+4(2).

YER = P_DATE+0(4).

FMON = DATE1+4(2).

FYER = DATE1+0(4).

LOOP AT IT_WPFCAST.

IF IT_WPFCAST-CYEAR NE YER AND IT_WPFCAST-CYEAR NE FYER.

DELETE IT_WPFCAST.

ENDIF.

ENDLOOP.

*- start of changes

data:

cperiod type spmon,

period1 type spmon,

period2 type spmon.

*- end of changes

LOOP AT IT_WPFCAST.

*- start of changes

clear: cperiod, period1, period2.

concatenate IT_WPFCAST-CMONTH IT_WPFCAST-CYEAR to cperiod.

concatenate MON YER to period1.

concatenate FMON FYER to period2.

*IF IT_WPFCAST-CMONTH LT MON OR IT_WPFCAST-CMONTH GT FMON.

IF cperiod LT period1 OR cperiod GT period2.

*- end of changes

DELETE IT_WPFCAST.

ENDIF.

ENDLOOP.

DESCRIBE TABLE IT_WPFCAST LINES LINES.

IF LINES GT 0.

RETMSG = 'SUCCESS'.

ELSE.

RETMSG = 'FAILURE'.

ENDIF.

ENDFUNCTION.