{"id":851,"date":"2012-08-02T13:22:47","date_gmt":"2012-08-02T13:22:47","guid":{"rendered":"http:\/\/www.gennard.net\/blog\/?p=851"},"modified":"2012-08-02T13:22:47","modified_gmt":"2012-08-02T13:22:47","slug":"reusing-cobol","status":"publish","type":"post","link":"http:\/\/www.gennard.net\/blog\/2012\/08\/reusing-cobol\/","title":{"rendered":"Re-using COBOL rather than converting it to C#"},"content":{"rendered":"<p>While reading a article on-line about using &#8220;<a href=\"http:\/\/www.semanticdesigns.com\/Products\/Services\/COBOLMigration.html\">NACA transcoder<\/a>&#8221; to translate COBOL into Java<br \/>\nit got me thinking about modernizing COBOL.   <\/p>\n<p>While I agree 100% about the actual code generated by the NACA transcoder is not<br \/>\nmaintainable, I disagree that converting it to C# helps you modernize the code is<br \/>\nthe only solution.<\/p>\n<p>Using Visual COBOL the same code can be cut-pasted into a Class that exposes itself<br \/>\nin the same way as the C# he produces.   Moving a legacy COBOL program into a Class<br \/>\nis just one way of reusing COBOL but in order to compare like with like, below is<br \/>\nthe actual COBOL Class.    This COBOL class can be compiled using Visual COBOL to<br \/>\na .Net assembly or Java bytecode.<\/p>\n<pre>class-id Example public.\r\n\r\nworking-storage section.\r\n01 COMPANY.\r\n 05 COMPANY-NAME        PIC X(60) VALUE \"Semantic Designs\".\r\n 05 COMPANY-ADDRESS.\r\n  10 STREET PIC X(80)    VALUE \"13171 Pond Springs Rd.\".\r\n  10 CITY.\r\n   15 CITY-NAME           PIC X(40) VALUE \"Austin\".\r\n   15 FILLER              PIC XX VALUE \", \".\r\n   15 CITY-STATE          PIC XX VALUE \"TX\".\r\n   15 ZIP.\r\n    20 ZIP-5              PIC 9(5) VALUE 78729.\r\n    20 FILLER             PIC X VALUE \"-\".\r\n    20 ZIP-E4             PIC 9(4) VALUE 7102.\r\n01 LINE-ITEM.\r\n 05 ITEM                  PIC X(20) VALUE \"Item Description\".\r\n 05 AMOUNT                PIC 999 VALUE 217.\r\n 05 PRICE                 PIC 9999V99 VALUE 24.95.\r\n\r\n77 TOTAL-AMOUNT           PIC 999999V99.\r\n77 DISCOUNT-THRESHOLD     PIC 999999V99 VALUE 1111.11.\r\n77 DISCOUNT-PERCENT       PIC 99 VALUE 20.\r\n77 DISCOUNT-AMOUNT        PIC 99999999V99.\r\n\r\n01 TOTAL-AMOUNT-FORMAT    PIC 999999.99.\r\n01 TotalAmount            string public.\r\n\r\nmethod-id ComputeTotal.\r\nprocedure division.\r\n  MULTIPLY AMOUNT BY PRICE GIVING TOTAL-AMOUNT.\r\n  IF TOTAL-AMOUNT &gt; DISCOUNT-THRESHOLD\r\n   MULTIPLY TOTAL-AMOUNT BY DISCOUNT-PERCENT\r\n    GIVING DISCOUNT-AMOUNT\r\n  DIVIDE 100 INTO DISCOUNT-AMOUNT\r\n  SUBTRACT DISCOUNT-AMOUNT FROM TOTAL-AMOUNT.\r\n\r\n  move TOTAL-AMOUNT to TOTAL-AMOUNT-FORMAT\r\n  set TotalAmount to TOTAL-AMOUNT-FORMAT\r\n goback.\r\nend method.\r\n\r\nmethod-id. DisplayTotal.\r\nprocedure division.\r\n DISPLAY COMPANY-NAME.\r\n DISPLAY \"Total: \", TOTAL-AMOUNT-FORMAT\r\nend method.\r\n\r\nmethod-id. PerformTask.\r\nprocedure division.\r\n invoke self::ComputeTotal()\r\n invoke self::DisplayTotal()\r\nend method.\r\n\r\nend class.<\/pre>\n<p>A C# program that uses the class above&#8230;.  the same can also be done with Java&#8230;<\/p>\n<pre>\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\n\r\nnamespace UseExample\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            new Example().PerformTask();\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n<p>Another approach would be keep the legacy COBOL and create a wrapper class<br \/>\nthat just uses the legacy COBOL.<\/p>\n<pre>\r\n       class-id Example2.\r\n\r\n       working-storage section.\r\n\r\n       method-id ComputeTotal.\r\n       procedure division.\r\n           call \"COMPUTE-TOTAL\".\r\n       goback.\r\n       end method.\r\n\r\n       method-id. DisplayTotal.\r\n       procedure division.\r\n           call \"DISPLAY-TOTAL\".\r\n       end method.\r\n       \r\n       method-id. PerformTask.\r\n       procedure division.\r\n           invoke self::ComputeTotal()\r\n           invoke self::DisplayTotal()\r\n       end method.\r\n\r\n       end class.\r\n<\/pre>\n<p>Then to make the DISPLAY-TOTAL, COMPUTE-TOTAL accessible to the class add two entry-points so<br \/>\nthey can be used with the CALL verb eg:<\/p>\n<pre>\r\n        EXTERNAL-EPS.\r\n          \r\n        ENTRY \"DISPLAY-TOTAL\".\r\n           PERFORM DISPLAY-TOTAL.\r\n           GOBACK.\r\n           \r\n        ENTRY \"COMPUTE-TOTAL\".\r\n           PERFORM COMPUTE-TOTAL.\r\n           GOBACK.\r\n<\/pre>\n<p>I personally think this it is quite a reasonable way to reuse COBOL&#8230;. plus the same code works under CLR<br \/>\nand JVM&#8230;. bonus&#8230;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While reading a article on-line about using &#8220;NACA transcoder&#8221; to translate COBOL into Java it got me thinking about modernizing COBOL. While I agree 100% about the actual code generated by the NACA transcoder is not maintainable, I disagree that &hellip; <a href=\"http:\/\/www.gennard.net\/blog\/2012\/08\/reusing-cobol\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[74,205,208,209,216,204,206,188],"_links":{"self":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/851"}],"collection":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/comments?post=851"}],"version-history":[{"count":26,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/851\/revisions"}],"predecessor-version":[{"id":877,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/851\/revisions\/877"}],"wp:attachment":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/media?parent=851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/categories?post=851"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/tags?post=851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}