EXECUTE "SET-THOUS ."
EXECUTE "SET-DEC ,"
EXECUTE "DATE.FORMAT"
OPEN "","TPSREMPLACEAIDANT" TO F1 THEN
OPEN "","TPSDETAILSINTERV" TO F2 THEN
READ ENR_NOUVEAU FROM F1, "009570113975" THEN

    k = 0
    LOOP
	k = k + 1
    WHILE ENR_NOUVEAU<1,k> # ""

		t = 0
		
		LOOP
			t = t + 1
		WHILE ENR_NOUVEAU<5,k,t> # ""
			READ ENR2 FROM F2, ENR_NOUVEAU<5,k,t> THEN
				ENR_NOUVEAU<3,k,t> = ENR_NOUVEAU<5,k,t>[11,5]
				ENR_NOUVEAU<4,k,t> = ENR2<2>
				WRITE  ENR2 ON F2, ENR_NOUVEAU<5,k,t>
			END
		REPEAT
	
    REPEAT

    W_DateMin = "13975"
    W_DateMax = "14178"
    k = 0
    LOOP
	k = k + 1
    WHILE ENR_NOUVEAU<1,k> # ""

	W_Partiel = "F"
	IF ENR_NOUVEAU<3,k,1> - W_DateMin >= 7 THEN
		W_Partiel = "V"
	END ELSE
		t = 1
		W_Max = ENR_NOUVEAU<4,k,1>
		LOOP
			t = t + 1
		WHILE ENR_NOUVEAU<5,k,t> # "" AND W_Partiel = "F"
			IF ENR_NOUVEAU<3,k,t> - W_Max >= 7 THEN
				W_Partiel = "V"
			END
			IF W_Max < ENR_NOUVEAU<4,k,t> THEN
				W_Max = ENR_NOUVEAU<4,k,t>
			END
		REPEAT
		IF W_Partiel = "F" THEN
			IF W_DateMax - W_Max >= 7 THEN
				W_Partiel = "V"
			END
		END
	END
	IF W_Partiel = "F" THEN
		ENR_NOUVEAU<2,k> = "2"
	END ELSE
	END
    REPEAT
END
END
END
STOP
