{"id":143,"date":"2009-11-10T21:51:06","date_gmt":"2009-11-10T20:51:06","guid":{"rendered":"http:\/\/www.gennard.net\/blog\/?p=143"},"modified":"2009-11-10T21:51:06","modified_gmt":"2009-11-10T20:51:06","slug":"too-iterate-or-not","status":"publish","type":"post","link":"http:\/\/www.gennard.net\/blog\/2009\/11\/too-iterate-or-not\/","title":{"rendered":"Too Iterate or not&#8230;"},"content":{"rendered":"<p>Over the next couple of weeks, I will explore some of the reasons why I think managed environments are good for COBOL.<\/p>\n<p>So.. lets the show on the road&#8230;<\/p>\n<p>Setting up arrays\/occurs items in COBOL and manipulating them can be painful.  Lets look at some traditional code for playing around with a &#8220;months&#8221; table.<\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n       01 month-val.<br \/>\n           05  FILLER                    PIC X(10)  value \"January\".<br \/>\n           05  FILLER                    PIC X(10)  value \"February\".<br \/>\n           05  FILLER                    PIC X(10)  value \"March\".<br \/>\n           05  FILLER                    PIC X(10)  value \"April\".<br \/>\n           05  FILLER                    PIC X(10)  value \"May\".<br \/>\n           05  FILLER                    PIC X(10)  value \"June\".<br \/>\n           05  FILLER                    PIC X(10)  value \"July\".<br \/>\n           05  FILLER                    PIC X(10)  value \"August\".<br \/>\n           05  FILLER                    PIC X(10)  value \"September\".<br \/>\n           05  FILLER                    PIC X(10)  value \"October\".<br \/>\n           05  FILLER                    PIC X(10)  value \"November\".<br \/>\n           05  FILLER                    PIC X(10)  value \"December\".<\/p>\n<p>       01 month-tab redefines month-val.<br \/>\n           05  months occurs 12 times.<br \/>\n               10  month-NAME            PIC X(10).<\/p>\n<p>       01 month                          PIC 99.<\/p>\n<p>       01 secondQuarterMonths            pic x(70).<\/p>\n<p>       display \"The months are:\"<br \/>\n       perform varying month from 1 by 1 until month equals 12<br \/>\n         display \" \" months(month)<br \/>\n       end-perform<\/p>\n<p>       display \" \"<br \/>\n       display \"The second quarter months are: \"<\/p>\n<p>       string months(4) delimited by space<br \/>\n              \"\/\" delimited by size<br \/>\n              months(5) delimited by space<br \/>\n              \"\/\" delimited by size<br \/>\n              months(6) delimited by space<br \/>\n          into secondQuarterMonths<br \/>\n          on overflow<br \/>\n             display \"FATAL Error - secondQuarterMonths is too small\"<br \/>\n             stop run<br \/>\n       end-string<\/p>\n<p>       display \" \" secondQuarterMonths<br \/>\n<\/code><\/p>\n<p>Now, imagine we can use one or two of the .Net&#8217;s base class libraries combined with some nifty natural extensions to COBOL to do some of the heavy lifting.<\/p>\n<p>Defining the month item as a native .Net type ie: a string combined with using the base class libraries Split methods allows us to setup a array quickly.<\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n        01 commaDelimited       string value<br \/>\n         \"January,February,March,April,May,June,July,August,\" &<br \/>\n         \"September,October,November,December\".<\/p>\n<p>        01 months              string occurs any.<br \/>\n        01 month               string.<\/p>\n<p>        01 secondQuarterMonths  string.<\/p>\n<p>        set months to commaDelimited::\"Split\"(',')<\/p>\n<p>        display \"The months are: \"<br \/>\n        perform varying month through months<br \/>\n          display \" \" month<br \/>\n        end-perform<\/p>\n<p>        display \" \"<br \/>\n        display \"The second quarter months are: \"<\/p>\n<p>        set secondQuarterMonths to type \"System.String\"::\"Join\"('\/', months, 3, 3)<\/p>\n<p>        display \" \" secondQuarterMonths<br \/>\n<\/code><\/p>\n<p>The .Net version, besides being smaller feels much easier to read, especially if you have any exposure to the .Net base class library from other languages such as C# or VB.Net.<\/p>\n<p>Of course in a real world example, we don&#8217;t need to use the split method to setup an array, we could just use the &#8220;values&#8221; clause&#8230; for example:<\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n      01 months  string occurs 12 values<br \/>\n         \"January\" \"February\" \"March\" \"April\" \"May\" \"June\"<br \/>\n         \"July\" \"August\" \"September\" \"October\" \"November\" \"December\".<\/p>\n<p>       01 month string.<\/p>\n<p>           perform varying month through months<br \/>\n               display month<br \/>\n           end-perform<br \/>\n<\/code><\/p>\n<p>If however you don&#8217;t want to hardcode the months, you can always use: CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName() in the System.Globalization namespace. \ud83d\ude42<\/p>\n<p>So&#8230; lets just do it&#8230;<\/p>\n<p><code lang=\"cobol\" width=\"800\" lines=\"-1\" nowrap=\"0\"><br \/>\n       01 Months string occurs any.<br \/>\n       01 Month string.<\/p>\n<p>       set Months to type \"System.Globalization.DateTimeFormatInfo\"::<br \/>\n          \"CurrentInfo\"::\"MonthNames\"<\/p>\n<p>       perform varying Month through Months<br \/>\n          display Month<br \/>\n       end-perform<br \/>\n<\/code><\/p>\n<p>Now, I hope you feel like I do that COBOL and .Net are indeed perfect partners to each other.<\/p>\n<hr>\n<p>The above COBOL .Net code will execute on Micro Focus Net Express and I suspect it will also work on Fujitsu&#8217;s netCobol too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the next couple of weeks, I will explore some of the reasons why I think managed environments are good for COBOL. So.. lets the show on the road&#8230; Setting up arrays\/occurs items in COBOL and manipulating them can be &hellip; <a href=\"http:\/\/www.gennard.net\/blog\/2009\/11\/too-iterate-or-not\/\">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,32],"tags":[69,208,209,117],"_links":{"self":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/143"}],"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=143"}],"version-history":[{"count":0,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/143\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/media?parent=143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/categories?post=143"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/tags?post=143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}