COBOL Positional Parameters

28 Jun

I’ve noticed some questions online about the use of positional parameters in COBOL.  Let me give you a quick example of how to use them.

Let’s say, for example, that you have a date in the format of MMDDYY (MonthDayYear), and you need to convert it to format CCYYMMDD (CenturyYearMonthDay).    You could do so with the following code:

So lets walk through this and see how it works…

For our example, we’ll assume that the value of OLD-DATE is 062514 (remember this is MMDDYY format, so this date represents June 25, 2014).   Our program moves the last two positions (positions 5 and 6) of OLD-DATE to positions 3 and 4 of NEW-DATE.   (The 5:2 means position 5 for a length of 2).   Next, it moves position 1 through 4 of OLD-DATE (MMDD) to positions 5 through 8 of NEW-DATE.   Lastly, we hard-code “20” in the first two positions of NEW-DATE.  Yes, I do hard-code centuries.  In the unlikely event that my program will still be in use at the turn of the 22nd century,  it will become someone else’s problem (and job security) at that point.

Leave a Reply

Your email address will not be published. Required fields are marked *