COBOL - Encontre o dia da semana para qualquer data de 01/01/0001 a 31/12/9999


Volta a página anterior

Volta ao Menu Principal


Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

l
Compativel com todos os compiladores e versões, exceto COBOL650 - comando REMAINDER não funciona
         1         2         3         4         5         6         7         8
12345678901234567890123456789012345678901234567890123456789012345678901234567890

      *---------------------------------------------------------------
       IDENTIFICATION DIVISION. 
      *---------------------------------------------------------------
       PROGRAM-ID.    ENCONDIA. 
       AUTHOR.        CARLOS ALBERTO DORNELLES.
      *---------------------------------------------------------------
      * SISTEMA     : SICAD
      * PROGRAMA    : ENCONDIA
      * OBJETIVO    : ENCONTRE O DIA DA SEMANA PARA QUALQUER DATA DE 
      *               01/01/0001 A 31/12/9999
      * ANALISTA    : CARLOS ALBERTO DORNELLES
      * LINGUAGEM   : COBOL
      * VERSAO      : V.001
      * DATA        : 15/05/2011
      *---------------------------------------------------------------
      *                           MANUTENCAO
      *---------------------------------------------------------------
      * VRS DD.MM.AA AUTOR        DESCRICAO
      *
      *---------------------------------------------------------------

      *---------------------------------------------------------------
       DATA DIVISION. 
      *---------------------------------------------------------------
       WORKING-STORAGE SECTION. 

       01  F                VALUE '12060708091011'. 
           05  FF           PIC 9(002) OCCURS 7. 
       01  WS-AUXILIARES.
           05  WS-ANO       PIC 9(004). 
           05  WS-MES       PIC 9(002). 
           05  WS-DIA       PIC 9(002). 
           05  A            PIC 9(002)     VALUE ZEROES. 
           05  B            PIC 9(001)     VALUE ZEROES. 
           05  C            PIC 9(002)     VALUE ZEROES. 
           05  E            PIC 9(004)     VALUE 0012. 
           05  T            PIC 9(004)     VALUE ZEROES. 
           05  I            PIC 9(001)     VALUE 1. 

      *---------------------------------------------------------------
       PROCEDURE DIVISION. 
      *---------------------------------------------------------------

       0001A. 
           DISPLAY 'Entre com o ano - 4 digitos >= 0001 e <= 9999' 
           ACCEPT WS-ANO. 

       0002A. 
           DISPLAY 'Entre com mes)' 
           ACCEPT WS-MES 
           IF WS-MES LESS THAN 1 OR GREATER THAN 12 
              DISPLAY 'Mes invalido' 
              GO 0002A
           END-IF. 

       0003A. 
           DISPLAY 'Entre com o dia' 
           ACCEPT WS-DIA 
           IF WS-DIA LESS THAN 1 OR GREATER THAN 31 
              DISPLAY 'Dia invalido' 
              GO 0003A
           END-IF 
           MOVE WS-DIA TO C. 

       0000X. 
           COMPUTE A = FF (I) 
           IF E EQUAL WS-ANO 
              GO 0000Y
           END-IF 
           ADD 1 TO I 
           IF I GREATER THAN 7 
              COMPUTE I = 1 
           END-IF 
           DIVIDE E BY 4 GIVING T REMAINDER B
           IF E LESS THAN WS-ANO AND B EQUAL 0 
              ADD 1 TO I
           END-IF 
           IF I GREATER THAN 7 
              COMPUTE I = 1
           END-IF 
           ADD 1 TO E 
           GO 0000X. 

       0000Y. 
           IF B EQUAL 0 AND WS-MES GREATER THAN 2   
              ADD 1 TO A
           END-IF 

           EVALUATE WS-MES
               WHEN  1 
               WHEN  10 
                     ADD A TO WS-DIA 
               WHEN  2 
               WHEN  3 
               WHEN  11 
                     ADD A 3 TO WS-DIA 
               WHEN  4 
               WHEN  7 
                     SUBTRACT 1 FROM A 
                     ADD A TO WS-DIA 
               WHEN  5 
                     ADD A 1 TO WS-DIA 
               WHEN  6 
                     ADD A 4 TO WS-DIA 
               WHEN  8 
                     ADD A 2 TO WS-DIA 
               WHEN  9 
               WHEN  12 
                     SUBTRACT 2 FROM A 
                     ADD A TO WS-DIA 
               WHEN OTHER  
                     DISPLAY 'Falha na rotina do mes' 
           END-EVALUATE 

           DIVIDE WS-DIA BY 7 GIVING A REMAINDER B 
           DISPLAY C '/' WS-MES '/' WS-ANO ' eh:'. 

           EVALUATE B
               WHEN  0 
                     DISPLAY 'Domingo' 
               WHEN  1 
                     DISPLAY 'Segunda' 
               WHEN  2 
                     DISPLAY 'Terca  ' 
               WHEN  3 
                     DISPLAY 'Quarta ' 
               WHEN  4 
                     DISPLAY 'Quinta ' 
               WHEN  5 
                     DISPLAY 'Sexta  ' 
               WHEN  6 
                     DISPLAY 'Sabado ' 
               WHEN OTHER 
                     DISPLAY 'Falha na rotina do dia' 
           END-EVALUATE 

           STOP RUN. 

      * Resultado do teste realizado:

       Entre com o ano - 4 digitos >= 0001 e <= 9999 = 1981

       Entre com o mes = 5 

       Entre com o dia = 6

       06/05/1981 é Quinta