Sitemap

Mainframe Database Programming Fundamentals 2

Intermediate Structured Programming

--

Press enter or click to view image in full size
Photo by Jack Gisel on Unsplash

This is a continuation of the previous post i.e. “Mainframe Database Programming Fundamentals — A structured programming approach”. This post highlights several variations of Program Control Structures and Program Modularization objects such as Program, Sub Program, Sub Routine and Function. The code examples are taken from the Nat914win official documentation (refer Nat914win fs-about).

(1) Variations of Program Control Structures

(1.1) IF SELECTION

The IF SELECTION statement is used to verify that in a sequence of alphanumeric fields one and only one contains a value (refer Nat914win ifselec).

** Example 'IFSEL': IF SELECTION                                        
************************************************************************
DEFINE DATA LOCAL
1 #A (A1)
1 #B (A1)
END-DEFINE
*
INPUT 'Select one function:' //
9X 'Function A:' #A
9X 'Function B:' #B
*
IF SELECTION NOT UNIQUE #A #B
REINPUT 'Please enter one function only.'
END-IF

*
IF #A NE ' '
WRITE 'Function A selected.'
END-IF
IF #B NE ' '
WRITE 'Function B selected.'
END-IF
*
END

(1.2) DECIDE ON

The DECIDE ON statement is used to specify multiple actions to be performed depending on the value (or values) contained in a variable (refer Nat914win decideon). There are two types of DECIDE ON that are (1) DECIDE ON FIRST VALUE and (2) DECIDE ON EVERY VALUE.

DECIDE ON FIRST VALUE:

** Example 'DECEX3': DECIDE ON (with FIRST option)                      
************************************************************************
*
SET KEY ALL
INPUT 'Enter any PF key' /
'and check result' /
*
DECIDE ON FIRST VALUE OF *PF-KEY
VALUE 'PF1'
WRITE 'PF1 key entered.'
VALUE 'PF2'
WRITE 'PF2 key entered.'
ANY VALUE
WRITE 'PF1 or PF2 key entered.'
NONE VALUE
WRITE 'Neither PF1 nor PF2 key entered.'
END-DECIDE

*
END

DECIDE ON EVERY VALUE:

** Example 'DECEX4': DECIDE ON (with EVERY option)                      
************************************************************************
DEFINE DATA LOCAL
1 #FIELD (N1)
END-DEFINE
*
INPUT 'Enter any value between 1 and 9:' #FIELD (SG=OFF)
*
DECIDE ON EVERY VALUE OF #FIELD
VALUE 1 : 4
WRITE 'Content of #FIELD is 1-4'
VALUE 2 : 5
WRITE 'Content of #FIELD is 2-5'
ANY VALUE
WRITE 'Content of #FIELD is 1-5'
ALL VALUE
WRITE 'Content of #FIELD is 2-4'
NONE VALUE
WRITE 'Content of #FIELD is not 1-5'
END-DECIDE

*
END

(1.3) DECIDE FOR

Get Mohamad Mahmood’s stories in your inbox

Join Medium for free to get updates from this writer.

The DECIDE FOR statement is used to decide for one or more actions depending on multiple conditions (cases) (refer Nat914win decidefo). There are two types of DECIDE FOR that are (1) DECIDE FOR FIRST CONDITION and (2) DECIDE FOR EVERY CONDITION.

DECIDE FOR FIRST CONDITION:

** Example 'DECEX1': DECIDE FOR (with FIRST option)                     
************************************************************************
DEFINE DATA LOCAL
1 #FUNCTION (A1)
1 #PARM (A1)
END-DEFINE
*
INPUT #FUNCTION #PARM
*
DECIDE FOR FIRST CONDITION
WHEN #FUNCTION = 'A' AND #PARM = 'X'
WRITE 'Function A with parameter X selected.'
WHEN #FUNCTION = 'B' AND #PARM = 'X'
WRITE 'Function B with parameter X selected.'
WHEN #FUNCTION = 'C' THRU 'D'
WRITE 'Function C or D selected.'
WHEN NONE
REINPUT 'Please enter a valid function.'
MARK *#FUNCTION
END-DECIDE
*
END

DECIDE FOR EVERY CONDITION:

** Example 'DECEX2': DECIDE FOR (with EVERY option)                     
************************************************************************
DEFINE DATA LOCAL
1 #FIELD1 (N5.4)
END-DEFINE
*
INPUT #FIELD1
*
DECIDE FOR EVERY CONDITION
WHEN #FIELD1 >= 0
WRITE '#FIELD1 is positive or zero.'
WHEN #FIELD1 <= 0
WRITE '#FIELD1 is negative or zero.'
WHEN FRAC(#FIELD1) = 0
WRITE '#FIELD1 has no decimal digits.'
WHEN ANY
WRITE 'Any of the above conditions is true.'
WHEN ALL
WRITE '#FIELD1 is zero.'
WHEN NONE
IGNORE
END-DECIDE
*
END

(2) Program Modularization objects

Most computer applications usually do not consist of a single huge program, but is split into several object modules which are connected to each others in a clearly defined way (refer Nat914win pg_obj_pgm_routine). The following example (refer Nat914win fs-exstub) demonstrates the decomposition of a Program into separate objects such as Sub Program, Sub Routine, Map, DDM, Global Data and Local Data.

(File name: PGM01.NSP)

DEFINE DATA
GLOBAL USING GDA01
LOCAL USING LDA01
END-DEFINE
*
RP1. REPEAT
*
INPUT USING MAP 'MAP01'
*
IF #NAME-START = '.' THEN
ESCAPE BOTTOM (RP1.)
END-IF
*
IF #NAME-END = ' ' THEN
MOVE #NAME-START TO #NAME-END
END-IF
*
RD1. READ EMPLOYEES-VIEW BY NAME
STARTING FROM #NAME-START
ENDING AT #NAME-END
*
IF LEAVE-DUE >= 20 THEN
PERFORM MARK-SPECIAL-EMPLOYEES
ELSE
RESET #MARK
END-IF
*
RESET #MAKE #MODEL
CALLNAT 'SPGM01' PERSONNEL-ID #MAKE #MODEL
*
WRITE TITLE
/ '*** PERSONS WITH 20 OR MORE DAYS LEAVE DUE ***'
/ '*** ARE MARKED WITH AN ASTERISK ***'//
*
DISPLAY 1X '//N A M E' NAME
1X '//DEPT' DEPT
1X '/LV/DUE' LEAVE-DUE
' ' #MARK
1X '//MAKE' #MAKE
1X '//MODEL' #MODEL
*
END-READ
*
IF *COUNTER (RD1.) = 0 THEN
REINPUT 'No employees meet your criteria.'
END-IF
*
END-REPEAT
*
END

The above example shows how a database application program is developed based on Structured Programming approach with emphasis on the Program Modularization technique. Nowadays, most applications are running through Client-Server architecture which requires them to be separated into Server-Side and Client-Side codes. The Server-Side codes manage the database and application logic while the Client-Side codes manage the content presentation. The performance of the Server-Side codes are evaluated based on how they respond to the requests that come from the Client-Side codes. On the other hand, the performance of the Client-Side codes are evaluated based on how they provide seamless interaction between the front end users and the back end systems. The introduction of AJAX has enhanced the performance of Client-Side codes (refer Kluge 2007).

To be continued in the next part.

--

--

Mohamad Mahmood
Mohamad Mahmood

Written by Mohamad Mahmood

Programming (Mobile, Web, Database and Machine Learning). Learned life lessons at the Center for Artificial Intelligence Technology (CAIT), FTSM, UKM, Malaysia.