home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 263,863 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All   
   Re: And so? (VMS/XDE) (1/2)   
   01 Dec 25 20:14:15   
   
   From: arne@vajhoej.dk   
      
   On 12/1/2025 8:06 PM, Arne Vajhøj wrote:   
   > There is also something in the Cobol language.   
   >   
   > Large files with one data division, lots of paragraphs   
   > and lots of perform's is easy to code, but it is also   
   > bad for reusable code.   
   >   
   > It is sort of the same as having large C or Pascal files   
   > with all variables global and all functions/procedures   
   > without arguments.   
   >   
   > It is possible to do it right, but when people have   
   > to chose between the easy way and the right way, then ...   
      
   And a long post to illustrate.   
      
   $ type m1.cob   
   identification division.   
   program-id.m1.   
   *   
   data division.   
   working-storage section.   
   01 ia.   
       03 ia-elm pic 9(8) comp occurs 5 times.   
   01 bia.   
       03 bia-elm pic 9(8) comp occurs 7 times.   
   01 xa.   
       03 xa-elm comp-2 occurs 5 times.   
   01 i pic 9(8) comp.   
   01 j pic 9(8) comp.   
   01 startj pic 9(8) comp.   
   01 temp-ia-elm pic 9(8) display.   
   01 temp-bia-elm pic 9(8) display.   
   01 temp-xa-elm pic 9(8)v9(2) display.   
   01 temp-i pic 9(8) display.   
   01 temp-ia pic 9(8) comp.   
   01 temp-bia pic 9(8) comp.   
   01 temp-xa comp-2.   
   *   
   procedure division.   
   main-paragraph.   
        move 3 to ia-elm(1)   
        move 5 to ia-elm(2)   
        move 7 to ia-elm(3)   
        move 6 to ia-elm(4)   
        move 4 to ia-elm(5)   
        display "Before:"   
        perform print-ia   
        perform sort-ia   
        display "After:"   
        perform print-ia   
        move 3 to bia-elm(1)   
        move 5 to bia-elm(2)   
        move 7 to bia-elm(3)   
        move 6 to bia-elm(4)   
        move 4 to bia-elm(5)   
        move 2 to bia-elm(6)   
        move 8 to bia-elm(7)   
        display "Before:"   
        perform print-bia   
        perform sort-bia   
        display "After:"   
        perform print-bia   
        move 3.3 to xa-elm(1)   
        move 5.5 to xa-elm(2)   
        move 7.7 to xa-elm(3)   
        move 6.6 to xa-elm(4)   
        move 4.4 to xa-elm(5)   
        display "Before:"   
        perform print-xa   
        perform sort-xa   
        display "After:"   
        perform print-xa   
        stop run.   
   sort-ia.   
        perform varying i from 1 by 1 until i >= 5   
            compute startj = i + 1   
            perform varying j from startj by 1 until j > 5   
                if ia-elm(j) < ia-elm(i) then   
                    move ia-elm(j) to temp-ia   
                    move ia-elm(i) to ia-elm(j)   
                    move temp-ia to ia-elm(i)   
                end-if   
            end-perform   
        end-perform.   
   print-ia.   
        perform varying i from 1 by 1 until i > 5   
            move i to temp-i   
            move ia-elm(i) to temp-ia-elm   
            display temp-i " : " temp-ia-elm   
        end-perform.   
   sort-bia.   
        perform varying i from 1 by 1 until i >= 7   
            compute startj = i + 1   
            perform varying j from startj by 1 until j > 7   
                if bia-elm(j) < bia-elm(i) then   
                    move bia-elm(j) to temp-bia   
                    move bia-elm(i) to bia-elm(j)   
                    move temp-bia to bia-elm(i)   
                end-if   
            end-perform   
        end-perform.   
   print-bia.   
        perform varying i from 1 by 1 until i > 7   
            move i to temp-i   
            move bia-elm(i) to temp-bia-elm   
            display temp-i " : " temp-bia-elm   
        end-perform.   
   sort-xa.   
        perform varying i from 1 by 1 until i >= 5   
            compute startj = i + 1   
            perform varying j from startj by 1 until j > 5   
                if xa-elm(j) < xa-elm(i) then   
                    move xa-elm(j) to temp-xa   
                    move xa-elm(i) to xa-elm(j)   
                    move temp-xa to xa-elm(i)   
                end-if   
            end-perform   
        end-perform.   
   print-xa.   
        perform varying i from 1 by 1 until i > 5   
            move i to temp-i   
            move xa-elm(i) to temp-xa-elm   
            display temp-i " : " temp-xa-elm   
        end-perform.   
   $ cob M1   
   $ link M1   
   $ run M1   
   Before:   
   00000001 : 00000003   
   00000002 : 00000005   
   00000003 : 00000007   
   00000004 : 00000006   
   00000005 : 00000004   
   After:   
   00000001 : 00000003   
   00000002 : 00000004   
   00000003 : 00000005   
   00000004 : 00000006   
   00000005 : 00000007   
   Before:   
   00000001 : 00000003   
   00000002 : 00000005   
   00000003 : 00000007   
   00000004 : 00000006   
   00000005 : 00000004   
   00000006 : 00000002   
   00000007 : 00000008   
   After:   
   00000001 : 00000002   
   00000002 : 00000003   
   00000003 : 00000004   
   00000004 : 00000005   
   00000005 : 00000006   
   00000006 : 00000007   
   00000007 : 00000008   
   Before:   
   00000001 : 0000000330   
   00000002 : 0000000550   
   00000003 : 0000000770   
   00000004 : 0000000660   
   00000005 : 0000000440   
   After:   
   00000001 : 0000000330   
   00000002 : 0000000440   
   00000003 : 0000000550   
   00000004 : 0000000660   
   00000005 : 0000000770   
   $ type lib2.cob   
   identification division.   
   program-id.sort-i.   
      
   data division.   
   working-storage section.   
   01 i pic 9(8) comp.   
   01 j pic 9(8) comp.   
   01 startj pic 9(8) comp.   
   01 temp-ia pic 9(8) comp.   
   linkage section.   
   01 n-ia pic 9(8) comp.   
   01 ia.   
       03 ia-elm pic 9(8) comp occurs 0 to 1000 times depending on n-ia.   
      
   procedure division using n-ia, ia.   
   main-paragraph.   
        perform varying i from 1 by 1 until i >= n-ia   
            compute startj = i + 1   
            perform varying j from startj by 1 until j > n-ia   
                if ia-elm(j) < ia-elm(i) then   
                    move ia-elm(j) to temp-ia   
                    move ia-elm(i) to ia-elm(j)   
                    move temp-ia to ia-elm(i)   
                end-if   
            end-perform   
        end-perform.   
   end program sort-i.   
   ****   
   identification division.   
   program-id.print-i.   
      
   data division.   
   working-storage section.   
   01 i pic 9(8) comp.   
   01 temp-ia-elm pic 9(8) display.   
   01 temp-i pic 9(8) display.   
   linkage section.   
   01 n-ia pic 9(8) comp.   
   01 ia.   
       03 ia-elm pic 9(8) comp occurs 0 to 1000 times depending on n-ia.   
      
   procedure division using n-ia, ia.   
   main-paragraph.   
        perform varying i from 1 by 1 until i > n-ia   
            move i to temp-i   
            move ia-elm(i) to temp-ia-elm   
            display temp-i " : " temp-ia-elm   
        end-perform.   
   end program print-i.   
   ****   
   identification division.   
   program-id.sort-x.   
      
   data division.   
   working-storage section.   
   01 i pic 9(8) comp.   
   01 j pic 9(8) comp.   
   01 startj pic 9(8) comp.   
   01 temp-xa comp-2.   
   linkage section.   
   01 n-xa pic 9(8) comp.   
   01 xa.   
       03 xa-elm comp-2 occurs 0 to 1000 times depending on n-xa.   
      
   procedure division using n-xa, xa.   
   main-paragraph.   
        perform varying i from 1 by 1 until i >= n-xa   
            compute startj = i + 1   
            perform varying j from startj by 1 until j > n-xa   
                if xa-elm(j) < xa-elm(i) then   
                    move xa-elm(j) to temp-xa   
                    move xa-elm(i) to xa-elm(j)   
                    move temp-xa to xa-elm(i)   
                end-if   
            end-perform   
        end-perform.   
   end program sort-x.   
   ****   
   identification division.   
   program-id.print-x.   
      
   data division.   
   working-storage section.   
   01 i pic 9(8) comp.   
   01 temp-xa-elm pic 9(8)v9(2) display.   
   01 temp-i pic 9(8) display.   
   linkage section.   
   01 n-xa pic 9(8) comp.   
   01 xa.   
       03 xa-elm comp-2 occurs 0 to 1000 times depending on n-xa.   
      
   procedure division using n-xa, xa.   
   main-paragraph.   
        perform varying i from 1 by 1 until i > n-xa   
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca