Ver Mensaje Individual
  #4
Antiguo 19 de abril de 2022, 19:12
Joseg
El Foro es mi casa
Activista del Foro: Activista del Foro - Issue reason: Por participación activa Innovación: Por aportar innovaciones - Issue reason: Por aportar soluciones innovadoras en varias ocasiones 
Última Actividad 17.09.2026 18:23
Posts Posts: 401
Likes enviados Enviados: 130
Likes recibidos Recibidos: 179

Hummmm !

É necessário mais código, teste isto.
Havia muitas considerações a analisar.
No entanto assume que o 1º dia da semana é "Segunda-feira" (Lunes)
Código COBOL:
  1.  data division.
  2.  working-storage section.
  3.  01 input-data pic 9(8) value 20220101.
  4.  01 integer-of-input-data binary pic 9(8).
  5.  01 work-table.
  6.      02 work-item occurs 3.
  7.         03 work-year binary pic 9(4).
  8.         03 work-jan-4 binary pic 9(8).
  9.         03 work-first-date binary pic 9(8).
  10.  01 work-sub binary pic 9(4).
  11.  01 week-for-input-data pic 9(2).
  12.  procedure division.
  13.  inicio.
  14.       perform with test after until input-data = 0
  15.       display "Digite a data YYYYMMDD: " with no advancing
  16.       accept input-data
  17.       if input-data = 0
  18.          exit program
  19.       else
  20.          perform calculos
  21.          display "Nr. da semana da data: " input-data " e "
  22.          week-for-input-data " do ano: " work-year (work-sub)
  23.       end-if
  24.       end-perform
  25.       exit program
  26.       .
  27.  calculos.
  28.       divide input-data by 10000 giving work-year (2)
  29.       subtract 1 from work-year (2) giving work-year (1)
  30.       add 1 to work-year (2) giving work-year (3)
  31.       perform varying work-sub from 1 by 1
  32.          until work-sub > 3
  33.            compute work-jan-4 (work-sub) =
  34.            function integer-of-date(work-year (work-sub) * 10000 + 0104)
  35.            compute work-first-date (work-sub) =(function integer ((work-jan-4 (work-sub) - 1) / 7)) * 7 + 1
  36.        end-perform
  37.        compute integer-of-input-data = function integer-of-date (input-data)
  38.        evaluate integer-of-input-data
  39.           when work-first-date (1) thru (work-first-date (2) - 1)
  40.                move 1 to work-sub
  41.                perform calculate-nr-semana
  42.           when work-first-date (2) thru (work-first-date (3) - 1)
  43.                move 2 to work-sub
  44.                perform calculate-nr-semana
  45.           when other
  46.                move 3 to work-sub
  47.                perform calculate-nr-semana
  48.        end-evaluate
  49.        .
  50.  calculate-nr-semana.
  51.        compute week-for-input-data = (function integer ((integer-of-input-data - work-first-date (work-sub)) / 7)) + 1
  52.        .
Joseg is offline   Responder Con Cita