cobol - goback and GO TO paragraph -
is there way can let me cancel effect of "go to" in cobol example:
perform procedure1 thru e--procedure1 display "perform procedure2 thru e--procedure2" perform procedure2 thru e--procedure2 goback. procedure1 section. display "begin============proc procedure1" perform lecture thru e--lecture perform endd thru e--endd display " endd============proc procedure1" continue. exit. e--procedure1. exit. lecture. display "i label lecture" go endd continue. e--lecture. exit. endd. display "i label endd" continue. e--endd. exit. procedure2 section. display "begin============proc procedure2" display "i label procedure2" display " endd============proc procedure2" continue. e--procedure2. exit.
when code executed, won't see display "perform procedure2 thru e--procedure2", beacause when made go paragraph endd, control permantely transfered paragraph , think there no way can use goback end of proc1 ? am-i wrong ?
@bill
this program trying translate:
goto5pow : proc options(main); dcl file001 file input record env(recsize(15)); dcl ctr1 pic'99' init('0'); dcl carte char(15); call procedure1; put skip list("perform procedure2 thru e--procedure2"); call procedure2; procedure1: proc; put skip list("begin============proc procedure1"); on endfile(file001) goto endd; lecture: put skip list("i label lecture"); read file(file001) into(carte); ctr1 = ctr1 + 1; put skip list("record "||ctr1||"=/" || carte ||"/"); if carte="aaaaaaaaaaaaaaa" goto endd; endd: put skip list("i label endd"); put skip list(" endd============proc procedure1"); end procedure1; procedure2 : proc; put skip list("begin============proc procedure2"); put skip list("i label procedure2"); put skip list(" endd============proc procedure2"); end procedure2; end goto5pow ;
the output is:
begin============proc procedure1 label lecture record 01=/aaaaaaaaaaaaaaa/ label endd endd============proc procedure1 perform procedure2 thru e--procedure2 begin============proc procedure2 label procedure2 endd============proc procedure2
but cobol, generated output:
begin============proc procedure1 label lecture record 01=/aaaaaaaaaaaaaaa/ label endd begin============proc procedure2 label procedure2 endd============proc procedure2
as bill said, not use thru. use either procedures or sections; not both. on endfile(file001) sets exception handler end-of file
this program should be:
03 pic x value 'n'. 88 file001-eof value 'y'. 88 file001-has-data value 'n'. perform procedure1 display "perform procedure2 thru e--procedure2" perform procedure2 goback. procedure1 section. display "begin============proc procedure1" display "i label lecture" read file001 @ end set file001-eof true end-read if file001-has-data compute ctr1 = ctr1 + 1; end-if display "i label endd" display " endd============proc procedure1" exit. e--procedure1. exit. procedure2 section. display "begin============proc procedure2" display "i label procedure2" display " endd============proc procedure2" continue. e--procedure2. exit.
for people more familiar java / c#
on endfile(file001) goto endd;
setups exception or error handler end-of-file condition. in java like:
try { .... } catch (endoffile e) { goto endd; }
Comments
Post a Comment