0
Former Member
Jan 27, 2009 at 11:19 AM

# Calculate working days

54 Views

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.)

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.