  --CalcBuisnessDy.RMD
  --9/5/2017

  DROP TABLE tmpholidaytbl

  CREATE TEMPORARY TABLE `TmpHolidayTbl` +
    (`DtOfHoliday` DATE)

  LOAD `TmpHolidayTbl`
  NONUM
1/2/2017
1/16/2017
1/20/2017
5/29/2017
7/4/2017
9/4/2017
10/9/2017
11/10/2017
11/23/2017
12/25/2017
  END

  CLEAR ALL VAR

  SET VAR vstartdate DATE = 6/15/2017
  SET VAR vstartwith DATE = (ADDDAY(.vstartdate, -1))
  SET VAR vnxtwrkday DATE = NULL
  SET VAR venddate DATE = 7/15/2017
  SET VAR vendwith DATE = (ADDDAY(.venddate, 1))
  SET VAR vnumbbusday INTEGER = 0
  SET VAR vrowsholiday INTEGER = 0

  SET VAR vnxtwrkday = (DNW(.vstartwith))

  SELECT COUNT(*) INTO vrowsholiday INDICATOR iv1 FROM tmpholidaytbl WHERE dtofholiday = .vnxtwrkday

  IF vnxtwrkday = vstartdate AND vrowsholiday = 0 THEN
    SET VAR vnumbbusday = 1
  ENDIF

  WHILE vnxtwrkday < vendwith THEN

    SET VAR vnxtwrkday = (DNW(.vnxtwrkday))

    SET VAR vrowsholiday = 0
    SELECT COUNT(*) INTO vrowsholiday INDICATOR iv1 FROM tmpholidaytbl WHERE dtofholiday = .vnxtwrkday

    IF vnxtwrkday < vendwith AND vrowsholiday = 0 THEN
      SET VAR vnumbbusday = (.vnumbbusday + 1)
    ENDIF

  ENDWHILE

  RETURN
