Preparing and Using a Program [ COBOL/HP-UX Getting Started for the Series 700 and 800 ] MPE/iX 5.0 Documentation
COBOL/HP-UX Getting Started for the Series 700 and 800
Preparing and Using a Program
This sample session illustrates all the essential steps in preparing an
application for use in COBOL Toolbox:
* compiling - checking its syntax and producing intermediate code
* animating - testing and debugging it
* generating - producing an object program in native machine code
* running it
See the section "Packaging" for how to prepare a program to run
outside the COBOL Toolbox system so you can deliver it to your users.
Entering COBOL Toolbox
1. Copy the source file tictac.cbl into one of your work directories.
You will find this file in the directory containing the tutorial
programs supplied with COBOL Toolbox. This is subdirectory "demo"
within the directory pointed to by the $COBDIR environment
variable.
2. Enter:
tbox
The system displays the Toolbox main menu screen, as shown in Figure 3-1
(*).
Figure 3-1. The Toolbox Development Environment Main Screen
This screen consists of four parts:
* the text area
* the information line
* the menu
* the message area
The text area means the main body of the screen.
The menu, at the bottom of the screen, shows the functions available at
this point. Each function has a function key (shown as Fnn=) associated
with it; pressing the key activates the function. There are two other
menus behind the one you can see. Pressing Alt (that is, /a) displays
one (the Alt menu) and Ctrl (/c) displays the other (the Ctrl menu).
Above the menu is the third part of the screen, the information line.
This line contains a mixture of fixed and variable information. For
example, the information line can contain the menu name, the name of the
program you are working with, the status of the Insert, Caps,
Num Lock and Scroll Lock keys, and toggle settings. A toggle is a key
that selects between options.
The message area is below the menu, on the bottom line of your display,
and is where messages are usually displayed.
At this point the text area contains the Toolbox banner, which displays
information about the new features in this release.
This format of screen is used in most of the COBOL Toolbox tools. A
function key may serve one of three purposes:
* to enter another menu
* to perform a function, leaving you in the same menu or returning
you to a higher level one
* to set a toggle
The Escape key on a menu usually leaves the menu and takes you back up to
the one you invoked it from.
Help
You can get Help on every menu by pressing F1=help.
3. Press F1=help
You will see that the text area is replaced by text. There is more
information than fits on one screen, and if you press F1 again the
next page appears. The information presented is relevant to the menu
from which Help is invoked; here you see general information about
COBOL Toolbox and the main functions because you pressed F1 on the
main menu.
4. Press Space (or F1 if you are on the last page of help) to return to
the main menu.
Editing
You're now going to invoke the COBOL Editor. This editor is designed
especially for COBOL programs, although it can be used for any type of
source file.
5. Press F2=edit
The work area clears and a new menu appears, shown in Figure 3-2 .
Figure 3-2. The COBOL Editor Main Menu
The COBOL Editor allows you either to type in COBOL source, or to
load in a file created previously. If you were creating a new
program you would type it now. However, the source of Tictac is
supplied on disk for you. You simply need to load it into the COBOL
Editor.
Accessible from the main menu are two more menus - the Alt menu and
the Ctrl menu - which you get to by pressing Alt (that is, /a) and
Ctrl (/c).
6. Press Alt (/a) and F3=load file.
(From now on we will write this as simply "press Alt+F3"; similarly,
holding down the Ctrl key while pressing F3 will be written as "press
Ctrl+F3".)
The Load File menu appears. It includes a line on which to type the
name of the file to load. The directory you are in is already
displayed on this line to save you typing it.
7. Enter:
tictac
The source code is displayed with the cursor positioned under the
first statement on line 1. The main menu of the COBOL Editor
returns.
Compiling
You may have noticed that the Toolbox main menu has keys for the Compile
and Animate functions. However, you can also access these functions from
within the COBOL Editor, and we will do it this way in this tutorial.
8. From the COBOL Editor's main menu, press F2=COBOL once. Do not hold
it down, as this would make it repeat.
The COBOL menu appears.
9. Press F2= compile /animate once.
The COBOL menu appears. On this menu, F2 is a toggle selecting
*whether you will compile, animate, or both. Its setting is shown
on the information line, and changes each time you press.
10. Press F2= check /animate several times, until its setting becomes
"Cmp +Anim".
11. Press Enter to begin compiling.
The COBOL Editor screen disappears and you see the source listing
scrolling rapidly up the screen. The Compiler is checking the
program for syntax errors and producing intermediate code. It
outputs this code in a file with extension .int. and produces extra
information needed by the Animator in a .idy file. When it has
finished the Animator screen appears.
Animating
Note: Animator animates .int files; if it finds a .gnt file, it runs
it without animation. If you run through this sample session a
second time, make sure you have no tictac.gnt file left from the
previous time.
The Animator screen is shown in Figure 3-3 . Now use Animator to
watch the source code executing.
Figure 3-3. The Animator Screen
The source code is displayed with the cursor positioned under the first
executable statement:
perform with test after
The Animate main menu appears at the bottom of the screen. It displays
an information line containing the program name Tictac, and level, speed,
Ins, Caps, Num and Scroll indicators. The next two lines contain the
function and letter key options you use to control the way the program is
animated.
Controlling the Speed.
You can execute your program in one of three modes: Step, Go and Zoom.
When you execute your program in Step mode, you manually control the
execution of each statement. In Go mode, you initially set the speed of
execution, then watch as each statement is automatically executed. Zoom
mode executes the entire program without displaying the source until it
reaches the end of the program (you can interrupt it, or set a breakpoint
where it will stop). These modes of execution are described in the
following sections.
Stepping Through the Program.
The first letter command on the Animate menu is Step.
12. Press S to begin stepping through your program.
The cursor is now positioned under the next executable statement:
call clear-screen
13. Press Step again twice.
This positions the cursor on the DISPLAY statement and then executes
the statement.
This causes a brief display of the user screen in its current state.
The user screen is the screen displayed by the program itself, that
is, the screen that would be seen by the user if you were running
the program without Animator. The screen showing the source is
called the Animator screen. The user screen briefly appears each
time you execute a DISPLAY statement.
The cursor then moves to the beginning of the statement:
perform init
14. Now press F2=view.
The user screen appears showing the text displayed by the executed
DISPLAY statement:
To select a square type a number between 1 and 9
You can use the view facility to view the user screen at any time
during animation.
15. Press any key to return to the Animator screen.
16. Now execute the next three statements in the program by pressing
Step three times.
Each time you press Step another statement is executed, and you can
see what is actually happening in the program.
Executing in Go Mode.
In Go mode, your program is automatically executed at the speed you
select, and you can watch exactly what is happening in the program.
17. To start Go mode, press G.
The Go menu shown in Figure 3-4 appears at the bottom of the
screen as execution begins. The program is currently executing at a
speed of 5, the default setting.
Figure 3-4. The Go Menu
18. Press 7 to increase the speed.
This change in speed is displayed on the information line. You can
set execution speed from either the Animate main menu or the Go
menu. The range of speeds is from 0 to 9, with 0 the slowest speed.
You can change this speed at any time during execution by pressing a
key between 0 and 9.
Program execution halts when an ACCEPT statement is encountered.
The system now pauses on the user screen after executing the ACCEPT
statement on line 114 anticipating data entry.
19. Respond by typing N to indicate that you will be the one to start
the game.
The system continues animation in Go mode at a speed of 7 and pauses
after the next ACCEPT, displaying the user screen and prompting
again for data entry.
20. Select square 9 by pressing 9 on your keyboard.
This places an "X" in square 9 and resumes program execution in Go
mode. Remember, you can press F2=view at any time to see the user
program's screen.
Execution stops again when you are prompted to select another
square. Notice that the system has placed a 0 in square 5.
21. Press 8 to select the square and to resume execution.
You can temporarily halt execution at any time.
22. Press Escape.
The message:
Keyboard interrupt
appears at the bottom of the screen. The cursor is positioned on
the next executable statement.
Executing in Zoom Mode.
23. Now press Z to begin execution in Zoom mode.
The program resumes execution at full speed and displays only the
user screen. Continue playing until the game is complete. Then the
message:
Play again?
appears.
24. Respond by typing N (No).
The source code returns to the screen with the cursor positioned
under STOP RUN, indicating that the program has completed execution.
The message:
STOP RUN encountered with RETURN-CODE=+00000: use Escape to
terminate
appears at the bottom of the screen.
Exiting Animator.
25. Press Escape to terminate your Animator session.
The message:
Exit from animator? Y/N
appears at the bottom of the screen.
26. Press Y (Yes) to return to the COBOL Editor's main menu.
The source listing again appears in the text area, ready for further
editing should it be required.
27. Press Escape to exit from the COBOL Editor.
This returns you to the main menu of Toolbox.
Generating Native Code
Generation of native code is optional in COBOL Toolbox. The .int file
created when compiling contains intermediate code, required by the
Animator. This can also be run without further preparation, using the
Run option as described in the section Running below.
However, you can use the Generate function on the Toolbox main menu to
create a file with extension .gnt containing native machine code, which
executes faster than intermediate code. Both the .int file and the .gnt
file can be run using the Run option.
You create an optimized tictac.gnt as follows.
28. Press F5=generate on the Toolbox main menu.
A menu appears enabling you to specify the program to be compiled
and giving you access to various functions and options useful at
this point. Because you have just been working with tictac, its
name is already set there as default; and the default settings of
the menu are what we want. So you do not have to type anything on
this menu.
29. Press Enter
The system displays a banner identifying the Generator and some
directives that COBOL Toolbox has automatically set. The function
finishes after just a few seconds, and the following message
appears:
Data=xxxxxxxxx Code=yyyyyyyyy Literals=zzzzzzzzz
This means the compilation produced an object program needing
xxxxxxxxx bytes of data storage, yyyyyyyyy bytes of storage for
Procedure Division code, and zzzzzzzzz for storing literals.
You are then returned to the Toolbox main menu.
Running the Program
You run a program in the same way whether you are running intermediate
code or generated code.
30. Press F6=run
A menu appears enabling you to specify the program to be run and
giving you access to various functions and options useful at this
point. However, because you have just been working with tictac, its
name is already set there as default; and the default settings of
the menu are what we want. So you do not enter anything on this
menu.
31. Press Enter
The system runs the program, which starts off by displaying the
first message of the game on your screen. Have fun playing it; it
can be beaten!
Leaving Toolbox
At the end of the game, Tictac displays the message:
Play again?
32. Press N for "No".
You are returned to the Toolbox main menu.
33. Press Escape to leave the Toolbox system
COBOL Toolbox displays a message asking you to confirm that you want
to leave.
34. Press Y for "Yes".
COBOL Toolbox exits, and you are returned to the operating system.
MPE/iX 5.0 Documentation