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: 

Calculate working days

Former Member
0 Kudos

Hello all,

I have this report , which wants to see which are : the 8th, 9th, 10th, 11th, 12 th working days for January

If I am in 8-th working day (for example) I want to raise an event.

The problem is that I always will count 8 , because I count the string for January :

0100101110011111001111100111110

I need something relative to my current date...I guess ...

Or any other method to find out the 8-th working day?

(My method is that in table TFACS there is a string for every month.

1 means working day, 0 means not working day.)

Please help.

REPORT ZW_DAYS.

TABLES : TFACS.

DATA: GI_CURSOR TYPE CURSOR,

GI_TABIX TYPE SY-TABIX,

GT_TFACS TYPE TABLE OF TFACS.

DATA: TEXT(50) TYPE C,

LEN TYPE I,

IND TYPE I,

POS TYPE I,

CNT_ONE TYPE I,

CNT_ZERO TYPE I,

DAY_VAR(2) TYPE C.

FIELD-SYMBOLS: <GT_TFACS> TYPE TFACS.

DAY_VAR = SY-DATUM+6(2).

OPEN CURSOR GI_CURSOR FOR

*select data for factory calender Germany (01) and year 2009

SELECT * FROM TFACS

WHERE IDENT EQ '01' AND JAHR EQ '2009'.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

MOVE 100 TO GI_TABIX.

DO.

FETCH NEXT CURSOR GI_CURSOR

INTO TABLE GT_TFACS

PACKAGE SIZE GI_TABIX.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

*loop on internal table

LOOP AT GT_TFACS ASSIGNING <GT_TFACS>.

TEXT = <GT_TFACS>-MON01.

LEN = STRLEN( TEXT ).

LEN = LEN + 1.

DO LEN TIMES.

IND = SY-INDEX.

POS = SY-TABIX.

IND = IND - 1.

IF TEXT+IND(POS) = '1'.

*number of working days increases with 1

CNT_ONE = CNT_ONE + 1.

IF CNT_ONE EQ 8.

WRITE : / '8th working day'.

EXIT.

ELSEIF CNT_ONE EQ 9.

WRITE : / '9th working day'.

EXIT.

ELSEIF CNT_ONE EQ 10.

WRITE : / '10th working day'.

EXIT.

ELSEIF CNT_ONE EQ 11.

WRITE : / '11th working day'.

EXIT.

ELSEIF CNT_ONE EQ 12.

WRITE : / '12th working day'.

EXIT.

ENDIF.

ELSEIF TEXT+IND(POS) = '0'.

*number of holidays days increases with 1

CNT_ZERO = CNT_ZERO + 1.

ENDIF.

ENDDO.

WRITE : /.

WRITE: 'January :' COLOR 1, <GT_TFACS>-MON01.

ENDLOOP.

REFRESH GT_TFACS.

ENDDO.

WRITE / .

WRITE ' The number of working days is :'.

WRITE CNT_ONE COLOR 5.

WRITE / .

WRITE ' The number of holiday days is :'.

WRITE CNT_ZERO COLOR 7.

WRITE : / DAY_VAR.

CLOSE CURSOR GI_CURSOR.

1 ACCEPTED SOLUTION

sujeet2918
Active Contributor
0 Kudos

Hello Ariana,

you can use the below Function Module

J_5H9_ULTIMO_CALCULATION

Have a Nice day,

Regards,

Sujeet

3 REPLIES 3

sujeet2918
Active Contributor
0 Kudos

Hello Ariana,

you can use the below Function Module

J_5H9_ULTIMO_CALCULATION

Have a Nice day,

Regards,

Sujeet

Former Member
0 Kudos

hi,

u can use like this

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = date

days = '99'

months = '00'

signum = '+'

years = '00'

IMPORTING

calc_date = calc_date.

date = calc_date.

if u want to find 8th day put 8 on daya and give sign as +

0 Kudos

I modified it like this and works:

..............................................................................

LOOP AT GT_TFACS ASSIGNING <GT_TFACS>.

TEXT = <GT_TFACS>-MON01.

LEN = STRLEN( TEXT ).

WRITE : 'len' , LEN.

DO LEN TIMES.

IND = SY-INDEX.

POS = SY-TABIX.

IND = IND - 1.

IND_VAR = IND + 1.

WRITE: / 'ind', IND_VAR.

WRITE : 'pos'.

WRITE POS.

IF TEXT+IND(POS) = '1'.

*number of working days increases with 1

CNT_ONE = CNT_ONE + 1.

IF CNT_ONE EQ 8 AND ( DAY_VAR = IND_VAR ).

WRITE : / '8th working day'.

EXIT.

........................................................................................

I hope it will help some other persons.