Cobol: не удается найти причину ошибки бесконечного цикла в сопоставлении файлов - PullRequest
0 голосов
/ 03 декабря 2018

Я пытался узнать о сопоставлении файлов в школе.Проходя через мой код, я получаю бесконечный цикл, но я не совсем уверен, что его вызывает.Все, что я знаю, это где-то в моем файле, соответствующем части кода.

01 Procedure Division.  
02   A-Para.
03      Perform Process-Para Until EOFa = "Y"
04        and EOFb = "Y"
05   Process-Para.  
06       Add 1 to counter
07       
08       If inFileSorted-empNum = timeFileSorted-empNum
09           Perform check-Para
10       End-If.
11   
12   check-Para. 
13       Perform ReadTimeFile
14       If changeEmployee equals "Y"
15           Perform Compute-Para
16       End-If
17       If timeFileSorted-empNum not equal to inFileSorted-empNum
18           Perform ReadinFile
19           If changeEmployee equals "Y"
20               Perform Compute-Para
21           End-If
22       End-If
23       
24       Perform 510-Calculate
25       Perform Display-Para.
26
27    ReadTimeFile. 
28       Move spaces to changeEmployee
29       
30       If not EOFb = "Y"
31           Move timeFileSorted-empNum to oldEmpNum              
32           Read timeFileSort             
33           At end
34               Move "Y" to EOFb
35               Move high-value to timeFileSorted-empNum
36           Not at end
37               Move timeFileSorted-empNum to newEmpNum  
38               If (oldEmpNum not equal newEmpNum)
39                   Move "Y" to changeEmployee
40               End-If
41           End-Read
42       End-If.  
43
44    ReadinFile.  
45       Move spaces to changeEmployee
46       
47       If not EOFa = "Y"
48           Move inFileSorted-empNum to oldEmpNum
49           Read Lab10-sort-File
50           At end
51               Move "Y" to EOFa
52               Move high-value to inFileSorted-empNum                  
53           Not at end
54               Move inFileSorted-empNum to newEmpNum  
55               If (oldEmpNum not equal newEmpNum)
56                  Move "Y" to changeEmployee
57               End-If
58           End-Read
59       End-If.

Может ли кто-нибудь помочь мне найти причину этой проблемы?Любая помощь будет принята с благодарностью.

1 Ответ

0 голосов
/ 03 декабря 2018

Одной из возможных причин (в Process-Para) является

08       If inFileSorted-empNum = timeFileSorted-empNum
09           Perform check-Para
10       End-If.

, если inFileSorted-empNum не = timeFileSorted-empNum, он будет пропускать через check-Paraи не читает ни один файл


лучший вариант

Это не предназначено для работы, но чтобы показать вам, как структурировать код.Обратите внимание, что по крайней мере один файл читается каждый раз через цикл

open infile, timefile
Perform read-inFile
Perform read-timeFile
perform until EOFa = "Y" or EOFb = "Y"
    evaluate true
    when inFileSorted-empNum < timeFileSorted-empNum
        ...
        Perform read-inFile
    when inFileSorted-empNum > timeFileSorted-empNum
        ...
        Perform read-timeFile
    when Other
       ...
        Perform read-timeFile  ???
    end-evaluate
end-perform

perform until EOFa = "Y"
    ...
end-perform

perform until EOFb not = "Y"
    ...
end-perform
.
...