Program Design -- art or science?

Given a problem, some programmers start coding immediately.  Without  proper planning, many are destined to spend substantial time going from one debugging session to another.

The larger the problem becomes, the harder it is to know all the details of its solution before coding.

----------------------------------------------------------------------------------------------------------
The art/science of program design involves the process of planning what is going to be coded before coding starts.

Since the program code represents the solution to a problem, what is needed is

The process of program design is to decompose a large complex problem to a series of smaller problems that are easier to understand and to code.

Since large problems are harder to solve than small ones, analysis of the problem is required to partition a large problem into a series of smaller parts.

----------------------------------------------------------------------------------------------------------
Each program part should

The program parts are usually called modules. In COBOL, module is a term which could refer to either a paragraph, program, or subprogram.

----------------------------------------------------------------------------------------------------------

Structured Program Design requires that the modules are
 

----------------------------------------------------------------------------------------------------------
Modules  -- should have a single, unique task.

Based on the principle that its hard to maintain what you don't see, COBOL paragraphs should be less than 24 lines long for TSO or less than 60 lines if maintained from printouts.

----------------------------------------------------------------------------------------------------------
The basic structure of a Program has both procedural and hierarchical characteristics.

Procedural characteristics define the order that governs processing,

    x happens first, then y, and so on.

A program hierarchy is like an organization chart that defines the rank of the various program modules.
 

----------------------------------------------------------------------------------------------------------
Why use Top-Down, stepwise refinement?

The larger a program gets, the more important it is to break the program into small independent subroutines. It is easier to solve small programming problems than large ones.
 

----------------------------------------------------------------------------------------------------------
How is a Top-Down strategy applied?
  ----------------------------------------------------------------------------------------------------------
Suggested steps for top-down program design:

1) Define the high-level structure.

    Virtually all applications have three processing functions

    Initiate, Application_Purpose(s), Terminate.

    Identify the one or more major purpose(s) of the program.
    Each purpose requires its own hierarchical control structure.
    What is going to happen to a record?  Will it be added,
    deleted, modified or reported, etc.?

2)  Keep factoring the Initiate, Application _Purpose and Terminate
    functions into more detailed, lower-level functions which cannot
    be further factored.

    Detailed Initiate functions can include:
    building and loading tables
    defining constants and accumulators
    opening files
    file merging or sorting
    printing report headings
    displaying (main) menu
    get the first input record

    Detailed Application _Purpose functions can include:
    edit input records
    get a secondary record
    perform calculations
    make decisions
    accumulate totals
    write a detail line
    write a complete record
    create control breaks (headings/footings)
    get the next record
    redisplay a menu
 
    Detailed Terminate Processing functions can include:
    calculating control totals
    printing control totals
    closing files

3) Add the procedural step details necessary to accomplish the tasks.

 ----------------------------------------------------------------------------------------------------------
Structure Charts

A structure chart graphically portrays how a program is partitioned into modules and shows the control structure relationship among the modules.
----------------------------------------------------------------------------------------------------------
Notation conventions for structured charts

Module - represented by a rectangular box with a name inside.

Modules:

Types of modules:
  ----------------------------------------------------------------------------------------------------------
Connection -- a line joining two modules shows a "call" or "perform" from one module to another.

A ---> B   Means that A calls B

After B does its function, it returns control to A.
 
What can be deduced from the code in A and B from knowledge that A calls B?  Do you know how many times the call with occur?
----------------------------------------------------------------------------------------------------------
Pseudo code --

    an attempt by the programmer to plan the step by step instructions for
    accomplishing a task by using code that almost looks like COBOL.
    There are NO rules regarding what is good pseudo-code.
----------------------------------------------------------------------------------------------------------
Flowchart --

    A diagram frequently used to help explain the function of a program to
    someone else.  I have never seen a good programmer use flowcharts to
    help design a program.

    I DO NOT RECOMMEND FLOWCHARTS AS PART OF THE PROGRAM PLANNING PROCESS!
    I believe flowcharts are a waste of time for planning.
----------------------------------------------------------------------------------------------------------
MOVE statement:

    MOVE Field-1 TO Field-2 (...)
 
 

When the MOVE operation is completed, both field-1 and field-2 contain the same value.

----------------------------------------------------------------------------------------------------------
Elementary MOVE

The receiving and sending items have a PIC clause or the sending item is a literal.

In order to do the MOVE correctly, the computer must check the attributes of the sending and receiving fields to determine if any data requires change to a different format.

----------------------------------------------------------------------------------------------------------
NUMERIC MOVES

The data is aligned on the assumed decimal point and, if necessary,        truncated or padded with zeros.
 
 The integer portion of the sending field is moved to the integer portion of  the receiving field.  The digits are transferred from left to right.

 The decimal portion of the sending field is moved to the decimal portion of  the receiving field.  The digits are transferred from right to left.

----------------------------------------------------------------------------------------------------------
Given the following fields

FIELD-1 PICTURE 9999V9.
FIELD-2 PICTURE 999.
FIELD-3 PICTURE 99999.
FIELD-4 PICTURE 9999V99.
FIELD-5 PICTURE 99V9.
FIELD-6 PICTURE $$$.99

WHAT are the contents of the fields based on the subsequent MOVEs

 MOVE 1000.8 to FIELD-1.

 MOVE FIELD-1 TO  FIELD-2,
    FIELD-3,
    FIELD-4,
    FIELD-5,
    FIELD-6.

----------------------------------------------------------------------------------------------------------
NONNUMERIC OR ALPHANUMERIC MOVE

When the receiving field has a PICTURE of X's or A's or is a group item, data is normally moved from left to right unless the JUSTIFIED clause is specified for an elementary move.

Given the following items,

FIELD-1 PICTURE XXXX.
FIELD-2 PICTURE XX.
FIELD-3 PICTURE XXXXX.
FIELD-4 PICTURE XXXXX JUSTIFIED RIGHT.
 
MOVE 'ABC' TO FIELD-1

MOVE FIELD-1 TO  FIELD-2
   FIELD-3
   FIELD-4.

----------------------------------------------------------------------------------------------------------

Programs 2 through 2D in Supplementary Materials for COBOL & CICS

----------------------------------------------------------------------------------------------------------

WRITE rec FROM identifier AFTER identifier

Is the same as

MOVE identifier to rec
WRITE rec AFTER identifier

----------------------------------------------------------------------------------------------------------
Use this

007500     WRITE OUT-REC FROM HEADER-ONE AFTER PAGE.
007600     WRITE OUT-REC FROM HEADER-TWO AFTER 1.
007700     WRITE OUT-REC FROM HEADER-ONE AFTER 1.

Or use this

7500 MOVE HEADER-ONE TO OUT-REC
7501 WRITE OUT-REC AFTER PAGE.
7502 MOVE HEADER-TWO TO OUT-REC
7503 WRITE OUT-REC AFTER 1.
7504 MOVE HEADER-ONE TO OUT-REC
7505 WRITE OUT-REC AFTER 1

----------------------------------------------------------------------------------------------------------
Sequence for sending mainframe assignments to John via email.

1)     Submit your JCL.
2)     Go to SDSF (L2.H)
3)     Select your output
4)     If the output looks good enough for grading
       type "KEYS" on the command line
5)     Make sure your PF23 key has the following assignment.
       PF23 . . prt odsn csc.printout; prt; prt close
       If it doesn't, type the commands into PF23 and press ENTER
6)     PF3 from the KEYS display
7)     Press the PF23 key (Shift PF11)
8)     Browse your CCPDxx.CSC.PRINTOUT file on the mainframe
       with =1 to be sure it has the data you want graded.
9)     Logon to Shrike.
10)    Ask for ftp connection to moses
       shrike% ftp moses.cs.depaul.edu
11)    Logon to moses with your mainframe logon-ID
       Name (moses.cs.depaul.edu:jpetlick): ccpdxx <-- where xx is your nbr
12)    Password: ______  <-- use your mainframe password
13)    ftp> get csc.printout <-- copy your printout to shrike
14)    ftp> quit   <-- exit the ftp hookup
15)    To browse the dataset use 'pg csc.printout'
16)    If you want the dataset graded, mail it to me.
       shrike% mail jpetlick@condor.depaul.edu < csc.printout
 

All assignments mailed to me get a grade.  Grades cannot be improved with subsequent submissions of the same assignment.  Each subsequent submission of the same assignment gets a two point penalty (-2).