2007 Jun 11 12:25 PM
hi i want to get difference between date.
i written below code but bug is coming please help me .
form data_retrieval.
DATA wa_days LIKE P0347-SCRDD.
DATA int_bseg1 LIKE TABLE OF int_bseg WITH HEADER LINE .
DATA: begin of int_bseg occurs 0,
zuonr like bseg-zuonr,
end of int_bseg.
DATA: date LIKE sy-datum,
date1 like P0001-BEGDA.
*changedate(10) TYPE c.
DATA: BEGIN OF it_date1, " To accept date into a internal table
yyyy(4),
mm(2),
dd(2),
END OF it_date1.
DATA: BEGIN OF it_date2, " Internal table for dd/mm/yyyy format
dd(2),
mm(2),
yyyy(4),
END OF it_date2.
DATA: BEGIN OF it_date3, " To accept date into a internal table
yyyy(4),
mm(2),
dd(2),
END OF it_date3.
DATA: BEGIN OF it_date4, " Internal table for dd/mm/yyyy format
dd(2),
mm(2),
yyyy(4),
END OF it_date4.
date = sy-datum.
it_date1 = date.
MOVE-CORRESPONDING it_date1 TO: it_date2.
select single zuonr from bseg into corresponding fields of int_bseg.
LOOP AT int_bseg.
date1 = int_bseg-zuonr.
it_date3 = date1.
MOVE-CORRESPONDING it_date3 TO: it_date4.
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
DATE1 = it_date4
DATE2 = it_date2
OUTPUT_FORMAT = '03'
IMPORTING
YEARS =
MONTHS =
DAYS = wa_days
EXCEPTIONS
INVALID_DATES_SPECIFIED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform.
hi i want to get difference between date.
i written below code but bug is coming please help me .
form data_retrieval.
DATA wa_days LIKE P0347-SCRDD.
DATA int_bseg1 LIKE TABLE OF int_bseg WITH HEADER LINE .
DATA: begin of int_bseg occurs 0,
zuonr like bseg-zuonr,
end of int_bseg.
DATA: date LIKE sy-datum,
date1 like P0001-BEGDA.
*changedate(10) TYPE c.
DATA: BEGIN OF it_date1, " To accept date into a internal table
yyyy(4),
mm(2),
dd(2),
END OF it_date1.
DATA: BEGIN OF it_date2, " Internal table for dd/mm/yyyy format
dd(2),
mm(2),
yyyy(4),
END OF it_date2.
DATA: BEGIN OF it_date3, " To accept date into a internal table
yyyy(4),
mm(2),
dd(2),
END OF it_date3.
DATA: BEGIN OF it_date4, " Internal table for dd/mm/yyyy format
dd(2),
mm(2),
yyyy(4),
END OF it_date4.
date = sy-datum.
it_date1 = date.
MOVE-CORRESPONDING it_date1 TO: it_date2.
select single zuonr from bseg into corresponding fields of int_bseg.
LOOP AT int_bseg.
date1 = int_bseg-zuonr.
it_date3 = date1.
MOVE-CORRESPONDING it_date3 TO: it_date4.
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
DATE1 = it_date4
DATE2 = it_date2
OUTPUT_FORMAT = '03'
IMPORTING
YEARS =
MONTHS =
DAYS = wa_days
EXCEPTIONS
INVALID_DATES_SPECIFIED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform.
2007 Jun 11 12:30 PM
Hi,
If you want the difference in days, you can just find the difference by giving date1 - date2. the date format should be in format of sy-datum.
You can change the format in displaying. Not in the logic part.
Regards,
Rusidar
2007 Jun 11 12:36 PM
Hi ...
i corrected the code of your program .... but there is no display logic ...means no write statments .....
anyway the code was activated.
dATA wa_days LIKE P0347-SCRDD.
DATA: begin of int_bseg occurs 0,
zuonr like bseg-zuonr,
end of int_bseg.
DATA int_bseg1 LIKE TABLE OF int_bseg WITH HEADER LINE .
DATA: date LIKE sy-datum,
date1 like P0001-BEGDA.
*changedate(10) TYPE c.
DATA: BEGIN OF it_date1, " To accept date into a internal table
yyyy(4),
mm(2),
dd(2),
END OF it_date1.
DATA: BEGIN OF it_date2, " Internal table for dd/mm/yyyy format
dd(2),
mm(2),
yyyy(4),
END OF it_date2.
DATA: BEGIN OF it_date3, " To accept date into a internal table
yyyy(4),
mm(2),
dd(2),
END OF it_date3.
DATA: BEGIN OF it_date4, " Internal table for dd/mm/yyyy format
dd(2),
mm(2),
yyyy(4),
END OF it_date4.
date = sy-datum.
it_date1 = date.
MOVE-CORRESPONDING it_date1 TO: it_date2.
select single zuonr from bseg into corresponding fields of int_bseg.
LOOP AT int_bseg.
date1 = int_bseg-zuonr.
it_date3 = date1.
MOVE-CORRESPONDING it_date3 TO: it_date4.
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
DATE1 = it_date4
DATE2 = it_date2
OUTPUT_FORMAT = '03'
IMPORTING
* YEARS =
* MONTHS =
DAYS = wa_days
* EXCEPTIONS
* INVALID_DATES_SPECIFIED = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endloop .Girish
2007 Jun 11 12:37 PM
hi,
Just use this FM.
data: dat1 type sy-datum.
data: dat2 type sy-datum.
data: days like P0347-SCRDD.
dat1 = '20061212'.
dat2 = '20071212'.
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
DATE1 = dat2
DATE2 = dat1
OUTPUT_FORMAT = '02'
IMPORTING
DAYS = days .
Write:/ days.Regards
Anversha
2007 Jun 11 12:50 PM
Hi,
Try this code:
REPORT ZDATEDIFF.
DATA: EDAYS LIKE VTBBEWE-ATAGE,
EMONTHS LIKE VTBBEWE-ATAGE,
EYEARS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
exporting
i_date_from = FROMDATE
i_date_to = TODATE
I_FLG_SEPARATE = ' '
IMPORTING
E_DAYS = EDAYS
E_MONTHS = EMONTHS
E_YEARS = EYEARS.
WRITE:/ 'Difference in Days ', EDAYS.
WRITE:/ 'Difference in Months ', EMONTHS.
WRITE:/ 'Difference in Years ', EYEARS.
INITIALIZATION.
FROMDATE = SY-DATUM - 60.
Regards,
Bhaskar
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |