UPPERCASE to lowercase with Cobol (oh yeah!)

What you say, why? Why not! It’s a good example of how easy it is to do this sort of processing in Cobol. This program prompts for the name of an ASCII file ( in uppercase) to be convert, and the name of the converted file. It then checks to see if the file exists, and if not, exits the program. IF the uppercase file does exist, it converts all UPPERCASE characters found to lowercase, line-by-line, using inspect, and then writes them to the output file.

*> Program to convert a program from UPPERCASE to lowercase

identification division.
program-id. conv2lower.

environment division.
input-output section.
file-control.
select input-file assign to dynamic fname-uc
              organization is line sequential
              file status is upperFS.
select output-file assign to dynamic fname-lc
              organization is line sequential
              file status is lowerFS.

data division.
file section.
fd input-file.
    01 sample-input pic x(80).
fd output-file. 
    01 output-line pic x(80).

working-storage section.
77 fname-uc      pic x(30).
77 fname-lc      pic x(30).
77 eof-switch    pic 9 value 1.
77 upperFS       pic xx.
77 lowerFS       pic xx.
77 answer        pic x.

01 input-area.
   02 line1      pic x occurs 80 times.
01 output-area.
   02 out-line   pic x(80).

procedure division.
    display "Input uppercase filename? ".
    accept fname-uc.
 
    open input input-file. 
    if upperFS not = "00" then
        if upperFS = "35" then
            display "File not found: ", fname-uc
            stop run
        end-if
    end-if.

    display "Output lowercase filename? ".
    accept fname-lc.
 
    open output output-file.
 
    read input-file into input-area 
        at end move zero to eof-switch
    end-read.
 
    perform proc-body
        until eof-switch is equal to zero.
 
    close input-file.
    close output-file.
 
    stop run.

proc-body.
    inspect input-area converting "ABCDEFGHIJKLMNOPQRSTUVWXYZ"            to "abcdefghijklmnopqrstuvwxyz".
 
     move input-area to out-line.
     write output-line from output-area.

     read input-file into input-area 
         at end move zero to eof-switch
     end-read.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s