Using screens and adding two numbers - addda.cbl

Slides:



Advertisements
Similar presentations
Check Digit - Mod 11 Please use speaker notes for additional information!
Advertisements

DEVELOPING ICT SKILLS PART -TWO
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
MACREX Indexing Software. Getting Started: Basic Basics.
ABNIAC The following slide presentation is to acquaint the student with ABNIAC. The version used for presentation is the Java version, which can be found.
Programming Logic and Design Fourth Edition, Introductory
Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
Downloading a COBOL program from CIS12 site! Please use speaker notes for additional information!
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
Introduction to the WebBoard Terry Dennis. The WebBoard - Our Connection The WebBoard URL is
InvEasy (Project1) Please use speaker notes for additional information!
Modifications to program Addda.cbl Please use speaker notes for additional information!
How to create a Splash Screen in MS Access Carlos Coronel.
Playing Music in Alice By David Yan Under the direction of Professor Susan Rodger July 2015.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Totals on the Screen Please use speaker notes for additional information!
Array - adding to array at run time Please see speaker notes for additional information!
HELLO WORLD program in COBOL - CIS12 Please use speaker notes for additional information!
Chapter 2 part #1 C++ Program Structure
JDS5 Training Guide. On Start Up you will see this screen click the OK button Click OK.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
Today We Will Review: Operating Systems (Windows) (week 3 & 4) Starting up MS Windows Desktop and its contents Functions of the desktop components Brain.
Mail Merge Introduction to Word Processing ITSW 1401 Instructor: Glenda H. Easter Introduction to Word Processing ITSW 1401 Instructor: Glenda H. Easter.
Making a 24hr Timer.
Development Environment
Excel Training - Part One
Chapter 1: An Introduction to Visual Basic 2015
Lesson 3: Customizing Document Elements
Chapter 2 part #1 C++ Program Structure
Multiple Classes and Inheritance
Eclipse Navigation & Usage.
Current outstanding balance
Computer Programming I
Basic operations in Matlab
3.01 Apply Controls Associated With Visual Studio Form
Creating a Windows Server 2012 R2 Datacenter Virtual machine
Creating a Windows Server 2016 Datacenter Virtual machine
Keyboard Input and Screen Display ––––––––––– Interactive Programming
Intro to PHP & Variables
Please use speaker notes for additional information!
Access Database for CIS17
Multi-host Internet Access Portal (MIAP) Enhancement Guide
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
The SMS Query Menu System for the iSeries
Designing and Debugging Batch and Interactive COBOL Programs
Introduction to Access 2003
MODULE 7 Microsoft Access 2010
Chapter 3 The DATA DIVISION.
Please use speaker notes for additional information!
GDSS – Digital Signature
Please use speaker notes for additional information!
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
CTAERN/DOE System Level Counselor Coordinator Profile Entry Initiative
File Management File Explorer © EIT, Author Gay Robertson, 2017.
Microsoft Official Academic Course, Access 2016
Access Database for CIT12
Text / Serial / Sequential Files
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
File Analysis with MicroSoft DEBUG
CTAERN/DOE System Level Counselor Coordinator Profile Entry Initiative
Palm Basic Applications
Running a Java Program using Blue Jay.
Chapter 1 Introducing Small Basic
More on If statements (Calculate, Calculate1, Calculate2)
Chapter 1 c++ structure C++ Input / Output
Wings 2.0 Business Flow Reference
Chapter 2 part #1 C++ Program Structure
Point of Rental Training
Presentation transcript:

Using screens and adding two numbers - addda.cbl Please use speaker notes for additional information! The program discussed in this presentation uses the basic Display and Accept statements to take in two numbers. The numbers are then added together and the answer is displayed. When the user has viewed the answer, enter can be pressed to terminate the program.

IDENTIFICATION DIVISION. ADDDA.CBL IDENTIFICATION DIVISION. PROGRAM-ID. ADDPROG. AUTHOR. GROCER. *ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-AREA. 05 GET-ACCEPT-ANS PIC X VALUE SPACES. 05 FIRST-NUMBER PIC 999 VALUE 0. 05 SECOND-NUMBER PIC 999 VALUE 0. 05 ADD-ANS PIC 9999 VALUE 0. PROCEDURE DIVISION. MAINLINE. DISPLAY "ENTER THE FIRST NUMBER (UNDER 1000)". ACCEPT FIRST-NUMBER. DISPLAY "ENTER THE SECOND NUMBER (UNDER 1000)". ACCEPT SECOND-NUMBER. ADD FIRST-NUMBER TO SECOND-NUMBER GIVING ADD-ANS. DISPLAY "THE ANSWER IS " ADD-ANS. DISPLAY "PRESS ENTER TO END THE PROGRAM". ACCEPT GET-ACCEPT-ANS. STOP RUN. This is the code for the program that is being discussed.

ADDDA.CBL I want to open an existing program to compile and execute, so I will select Open for edit... If you want to key in a new program then click new and start keying in the program. If the program exists and you want to bring it up to either make changes or to compile and execute, then click Open for edit...

ADDDA.CBL Click on addda.cbl and then click OK or simply double click on addda.cbl. Note that when you open for edit, only source programs with a .cbl extension are shown. In this example, I am looking at the a drive and there is only one program there.

ADDDA.CBL This shows the program that was opened, addda.cbl. Note that in the DATA DIVISION, there is a WORKING-STORAGE SECTION that contains an area called 01 INPUT-AREA. There is no picture associated with this area because it is used to group other entries. The picture is only given at the lowest level when you are defining the actual piece of data. In this program I have GET-ACCEPT-ANS which is a one character alphanumeric field (can accept anything) with an initial value of spaces. This means that when the program starts, this one character will contain a space. There are also two areas to accept numbers that are entered that we want to add together. These two areas are called FIRST-NUMBER and SECOND-NUMBER. Since I want numbers that are no bigger than three characters and since I want numeric data the picture I am using is 999. Just as an X means alphanumeric data, a 9 means numeric data only. There is also an A that means alphabetic data only but this is rarely used. I have also decided to give these two fields an initial value of 0. When the user enters data, these fields will hold the user input, but when the program starts they will have an initial value of 0. Finally I have set up an area in memory called ADD-ANS that will hold the result of the calculation that I am going to do. It also has a numeric picture with an initial value of 0. However since I am adding two numbers with a maximum of 3 digits, the answer needs to be 4 digits to ensure that I can hold the entire answer. The answer will be put here when the calculation is done and then it will be displayed on the screen so the user can see the answer.

ADDDA.CBL This is the same image as the previous slide. Here I want to discuss the PROCEDURE DIVISION. There are four commands being used: DISPLAY, ACCEPT, ADD and STOP RUN. The commands are all located within the MAINLINE paragraph. The program will execute the command lines in order when the program is run. First it will display a request for the first number, then it will accept the number and store it in memory under the name FIRST-NUMBER (defined in WORKING-STORAGE). Then it will display a request for the second number and accept and store that in SECOND-NUMBER. Then it will add the two numbers together and store the answer in ADD-ANS. Next the answer and some messages will be displayed on the screen. The ACCEPT GET-ACCEPT-ANS will wait for the user to respond. When the user presses ENTER, the program will execute STOP RUN and the program will run. Remember, before any of this happens the source program needs to be compiled and an object program produced. It is when the object program is executed (run) that we will see the program in action.

ADDDA.CBL To compile the program, go to Compile/Run and select Compile Program. Remember you may see slightly different menu options in the lab.

ADDDA.CBL The program has been successfully compiled and the line numbers have been assigned.

ADDDA.CBL After closing the source program (.cbl), I use Open for execution to open the object program (.int). I have now closed the file - to do this I did File/Close. I now want to open the object program. To do this I do File/Open for execution...

ADDDA.INT I am now going to select addda.int and open the file for execution.

ADDDA.INT This shows addda.int with the first line highlighted. It is ready to be run.

ADDDA.INT The second number has been entered, but ENTER has not been pressed so the cursor is waiting. When Enter has been pressed the ACCEPT of the second number will be complete. Note that the user enters the number and then presses enter. In this case, we are entering a two digit number, we might be entering a one digit number. Pressing enter says we are done.

ADDDA.INT PROCEDURE DIVISION. MAINLINE. DISPLAY "ENTER THE FIRST NUMBER (UNDER 1000)". ACCEPT FIRST-NUMBER. DISPLAY "ENTER THE SECOND NUMBER (UNDER 1000)". ACCEPT SECOND-NUMBER. ADD FIRST-NUMBER TO SECOND-NUMBER GIVING ADD-ANS. DISPLAY "THE ANSWER IS " ADD-ANS. DISPLAY "PRESS ENTER TO END THE PROGRAM". ACCEPT GET-ACCEPT-ANS. STOP RUN. The two numbers have been calculated and the answer has been displayed. Note that 12 plus 24 is 36. Because we specified the answer as 4 digits the two leading 0s are shown. Later we will learn ways to avoid that. We are now waiting for the user to press ENTER to end the program.

ADDDA.INT STOP RUN has been encountered.

We are ready to execute the first command (it is highlighted). Step through I want to see data so I will use the icon with the foot step and the magnifying glass. We are ready to execute the first command (it is highlighted). We are now going to step through the program watching the instructions as they execute. This can be valuable when we are trying to figure out a logic problem. Stepping through the program can be done by pressing the icon that looks like a foot step. If we want to step through and see the data as well we use the foot step and the magnifying glass icon.

Step through The first message has been displayed and the second command is highlighted. The user will enter a number and it will be stored in FIRST-NUMBER.

As a result of the ACCEPT, 12 is now stored in FIRST-NUMBER. Step through As a result of the ACCEPT, 12 is now stored in FIRST-NUMBER. We have now moved to the third command - when I click the icon, it will be executed and we will move to the fourth command.

Step through We have now moved to the forth command and the message from the third command is visible on the screen.

Step through The second number has now been entered and is stored in the data name I made up which is SECOND-NUMBER. Note that in this example, I entered 12 as both the first number and the second number. In the last example, I entered different numbers.

Step through We have now moved past the ADD so the answer is stored in ADD-ANS. Notice that you can see the content of FIRST-NUMBER, SECOND-NUMBER and ADD-ANS. However the display has not been executed (I need to click on the icon) so the answer has not yet been displayed on the screen.

Step through We have now moved to the line after the answer is displayed (we have not executed it yet), so the answer appears on the screen. Notice again that this DISPLAY puts out both a message and the contents of a field that was set up in WORKING-STORAGE and is stored in memory.

Step through Control has now moved to the ACCEPT and the last display is on the screen.

Step through The user has responded and control has moved to past the ACCEPT.

User clicks OK to end the program. Step through User clicks OK to end the program. STOP RUN has been executed and the program ended normally. When the user click OK, the program will be completely done.