Application Development 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: 

Doubt in function module...Urgent!!

Former Member
0 Kudos

hii all

I want to find the difference between sy-datum and BLDAT and have to get only the days value...

for eg...

sydatum(28.11.2007) - bldat(24.11.2007)= Days(4)

4 must the result... so i used the function module C14B_DIFF_BT_2_DATES..

but im unable to get the result...

my code is.....

&----


*& Report ZAGE1

*&

&----


*&

*&

&----


REPORT ZAGE1.

type-pools : slis,icon.

tables : bsid,kna1,knvv.

data : d_fieldcat type slis_t_fieldcat_alv,

d_fieldcat_wa type slis_fieldcat_alv.

data : begin of itab_bsid occurs 0,

kunnr like bsid-kunnr,

bukrs like bsid-bukrs,

bldat like bsid-bldat,

waers like bsid-waers,

belnr like bsid-belnr,

end of itab_bsid.

data : begin of itab_kna1 occurs 0,

kunnr like kna1-kunnr,

end of itab_kna1.

data : begin of itab_knvv occurs 0,

kunnr like knvv-kunnr,

zterm like knvv-zterm,

end of itab_knvv.

data : begin of itab_key occurs 0,

kunnr like bsid-kunnr,

bukrs like bsid-bukrs,

bldat like bsid-bldat,

waers like bsid-waers,

belnr like bsid-belnr,

zterm like knvv-zterm,

due type i,

end of itab_key.

selection-screen : begin of block blk1 with frame title text-001.

parameters : p_cc like bsid-bukrs.

selection-screen : end of block blk1.

select distinct kunnr bukrs bldat waers belnr from bsid into corresponding fields of table itab_bsid where bukrs = p_cc.

if not itab_bsid[] is initial.

select kunnr from kna1 into corresponding fields of table itab_kna1 for all entries in itab_bsid where kunnr = itab_bsid-kunnr.

if not itab_kna1[] is initial.

select kunnr zterm from knvv into corresponding fields of table itab_knvv for all entries in itab_kna1 where kunnr = itab_kna1-kunnr.

endif.

endif.

loop at itab_bsid.

itab_key-kunnr = itab_bsid-kunnr.

itab_key-bukrs = itab_bsid-bukrs.

itab_key-bldat = itab_bsid-bldat.

itab_key-waers = itab_bsid-waers.

itab_key-belnr = itab_bsid-belnr.

append itab_key.

clear itab_key.

endloop.

sort itab_key by kunnr.

loop at itab_key.

read table itab_knvv with key kunnr = itab_key-kunnr.

if sy-subrc = 0.

itab_key-zterm = itab_knvv-zterm.

modify itab_key transporting zterm.

endif.

endloop.

d_fieldcat_wa-fieldname = 'KUNNR'.

d_fieldcat_wa-seltext_l = 'CUSTOMER'.

d_fieldcat_wa-col_pos = 1.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'BUKRS'.

d_fieldcat_wa-seltext_l = 'COMPANY CODE'.

d_fieldcat_wa-col_pos = 2.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'WAERS'.

d_fieldcat_wa-seltext_l = 'CURRENCY'.

d_fieldcat_wa-col_pos = 3.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'BLDAT'.

d_fieldcat_wa-seltext_l = 'DOCUMENT DATE'.

d_fieldcat_wa-col_pos = 4.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'BELNR'.

d_fieldcat_wa-seltext_l = 'DOCUMENT NO'.

d_fieldcat_wa-col_pos = 5.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'ZTERM'.

d_fieldcat_wa-seltext_l = 'PAYMENT TERMS'.

d_fieldcat_wa-col_pos = 6.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

*data : due type i.

loop at itab_key.

CALL FUNCTION 'C14B_DIFF_BT_2_DATES'

EXPORTING

I_DATE_FROM = itab_key-bldat

I_DATE_TO = sy-datum

IMPORTING

E_DAYS = itab_key-due

  • E_MONTHS = months

  • E_YEARS = years

  • EXCEPTIONS

  • PLAUSIBILITY_CHECK_FAILED = 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.

append itab_key.

endloop.

d_fieldcat_wa-fieldname = 'DUE'.

d_fieldcat_wa-seltext_l = 'DUE DATE'.

d_fieldcat_wa-col_pos = 7.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

data : gd_repid like sy-repid.

gd_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = gd_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

  • IS_LAYOUT =

IT_FIELDCAT = d_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • IR_SALV_FULLSCREEN_ADAPTER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = itab_key[]

  • EXCEPTIONS

  • PROGRAM_ERROR = 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.

Urgent plz help me....!!

Regards

Asha

8 REPLIES 8

Former Member
0 Kudos

Check the following code for subtract years/months/date from particular date:

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.

For difference between two dates.

data : date1 like sy-datum,

date2 like sy-datum,

diff(10 ) type c.

date1 = '20071003'.

date2 = '20071104' .

CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

EXPORTING

I_DATUM_BIS = date1

I_DATUM_VON = date2

  • I_KZ_EXCL_VON = '0'

  • I_KZ_INCL_BIS = '0'

  • I_KZ_ULT_BIS = ' '

  • I_KZ_ULT_VON = ' '

  • I_STGMETH = '0'

  • I_SZBMETH = '1'

IMPORTING

E_TAGE = diff

EXCEPTIONS

DAYS_METHOD_NOT_DEFINED = 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 .

Former Member
0 Kudos

hi

declare a variable.

loc_diff = bldat - sy-datum .

then loc_diff1+4(2)

will give u the result

regards

karthik

0 Kudos

hii

i hav tried it like the below

data : loc_diff type i.

loop at itab_key.

loc_diff = itab_key-bldat - sy-datum .

write : loc_diff +4(2).

endloop.

but its giving error "unable to interpret '+'...plz help me in this

0 Kudos

did u try to replace append with modify

Message was edited by:

Rajesh

0 Kudos

Hi,

try like this..don't give any space..

write : loc_diff+4(2).

Regards,

Nagaraj

0 Kudos

Hi Asha,

offset operations are only possible with Character type variables, change the declaration of loc_diff as type n and write as suggested above

varma_narayana
Active Contributor
0 Kudos

Hi..

To get the difference in number of Days you can directly subtract the Date variable from another Date variable.

Eg:

V_int = V_date1 - V_date2.

Write:/ V_int.

OR

Check the following code for subtract years/months/date from particular date:

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.

Cheers....

Former Member
0 Kudos

loop at itab_key.

CALL FUNCTION 'C14B_DIFF_BT_2_DATES'

EXPORTING

I_DATE_FROM = itab_key-bldat

I_DATE_TO = sy-datum

IMPORTING

E_DAYS = itab_key-due

  • E_MONTHS = months

  • E_YEARS = years

  • EXCEPTIONS

  • PLAUSIBILITY_CHECK_FAILED = 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.

append itab_key. " <b>Replace append with modify</b>

endloop.