Saturday 15 May 2010

cobol85 - In a perform, the code will not do math after displaying a line. (COBOL 85) -



cobol85 - In a perform, the code will not do math after displaying a line. (COBOL 85) -

doing amortization schedule. have set in 300-report module display line payment information, after display update info if payment made. supposed stop @ balance of $0 write text file.

problem is, displays line, , instead of doing new math, displays same line on , over, hence creating endless loop.

300-report. move ws-begyear ws-rep-year move ws-begmonth ws-rep-mo move ws-principal ws-rep-prin move ws-interest ws-rep-int move ws-term ws-rep-term compute ws-rep-beg-bal-m = ws-principal * (1+ws-int-dec) move ws-rep-beg-bal-m ws-rep-beg-bal move ws-principal ws-rep-beg-bal-m move ws-payment-tot ws-rep-payment compute ws-int-paid-m = ws-principal * ws-int-dec move ws-int-paid-m ws-int-paid compute ws-cur-prin-m = ws-principal - (ws-payment-tot - ws-int-paid-m) move ws-cur-prin-m ws-cur-prin compute ws-end-bal-m = ws-rep-beg-bal-m - ws-payment-tot move ws-end-bal-m ws-end-bal write of-line ws-title3 write of-line ws-title4 write of-line ws-line write of-line ws-prin-line write of-line ws-int-line write of-line ws-term-line write of-line ws-line write of-line ws-headers write of-line ws-header-sep. perform until ws-end-bal-m <= 0 write of-line ws-rep-data-line display ws-rep-data-line add together 1 ws-pmt-num add together 1 ws-rep-mo if ws-rep-mo = 13 add together 1 ws-rep-year move 01 ws-rep-mo end-if move ws-end-bal ws-rep-beg-bal compute ws-int-paid-m = ws-rep-beg-bal-m * ws-int-dec move ws-int-paid-m ws-int-paid compute ws-cur-prin-m = ws-rep-beg-bal-m - (ws-payment-tot - ws-int-paid-m) move ws-cur-prin-m ws-cur-prin compute ws-end-bal-m = ws-rep-beg-bal-m - ws-payment-tot move ws-end-bal-m ws-end-bal end-perform

you problem (perhaps not one) here:

compute ws-end-bal-m = ws-rep-beg-bal-m - ws-payment-tot

neither ws-rep-beg-bal-m nor ws-payment-tot changed within loop, reply going same, , loop can never terminate.

you can create things easier naming things better, paying attending how things coded , using things more naturally represent doing. instance:

compute ws-rep-beg-bal-m = ws-principal * (1+ws-int-dec) move ws-rep-beg-bal-m ws-rep-beg-bal move ws-principal ws-rep-beg-bal-m

is improve as

compute ws-rep-beg-bal = ws-principal * ( 1 + ws-int-dec) move ws-principal ws-rep-beg-bal-m

this named, without reader having total clue what:

ws-end-bal-m ws-rep-beg-bal-m ws-rep-beg-bal ws-end-bal

especially when things this:

move ws-end-bal ws-rep-beg-bal

also:

subtract this-monthly-amount outstanding-amount

is easier understand purpose than:

compute this-monthly-amount = this-monthly-amount - outstanding-amount

especially when scattered amongst computes doing other things.

combine of above, , have piece of code hard understand @ glance.

the "shortest code reproduce" has 2 intents: firstly, may find problem whilst doing it; secondly, helps else looking @ problem.

you have big fat loop, of import status controls loop. remove except affects starting value , how value gets modified. of import include info definitions. on occasion have needs signed, isn't.

ws-payment-tot not target field in 300-report. value determined elsewhere. pointed out in comments @julien mousset, if ever zero, , ever affects decrement in loop, have big fat loop. need see definition, , ws-payment-tot set, , whether perform of 300-report conditional on beingness non-zero.

similar ws-principal source of ws-rep-beg-bal-m.

now take out not command of loop.

300-report. move ws-principal ws-rep-beg-bal-m compute ws-end-bal-m = ws-rep-beg-bal-m - ws-payment-tot perform until ws-end-bal-m <= 0 display "here in bfl" compute ws-end-bal-m = ws-rep-beg-bal-m - ws-payment-tot end-perform

we can normalise utilize ws-principal in place of ws-rep-beg-bal-m.

300-report. compute ws-end-bal-m = ws-principal - ws-payment-tot perform until ws-end-bal-m <= 0 display "here in bfl" compute ws-end-bal-m = ws-principal - ws-payment-tot end-perform

in producing "shortest code reproduce" can see calculation within loop calculation initial value of loop. if ws-principal zero, loop never entered. if ws-principal = ws-payment-tot, loop never entered. other situations, loop bfl.

you have construction backwards.

it not thought set things "for next time". means doing unnecessary work, confusing reader, , making hard maintain programme unclear when fields can have processing safely changed.

write out lines first.

in loop, work subsequent detail lines (if there any) , write out @ lastly thing in loop.

you have no "pagination" logic. if have more number-of-lines-on-page of detail lines, going ugly, if 1 "whatever" printed per execution of program.

something this:

add together 1 ws-rep-mo if ws-rep-mo = 13 add together 1 ws-rep-year move 01 ws-rep-mo end-if

is improve as:

if ws-rep-mo = 12 add together 1 ws-rep-year move 1 ws-rep-mo else add together 1 ws-rep-mo end-if

now ws-rep-mo never becomes logically invalid.

even better, 88 on ws-rep-mo:

if ws-rep-prev-month-was-december add together 1 ws-rep-year move 1 ws-rep-mo else add together 1 ws-rep-mo end-if

now @ more obvious doing, , why.

where have code same, set in paragraph (or section if using those) , perform it. when code needs change, have 1 place alter it. give paragraph name, , can start "read" program.

you beginner cobol. if "patch up" go along, end horrible programme hard follow, hard maintain.

don't afraid start again. if possible, start working programme produces study , has pagination in it. set in high-level logic , 1 time proved, move on down.

we used design programs pencil , paper (usually on of old programme listing) run through design, pencil, paper , brain. transfer design "skeleton" programme basics of wanted. add together details, high low. @ each stage "desk-check" means through code again, pencil, paper , brain.

you utilize compiler spot typos. prepare those. clean compile, , you've done lot of stuff programme working.

doing you'll miss out on "oh rats!" moments when find after writing code have create major changes.

with experience, of process in head.

these days you're sitting in front end of pc. still recommend "paper , pencil" route, if implement utilize of pc.

if sit down downwards , write cobol program, patch testing fails, results not anyone.

i see posted whole programme originally.

you perform 100- within 100-. not good, if escape getting bfl (depends on compiler).

you taking info screen, typed human. must verify that.

using freeformat layout not exclude helping , else using indentation.

when testing must seek hard break program. otherwise user break first time out.

cobol cobol85

No comments:

Post a Comment