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:Β 

to find the no of working days b/w given date

Former Member
0 Kudos

Hi ABAP Experts,

Here i have one requirement .

table is tfacs

in this table i want to know the no of working days b/w the given date. Here i have attached my code .pls go through it and do me needful.

TABLES : tfacs,vbrk.

DATA: BEGIN OF ty_tfacs OCCURS 0,

ident TYPE tfacs-ident,

jahr TYPE tfacs-jahr,

mon01 TYPE tfacs-mon01,

mon02 TYPE tfacs-mon02,

mon03 TYPE tfacs-mon03,

mon04 TYPE tfacs-mon04,

mon05 TYPE tfacs-mon05,

mon06 TYPE tfacs-mon06,

mon07 TYPE tfacs-mon07,

mon08 TYPE tfacs-mon08,

mon09 TYPE tfacs-mon09,

mon10 TYPE tfacs-mon10,

mon11 TYPE tfacs-mon11,

mon12 TYPE tfacs-mon12,

basis TYPE tfacs-basis,

fenum TYPE tfacs-fenum,

wenum TYPE tfacs-wenum,

load TYPE tfacs-load,

string1(31) TYPE c,

string2(31) TYPE c,

string3(31) TYPE c,

string4(31) TYPE c,

string5(31) TYPE c,

string6(31) TYPE c,

string7(31) TYPE c,

string8(31) TYPE c,

string9(31) TYPE c,

string10(31) TYPE c,

string11(31) TYPE c,

string12(31) TYPE c,

uk(31) TYPE c,

total1 TYPE i,

total2 TYPE i,

total3 TYPE i,

total4 TYPE i,

total5 TYPE i,

total6 TYPE i,

total7 TYPE i,

total8 TYPE i,

total9 TYPE i,

total10 TYPE i,

total11 TYPE i,

total12 TYPE i,

END OF ty_tfacs.

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : s_jahr FOR tfacs-jahr MODIF ID b1.

SELECT-OPTIONS : mon FOR tfacs-mon01 MODIF ID b1.

SELECT-OPTIONS : s_month FOR vbrk-erdat MODIF ID b2.

SELECTION-SCREEN : END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME.

PARAMETERS r1 RADIOBUTTON GROUP c DEFAULT 'X' USER-COMMAND flag .

PARAMETERS r2 RADIOBUTTON GROUP c .

SELECTION-SCREEN END OF BLOCK b.

*----


*

  • INITIALIZATION

*----


INITIALIZATION.

AT SELECTION-SCREEN OUTPUT.

IF r1 NE space.

LOOP AT SCREEN.

IF screen-group1 EQ 'B2'.

screen-output = 1.

screen-active = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT SCREEN.

IF screen-group1 EQ 'B1'.

screen-output = 1.

screen-active = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ENDIF.

  • ----------------------------------------------------------------------

*

  • start - of - selection

  • ----------------------------------------------------------------------

start-of-selection.

IF r1 = 'X'.

PERFORM get-data.

PERFORM display-data.

ENDIF.

  • &---------------------------------------------------------------------

*

  • & form get-data

  • &---------------------------------------------------------------------

*

  • text

  • ----------------------------------------------------------------------

*

  • --> p1 text

  • <-- p2 text

  • ----------------------------------------------------------------------

*

form get-data .

DATA : total1 TYPE i.

SELECT * FROM tfacs INTO TABLE ty_tfacs

WHERE ident EQ 'IN'

AND jahr IN s_jahr.

LOOP AT ty_tfacs WHERE ident = 'IN'.

IF sy-subrc EQ 0.

PERFORM get_string USING ty_tfacs-string1

ty_tfacs-mon01

ty_tfacs-total1.

PERFORM get_string USING ty_tfacs-string2

ty_tfacs-mon02

ty_tfacs-total2.

PERFORM get_string USING ty_tfacs-string3

ty_tfacs-mon03

ty_tfacs-total3.

PERFORM get_string USING ty_tfacs-string4

ty_tfacs-mon04

ty_tfacs-total4.

PERFORM get_string USING ty_tfacs-string5

ty_tfacs-mon05

ty_tfacs-total5.

PERFORM get_string USING ty_tfacs-string6

ty_tfacs-mon06

ty_tfacs-total6.

PERFORM get_string USING ty_tfacs-string7

ty_tfacs-mon07

ty_tfacs-total7.

PERFORM get_string USING ty_tfacs-string8

ty_tfacs-mon08

ty_tfacs-total8.

PERFORM get_string USING ty_tfacs-string9

ty_tfacs-mon09

ty_tfacs-total9.

PERFORM get_string USING ty_tfacs-string10

ty_tfacs-mon10

ty_tfacs-total10.

PERFORM get_string USING ty_tfacs-string11

ty_tfacs-mon11

ty_tfacs-total11.

PERFORM get_string USING ty_tfacs-string12

ty_tfacs-mon12

ty_tfacs-total12.

ENDIF.

ty_tfacs-uk = ty_tfacs-total1 + ty_tfacs-total2

+ ty_tfacs-total3 + ty_tfacs-total4

+ ty_tfacs-total5 + ty_tfacs-total6

+ ty_tfacs-total7 + ty_tfacs-total8

+ ty_tfacs-total9 + ty_tfacs-total10

+ ty_tfacs-total11 + ty_tfacs-total12.

MODIFY ty_tfacs TRANSPORTING total1 total2 total3

total4 total5 total6

total7 total8 total9

total10 total11 total12

uk.

ENDLOOP.

  • PERFORM write1-data USING 'COU' 'YEAR' 'MONTH01'

  • 'MONTH02' 'MONTH03' 'MONTH04'

  • 'MONTH05' 'MONTH06' 'MONTH07'

  • 'MONTH08' 'MONTH09' 'MONTH10'

  • 'MONTH11' 'MONTH12' 'TOTAL WDAYS' .

  • LOOP AT ty_tfacs.

  • PERFORM write1-data USING ty_tfacs-ident ty_tfacs-jahr

  • ty_tfacs-total1 ty_tfacs-total2

  • ty_tfacs-total3 ty_tfacs-total4

  • ty_tfacs-total5 ty_tfacs-total6

  • ty_tfacs-total7 ty_tfacs-total8

  • ty_tfacs-total9 ty_tfacs-total10

  • ty_tfacs-total11 ty_tfacs-total12

  • ty_tfacs-uk.

*

  • ENDLOOP.

ENDFORM. " get-data

TOP-OF-PAGE.

FORMAT COLOR 5 ON.

WRITE :/10 'COUNTRY',

20 'YEARS',

35 'MON01',

45 'MON02',

55 'MON03',

65 'MON04',

75 'MON05',

85 'MON06',

95 'MON07',

105 'MON08',

115 'MON09',

125 'MON10',

135 'MON11',

145 'MON12',

170 'total wdays'.

FORMAT COLOR OFF.

WRITE πŸ˜• SY-ULINE.

*&----


*

*& Form display-data

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM display-data .

LOOP AT ty_tfacs.

WRITE :/10 ty_tfacs-ident,

20 ty_tfacs-jahr,

30 ty_tfacs-total1,

40 ty_tfacs-total2,

50 ty_tfacs-total3,

60 ty_tfacs-total4,

70 ty_tfacs-total5,

80 ty_tfacs-total6,

90 ty_tfacs-total7,

100 ty_tfacs-total8,

110 ty_tfacs-total9,

120 ty_tfacs-total10,

130 ty_tfacs-total11,

140 ty_tfacs-total12,

150 ty_tfacs-uk.

ENDLOOP.

*

*

*

ENDFORM. " display-data

*&----


*

*& form get_string

*&----


*

  • text

*----


*

  • -->p_0250 text

  • -->p_0251 text

  • -->p_0252 text

*----


form get_string using p_0250 " month

p_0251 " string

p_0252. " total

p_0250 = p_0251. " move month to string

TRANSLATE p_0250 USING '0 ' . " translate

CONDENSE p_0250 NO-GAPS. " condense

p_0252 = STRLEN( p_0250 ). " pass length of string to total

ENDFORM. " get_string

***&----


**-

***

***& Form write1-data

***&----


**-

***

      • text

***----


*

**

    • -->P_0306 text

    • -->P_0307 text

    • -->P_0308 text

    • -->P_0309 text

    • -->P_0310 text

    • -->P_0311 text

    • -->P_0312 text

    • -->P_0313 text

    • -->P_0314 text

    • -->P_0315 text

    • -->P_0316 text

    • -->P_0317 text

    • -->P_0318 text

    • -->P_0319 text

    • -->P_0320 text

**----


*

**

*form write1-data using p_0306

  • p_0307

  • p_0308

  • p_0309

  • p_0310

  • p_0311

  • p_0312

  • p_0313

  • p_0314

  • p_0315

  • p_0316

  • p_0317

  • p_0318

  • p_0319

  • p_0320.

*

*

*WRITE πŸ˜• p_0306,

  • p_0307,

  • p_0308 left-justified,

  • p_0309 left-justified,

  • p_0310 left-justified,

  • p_0311 left-justified,

  • p_0312 left-justified,

  • p_0313 left-justified,

  • p_0314 left-justified,

  • p_0315 left-justified,

  • p_0316 left-justified,

  • p_0317 left-justified,

  • p_0318 left-justified,

  • p_0319 left-justified,

  • p_0320 left-justified.

*

*

*ENDFORM. " write1-data

from this report what i am getting is year and its 12 months but my requirement is i will give date using select options and i should get the total no of working days in b/w this date.

9 REPLIES 9

former_member181995
Active Contributor
0 Kudos

ICG,

just look at this:

DAYS_BETWEEN_TWO_DATES

also see:

check if this fm works

HR_HK_DIFF_BT_2_DATES".
or
SD_DATETIME_DIFFERENCE

please tell which of them worked for you....

Amit.

Edited by: Amit on Jun 25, 2008 11:23 AM

Former Member
0 Kudos

Hi,

Use function module DAYS_BETWEEN_TWO_DATES.

I hope this will solve your problem.

0 Kudos

Thanq for ur answer.

but, pls once see the table tfacs and let me know how my problem will be solved.

Former Member
0 Kudos

hiiii

if you want to get number of days between two dates then use FM FIMA_DAYS_BETWEEN_TWO_DATES

if you are considering bussiness days then use following FM

K_ABC_WORKDAYS_FOR_PERIODS_GET

RKE_SELECT_FACTDAYS_FOR_PERIOD

regards

twinkal

Former Member
0 Kudos

Hi,

Pls go thru the following links as they might be useful.

Warm Regards

R Adarsh

Former Member
0 Kudos

Hi,

Use the Fucntion module DAYS_BETWEEN_TWO_DATES.

I hope this will solve your problem.

Help children of U.N World Food Program by rewarding points and encourage others to answer your queries.

0 Kudos

Hi,

pls go through the table tfacs and i want to find the no of working days b/w the given date .pls check in tfacs whether my requirement is going to be done.

kesavadas_thekkillath
Active Contributor
0 Kudos

Pass the date range and plant to below code..
working_days will hold the total no of working days

DATA: it_days LIKE STANDARD TABLE OF rke_dat .
 
  SELECT SINGLE fabkl INTO calendar_code FROM t001w CLIENT          
  SPECIFIED  WHERE mandt = sy-mandt AND werks = plant.
 
  CALL FUNCTION 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
    EXPORTING
      i_datab               = first_date 
      i_datbi               =  last_date
      i_factid              = calendar_code
    TABLES
      eth_dats              = it_days
    EXCEPTIONS
      date_conversion_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.
 
  DESCRIBE TABLE it_days LINES working_days.

Former Member
0 Kudos

Use the following code to find no of working days b/w given date. Use the correct factory_calendar_id in the function module. L_DAYS will display the required result:

PARAMETERS: p_date1 TYPE sydatum,

p_date2 TYPE sydatum.

DATA: date1 LIKE scal-date,

date2 LIKE scal-date,

correction LIKE scal-indicator,

calendar LIKE scal-fcalid,

factorydate1 LIKE scal-facdate,

workday1 LIKE scal-indicator,

factorydate2 LIKE scal-facdate,

workday2 LIKE scal-indicator,

l_days TYPE scal-facdate.

CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'

EXPORTING

date = p_date1

correct_option = '+'

factory_calendar_id = 'US'

IMPORTING

date = date1

factorydate = factorydate1

workingday_indicator = workday1

EXCEPTIONS

correct_option_invalid = 1

date_after_range = 2

date_before_range = 3

date_invalid = 4

factory_calendar_not_found = 5.

IF sy-subrc = 0.

CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'

EXPORTING

date = p_date2

correct_option = '+'

factory_calendar_id = 'US'

IMPORTING

date = date2

factorydate = factorydate2

workingday_indicator = workday2

EXCEPTIONS

correct_option_invalid = 1

date_after_range = 2

date_before_range = 3

date_invalid = 4

factory_calendar_not_found = 5.

IF sy-subrc = 0.

l_days = factorydate2 - factorydate1.

WRITE: / l_days.

ENDIF.

ENDIF.