Business Programming Language
Part Two - Challenge #15

Background:

You use computer programs many times a day. Each time you use your cell phone or access the internet, you are executing computer programs. The vast majority of the time you pay for something, computer programs are being executed. 92% of money is digital, meaning the money is controlled by computers. Only 8% of money is physical coins and paper.

Computer programs are computer instructions and programming languages are used to create the computer programs. Understanding computer programming languages is a fundamental skill in today's highly digitized world. Experienced computer programmers know after learning the first computer programming language, it is increasingly easy to learn and use other computer programming languages.

One programming language was designed specifically for business, COBOL, COmmon Business-Oriented Language. COBOL is one of the early programming languages. COBOL programming language continually improved over decades as did the business logic written in COBOL. COBOL code is processing some of the worlds most critical data every day. COBOL was tailor made for processing critical back-end data. The benefit of knowing this programming language is the ability to understand the critical day to day business logic implemented by employees probably long retired from a company.

During the past few decades, several major programming languages emerged with the internet, such as Java, Java Script, C/C++, Python, etc. These programming languages and the internet are tailor made for each other just as COBOL was tailor made for processing back-end critical data. Newer programming languages, such as SWIFT and GO, continue to emerge with the emergence of internet devices and blockchain.

Each of these programming languages are important in the technology area they best serve. A highly experienced application developer will take the time to thoroughly understand the critical back-end programs to write highly efficient front-end programs. Quite often, a minor change to back-end programs can make front-end programs much simpler to write and maintain while being significantly more efficient. An example would be a mobile phone program that communicates with a mainframe program to check a bank balance where the front-end mobile phone is written in Java Script or SWIFT and the back-end mainframe program is written in COBOL.

COBOL programming language is an excellent starting place to learn how to create computer programs.

Reasons include:

  • Easy to read and maintain as a result of English-like syntax
  • Emphasis on inputs and outputs
  • Split into logical sections called Divisions
      Define program inputs and outputs
      Declare program variables
      Business logic using the above inputs, outputs, and variables
  • Program syntax is compiled validating the syntax prior to execution
      Compiled programs are more efficient for high volume and high frequency processing
      Re-compile is only required when source code needs to be changed
  • Large Enterprise employers have lots of critical COBOL programs
      COBOL on a resume is attention getting and could help get that interview
      Employers are aware it is a mistake to re-write highly efficient COBOL into a different programming language
      Employers are aware it is relatively easy to web enable back-end COBOL processing without making program changes
There are over 220 billion lines of COBOL programs running today, which equates to around 80% of the world's actively used code. z/OS on the mainframe can run COBOL programs written for previous generation operating systems as well as today's 64 bit operating systems without requiring a recompile of the programs which is a huge benefit to large enterprises with applications that run 24 hours a day, 7 days a week.

The contest system will use the latest release of COBOL. Enterprise COBOL for z/OS, V6.1 continues the IBM commitment to COBOL on z/OS. Companies gain the benefit of new investment combined with more than 50 years of IBM experience in compiler development. This allows new code and recompiles of existing code to exploit hardware efficiencies introduced with state-of-the-art mainframes.

This challenge uses COBOL programming language to demonstrate fundamental programming skills. All programming languages can accomplish the same computer instructions using different syntax. If all programming languages can accomplish the same computer instructions just using different syntax, then why so many different programming languages? If you are interested in an answer to the question, then please read a brief explanation posted in stackoverflow below:

Why are there so many programming languages?.

Challenge Preparation:

The challenge is to correct an existing COBOL syntax problem, then enhance the same COBOL program.

NOTE: If you already have some experience with COBOL or you just want to try to complete the challenge without preparation, then go for it. If you struggle with completing the challenge, then please review the challenge preparation.

In Part 3, some of the challenges include COBOL. The Part 3 challenges will assume knowledge of challenge preparation below.

The following will prepare you to accomplish the challenge.
So, if you do not review this now and you decide to tackle Part 3, then remember this is here to review later as needed.

  1. Compile COBOL programming language into executable program that writes a single line
  2. Review simple read and write
  3. Review simple read numbers, add numbers and write the sum
  4. Review simple character string read, move character string operation, and write the moved character string
  5. Review simple read from data set name and write to different data set name
  6. Review boolean logic using COBOL IF/THEN/ELSE and EVALUATE
  7. Review do loop iteration and transfer control processing using COBOL PERFORM
  8. Review iteration processing to read and change a stream of records using COBOL PERFORM
  9. Review COBOL compile syntax error and correction using intrinsic function capability
  10. Review COBOL string capability
  11. IBM Enterprise COBOL professional documentation

To accomplish the above challenge preparation, you will be given explicit instructions to follow and you will be directed to a different web site to read an explanation.

  1. Compile COBOL programming language into executable program that writes a single line
    tso submit 'zos.mtm2017.public.cobol(cbl1)'

    =sd ; owner your_id ; st

    sj to the left of CBL1

    Observe the following:
    • JCL PROCEDURE, IGYWCLG, used to compile the in-stream COBOL program language statements
        create executable program a.k.a. "link edit", and run (execute) the program

    NOTE: Use Function Key 3, F3 , as needed to exit and return to previous panels.
    Review output using SDSF ST panel as follows:

    ? to the left of CBL1
    Observe 6 DDNAMEs in CBL1 output
    JESMSGLG - JCL job return code for each of 3 JCL steps COBOL (compile), LKED (link edit), GO (run)
    JESJCL - expanded JCL from IGYWCLG PROCEDURE
    JESYSMSG - system message associated with job execution
    SYSPRINT (COBOL - ProcStep) - COBOL program language compile output
    SYSPRINT (LKED - ProcStep) - create executable program
    SYSOUT (GO - ProcStep) - output from program execution
    select s each DDNAME above and review the DDNAME output

    =sd ; st

    sj to the left of CBL1
    Observe COBOL programming source code to DISPLAY literal characters

    Note: If the command input area is not long enough to enter desired tso submit command, navigate back to the SJ panel, or to ISPF option 6 (ISPF command shell) to enter command. From ISPF option 6 (ISPF command shell), prefixing the submit command with TSO is optional. In fact a command such as submit entered without TSO will be remembered on the ISPF command shell and can be used later retrieved for optional modification and reexecution.
  2. Review simple read and write
    tso submit 'zos.mtm2017.public.cobol(cbl2)'

    =sd ; st

    sj to the left of CBL2

    Observe the following:
    • DATA DIVISION and WORKING STORAGE SECTION are used to define a program variable data field, DATA-RECORD, to store the ACCEPTed value and DISPLAY content in the variable field
    • The declared data type, PIC X(80), is a picture clause where X means character format and 80 is the length of the data field.

    Review information about COBOL program structure at URL below
      Thanks to University of Limerick for an excellent description
      Scroll forward in the link below - start reading at COBOL coding rules
    COBOL Program Structure from University of Limerick

    Review information about COBOL basic syntax at URL below
    COBOL Basic Syntax

    Review information about COBOL data types at URL below
    COBOL Data Types

    Review information about COBOL basic verbs at URL below
    COBOL Basic Verbs


    Review output using SDSF ST panel as outlined in #1

  3. Review simple read numbers, add numbers and write the sum
    tso submit 'zos.mtm2017.public.cobol(cbl3)'

    =sd ; st

    sj to the left of CBL3

    Observe the following:
    • INPUT-AREA declares several variables
    • Example is FIRST-NUMBER with a PIC 999 which means the length is a fixed 3 numeric structured field.
      Important - the behavior of fixed structured numeric fields include:
      1. When PIC 999, then input of 1234 would be read as 123 truncating last number
      2. When PIC 999, then input of 23 would be read as 230 where zero is at the end of the field
      3. When PIC 999, then input of 023 would be read as 023 where data field includes leading zero for correct arithmetic operations using this number
      4. Given a sum field such as ADD-ANS PIC 9999, when the value exceeds 4 numbers, then the leading number will be truncated
      5. Program techniques exist to insert zero in leading position when number is less than length of field
      6. Compiler options exist to take action when truncation occurs as a result of a sum exceeding length of field

    Review output using SDSF ST panel as outlined in #1

  4. Review simple character string read, move character string operation, and write the moved character string
    tso submit 'zos.mtm2017.public.cobol(cbl4)'

    =sd ; st

    sj to the left of CBL4

    Observe the following:
    • FIRST-CHARS data type is character length of 80
    • SECOND-CHARS data type is character length 1
    • MOVE character field with length of 80 TO a character field with length of 1
    • Review the program output to see character truncation behavior
    • COBOL programming techniques exist to determine length of character field and take action based upon the length

    Review output using SDSF ST panel as outlined in #1

  5. Review simple read from data set name and write to different data set name
    tso submit 'zos.mtm2017.public.cobol(cbl5)'

    =sd ; st

    sj to the left of CBL5

    Observe the following:
    • COBOL verbs READ and WRITE are designed to associate internal file name with a JCL DDNAME while ACCEPT and DISPLAY are designed to read and write from default input and output
    • INPUT-OUTPUT SECTION and FILE-CONTROL is used to identify input and output file information
      1. SELECT identifies a program internal name
      2. ASSIGN TO identifies a JCL DDNAME associated with the program internal name
      3. FILE SECTION describes attributes of the SELECTed files
      4. FD - File Descriptor
    • Notice the JCL DDNAMEs RECIN and PRINT at the bottom
    • Read the PROCEDURE DIVISION file handling verbs and compare to PRINT DDNAME output

    Review information about COBOL File Control at URL below
    COBOL File Organization

    Review information about COBOL File Handling Verbs at URL below
    COBOL File Handing Verbs

    Review output using SDSF ST panel as outlined in #1 with one exception -
    CBL5 output includes PRINT DDNAME to instead of SYSOUT DDNAME

  6. Review boolean logic using COBOL verbs IF/THEN/ELSE and EVALUATE
    tso submit 'zos.mtm2017.public.cobol(cbl6)'

    =sd ; st

    sj to the left of CBL6

    Observe the following:
    • JCL PROCEDURE is IGYWCL with parameter CBLPGM=CBL6
      1. IGYWCL created a permanent program, CBL6, in hlq.LOAD
      2. Previous jobs used JCL PROCEDURE IGYWCLG that created a temporary program
          where IGYWCL created a permanent program that can be executed repeatedly without repeatedly compiling the program language source code
          You will execute the permanent program, CBL6, repeatedly from TSO/ISPF interface
    • Read code from EVALUATE to END-EVALUATE
    • Read code from IF to END-IF
    • A period exists after END-IF indicating end of a sentence
      1. A period can terminate a PROCEDURE DIVISION paragraph
      2. A period can terminate a PROCEDURE DIVISION sentence
      3. A period can terminate a PROCEDURE DIVISION statement
      4. A PROCEDURE DIVISION statement without a period is logic embedded within the sentence
    • IF to END-IF is a sentence with many statements
    • EVALUATE to END-EVALUATE is a statement within an existing sentence
    • Therefore, the sentence ( IF to END-IF. ) is compounded true/false program logic

    You will now repeatedly execute program CBL6 to help you understand the above explanation

    From ISPF Command Shell panel =6, enter the following:
    call load(cbl6)

    Interact with the CBL6 program logic considering the above explanation of CBL6 source code
      Note: You can enter input using lowercase and/or uppercase characters.

    Review output using SDSF ST panel as outlined in #1

  7. Review do loop iteration and transfer control processing using COBOL PERFORM
    tso submit 'zos.mtm2017.public.cobol(cbl7)'

    =sd ; st

    sj to the left of CBL7

    NOTE: Thanks again to University of Limerick for an excellent explanation and example COBOL code to demonstrate iteration (do loop ) processing and transfer of control processing.

    Review information about COBOL iteration and transfer control processing at:
    COBOL PERFORM explanation from University of Limerick

    Observe the following:
    • CBL7 source code is from University of Limerick site with explanation of iteration logic and transfer of control using the PERFORM verb
    • PERFORM in-line is generally used for iteration (do loop) logic
    • PERFORM out-of-line is used for transfer of control (branch to then return) logic

    Review output using SDSF ST panel as outlined in #1

  8. Review iteration processing to read and change a stream of records using COBOL PERFORM
    tso submit 'zos.mtm2017.public.cobol(cbl8)'

    =sd ; st

    sj to the left of CBL8

    Observe the following:
    • CBL8 might look familiar
      A previous challenge required a JCL modifiication to make COBOL CBLRDWR source code execute successfully
      CBL8 was copied from CBLRDWR, then modified as follows
      1. REC-STORAGE was structured into 2 fields, REC-NUMBER and REC-TEXT
      2. An in-line PERFORM sentence is used to loop through a read operation to read input records until the last record
      3. The in-line PERFORM sentence includes execution of an out-of-line PERFORM to execute code located at CHANGE-REC, then return control to the in-line PERFORM to read the next record
      4. The out-of-line PERFORM code at CHANGE-REC modifies the input record field, REC-TEXT, to literal Hello COBOL before writing the record

    Review output using SDSF ST panel as outlined in #1

  9. Review COBOL compile syntax error and correction using intrinsic function capability
    tso submit 'zos.mtm2017.public.cobol(cbl9)'

    =sd ; st

    sj to the left of CBL9A and CBL9B

    Observe the following:
    • The source code is similar to code seen earlier with several differences
      1. FIRST-NUMBER is declared as character, PIC X(3), instead of numeric, PIC 9(3)
      2. SECOND-NUMBER is declared as character, PIC X(3), instead of numeric, PIC 9(3)
      3. COMPUTE verb is used to add FIRST-NUMBER and SECOND-NUMBER
    • CBL9 consists of 2 jobs, CBL9A and CBL9B
    • CBL9A fails to compile as a result of arithmetic attempted on character data type
    • CBL9B successfully compiles and executes as a result of applying an intrinsic function
      1. FUNCTION NUMVAL(FIRST-NUMBER) converted character data type to numeric data type
      2. FUNCTION NUMVAL(SECOND-NUMBER) converted character data type to numeric data type
    • Enterprise COBOL has many intrinsic functions
    • COBOL intrinsic functions are effectively reusable code that significantly reduces the number of lines you need to code to accomplish a task in the logic

    Review output using SDSF ST panel as outlined in #1

  10. Review COBOL string capability
    tso submit 'zos.mtm2017.public.cobol(cbl10)'

    =sd ; st

    sj to the left of CBL10

    Observe the following:
    • While possible in the DATA DIVISION to declare different views of a record or of fields within a record, any string can have a starting position and length immediately applied in the PROCEDURE DIVISION giving a unique view of the string
    • LITERAL-STRING(2:5) is an example of unique view immediately applied to an existing string in the PROCEDURE DIVISION

    Review output using SDSF ST panel as outlined in #1

  11. IBM Enterprise COBOL for z/OS professional documentation

    Congratulations! If you stepped through the challenge preparation, then you can claim to know COBOL. You can signup for a COBOL class at your University and get a very good grade. COBOL is skill that can be an attention getter on a resume to help secure an interview with a large enterprise where the core business logic is COBOL.

    Below are the COBOL professional manuals used by large enterprise application developers

Challenge:

COBOL program language source code, CBL15, is available to:

  1. read first set of numbers declared as packed decimal data type
  2. total first set of numbers
  3. read second set of numbers declared as a character data type
  4. total first and second set of numbers
  5. write grand total to hlq.P2.OUTPUT(#15)

The following actions are needed to complete the last Part 2 challenge:

  1. edit hlq.SOURCE
  2. s cbl15 to select new empty member named cbl15
  3. copy COBOL program language source code from 'zos.mtm2017.public.cobol(cbl15)'
  4.   Note: enter hilite cobol color code known COBOL reserved word syntax.
  5. submit
  6. review CBL15 output
  7. identify compile errors
  8. edit hlq.SOURCE(CBL15), correct compile errors, and resubmit until execution is successful

Hint: Only 1 line in CBL15 requires 2 changes to successfully execute program

Successful execution of CBL15 writes the total of all read numbers into hlq.P2.OUTPUT(#15)

You just completed Part 2. Time to check your work.

Next: Completing Part 2