OpenCOBOL is an open-source COBOL compiler. OpenCOBOL implements a
substantial part of the COBOL 85 and COBOL 2002 standards,
as well as many extensions of the existent COBOL compilers.
OpenCOBOL translates COBOL into C and compiles the translated code using
the native C compiler. You can build your COBOL programs on various
platforms, including Unix/Linux, Mac OS X, and Microsoft Windows.
COBOL is an acronym for COmmon Business Oriented Language. This author
has always thought of it as "Common Business" Oriented more than
Common "Business Oriented", but that emphasis is perhaps up to the readers
point of view.
The compiler is licensed under GNU General Public License.
The run-time library is licensed under GNU Lesser General Public License.
All source codes are copyright by the respective authors.
OpenCOBOL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Yes. Debian APT, and RPM packages exist. Packages for NetBSD. Many.
Google opencobol packages for any late breaking news.
A Debian apt binary package exists for OpenCOBOL 1.0 as open-cobol and
lists dependencies of
- libc6 (>= 2.7-1),
- libcob1,
- libcob1-dev (= 1.0-1),
- libdb4.5 (>= 4.5.20-3),
- libdb4.5-dev,
- libgmp3-dev,
- libgmp3c2,
- libltdl3-dev,
- libncurses5 (>= 5.6+20071006-3)
Thanks to the gracious efforts of Bart Martens, bartm on Debian's .org domain.
Also check out http://www.kiska.net/opencobol/ for binary builds on various
platforms. Thanks to Sergey Kashyrin.
OpenCOBOL 1.0 implements a substantial portion of COBOL 85,
supports many of the advances and clarifications of COBOL 2002,
and includes many extensions in common use from Micro Focus COBOL,
ACUCOBOL and other exsistent compilers.
OpenCOBOL 1.1 implements a more substantial portion of the COBOL 85
Dialect, COBOL 2002 and a growing number of vendor extensions.
Some proposed COBOL 2008 features have also been implemented.
Compatibility support includes:
- MF for Micro Focus
- IBM for IBM compatibility
- MVS
- BS2000
OpenCOBOL also includes some advanced features allowing source code such as
CALL "cfunction" USING BY REFERENCE ADDRESS OF VAR-IN-LINKAGE-SECTION.
Passing the equivalent of char**, pointer to pointer to char. Just as a
small example of the level of coverage provided by OpenCOBOL.
This author believes so. For an open source implementation of COBOL,
OpenCOBOL may surprise you in the depth and breadth of its COBOL standard
feature support, usability and robustness.
Many people. In particular Keisuke Nishida and Roger While.
See the THANKS file in the source code archive for more names of people
that have worked on the OpenCOBOL project. Roger points out that the list
is woefully incomplete. To quote:
The OC project would not have been where it is today without the
significant/enormous help from many-many persons. The THANKS
file does not even do justice to this.
Why yes it does. 74 syntax tests, 170 coverage tests, and 16 data
representation tests at last count. From the development tarball,
$ make check will evaluate and report on the test suite.
Many. OpenCOBOL achieves a very high level of COBOL 85 conformance.
The National Institute of Standards and Technology, NIST, maintains a
COBOL 85 implementation verification suite of tests. An archive of the tests
can be found at
http://www.itl.nist.gov/div897/ctg/cobol_form.htm
Instructions for use of the NIST suite is included in the build archive under:
tests/cobol85/README
Basically, it is a simple uncompress and make then sit back and
relax. The scripts run OpenCOBOL over some 364 programs/modules and
includes thousands of test passes.
Test Modules
------------
Core tests:
NC - COBOL nucleus tests
SM - COPY sentence tests
IC - CALL sentence tests
File I-O tests:
SQ - Sequential file I-O tests
RL - Relative file I-O tests
IX - Indexed file I-O tests
ST - SORT sentence tests
Advanced facilities:
IF - Intrinsic Function tests
The summary.log from a run in July 2008:
Module programs executed error crash details
------ -------- -------- ----- ----- -------
NC 92 92 0 0 4363,0,6,11/4380
SM 15 13 0 0 289,2,3,1/295
IC 24 21 3 0 240,0,4,0/244
SQ 81 81 0 0 512,0,6,81/599
RL 32 32 0 0 1827,0,5,0/1832
IX 39 39 0 0 507,0,1,0/508
ST 39 39 0 0 278,0,0,0/278
IF 42 42 0 0 732,0,0,0/732
------ -------- -------- ----- ----- -------
Total 364 359 3 0
OpenCOBOL has a legacy dating back to 1959. Many features of the COBOL
standard provide defaults more suitable to mainframe architecture than the
personal computer a 3rd millennium OpenCOBOL developer will likely be using.
OpenCOBOL, by default, generates code optimized for big-endian hardware.
Fairly dramatic speed improvements on Intel architecture can come from simple
USAGE IS COMPUTATIONAL-5 clauses in the DATA DIVISION.
Attention!
Look into this
Yes. Through standard IO redirection and the extended
ACCEPT ... FROM ENVIRONMENT ... feature, OpenCOBOL is more than capable
of supporting advanced CGI programming.
COBOL >>SOURCE FORMAT IS FIXED
******************************************************************
* Author: Brian Tiffin, Francois Hiniger
* Date: 30-Aug-2008
* Purpose: Display the CGI environment space
* Tectonics: cobc -x cgienv.cob
* Move cgienv to the cgi-bin directory as cgienv.cgi
* browse http://localhost/cgi-bin/cgienv.cgi or cgienvform.html
******************************************************************
identification division.
program-id. cgienv.
environment division.
input-output section.
file-control.
select webinput assign to KEYBOARD.
data division.
file section.
fd webinput.
01 postchunk pic x(1024).
working-storage section.
78 name-count value 24.
01 newline pic x value x'0a'.
01 name-index pic 99 usage comp-5.
01 value-string pic x(256).
01 environment-names.
02 name-strings.
03 filler pic x(20) value 'DOCUMENT_ROOT'.
03 filler pic x(20) value 'GATEWAY_INTERFACE'.
03 filler pic x(20) value 'HTTP_ACCEPT'.
03 filler pic x(20) value 'HTTP_ACCEPT_CHARSET'.
03 filler pic x(20) value 'HTTP_ACCEPT_ENCODING'.
03 filler pic x(20) value 'HTTP_ACCEPT_LANGUAGE'.
03 filler pic x(20) value 'HTTP_CONNECTION'.
03 filler pic x(20) value 'HTTP_HOST'.
03 filler pic x(20) value 'HTTP_USER_AGENT'.
03 filler pic x(20) value 'PATH'.
03 filler pic x(20) value 'QUERY_STRING'.
03 filler pic x(20) value 'REMOTE_ADDR'.
03 filler pic x(20) value 'REMOTE_PORT'.
03 filler pic x(20) value 'REQUEST_METHOD'.
03 filler pic x(20) value 'REQUEST_URI'.
03 filler pic x(20) value 'SCRIPT_FILENAME'.
03 filler pic x(20) value 'SCRIPT_NAME'.
03 filler pic x(20) value 'SERVER_ADDR'.
03 filler pic x(20) value 'SERVER_ADMIN'.
03 filler pic x(20) value 'SERVER_NAME'.
03 filler pic x(20) value 'SERVER_PORT'.
03 filler pic x(20) value 'SERVER_PROTOCOL'.
03 filler pic x(20) value 'SERVER_SIGNATURE'.
03 filler pic x(20) value 'SERVER_SOFTWARE'.
02 filler redefines name-strings.
03 name-string pic x(20) occurs name-count times.
procedure division.
* Always send out the Content-type before any other IO
display
"Content-type: text/html"
newline
end-display.
display
"<html><body>"
end-display.
display
"<h3>CGI environment with OpenCOBOL</h3>"
end-display.
display
'<a href="/cgienvform.html">To cgienvform.html</a>'
"<p><table>"
end-display.
* Accept and display some of the known CGI environment values
perform varying name-index from 1 by 1
until name-index > name-count
accept value-string from environment
name-string(name-index)
end-accept
display
"<tr><td>"
name-string(name-index)
": </td><td>"
function trim (value-string trailing)
"</td></tr>"
end-display
if (name-string(name-index) = "REQUEST_METHOD")
and (value-string = "POST")
open input webinput
read webinput
at end move spaces to postchunk
end-read
close webinput
display
'<tr><td align="right">'
"First chunk of POST:</td><td>"
postchunk(1:72)
"</td></tr>"
end-display
end-if
end-perform.
display "</table></p></body></html>" end-display.
COOL goback.
cgienv.cgi form:
<html><head><title>OpenCOBOL sample CGI form</title></head>
<body>
<h3>OpenCOBOL sample CGI form</h3>
<form action="http://localhost/cgi-bin/cgienv.cgi" method="post">
<p>
Text: <input type="text" name="text"><br>
Password: <input type="password" name="password"><br>
Checkbox: <input type="checkbox" name="checkbox"><br>
<input type="radio" name="radio" value="ONE"> One<br>
<input type="radio" name="radio" value="TWO"> Two<br>
<input type="submit" value="Send"> <input type="reset">
</p>
</form>
</body>
</html>
Depends. OpenCOBOL is still in active development. Feature coverage
is growing, and while the current implementation offers great coverage,
applicability to any given situation would need to analyzed and risks
evaluated before commitment to production use.
The licensing allows for commercial use, but OpenCOBOL also ships with
notice of indemnity, meaning that there are no guarantees when using
OpenCOBOL, directly or indirectly.
There may be a time when commercial support of OpenCOBOL is offered, but
at the time of writing no known offering exists.
Search google just in case!
And yes, OpenCOBOL is used in production environments.
From [Roger]:
Incidentally, OC has been (and still is) used in production
environments since 2005.
(This includes projects that I personally worked on plus other
projects reported to me; these worldwide)
The OC project would not have been where it is today without the
significant/enormous help from many-many persons. The THANKS
file does not even do justice to this.
Attention!
Look into this - need more entries
Absolutely. Visit the opencobol.org website and either post a message asking
what needs to be done, or perhaps join the development mailing list to find
out the current state of development. See
Q. Is there an OpenCOBOL mailing list? for some details. OpenCOBOL is a
GPL licensed open source project and while [Roger] is the lead developer he
is quite open to code submissions. Having a central point of development
allows for consistency and the very high level of quality control enjoyed by
OpenCOBOL users.
Maybe.
A computer without COBOL and Fortran is like a piece of chocolate cake
without ketchup or mustard.
John Krueger
A determined coder can write COBOL programs in any language.
Author: unknown
Rumour has it that the object oriented specification for COBOL was code
named
ADD 1 TO COBOL GIVING COBOL.
Author: unknown
A less verbose, more concise version; very unCOBOL that
ADD 1 TO COBOL.
Thanks to aoirthoir
And, just because;
ADD 1 TO COBOL GIVING OpenCOBOL
A common dis of COBOL jokes that the acronym is:
Completely Obsolete Business Oriented Language.
Author unkown
We know better. The reality is:
Can't Obsolesce Because Of Legacy. And why would you want to?
Brian Tiffin
Ruby on Rails? Don't forget COBOL ON COGS.
http://www.coboloncogs.org/INDEX.HTM
Eat COBOL, 200 billion lines can't be wrong.
Brian Tiffin
What did COBOL yell to the escaping thief?
STOP RUN RETURNING NOW.
Brian Tiffin
What did COBOL reply to the executive? Why yes, I can
PERFORM JUMPS THRU HOOPS.
Brian Tiffin
What did OpenCOBOL reply to the executive? Sir, I can
PERFORM JUMPS THRU FLAMING-HOOPS UNTIL HELL-FREEZES-OVER.
And being COBOL, I have to show you how little code it takes:
identification division.
program-id. freeze.
data division.
working-storage section.
01 hell pic 9.
88 hell-freezes-over value 1.
procedure division.
perform jumps thru flaming-hoops until hell-freezes-over.
stop run.
jumps.
flaming-hoops.
divide 1 by 0 giving hell.
Brian Tiffin
Installation instructions can be found at OpenCOBOL Install.
- Debian
The Debian binary package makes installing OpenCOBOL 1.0 a snap.
From root or using sudo:
$ apt-get open-cobol
- Windows
- Build from sources under Cygwin or MinGW. Follow the instructions
from the site listed above.
Also see Q. What is the current version of OpenCOBOL?
OpenCOBOL relies on a native C compiler with POSIX compatibility.
GCC being a freely available compiler collection supported by most
operating systems currently (August 2008) in use.
OpenCOBOL requires the following external libraries to be installed:
- GNU MP (libgmp) 4.1.2 or later
- libgmp is used to implement decimal arithmetic.
GNU MP is licensed under GNU Lesser General Public License.
- GNU Libtool (libltdl)
- libltdl is used to implement dynamic CALL statements.
GNU Libtool is licensed under GNU Lesser General Public License.
NOTE - Libtool is not required for Linux and Windows
(including MinGW and Cygwin)
The following libraries are optional:
- Berkeley DB (libdb) 1.85 or later
- libdb can be used to implement indexed file I/O and SORT/MERGE.
Berkeley DB is licensed under the original BSD License (1.85) or their own
open-source license (2.x or later). Note that, as of 2.x, if you linked
your software with Berkeley DB, you must distribute the source code of
your software along with your software, or you have to pay royalty to
Oracle Corporation. For more information about Oracle Berkeley DB dual
licensing go to : Oracle / Embedded / Oracle Berkeley DB
- Ncurses (libncurses) 5.2 or later
- libncurses can be used to implement SCREEN SECTION.
Ncurses is licensed under a BSD-style license.
OpenCOBOL is a multi-stage command line driven compiler. Command line
options control what stages are performed during processing.
- Preprocess
- Translate
- Compile
- Assemble
- Link
- Build
OpenCOBOL produces intermediate C source code that is then passed to a configured
C compiler and other tools. the GNU C compiler, gcc being a standard.
The main tool, cobc, by default, produces modules, linkable shared
object files.
Example
$ cat hello.cob
Original source code;
000100* HELLO.COB OpenCOBOL FAQ example
000200 IDENTIFICATION DIVISION.
000300 PROGRAM-ID. hello.
000400 PROCEDURE DIVISION.
000500 DISPLAY "Hello World!".
000600 STOP RUN.
OpenCOBOL stages. Preprocess:
$ cobc -E hello.cob
Preprocess only; For one thing, FIXED format becomes FREE format. For another COPY is processed. Displays
# 1 "hello.cob"
IDENTIFICATION DIVISION.
PROGRAM-ID. hello.
PROCEDURE DIVISION.
DISPLAY "Hello World!".
STOP RUN.
to standard out.
Translate:
$ cobc -C hello.cob
Translate only; preprocesses and then translates the COBOL sources into C.
You can examine these files to get a good sense of how the OpenCOBOL
environment interacts with the native C facilities.
OpenCOBOL 1.1 produced hello.c.h and hello.c.
hello.c.h:
/* Generated by cobc 1.1.0 */
/* Generated from hello.cob */
/* Generated at Oct 04 2008 00:19:36 EDT */
/* OpenCOBOL build date Oct 01 2008 22:15:19 */
/* OpenCOBOL package date Oct 01 2008 16:31:26 CEST */
/* Compile command cobc -C hello.cob */
/* PROGRAM-ID : hello */
static unsigned char b_5[4] __attribute__((aligned)); /* COB-CRT-STATUS */
static unsigned char b_1[4] __attribute__((aligned)); /* RETURN-CODE */
static unsigned char b_2[4] __attribute__((aligned)); /* SORT-RETURN */
static unsigned char b_3[4] __attribute__((aligned)); /* NUMBER-OF-CALL-PARAMETERS */
/* attributes */
static cob_field_attr a_1 = {16, 4, 0, 0, NULL};
static cob_field_attr a_2 = {33, 0, 0, 0, NULL};
/* fields */
static cob_field f_5 = {4, b_5, &a_1}; /* COB-CRT-STATUS */
/* constants */
static cob_field c_1 = {12, (unsigned char *)"Hello World!", &a_2};
/* ---------------------------------------------- */
hello.c:
/* Generated by cobc 1.1.0 */
/* Generated from hello.cob */
/* Generated at Oct 04 2008 00:19:36 EDT */
/* OpenCOBOL build date Oct 01 2008 22:15:19 */
/* OpenCOBOL package date Oct 01 2008 16:31:26 CEST */
/* Compile command cobc -C hello.cob */
#define __USE_STRING_INLINES 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <libcob.h>
#define COB_SOURCE_FILE "hello.cob"
#define COB_PACKAGE_VERSION "1.1"
#define COB_PATCH_LEVEL 0
/* function prototypes */
static int hello_ (const int);
int hello (void);
/* functions */
int
hello ()
{
return hello_ (0);
}
/* end functions */
static int
hello_ (const int entry)
{
#include "hello.c.h" /* local variables */
static int initialized = 0;
static cob_field *cob_user_parameters[COB_MAX_FIELD_PARAMS];
static cob_module module = { NULL, NULL, &f_5, NULL, cob_user_parameters, 0, '.', '$', ',', 1, 1, 1, 0};
/* perform frame stack */
int frame_index;
struct frame {
int perform_through;
void *return_address;
} frame_stack[255];
/* Start of function code */
if (unlikely(entry < 0)) {
if (!initialized) {
return 0;
}
initialized = 0;
return 0;
}
module.next = cob_current_module;
cob_current_module = &module;
if (unlikely(initialized == 0))
{
if (!cob_initialized) {
cob_fatal_error (COB_FERROR_INITIALIZED);
}
cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL);
if (module.next)
cob_set_cancel ((const char *)"hello", (void *)hello, (void *)hello_);
(*(int *) (b_1)) = 0;
(*(int *) (b_2)) = 0;
(*(int *) (b_3)) = 0;
memset (b_5, 48, 4);
initialized = 1;
}
/* initialize frame stack */
frame_index = 0;
frame_stack[0].perform_through = -1;
/* initialize number of call params */
(*(int *) (b_3)) = cob_call_params;
cob_save_call_params = cob_call_params;
goto l_2;
/* PROCEDURE DIVISION */
/* hello: */
l_2:;
/* MAIN SECTION: */
/* MAIN PARAGRAPH: */
/* hello.cob:5: DISPLAY */
{
cob_new_display (0, 1, 1, &c_1);
}
/* hello.cob:6: STOP */
{
cob_stop_run ((*(int *) (b_1)));
}
cob_current_module = cob_current_module->next;
return (*(int *) (b_1));
}
/* end function stuff */
Generate assembler:
$ cobc -S hello.cob
hello.s:
.file "cob9141_0.c"
.text
.globl hello
.type hello, @function
hello:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl $0, (%esp)
call hello_
leave
ret
.size hello, .-hello
.data
.align 4
.type module.5786, @object
.size module.5786, 28
module.5786:
.long 0
.long 0
.long f_5.5782
.long 0
.long cob_user_parameters.5785
.byte 0
.byte 46
.byte 36
.byte 44
.byte 1
.byte 1
.byte 1
.byte 0
.local cob_user_parameters.5785
.comm cob_user_parameters.5785,256,32
.local initialized.5784
.comm initialized.5784,4,4
.section .rodata
.LC0:
.string "Hello World!"
.data
.align 4
.type c_1.5783, @object
.size c_1.5783, 12
c_1.5783:
.long 12
.long .LC0
.long a_2.5781
.align 4
.type f_5.5782, @object
.size f_5.5782, 12
f_5.5782:
.long 4
.long b_5.5776
.long a_1.5780
.align 4
.type a_2.5781, @object
.size a_2.5781, 8
a_2.5781:
.byte 33
.byte 0
.byte 0
.byte 0
.long 0
.align 4
.type a_1.5780, @object
.size a_1.5780, 8
a_1.5780:
.byte 16
.byte 4
.byte 0
.byte 0
.long 0
.local b_3.5779
.comm b_3.5779,4,16
.local b_2.5778
.comm b_2.5778,4,16
.local b_1.5777
.comm b_1.5777,4,16
.local b_5.5776
.comm b_5.5776,4,16
.section .rodata
.LC1:
.string "1.1"
.LC2:
.string "hello.cob"
.LC3:
.string "hello"
.text
.type hello_, @function
hello_:
pushl %ebp
movl %esp, %ebp
subl $2072, %esp
movl 8(%ebp), %eax
shrl $31, %eax
testl %eax, %eax
je .L4
movl initialized.5784, %eax
testl %eax, %eax
jne .L5
movl $0, -2052(%ebp)
jmp .L6
.L5:
movl $0, initialized.5784
movl $0, -2052(%ebp)
jmp .L6
.L4:
movl cob_current_module, %eax
movl %eax, module.5786
movl $module.5786, cob_current_module
movl initialized.5784, %eax
testl %eax, %eax
sete %al
movzbl %al, %eax
testl %eax, %eax
je .L7
movl cob_initialized, %eax
testl %eax, %eax
jne .L8
movl $0, (%esp)
call cob_fatal_error
.L8:
movl $0, 8(%esp)
movl $.LC1, 4(%esp)
movl $.LC2, (%esp)
call cob_check_version
movl module.5786, %eax
testl %eax, %eax
je .L9
movl $hello_, 8(%esp)
movl $hello, 4(%esp)
movl $.LC3, (%esp)
call cob_set_cancel
.L9:
movl $b_1.5777, %eax
movl $0, (%eax)
movl $b_2.5778, %eax
movl $0, (%eax)
movl $b_3.5779, %eax
movl $0, (%eax)
movl $4, 8(%esp)
movl $48, 4(%esp)
movl $b_5.5776, (%esp)
call memset
movl $1, initialized.5784
.L7:
movl $0, -4(%ebp)
movl $-1, -2044(%ebp)
movl $b_3.5779, %edx
movl cob_call_params, %eax
movl %eax, (%edx)
movl cob_call_params, %eax
movl %eax, cob_save_call_params
.L10:
movl $c_1.5783, 12(%esp)
movl $1, 8(%esp)
movl $1, 4(%esp)
movl $0, (%esp)
call cob_new_display
movl $b_1.5777, %eax
movl (%eax), %eax
movl %eax, (%esp)
call cob_stop_run
.L6:
movl -2052(%ebp), %eax
leave
ret
.size hello_, .-hello_
.ident "GCC: (Debian 4.3.1-9) 4.3.1"
.section .note.GNU-stack,"",@progbits
Compile only; outputs assembly file. Produces hello.s.
Produce object code:
$ cobc -c hello.cob
Compile and assemble, do not link. Produces hello.o.
Build modules:
$ cobc -m hello.cob
Build dynamically loadable module. The is the default behaviour.
This example produces hello.so or hello.dll.
Module run:
$ cobcrun hello
Will scan the DSO hello.so, and then link, load, and execute hello.
Attention!
Need a little OS/X info here
$ cobc -x hello.cob
Build an executable program. This examples produces hello or
hello.exe.
This is important. cobc produces a Dynamic Shared Object by default.
To create executables, you need to use -x.
$ ./hello
Hello World!
OpenCOBOL also supports features for multiple source, multiple language
programming, detailed in the FAQ at Q. Does OpenCOBOL support modules?.
cobcrun is the OpenCOBOL driver program that allows the execution of
programs stored in OpenCOBOL modules.
The cobc compiler, by default, produces modules (the -m option).
These modules are linkable dynamic shared objects (DSO). Using GNU/Linux
for example:
$ cobc -x hello.cob
$ ./hello
Hello World!
$ cobc hello.cob
$ cobcrun hello
Hello World!
The cobc -x hello.cob built an executable binary called hello. The
cobc hello.cob produced a DSO hello.so, and cobcrun resolves
the entry point and executes the code, right from the DSO.
cobcrun is the compiler author's preferred way to manage OpenCOBOL
development. It alleviates knowing which source file needs -x while
encouraging proper modular programming, a mainstay of OpenCOBOL.
cob-config is a program that can be used to find the C compiler flags
and libraries required for compiling. Using GNU/Linux for example:
$ cob-config
Usage: cob-config [OPTIONS]
Options:
[--prefix[=DIR]]
[--exec-prefix[=DIR]]
[--version]
[--libs]
[--cflags]
$ cob-config --libs
-L/usr/local/lib -lcob -lm -lgmp -lncurses -ldb
$ cob-config --cflags
-I/usr/local/include
You may need to use these features during mixed source language development,
usually by back-ticking the command output inline with other gcc commands.
Usage: cobc [options] file...
Options:
--help Display this message
--version, -V Display compiler version
-v Display the programs invoked by the compiler
-x Build an executable program
-m Build a dynamically loadable module (default)
-std=<dialect> Compile for a specific dialect :
cobol2002 Cobol 2002
cobol85 Cobol 85
ibm IBM Compatible
mvs MVS Compatible
bs2000 BS2000 Compatible
mf Micro Focus Compatible
default When not specified
See config/default.conf and config/\*.conf
-free Use free source format
-fixed Use fixed source format (default)
-O, -O2, -Os Enable optimization
-g Produce debugging information in the output
-debug Enable all run-time error checking
-o <file> Place the output into <file>
-b Combine all input files into a single
dynamically loadable module
-E Preprocess only; do not compile, assemble or link
-C Translation only; convert COBOL to C
-S Compile only; output assembly file
-c Compile and assemble, but do not link
-t <file> Generate and place a program listing into <file>
-I <directory> Add <directory> to copybook search path
-L <directory> Add <directory> to library search path
-l <lib> Link the library <lib>
-D <define> Pass <define> to the C compiler
-conf=<file> User defined dialect configuration - See -std=
--list-reserved Display all reserved words
-save-temps Do not delete intermediate files
-MT <target> Set target file used in dependency list
-MF <file> Place dependency list into <file>
-ext <extension> Add default file extension
-Wall Enable all warnings
-Wobsolete Warn if obsolete features are used
-Warchaic Warn if archaic features are used
-Wcolumn-overflow Warn if any text after column 72
-Wredefinition Warn incompatible redefinition of data items
-Wconstant Warn inconsistent constant
-Wparentheses Warn lack of parentheses around AND within OR
-Wterminator Warn lack of scope terminator (END-XXX)
-Wstrict-typing Warn type mismatch strictly
-Wimplicit-define Warn implicitly defined data items
-Wcall-params Warn non 01/77 items for CALL params (NOT set with -Wall)
-Wtruncate Warn possible field truncation (NOT set with -Wall)
-ftrace Generate trace code (Executed SECTION/PARAGRAPH)
-ftraceall Generate trace code (Executed SECTION/PARAGRAPH/STATEMENTS)
-fsyntax-only Syntax error checking only; don't emit any output
-fdebugging-line Enable debugging lines ('D' in indicator column)
-fsource-location Generate source location code (Turned on by -debug or -g)
-fimplicit-init Do automatic initialization of the Cobol runtime system
-fstatic-linkage Statically allocate non-USING LINKAGE parameters
-fsign-ascii Numeric display sign ASCII (Default on ASCII machines)
-fsign-ebcdic Numeric display sign EBCDIC (Default on EBCDIC machines)
-fstack-check PERFORM stack checking (Turned on by -debug or -g)
-ffold-copy-lower Fold COPY subject to lower case (Default no transformation)
-ffold-copy-upper Fold COPY subject to upper case (Default no transformation)
-fnotrunc Do not truncate binary fields according to PIC (ala MF)
-fnull-param Pass extra NULL terminating pointers on CALL statements
Using the std=<dialect> compiler option, OpenCOBOL can be configured to
compile using specific historical COBOL compiler features and quirks.
Supported dialects include:
- default
- cobol85
- cobol2002
- ibm
- mvs
- mf
- bs2000
For details on what options and switches are used to support these dialect
compiles, see the config/ directory of your OpenCOBOL installation. For
Debian GNU/Linux, that will be /usr/share/open-cobol/config/ if you used
APT to install an OpenCOBOL package or /usr/local/share/open-cobol/config/
after a build from the source archive.
For example: the bs2000.conf file restricts data representations to 2, 4 or
8 byte binary while mf.conf allows data representations from 1 thru 8 bytes.
cobol85.conf allows debugging lines, cobol2002.conf configures the
compiler to warn that this feature is obsolete.
Maybe. Style is a very personal developer choice. OpenCOBOL pays
homage to this freedom of choice. Here is the FIXED form header that
this author uses. It includes ocdoc lines.
*>>SOURCE FORMAT IS FIXED
*> ***************************************************************
*><* ===========
*><*
*><* ===========
*><* :Author:
*><* :Date:
*><* :Purpose:
*><* :Tectonics: cobc
*> ***************************************************************
identification division.
program-id. .
environment division.
configuration section.
input-output section.
file-control.
*> select
*> assign to
*> organization is
*> .
data division.
file section.
*>fd .
*> 01 .
working-storage section.
local-storage section.
linkage section.
screen section.
*> **************************************************************
procedure division.
goback.
end program .
*><*
*><* Last Update: dd-Mmm-yyyy
Fill in the program-id and end program to compile. Fill in the ocdoc
title for generating documentation.
ocdoc is a small utility used to annotate sample programs and to
support generation of Usage Documentation using COBOL sourced
ReStructuredText extract lines.
ocdoc.cob:
*>>SOURCE FORMAT IS FIXED
*> ***************************************************************
*><* =====================
*><* ocdoc.cob usage guide
*><* =====================
*><* .. sidebar:: Table of Contents
*><*
*><* .. contents:: :local:
*><*
*><* :Author: Brian Tiffin
*><* :Date: 30-Sep-2008
*><* :Rights: Copyright (c) 2008, Brian Tiffin.
*><* GNU FDL License.
*><* :Purpose: Extract usage document lines from COBOL sources.
*><* Using OpenCOBOL 1.1pr. OpenCOBOL is tasty.
*><* :Tectonics: cobc -x ocdoc.cob
*><* :Docgen: $ ./ocdoc ocdoc.cob ocdoc.rst ocdoc.html skin.css
*> ***************************************************************
*><*
*><* ------------
*><* Command line
*><* ------------
*><* *ocdoc* runs in two forms.
*><*
*><* Without arguments, *ocdoc* will act as a pipe filter.
*><* Reading from standard in and writing the extract to standard
*><+ out.
*><*
*><* The *ocdoc* command also takes an input file, an extract
*><+ filename, an optional result file (with optional
*><+ stylesheet) and a verbosity option *-v* or a
*><+ special *-fixed* flag (to force skipping sequence numbers).
*><* If a result file is given, ocdoc will automatically
*><* run an *rst2html* command using the SYSTEM service.
*><*
*><* Due to an overly simplistic argument handler, you can only
*><+ turn on verbosity or -fixed when using all four filenames.
*><*
*><* Examples::
*><*
*><* $ cat ocdoc.cob | ocdoc >ocdoc.rst
*><* $ ./ocdoc ocdoc.cob ocdoc.rst
*><* $ ./ocdoc ocdoc.cob ocdoc.rst
*><+ ocdoc.html skin.css -fixed
*><* ...
*><* Input : ocdoc.cob
*><* Output : ocdoc.rst
*><* Command: rst2html --stylesheet=skin.css
*><+ ocdoc.rst ocdoc.html
*><*
*><* -----------------
*><* What is extracted
*><* -----------------
*><* - Lines that begin with \*><\* *ignoring spaces*, are
*><+ extracted.
*><*
*><* - Lines that begin with \*><+ are appended to the
*><+ previous output line. As lines are trimmed of trailing
*><+ spaces, and *ocdoc* removes the space following the
*><+ extract triggers, you may need two spaces after an
*><+ ocdoc append.
*><*
*><* - Lines that begin with \*><[ begin a here document
*><+ with lines that follow extracted as is.
*><*
*><* - Lines that begin with \*><] close a here document.
*><+ Here document start and end lines are excluded from the
*><+ extract.
*><*
*><* -----------
*><* Source code
*><* -----------
*><* `Download ocdoc.cob
*><+ <http://opencobol.add1tocobol.com/ocdoc.cob>`_
*><* `See ocdocseq.cob
*><+ <http://opencobol.add1tocobol.com/ocdocseq.html>`_
*><*
*><! This is not extracted. Reminder of how to include source
*><! .. include:: ocdoc.cob
*><! :literal:
*><*
*><* -----------------------
*><* identification division
*><* -----------------------
*><*
*><* ::
*><*
*><[
identification division.
program-id. OCDOC.
environment division.
input-output section.
file-control.
select standard-input assign to KEYBOARD.
select standard-output assign to DISPLAY.
select source-input
assign to source-name
organization is line sequential
.
select doc-output
assign to doc-name
organization is line sequential
.
*><]
*><*
*><* -------------
*><* data division
*><* -------------
*><*
*><* ::
*><*
*><[
data division.
file section.
fd standard-input.
01 stdin-record pic x(256).
fd standard-output.
01 stdout-record pic x(256).
fd source-input.
01 source-record pic x(256).
fd doc-output.
01 doc-record pic x(256).
working-storage section.
01 arguments pic x(256).
01 source-name pic x(256).
01 doc-name pic x(256).
01 result-name pic x(256).
01 style-name pic x(256).
01 verbosity pic x(9).
88 verbose values "-v" "--v" "-verbose" "--verbose".
88 skipseqnum values "-fix" "-fixed" "--fix" "--fixed".
01 usagehelp pic x(6).
88 helping values "-h" "--h" "-help" "--help".
01 filter-flag pic x value low-value.
88 filtering value high-value.
01 line-count usage binary-long.
01 line-display pic z(8)9.
*><]
*><*
*><* Note the conditional test for end of here doc
*><*
*><* ::
*><*
*><[
01 trimmed pic x(256).
88 herestart value "*><[".
88 hereend value "*><]".
01 hereflag pic x value low-value.
88 heredoc value high-value.
88 herenone value low-value.
*><]
*><*
*><* Note the here-record adds an ocdoc extract to lines that
*><+ follow.
*><*
*><* ::
*><*
*><[
01 here-record.
02 filler pic x(5) value "*><* ".
02 here-data pic x(251).
01 seq-record.
02 filler pic x(7) value " ".
02 seq-data pic x(249).
01 doc-buffer pic x(256).
01 buffer-offset pic 999 usage comp-5 value 1.
01 buffer-flag pic x value low-value.
88 buffer-empty value low-value.
88 buffered-output value high-value.
01 counter pic 999 usage comp-5.
01 len-of-comment pic 999 usage comp-5.
01 first-part pic x(8).
88 special values "*><*" "*><+".
88 autodoc value "*><*".
88 autoappend value "*><+".
01 rst-command pic x(256).
01 result usage binary-long.
*><]
*><*
*><* ------------------
*><* procedure division
*><* ------------------
*><*
*><* ::
*><*
*><[
*> ***************************************************************
procedure division.
*><]
*><*
*><* Accept command line arguments. See if help requested.
*><*
*><* ::
*><*
*><[
accept arguments from command-line end-accept
move arguments to usagehelp
if helping
display
"$ ./ocdoc source markover [output [skin [--fixed]]]"
end-display
display "$ ./ocdoc" end-display
display
" without arguments extracts stdin to stdout"
end-display
goback
end-if
*><]
*><*
*><* Either run as filter or open given files. Two filenames
*><+ will generate an extract. Three will run the extract
*><+ through *rst2html* using an optional fourth filename
*><+ as a stylesheet.
*><*
*><* ::
*><*
*><[
*> Determine if this is running as a filter
if arguments not equal spaces
unstring arguments delimited by all spaces
into source-name doc-name
result-name style-name
verbosity
end-unstring
open input source-input
open output doc-output
else
set filtering to true
open input standard-input
open output standard-output
end-if
*><]
*><*
*><* Initialize the output buffer, and line count.
*><*
*><* ::
*><*
*><[
set buffer-empty to true
move 1 to buffer-offset
move spaces to doc-record
move 0 to line-count
*><]
*><*
*><* The read is either from file or stdin. Start with the
*><+ first record.
*><*
*><* ::
*><*
*><[
*> filtering requires different reader loop
if filtering
read standard-input
at end move high-values to stdin-record
end-read
move stdin-record to source-record
else
read source-input
at end move high-values to source-record
end-read
end-if
*><]
*><*
*><* The main loop starts here, having done a pre-read to start
*><+ things off.
*><*
*><* ::
*><*
*><[
perform until source-record = high-values
add 1 to line-count
*><]
*><*
*><* Small wrinkle if processing fixed form with sequence numbers,
*><+ as the heredoc end marker needs to be recognized
*><+ but we still want the sequence numbers in the heredoc.
*><*
*><* So files processed --fixed play some data shuffling games.
*><*
*><* ::
*><*
*><[
if skipseqnum
if heredoc
move source-record(7 : 248) to trimmed
move source-record to seq-data
move seq-record to source-record
else
move source-record(7 : 248) to source-record
move source-record to trimmed
end-if
else
move function trim(source-record leading) to trimmed
end-if
*><]
*><*
*><* First to check for here doc start and end, setting flag
*><+ if trimmed conditional the heredoc start or heredoc end
*><+ strings.
*><*
*><* ::
*><*
*><[
if herestart
set heredoc to true
end-if
if hereend
set herenone to true
end-if
*><]
*><*
*><* Inside the loop, we skip over heredoc entries.
*><+ If it is normal, than check for heredoc and include
*><+ source lines that follow, by prepending the extract tag
*><*
*><* ::
*><*
*><[
if (not herestart) and (not hereend)
if heredoc
move source-record to here-data
move here-record to trimmed
end-if
*><]
*><*
*><* Unstring the line, looking for special tags in the first
*><+ part.
*><*
*><* ::
*><*
*><[
unstring trimmed delimited by all spaces
into first-part
count in counter
end-unstring
*><]
*><*
*><* If special, we either buffer or append to buffer
*><*
*><* ::
*><*
*><[
evaluate true when special
if autoappend and buffer-empty
move spaces to doc-record
move 1 to buffer-offset
end-if
if autodoc and buffered-output
if filtering
move doc-record to stdout-record
write stdout-record end-write
else
write doc-record end-write
end-if
if verbose
display
function trim(doc-record trailing)
end-display
end-if
move spaces to doc-record
set buffer-empty to true
move 1 to buffer-offset
end-if
*><]
*><*
*><* Skip over where the tag was found plus an extra space.
*><* Adding 2 skips over the assumed space after a special tag
*><*
*><* ::
*><*
*><[
add 2 to counter
compute len-of-comment =
function length(trimmed) - counter
end-compute
if len-of-comment > 0
move trimmed(counter : len-of-comment)
to doc-buffer
else
move spaces to doc-buffer
end-if
*><]
*><*
*><* Buffer the line, either to position 1 or appending to last.
*><*
*><* ::
*><*
*><[
string
function trim(doc-buffer trailing)
delimited by size
into doc-record
with pointer buffer-offset
on overflow
move line-count to line-display
display
"*** truncation *** reading line "
line-display
end-display
end-string
set buffered-output to true
end-evaluate
end-if
*><]
*><*
*><* Again, we either read the next record from file or stdin.
*><*
*><* ::
*><*
*><[
if filtering
read standard-input
at end move high-values to stdin-record
end-read
move stdin-record to source-record
else
read source-input
at end move high-values to source-record
end-read
end-if
end-perform
*><]
*><*
*><* We may or may not end up with buffered data
*><*
*><* ::
*><*
*><[
if buffered-output
set buffer-empty to true
move 1 to buffer-offset
if filtering
move doc-record to stdout-record
write stdout-record end-write
else
write doc-record end-write
end-if
if verbose
display
function trim(doc-record trailing)
end-display
end-if
move spaces to doc-record
end-if
*><]
*><*
*><* Close the OpenCOBOL files
*><*
*><* ::
*><*
*><[
if filtering
close standard-output
close standard-input
else
close doc-output
close source-input
end-if
if verbose
display "Input : " function trim(source-name) end-display
display "Output : " function trim(doc-name) end-display
end-if
*><]
*><*
*><* If we have a result file, use the SYSTEM service to
*><+ generate an HTML file, possibly with stylesheet.
*><*
*><* ::
*><*
*><[
*> pass the extract through a markover, in this case ReST
move spaces to rst-command
if result-name not equal spaces
if style-name equal spaces
string
"rst2html " delimited by size
doc-name delimited by space
" " delimited by size
result-name delimited by space
into rst-command
end-string
else
string
"rst2html --stylesheet=" delimited by size
style-name delimited by space
" " delimited by size
doc-name delimited by space
" " delimited by size
result-name delimited by space
into rst-command
end-string
end-if
if verbose
display
"Command: "
function trim(rst-command trailing)
end-display
end-if
call "SYSTEM"
using rst-command
returning result
end-call
if result not equal zero
display "HTML generate failed: " result end-display
end-if
end-if
*><]
*><*
*><* And before you know it, we are done.
*><*
*><* ::
*><*
*><[
goback.
end program OCDOC.
*><]
*><*
*><* Don't forget to visit http://opencobol.org
*><*
*><* Cheers
*><*
*><* *Last edit:* 03-Oct-2008
See ocdoc.html for the output
from processing ocdoc.cob with ocdoc.
Yes and no. There is no embedded SQL in OpenCOBOL.
There are early prototypes
for SQLite at ocshell.c with a
sample usage program at
sqlscreen.cob and
supporting documentation at
sqlscreen.html
There are currently (August 2008) quite a few active developments for external SQL engine
access. Rumours of Postgres and libdbi wrappers abound.
COBOL is a reserved word rich language. The OpenCOBOL compiler recognizes:
Reserved Words
514 words in OC 1.1, 136 of which are marked not yet implemented.
378 functional reserved words, as of August 2008.
3.12.1 ACCEPT
ACCEPT variable FROM CONSOLE.
ACCEPT variable FROM ENVIRONMENT "path".
ACCEPT variable FROM COMMAND LINE.
ACCEPT screen-variable.
3.12.2 ACCESS
SELECT filename
ASSIGN TO "filename.dat"
ACCESS MODE IS RANDOM
RELATIVE KEY IS keyfield.
3.12.3 ACTIVE-CLASS
Not yet implemented. Object COBOL feature.
3.12.4 ADD
ADD 1 TO cobol GIVING OpenCOBOL END-ADD.
3.12.5 ADDRESS
SET pointer-variable TO ADDRESS OF linkage-store.
3.12.6 ADVANCING
DISPLAY "Legend: " WITH NO ADVANCING END-DISPLAY.
WRITE printrecord AFTER ADVANCING PAGE END-WRITE.
3.12.7 AFTER
PERFORM
WITH TEST AFTER
VARYING variable FROM 1 BY 1
UNTIL variable > 10
DISPLAY variable END-DISPLAY
END-PERFORM.
3.12.8 ALIGNED
3.12.9 ALL
INSPECT variable REPLACING ALL "123" WITH "456".
3.12.10 ALLOCATE
ALLOCATE based-var INITIALIZED RETURNING pointer-var.
3.12.11 ALPHABET
* Set up for a mixed case SORT COLLATING SEQUENCE IS
CONFIGURATION SECTION.
SPECIAL-NAMES.
ALPHABET name IS "AaBbCcDdEe..".
3.12.12 ALPHABETIC
IF variable IS ALPHABETIC
DISPLAY "alphabetic" END-DISPLAY
END-IF
3.12.13 ALPHABETIC-LOWER
IF variable IS ALPHABETIC-LOWER
DISPLAY "alphabetic-lower" END-DISPLAY
END-IF
3.12.14 ALPHABETIC-UPPER
DISPLAY variable "alphabetic-upper " WITH NO ADVANCING
IF variable IS ALPHABETIC-UPPER
DISPLAY "true" END-DISPLAY
ELSE
DISPLAY "false" END-DISPLAY
END-IF
3.12.15 ALPHANUMERIC
3.12.16 ALPHANUMERIC-EDITED
3.12.17 ALSO
3.12.18 ALTER
3.12.19 ALTERNATE
3.12.20 AND
3.12.21 ANY
3.12.22 ANYCASE
3.12.23 ARE
3.12.24 AREA
3.12.25 AREAS
3.12.26 ARGUMENT-NUMBER
3.12.27 ARGUMENT-VALUE
3.12.28 ARITHMETIC
3.12.29 ASx
3.12.30 ASCENDING
3.12.31 ASSIGN
3.12.32 ATx
3.12.33 ATTRIBUTE
3.12.34 AUTO
3.12.35 AUTO-SKIP
3.12.36 AUTOMATIC
3.12.37 AUTOTERMINATE
3.12.38 B-AND
3.12.39 B-NOT
3.12.40 B-OR
3.12.41 B-XOR
3.12.42 BACKGROUND-COLOR
05 BLANK SCREEN BACKGROUND-COLOR 7 FOREGROUND-COLOR 0.
3.12.43 BASED
01 based-var PIC X(80) BASED.
A sample posted by [human]:
*-----------------------------------------------------------------
IDENTIFICATION DIVISION.
PROGRAM-ID. 'MEMALL'.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES. DECIMAL-POINT IS COMMA.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
FILE SECTION.
*
WORKING-STORAGE SECTION.
*
77 mychar pic x.
01 REC-TEST BASED.
03 REC-TEST-PART1 PIC X(5500000).
03 REC-TEST-PART2 PIC X(0100000).
03 REC-TEST-PART3 PIC X(1200000).
03 REC-TEST-PART4 PIC X(1200000).
03 REC-TEST-PART5 PIC X(1700000).
*-----------------------------------------------------------------
LINKAGE SECTION.
*-----------------------------------------------------------------
PROCEDURE DIVISION.
declaratives.
end declaratives.
*-----------------------------------------------------------------
main section.
00.
FREE ADDRESS OF REC-TEST
display 'MEMALL loaded and REC-TEST FREEd before ALLOCATE'
accept mychar
*
IF ADDRESS OF REC-TEST = NULL
display 'REC-TEST was not allocated before'
ELSE
display 'REC-TEST was allocated before'
END-IF
accept mychar
*
ALLOCATE REC-TEST
move all '9' to REC-TEST
display 'REC-TEST allocated and filled with '
REC-TEST (1:9)
end-display
accept mychar
*
IF ADDRESS OF REC-TEST = NULL
display 'REC-TEST was not allocated before'
ALLOCATE REC-TEST
display 'REC-TEST allocated again, filled with '
REC-TEST (1:9)
end-display
ELSE
display 'REC-TEST was allocated before'
END-IF
accept mychar
*
*
FREE ADDRESS OF REC-TEST
display 'REC-TEST FREEd'
accept mychar
*
stop run
*
continue.
ex. exit program.
*-----------------------------------------------------------------
*--- End of program MEMALL ---------------------------------------
3.12.44 BEEP
DISPLAY "Beeeeep" LINE 3 COLUMN 1 WITH BEEP END-DISPLAY.
3.12.45 BEFORE
3.12.46 BELL
DISPLAY "Beeeeep" LINE 3 COLUMN 1 WITH BELL END-DISPLAY.
3.12.47 BINARY
3.12.48 BINARY-C-LONG
3.12.49 BINARY-CHAR
3.12.50 BINARY-DOUBLE
3.12.51 BINARY-LONG
3.12.52 BINARY-SHORT
3.12.53 BIT
3.12.54 BLANK
05 BLANK SCREEN BACKGROUND-COLOR 7 FOREGROUND-COLOR 0.
3.12.55 BLINK
3.12.56 BLOCK
3.12.57 BOOLEAN
3.12.58 BOTTOM
3.12.59 BYx
3.12.60 BYTE-LENGTH
3.12.62 CANCEL
3.12.63 CDx
3.12.64 CENTER
3.12.65 CFx
3.12.66 CHx
3.12.67 CHAIN
3.12.68 CHAINING
3.12.69 CHARACTER
3.12.70 CHARACTERS
3.12.71 CLASS
3.12.72 CLASS-ID
3.12.73 CLASSIFICATION
3.12.74 CLOSE
3.12.75 CODE
3.12.76 CODE-SET
3.12.77 COL
3.12.78 COLLATING
3.12.79 COLS
3.12.80 COLUMN
3.12.81 COLUMNS
3.12.82 COMMA
3.12.83 COMMAND-LINE
3.12.84 COMMIT
3.12.85 COMMON
3.12.86 COMMUNICATION
3.12.87 COMP
3.12.88 COMP-1
3.12.89 COMP-2
3.12.90 COMP-3
3.12.91 COMP-4
3.12.92 COMP-5
3.12.93 COMP-X
3.12.94 COMPUTATIONAL
3.12.95 COMPUTATIONAL-1
3.12.96 COMPUTATIONAL-2
3.12.97 COMPUTATIONAL-3
3.12.98 COMPUTATIONAL-4
3.12.99 COMPUTATIONAL-5
3.12.100 COMPUTATIONAL-X
3.12.101 COMPUTE
3.12.102 CONDITION
3.12.103 CONFIGURATION
3.12.104 CONSTANT
3.12.105 CONTAINS
3.12.106 CONTENT
3.12.107 CONTINUE
3.12.108 CONTROL
3.12.109 CONTROLS
3.12.110 CONVERTING
3.12.111 COPY
3.12.112 CORR
3.12.113 CORRESPONDING
3.12.114 COUNT
3.12.115 CRT
3.12.116 CURRENCY
3.12.117 CURSOR
3.12.118 CYCLE
3.12.119 DATA
3.12.120 DATA-POINTER
3.12.121 DATE
3.12.122 DAY
3.12.123 DAY-OF-WEEK
3.12.124 DEx
3.12.125 DEBUGGING
3.12.126 DECIMAL-POINT
3.12.127 DECLARATIVES
3.12.128 DEFAULT
3.12.129 DELETE
3.12.130 DELIMITED
3.12.131 DELIMITER
3.12.132 DEPENDING
3.12.133 DESCENDING
3.12.134 DESTINATION
3.12.135 DETAIL
3.12.136 DISABLE
3.12.137 DISK
3.12.138 DISPLAY
3.12.139 DIVIDE
3.12.140 DIVISION
3.12.141 DOWN
3.12.142 DUPLICATES
3.12.143 DYNAMIC
3.12.144 EBCDIC
Extended Binary Coded Decimal Interchange Code.
A character encoding common to mainframe systems, therefore COBOL, therefore
OpenCOBOL. Different than ASCII and OpenCOBOL supports both through
efficient mappings. See http://en.wikipedia.org/wiki/EBCDIC for more info.
3.12.145 ECx
3.12.146 EGI
3.12.147 ELSE
3.12.148 EMI
3.12.149 ENABLE
3.12.150 END
3.12.151 END-ACCEPT
3.12.152 END-ADD
3.12.153 END-CALL
3.12.154 END-COMPUTE
3.12.155 END-DELETE
3.12.156 END-DISPLAY
3.12.157 END-DIVIDE
3.12.158 END-EVALUATE
3.12.159 END-IF
3.12.160 END-MULTIPLY
3.12.161 END-OF-PAGE
3.12.162 END-PERFORM
3.12.163 END-READ
3.12.164 END-RECEIVE
3.12.165 END-RETURN
3.12.166 END-REWRITE
3.12.167 END-SEARCH
3.12.168 END-START
3.12.169 END-STRING
3.12.170 END-SUBTRACT
3.12.171 END-UNSTRING
3.12.172 END-WRITE
3.12.173 ENTRY
3.12.174 ENTRY-CONVENTION
3.12.175 ENVIRONMENT
3.12.176 ENVIRONMENT-NAME
3.12.177 ENVIRONMENT-VALUE
3.12.178 EOx
3.12.179 EOL
3.12.180 EOP
3.12.181 EOS
3.12.182 EQUAL
3.12.183 EQUALS
3.12.184 ERASE
3.12.185 ERROR
3.12.186 ESCAPE
3.12.187 ESI
3.12.188 EVALUATE
3.12.189 EXCEPTION
3.12.190 EXCEPTION-OBJECT
3.12.191 EXCLUSIVE
3.12.192 EXIT
3.12.193 EXPANDS
3.12.194 EXTEND
3.12.195 EXTERNAL
3.12.196 FACTORY
3.12.197 FALSE
3.12.198 FDx
3.12.199 FILE
3.12.200 FILE-CONTROL
3.12.201 FILE-ID
3.12.202 FILLER
3.12.203 FINAL
3.12.204 FIRST
3.12.205 FLOAT-EXTENDED
3.12.206 FLOAT-LONG
3.12.207 FLOAT-SHORT
3.12.209 FOR
3.12.210 FOREGROUND-COLOR
3.12.211 FOREVER
3.12.212 FORMAT
3.12.213 FREE
3.12.214 FROM
3.12.215 FULL
3.12.216 FUNCTION
DISPLAY FUNCTION TRIM(" trim off leading spaces" LEADING) END-DISPLAY.
3.12.217 FUNCTION-ID
3.12.218 GENERATE
3.12.219 GET
3.12.220 GIVING
ADD 1 TO cobol GIVING OpenCOBOL.
3.12.221 GLOBAL
3.12.222 GOx
3.12.224 GREATER
3.12.225 GROUP
3.12.226 GROUP-USAGE
3.12.227 HEADING
3.12.228 HIGH-VALUE
3.12.229 HIGH-VALUES
3.12.230 HIGHLIGHT
3.12.231 I-O
3.12.232 I-O-CONTROL
3.12.233 IDx
3.12.234 IDENTIFICATION
3.12.235 IFx
3.12.236 IGNORING
3.12.237 IMPLEMENTS
3.12.238 INx
3.12.239 INDEX
3.12.240 INDEXED
3.12.241 INDICATE
3.12.242 INHERITS
3.12.243 INITIAL
3.12.244 INITIALIZE
3.12.245 INITIALIZED
3.12.246 INITIATE
3.12.247 INPUT
3.12.248 INPUT-OUTPUT
3.12.249 INSPECT
3.12.250 INTERFACE
3.12.251 INTERFACE-ID
3.12.252 INTO
3.12.253 INTRINSIC
3.12.254 INVALID
3.12.255 INVOKE
3.12.256 ISx
3.12.257 JUST
3.12.258 JUSTIFIED
3.12.259 KEY
3.12.260 KEYBOARD
A special value for Standard Input:
file-control.
select cgi-in
assign to keyboard.
3.12.261 LABEL
3.12.262 LAST
3.12.263 LC_ALL
3.12.264 LC_COLLATE
3.12.265 LC_CTYPE
3.12.266 LC_MESSAGES
3.12.267 LC_MONETARY
3.12.268 LC_NUMERIC
3.12.269 LC_TIME
3.12.270 LEADING
3.12.271 LEFT
3.12.272 LENGTH
3.12.273 LESS
3.12.274 LIMIT
3.12.275 LIMITS
3.12.276 LINAGE
3.12.277 LINAGE-COUNTER
An internal OpenCOBOL noun, or Special Register. Value is readonly and is
maintained during WRITEs to files that have a LINAGE clause. Useful for
quick reports and logical page layouts.
3.12.278 LINE
3.12.279 LINE-COUNTER
3.12.280 LINES
3.12.281 LINKAGE
3.12.282 LOCAL-STORAGE
3.12.283 LOCALE
3.12.284 LOCK
3.12.285 LOW-VALUE
3.12.286 LOW-VALUES
3.12.287 LOWLIGHT
3.12.288 MANUAL
3.12.289 MEMORY
3.12.290 MERGE
3.12.291 MESSAGE
3.12.292 METHOD
3.12.293 METHOD-ID
3.12.294 MINUS
3.12.295 MODE
3.12.296 MOVE
3.12.297 MULTIPLE
3.12.298 MULTIPLY
3.12.299 NATIONAL
3.12.300 NATIONAL-EDITED
3.12.301 NATIVE
3.12.302 NEGATIVE
3.12.303 NESTED
3.12.304 NEXT
3.12.305 NOx
3.12.306 NONE
3.12.307 NORMAL
3.12.308 NOT
3.12.309 NULL
3.12.310 NULLS
3.12.311 NUMBER
3.12.312 NUMBERS
3.12.313 NUMERIC
3.12.314 NUMERIC-EDITED
3.12.315 OBJECT
3.12.316 OBJECT-COMPUTER
3.12.317 OBJECT-REFERENCE
3.12.318 OCCURS
3.12.319 OFx
3.12.320 OFF
3.12.321 OMITTED
3.12.322 ONx
3.12.323 ONLY
3.12.324 OPEN
3.12.325 OPTIONAL
3.12.326 OPTIONS
3.12.327 ORx
3.12.328 ORDER
3.12.329 ORGANIZATION
3.12.330 OTHER
3.12.331 OUTPUT
3.12.332 OVERFLOW
3.12.333 OVERLINE
3.12.334 OVERRIDE
3.12.335 PACKED-DECIMAL
3.12.336 PADDING
3.12.337 PAGE
3.12.338 PAGE-COUNTER
3.12.339 PARAGRAPH
3.12.340 PERFORM
3.12.341 PFx
3.12.342 PHx
3.12.343 PIC
3.12.344 PICTURE
Full standards support of all alpha, alphanumeric and numeric storage
specifiers as well as full support for edit and numeric-edit clauses.
An example of some of the PICTURE options:
*>>source format is free
*>*********************************************************************
*> Author: jrls (John Ellis)
*> Date: Oct-2008
*> Purpose: formated output examples using pic strings.
*>*********************************************************************
identification division.
program-id. picstring.
data division.
working-storage section.
*>
01 header.
05 filler pic xxx value "ln".
05 filler pic x(11) value " disp1".
05 filler pic x(11) value " disp2".
05 filler pic x(11) value " disp3".
05 filler pic x(11) value " disp4".
05 filler pic x(12) value " disp5".
05 filler pic x(9) value " an1".
05 filler pic x(14) value " phone".
05 filler pic x(10) value " date".
*>
01 headerLines pic x(90) value all "-".
*>
01 displayformats.
05 linenum pic 99 value 1.
05 disp1 pic zzz,zz9.99 value zero.
05 filler pic x value spaces.
05 disp2 pic $zz,zz9.99 value zero.
05 filler pic x value spaces.
05 disp3 pic ---,--9.99 value zero.
05 filler pic x value spaces.
05 disp4 pic $-z,zz9.99 value zero.
05 filler pic x value spaces.
05 disp5 pic -zz,zz9.zz- blank zero value zero.
05 filler pic x value spaces.
*><*an1 is actually a string field because of the embedded blanks, thus you put value spaces.
05 an1 pic 99b99b99 value spaces.
05 filler pic x value spaces.
05 phone pic bxxxbxxxbxxxx value spaces.
05 filler pic x value spaces.
05 dispdate pic 99/99/9999 value zero.
*>
procedure division.
0000-start.
*>
display headerLines.
display header.
display headerLines.
*><****************************************************
move 220.22 to disp1,
disp2.
move -220.22 to disp3,
disp4,
disp5.
inspect disp5 replacing first "-" by "(",
first "-" by ")".
move 10122008 to dispdate.
*><****************************************************
*><*Please note the results of moving 'abcd' to an1.
*><*an1 will show up as 00 00 00 because alpha data was
*><*moved into instead of numeric data.
*><*
*><*The phone field will display " abc def ghij" because
*><*'b' in the pic string.
*><****************************************************
move "abcd" to an1.
move "abcdefghij" to phone.
display displayformats.
add 1 to linenum.
move zero to disp4,
disp5.
*><****************************************************
*><*Here after moving data to an1 and phone, I use the
*><*inspect statement to replace the blanks.
*><****************************************************
move "123456" to an1.
move "5555551234" to phone.
inspect an1 replacing all " " by "-".
inspect phone replacing first " " by "(",
first " " by ")",
first " " by "-".
display displayformats.
inspect phone converting "23456789" to "adgjmptw".
display phone.
perform 0010-endProgram.
*>
0010-endProgram.
stop run.
*>
Outputs:
------------------------------------------------------------------------------------------
ln disp1 disp2 disp3 disp4 disp5 an1 phone date
------------------------------------------------------------------------------------------
01 220.22 $220.22 -220.22 $-220.22 (220.22) 00 00 00 abc def ghij 10/12/2008
02 220.22 $220.22 -220.22 $ 0.00 12-34-56 (555)555-1234 10/12/2008
(jjj)jjj-1adg
3.12.345 PLUS
3.12.346 POINTER
01 C-HANDLE USAGE IS POINTER.
CALL "open-lib" USING C-HANDLE
3.12.347 POSITION
3.12.348 POSITIVE
3.12.349 PRESENT
3.12.350 PREVIOUS
3.12.351 PRINTER
3.12.352 PRINTING
3.12.353 PROCEDURE
3.12.354 PROCEDURE-POINTER
3.12.355 PROCEDURES
3.12.356 PROCEED
3.12.357 PROGRAM
3.12.358 PROGRAM-ID
3.12.359 PROGRAM-POINTER
3.12.360 PROMPT
3.12.361 PROPERTY
3.12.362 PROTOTYPE
3.12.363 PURGE
3.12.364 QUEUE
3.12.365 QUOTE
3.12.366 QUOTES
3.12.367 RAISE
3.12.368 RAISING
3.12.369 RANDOM
3.12.370 RDx
3.12.371 READ
3.12.372 RECEIVE
3.12.373 RECORD
3.12.374 RECORDING
3.12.375 RECORDS
3.12.376 RECURSIVE
3.12.377 REDEFINES
3.12.378 REEL
3.12.379 REFERENCE
3.12.380 RELATION
3.12.381 RELATIVE
3.12.382 RELEASE
3.12.383 REMAINDER
3.12.384 REMOVAL
3.12.385 RENAMES
3.12.386 REPLACE
3.12.387 REPLACING
3.12.388 REPORT
3.12.389 REPORTING
3.12.390 REPORTS
3.12.391 REPOSITORY
3.12.392 REQUIRED
3.12.393 RESERVE
3.12.394 RESET
3.12.395 RESUME
3.12.396 RETRY
3.12.397 RETURN
3.12.398 RETURNING
3.12.399 REVERSE-VIDEO
3.12.400 REWIND
3.12.401 REWRITE
3.12.402 RFx
3.12.403 RHx
3.12.404 RIGHT
3.12.405 ROLLBACK
3.12.406 ROUNDED
3.12.407 RUN
3.12.408 SAME
3.12.409 SCREEN
3.12.410 SDx
3.12.411 SEARCH
3.12.412 SECONDS
3.12.413 SECTION
3.12.414 SECURE
3.12.415 SEGMENT
3.12.416 SELECT
3.12.417 SELF
3.12.418 SEND
3.12.419 SENTENCE
3.12.420 SEPARATE
3.12.421 SEQUENCE
3.12.422 SEQUENTIAL
3.12.423 SET
3.12.424 SHARING
3.12.425 SIGN
3.12.426 SIGNED
3.12.427 SIGNED-INT
3.12.428 SIGNED-LONG
3.12.429 SIGNED-SHORT
3.12.430 SIZE
3.12.431 SORT
* OpenCOBOL SORT verb example using standard in and standard out
identification division.
program-id. sorting.
environment division.
input-output section.
file-control.
select sort-in
assign keyboard
organization line sequential.
select sort-out
assign display
organization line sequential.
select sort-work
assign "sortwork".
data division.
file section.
fd sort-in.
01 in-rec pic x(255).
fd sort-out.
01 out-rec pic x(255).
sd sort-work.
01 work-rec pic x(255).
procedure division.
sort sort-work
ascending key work-rec
using sort-in
giving sort-out.
goback.
exit program.
end program sorting.
3.12.432 SORT-MERGE
3.12.433 SORT-RETURN
A SPECIAL-REGISTER used by the OpenCOBOL SORT routines.
- +000000000 for success
- +000000016 for failure
A programmer may set SORT-RETURN in an INPUT PROCEDURE.
3.12.434 SOURCE
3.12.435 SOURCE-COMPUTER
3.12.436 SOURCES
3.12.437 SPACE
3.12.438 SPACES
3.12.439 SPECIAL-NAMES
OpenCOBOL supports a fair complete set of the SPECIAL-NAMES in common use.
3.12.440 STANDARD
3.12.441 STANDARD-1
3.12.442 STANDARD-2
3.12.443 START
3.12.444 STATEMENT
3.12.445 STATUS
3.12.446 STEP
3.12.447 STOP
3.12.448 STRING
3.12.449 STRONG
3.12.450 SUB-QUEUE-1
3.12.451 SUB-QUEUE-2
3.12.452 SUB-QUEUE-3
3.12.453 SUBTRACT
3.12.454 SUM
3.12.455 SUPER
3.12.456 SUPPRESS
3.12.457 SYMBOL
3.12.458 SYMBOLIC
3.12.459 SYNC
3.12.460 SYNCHRONIZED
3.12.461 SYSTEM-DEFAULT
3.12.462 TABLE
3.12.463 TALLYING
3.12.464 TAPE
3.12.465 TERMINAL
3.12.466 TERMINATE
3.12.467 TEST
3.12.468 TEXT
3.12.469 THAN
3.12.470 THEN
3.12.471 THROUGH
3.12.472 THRU
3.12.473 TIME
3.12.474 TIMES
3.12.475 TOx
3.12.476 TOPx
3.12.477 TRAILING
3.12.478 TRUE
3.12.479 TYPE
3.12.480 TYPEDEF
3.12.481 UCS-4
3.12.482 UNDERLINE
3.12.483 UNIT
3.12.484 UNIVERSAL
3.12.485 UNLOCK
3.12.486 UNSIGNED
3.12.487 UNSIGNED-INT
3.12.488 UNSIGNED-LONG
3.12.489 UNSIGNED-SHORT
3.12.490 UNSTRING
3.12.491 UNTIL
3.12.492 UPx
3.12.493 UPDATE
3.12.494 UPON
3.12.495 USAGE
OpenCOBOL uses standard big-endian internal storage by default. USAGE
clauses influence the data representation. The INTEL architecture uses
little-endian form and OpenCOBOL programmers developing for this common
chipset may need to pay heed to this for performance purposes. As per
the standards, OpenCOBOL supports COMPUTATIONAL-5 native usage.
OpenCOBOL enables use of one to eight byte binary representations in both
big and little endian forms.
Along with full support of all common COBOL PICTURE clauses both storage
and display, OpenCOBOL supports USAGE clauses of:
- BINARY
- COMPUTATIONAL, COMP
- COMP-1
- COMP-2
- COMP-3
- COMP-4
- COMP-5
- COMP-X
- DISPLAY
- INDEX
- PACKED-DECIMAL
- POINTER
- PROGRAM-POINTER
- SIGNED-SHORT
- SIGNED-INT
- SIGNED-LONG
- UNSIGNED-SHORT
- UNSIGNED-INT
- UNSIGNED-LONG
- BINARY-CHAR SIGNED
- BINARY-CHAR UNSIGNED
- BINARY-CHAR
- BINARY-SHORT SIGNED
- BINARY-SHORT UNSIGNED
- BINARY-SHORT
- BINARY-LONG SIGNED
- BINARY-LONG UNSIGNED
- BINARY-LONG
- BINARY-DOUBLE SIGNED
- BINARY-DOUBLE UNSIGNED
- BINARY-DOUBLE
- BINARY-C-LONG SIGNED
- BINARY-C-LONG UNSIGNED
- BINARY-C-LONG
3.12.496 USE
3.12.497 USER-DEFAULT
3.12.498 USING
3.12.499 UTF-16
3.12.500 UTF-8
3.12.501 VAL-STATUS
3.12.502 VALID
3.12.503 VALIDATE
3.12.504 VALIDATE-STATUS
3.12.505 VALUE
3.12.506 VALUES
3.12.507 VARYING
3.12.508 WHEN
3.12.509 WITH
3.12.510 WORKING-STORAGE
3.12.511 WRITE
3.12.512 YYYYDDD
3.12.513 YYYYMMDD
3.12.514 ZERO
3.12.515 ZEROES
3.12.516 ZEROS
Yes. Quite nicely in fact. Dynamically! COBOL modules, and
object files of many other languages are linkable. As OpenCOBOL uses
intermediate C, linkage to other languages is well supported across many
platforms. The OpenCOBOL CALL instruction maps COBOL USAGE to many common
C stack frame data representations.
Multipart, complex system development is well integrated in the OpenCOBOL
model.
$ cobc -b hello.cob goodbye.cob
Combines both source files into a single dynamically loadable module.
Example produces hello.so.
Using the -l link library option, OpenCOBOL has access to most
shared libraries supported on it's platforms.
$ cobc -x -lcurl showcurl.cob
Will link the /usr/lib/libcurl.so (from the cURL project) to showcurl.
The OpenCOBOL CALL verb will use this linked library to resolve calls
at runtime.
Large scale systems are at the heart of COBOL development and OpenCOBOL
is no exception.
Argument passing in COBOL is normally accomplished through the
LINKAGE SECTION. This section does not allocate or initialize memory
as would definitions in the WORKING-STORAGE SECTION.
Care must be taken to inform COBOL of the actual source address of these
variables before use. Influences CHAINING and USING phrases.
See CALL for more details.
Under normal conditions, the LINKAGE SECTION is unallocated
and uninitialized. When a LINKAGE SECTION variable, that is not
part of the USING phrase (not a named calling argument), any
memory that has been addressed becomes unaddressable across calls.
-fstatic-linkage creates static addressing to the LINKAGE SECTION.
From [Roger]:
This relates to LINKAGE items that are NOT referred
to in the USING phrase of the PROCEDURE DIVISION.
It also only has relevance when the program is CALL'ed
from another prog.
This means that the addressability of these items must
be programmed (usually with SET ADDRESS) before reference.
Per default, the item loses it's addressability on exit
from the program. This option causes the module to retain
the item's address between CALL invocations of the program.
With some rumours that this may become the default in future releases of
OpenCOBOL, and the -fstatic-linkage option may be deprecated.
Yes. The freely available gnat system can be used and will create
object files that can be included in an OpenCOBOL project.
This example compiles an gnat package that includes hello and ingress
PROCEDURE and a echo FUNCTION. These will be called from an OpenCOBOL
adacaller.cob program.
The gnat specification file:
with Interfaces.C;
use Interfaces.C;
package HelloAda is
procedure hello;
procedure ingress(value : in INTEGER);
function echo(message : in char_array) return integer;
pragma export(C, hello);
pragma export(C, ingress);
pragma export(C, echo);
end HelloAda;
The gnat implementation body:
with Ada.Text_IO, Ada.Integer_Text_IO, Interfaces.C;
use Ada.Text_IO, Ada.Integer_Text_IO, Interfaces.C;
package body HelloAda is
procedure hello is
begin
Put_Line("Hello from Ada and OpenCOBOL");
New_Line;
end hello;
procedure ingress(value : in integer) is
begin
Put_Line("Passing integer to Ada from OpenCOBOL");
Put("OpenCOBOL passed: ");
Put(value);
New_Line;
New_Line;
end ingress;
function echo(message : in char_array) return integer is
begin
Put(To_Ada(message, true));
return To_Ada(message, true)'length;
end echo;
end HelloAda;
The adacaller.cob source file:
******************* adacaller.cob ********************************
>>SOURCE FORMAT IS FIXED
******************************************************************
* Author: Brian Tiffin
* Date: 08-Sep-2008
* Purpose: Demonstrate using Ada sub-programs
* Tectonics: gnatgcc -c helloada.adb
* gnatbind -n helloada
* gnatgcc -c b~helloada.abd
* cobc -x -lgnat caller.cob helloada.o b~helloada.o
******************************************************************
identification division.
program-id. caller.
data division.
working-storage section.
01 ada-message pic x(10) value "Ada echo" & x'0a' & x'00'.
01 result pic s9(9) value high-value.
*****************************************************************
procedure division.
begin.
call "adainit" end-call
call "hello" end-call
call "ingress" using by value 42 end-call
call "echo" using
by reference ada-message
returning result
end-call
display "Ada return: " result end-display
call "adafinal" end-call
goback
.
end program caller.
And the tectonics; Debian GNU/Linux build.sh:
gnatgcc -c helloada.adb
gnatbind -n helloada
gnatgcc -c b~helloada.adb
cobc -x -lgnat adacaller.cob helloada.o b~helloada.o
An important step is the creation of the object file from the gnatbind
output with -n that is used in the final OpenCOBOL executable.
Sample run using ./adacaller:
Hello from Ada and OpenCOBOL
Passing integer to Ada from OpenCOBOL
OpenCOBOL passed: 42
Ada echo
Ada return: +000000009
Yes. The OpenCOBOL 1.1 pre-release now includes support for
SCREEN SECTION. Experimental release for this support occurred in early
July, 2008.
The compiler recognizes most (if not all) of the
Screen description entry of the COBOL 2008 Draft standard.
External variables that influence screen handling include
- COB_SCREEN_EXCEPTIONS=Y
- To enable exceptions during ACCEPT.
- COB_SCREEN_ESCAPE=Y
- To enable handling of the escape key.
See Q. Does OpenCOBOL support CRT STATUS? for more information on
key codes and exception handling.
According to the standard a SCREEN SECTION ACCEPT does not need to be
proceeded by a DISPLAY. The extra DISPLAY won't hurt, but is not
necessary.
The FOREGROUND-COLOR and BACKGROUND-COLOR clauses will accept
78 black value 0.
78 blue value 1.
78 green value 2.
78 cyan value 3.
78 red value 4.
78 magenta value 5.
78 brown value 6.
78 white value 7.
The display of these colours are also influenced by HIGHLIGHT, LOWLIGHT
and REVERSE-VIDEO options. For instance, brown will display as yellow
when HIGHLIGHT is used.
Yes.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
CRT STATUS IS screen-status.
DATA DIVISION.
WORKING-STORAGE SECTION.
COPY screenio.
01 screen-status pic 9(4).
PROCEDURE DIVISION.
ACCEPT screen-sample.
IF screen-status = COB-SCR-F1
...
There is also a special OpenCOBOL variable, COB-CRT-STATUS
which can be used instead of the CRT STATUS special name.
There is also a COPY text that ships with OpenCOBOL, copy/screenio.cpy
that can be included in the DATA DIVISION and provides 78 level constants
for supported key status codes. Some values include:
- COB-SCR-F1 thru
- COB-SCR-F64
- COB-SCR-ESC
examine the file to see the other values.
CobCurses is an optional package designed to work with OpenCOBOL 1.0,
before OpenCOBOL 1.1 SCREEN SECTION support was initiated. It has many
features beyond simple SCREEN SECTION handling.
See http://sourceforge.net/projects/cobcurses for full details. This is a
major piece of work by Warren Gay, ve3wwg.
From an opencobol.org posting by Warren announcing release 0.95:
CobCurses is a package designed to allow Open-Cobol
programmers to create screens on open system platforms,
or those (like Windows) that can use PDCurses. Since
handcrafting screens is tedious work, this package
includes a "Screen Designer" utility.
All User Guides and Programmer Guide documentation can
be found on the source forge (see link at bottom).
==== RELEASE NOTES ====
A large number of internal changes were implemented in
this release, but first let's cover the user visible
improvements:
1. MENUS! Popup menus are now supported, and are available
in sdesign with every Action field. In fact, any sdesign
field that is marked with a diamond graphic, has the
ability to popup a menu with F1 (or ^O).
2. To support menus, FUNCTION keys are now available in
Action mode (though CONTROL-O is an alternate way
of opening a menu). This included a new event
callback NC-FKEY-EVENT.
3. GRAPHIC characters in the screen background. It is now
possible using sdesign to draw alternate-charset
graphics in your screen background. See the notes in
the opening help screen for the "Paint" function.
4. TRACE facilities. CobCurses now includes an
environment variable that can enable capturing of
trace information to a file for debugging. A routine
named NC_TRACE_MSG can also be used to add custom
messages to the trace file.
INTERNAL CHANGES:
The main two major internal changes were:
1. The terminal support has been virtualized, so that
the CobCurses routines deal with a "terminal"
object (not curses routines). This will eventually
lead to other possible windowing interfaces like
perhaps graphic X Window or native Windows support.
The other motivation for this was to allow CobCurses
to have one consistent set of constants for colours,
attributes and character sets. Previously, these
values were different depending upon the platform
and implementation of curses used.
2. Menu support has been provided independently of curses.
This is important for portability since PDCurses and
some platforms do not provide a curses menu library.
This also guarantees that CobCurses menus will behave
consistently on all platforms (and overcome menu paging
bugs in ncurses).
PLANNED FOR THE NEXT RELEASE:
Please avoid writing much code that works with colour pairs.
In the next release, it is planned to hide the colour pair
value altogether by using a TDC (Terminal Drawing Context).
This TDC will tie together attributes and colours, and
perhaps other "drawing contexts" so that you won't have to
manage colour pairs (this will be transparent). This will
also pave the way for graphical interfaces where a selected
font and line styles etc. may also be supported.
NOTES:
HPUX users will need to link with ncurses,
instead of the native HPUX curses libraries. I didn't
have time to fully investigate this, but the native
include files define things like MENU and ITEM types
that conflict with the CobCurses defined ones.
====
The release is available for download here:
http://sourceforge.net/projects/cobcurses
Yes. LINAGE sets up logical pages inside file descriptors enhancing
the WRITE operations and enabling the END-OF-PAGE clause.
FILE SECTION.
FD A-REPORT
LINAGE IS 13 LINES
TOP 2
FOOTING 2
BOTTOM 3.
LINAGE clauses can set:
TOP
LINES
FOOTING
BOTTOM
The LINAGE-COUNTER noun is maintained during writes to LINAGE output files.
Yes, many. As of the July 2008 1.1 pre-release
ABS, ACOS, ANNUITY, ASIN, ATAN, BYTE-LENGTH, CHAR, COS, CURRENT-DATE,
DATE-OF-INTEGER, DATE-TO-YYYYMMDD, DAY-OF-INTEGER, DAY-TO-YYYYDDD, E,
EXCEPTION-FILE, EXCEPTION-LOCATION, EXCEPTION-STATEMENT, EXCEPTION-STATUS,
EXP, EXP10, FACTORIAL, FRACTION-PART, INTEGER, INTEGER-OF-DATE,
INTEGER-OF-DAY, INTEGER-PART, LENGTH, LOCALE-DATE, LOCALE-TIME, LOG,
LOG10, LOWER-CASE, MAX, MEAN, MEDIAN, MIDRANGE, MIN, MOD, NUMVAL, NUMVAL-C,
ORD, ORD-MAX, ORD-MIN, PI, PRESENT-VALUE, RANDOM, RANGE, REM, REVERSE,
SECONDS-FROM-FORMATTED-TIME, SECONDS-PAST-MIDNIGHT, SIGN, SIN, SQRT,
STANDARD-DEVIATION, STORED-CHAR-LENGTH, SUM, TAN, TEST-DATE-YYYYMMDD,
TEST-DAY-YYYYMMDD, TRIM, UPPER-CASE, VARIANCE, WHEN-COMPILED, YEAR-TO-YYYY
3.23.1 ABS
Absolute value of numeric argument.
DISPLAY FUNCTION ABS(DIFFERENCE).
3.23.2 ACOS
The ACOS function returns a numeric value (in radians) that
approximates the arccosine of the argument.
The domain of the arccosine function is -1 to +1. Domain errors
return a result of 0. The inverse cosine function returns a range
of 0 thru π.
DISPLAY FUNCTION ACOS(-1).
3.23.3 ANNUITY
Compute the ratio of an annuity paid based on arguments of interest
and number of periods.
WORKING-STORAGE SECTION.
77 INTEREST PIC S9V9999 VALUE 0.08.
77 MONTHLY PIC S9V9999 VALUE ZERO.
77 PERIODS PIC 99 VALUE 36.
77 ANNUITY-VALUE PIC S9V9999 VALUE ZERO.
PROCEDURE DIVISION.
COMPUTE MONTHLY ROUNDED = INTEREST / 12
COMPUTE ANNUITY-VALUE ROUNDED =
FUNCTION ANNUITY (MONTHLY PERIODS)
DISPLAY "Monthly rate: " MONTHLY
" Periods: " PERIODS
" Annuity ratio: " ANNUITY-VALUE
END-DISPLAY.
Outputs:
Monthly rate: +0.0067 Periods: 36 Annuity ratio: +0.0314
3.23.4 ASIN
The ASIN function returns a numeric value (in radians) that
approximates the arcsine of the argument.
The domain of the arcsine function is -1 to +1. Domain errors
return a result of 0. The inverse sine function returns a range
of -π/2 thru π/2.
DISPLAY FUNCTION ASIN(-1).
3.23.5 ATAN
The ATAN function returns a numeric value (in radians) that
approximates the arctangent of the argument.
The domain of the arctangent function is all real numbers.
The inverse tangent function returns a range
of -π/2 thru π/2.
DISPLAY FUNCTION ATAN(1).
3.23.6 FUNCTION BYTE-LENGTH
The BYTE-LENGTH function returns an integer that is the internal
storage length of the given argument.
>>SOURCE FORMAT IS FIXED
******************************************************************
* Purpose: demonstrate intrinsic FUNCTION BYTE-LENGTH
******************************************************************
identification division.
program-id. bytelength.
data division.
working-storage section.
01 char-var usage binary-char.
01 short-var usage binary-short.
01 long-var usage binary-long.
01 double-var usage binary-double.
01 num1-var pic 9.
01 num4-var pic 99v99.
01 num9-var pic s9(9).
01 num18-var pic s9(18).
01 num18c-var pic s9(18) usage comp.
01 num18p-var pic s9(18) usage comp-3.
01 edit-var pic $zzzz9.99.
01 string-var pic x(10) value "abc".
01 newline pic x value x'0a'.
procedure division.
display
"num1-var len = " function byte-length(num1-var) newline
"num4-var len = " function byte-length(num4-var) newline
"num9-var len = " function byte-length(num9-var) newline
"num18-var len = " function byte-length(num18-var) newline
"num18c-var len = " function byte-length(num18c-var) newline
"num18p-var len = " function byte-length(num18p-var) newline
"edit-var len = " function byte-length(edit-var) newline
"12 len = " function byte-length(12) newline
"12.12 len = " function byte-length(12.12) newline
"1234567890.123 = " function
byte-length(1234567890.123) newline
"string-var len = " function byte-length(string-var) newline
"trim string = " function
byte-length(function trim(string-var)) newline
"char-var len = " function byte-length(char-var) newline
"short-var len = " function byte-length(short-var) newline
"long-var len = " function byte-length(long-var) newline
"double-var len = " function byte-length(double-var)
end-display
goback.
exit program.
Outputs:
num1-var len = 1
num4-var len = 4
num9-var len = 9
num18-var len = 18
num18c-var len = 8
num18p-var len = 10
edit-var len = 9
12 len = 2
12.12 len = 4
1234567890.123 = 13
string-var len = 10
trim string = 00000003
char-var len = 1
short-var len = 2
long-var len = 4
double-var len = 8
3.23.7 CHAR
The CHAR function returns a ONE character alphanumeric field
whose value is the character in the current collating sequence
having the ordinal position equal to the value of the integer
argument. The argument must be greater than 0 and less than or
equal to the number of positions in the collating sequence.
Errors in the argument range return 0 (the LOW-VALUE by default).
See ASCII or EBCDIC and details of the ALPHABET clause.
DISPLAY FUNCTION CHAR(66).
Would output A in the ASCII character set. Note this may
be different than what some expect. OpenCOBOL CHAR is 1 thru 128
not 0 thru 127 as a C programmer may be used to.
And to add a little confusion, most personal computers use an
extended character set, usually erroneously called ASCII with a
range of 0 to 255. A more appropriate name may be ISO-8859-1
Latin 1. See ASCII for more accurate details. This author
is often guilty of this misnomer of the use of the term ASCII.
3.23.8 COS
The COS function returns a numeric value that
approximates the cosine of the argument (in radians).
The domain of the cosine function is all real numbers, with
a nominal domain of 0 thru π with a zero returned at π/2.
The cosine function returns a range of -1 thru +1.
DISPLAY FUNCTION COS(1.5707963267949).
3.23.9 CURRENT-DATE
Returns an alphanumeric field of length 21 with the current date,
time and timezone information in the form
YYYYMMDDhhmmsscc±tznn.
DISPLAY FUNCTION CURRENT-DATE.
Example Output:
2008080921243796-0400
3.23.10 DATE-OF-INTEGER
Converts an integer date, days on the Gregorian since December 31
1600 to YYYYMMDD form.
DISPLAY DATE-OF-INTEGER(1)
DISPLAY DATE-OF-INTEGER(50000)
Outputs:
16010101
17371123
50,000 days after December 31, 1600 being November 23rd, 1737.
3.23.11 DATE-TO-YYYYMMDD
Converts a two digit year date format to four digit year form using
a sliding window pivot of the optional second argument. The pivot
defaults to 50.
The OpenCOBOL implementation of DATE-TO-YYYYMMDD also accepts an
optional third argument, replacing the default century value of
1900 and is treated as the years added to the given year portion of
the first argument and modified by the sliding 100 window pivot.
Domain errors occur for year values less than 1600 and greater than
999,999. There is no validation of the input date.
Because of the sliding window, this function is dependent on the date of
evaluation
DISPLAY FUNCTION DATE-TO-YYYYMMDD(000101)
DISPLAY FUNCTION DATE-TO-YYYYMMDD(500101)
DISPLAY FUNCTION DATE-TO-YYYYMMDD(610101)
DISPLAY FUNCTION DATE-TO-YYYYMMDD(990101)
DISPLAY FUNCTION DATE-TO-YYYYMMDD(990101, 50, 1900)
DISPLAY FUNCTION DATE-TO-YYYYMMDD(990101, -10, 1900)
DISPLAY FUNCTION DATE-TO-YYYYMMDD(990101, 50, 2000)
DISPLAY FUNCTION DATE-TO-YYYYMMDD(990101, 50, 2100)
When run in August, 2008 produces:
20000101
20500101
19610101
19990101
18990101
17990101
19990101
20990101
3.23.12 DAY-OF-INTEGER
Converts a Gregorian integer date form to Julian date form (YYYDDD)
based on days since December 31, 1600. Errors return 0.
DISPLAY FUNCTION DAY-OF-INTEGER(97336).
1867182
97,336 days after 16001231 being the 182nd day of the year 1867.
Canada's date of Confederation and recognized birthday.
3.23.13 DAY-TO-YYYYDDD
Converts a Julian 2 digit year and three digit dat integer to a
four digit year form. See DATE-TO-YYYYMMDD for some of the details
of the calculations involved.
3.23.14 E
3.23.15 EXCEPTION-FILE
This special-register holds the error number and name of the source
file that caused an input output exception. See EXCEPTION-STATUS
for an example.
3.23.16 EXCEPTION-LOCATION
This special-register can be queried for the location of the last
exception. See FUNCTION EXCEPTION-STATUS for example source code.
Note: This feature requires compilation with -fsource-location
compiler switch. This option is also turned on with -g debugging
info compiles. Information includes PROGRAM-ID, section and source
line.
3.23.17 EXCEPTION-STATEMENT
This special-register holds the statement that was executing when
the latest exception was raised. See FUNCTION EXCEPTION-STATUS
for an example. Note: This feature requires compilation with
-fsource-location compiler switch. This option is also turned on
with -g debugging info compiles.
3.23.18 EXCEPTION-STATUS
This FUNCTION returns the current exception status. The example
below is courtesy of Roger While, from a post he made announcing
the FUNCTION EXCEPTION- features.
Source format is free, compile with cobc -x -g -free except.cob:
IDENTIFICATION DIVISION.
PROGRAM-ID. MINIPROG.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. LINUX.
OBJECT-COMPUTER. LINUX.
SPECIAL-NAMES.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PRINTFILE ASSIGN TO "XXRXWXX"
FILE STATUS RXWSTAT.
DATA DIVISION.
FILE SECTION.
FD PRINTFILE.
01 PRINTREC PIC X(132).
WORKING-STORAGE SECTION.
01 RXWSTAT PIC XX.
PROCEDURE DIVISION.
A00-MAIN SECTION.
001-MAIN-PROCEDURE.
OPEN INPUT PRINTFILE.
DISPLAY "File Status: " RXWSTAT.
DISPLAY "EXCEPTION-FILE: " FUNCTION EXCEPTION-FILE.
DISPLAY "Return Length: "
FUNCTION LENGTH (FUNCTION EXCEPTION-FILE).
DISPLAY "EXCEPTION-STATUS: " FUNCTION EXCEPTION-STATUS.
DISPLAY "EXCEPTION-STATEMENT: " FUNCTION EXCEPTION-STATEMENT.
STRING "TOOLONG" DELIMITED SIZE INTO RXWSTAT.
DISPLAY "EXCEPTION-STATUS: " FUNCTION EXCEPTION-STATUS.
DISPLAY "EXCEPTION-STATEMENT: " FUNCTION EXCEPTION-STATEMENT.
DISPLAY "EXCEPTION-LOCATION: " FUNCTION EXCEPTION-LOCATION.
STOP RUN.
Example output:
File Status: 35
EXCEPTION-FILE: 35PRINTFILE
Return Length: 00000011
EXCEPTION-STATUS: EC-I-O-PERMANENT-ERROR
EXCEPTION-STATEMENT: OPEN
EXCEPTION-STATUS: EC-OVERFLOW-STRING
EXCEPTION-STATEMENT: STRING
EXCEPTION-LOCATION: MINIPROG; 001-MAIN-PROCEDURE OF A00-MAIN; 29
Tip
See the source file libcob/exception.def for a list of the plethora of
run-time exceptions supported by OpenCOBOL.
3.23.19 EXP
3.23.20 EXP10
3.23.21 FACTORIAL
3.23.22 FRACTION-PART
3.23.23 INTEGER
3.23.24 INTEGER-OF-DATE
3.23.25 INTEGER-OF-DAY
3.23.26 INTEGER-PART
3.23.27 FUNCTION LENGTH
3.23.28 FUNCTION LOCALE-DATE
3.23.29 LOCALE-TIME
3.23.30 LOG
3.23.31 LOG10
3.23.32 LOWER-CASE
3.23.33 MAX
3.23.34 MEAN
3.23.35 MEDIAN
3.23.36 MIDRANGE
3.23.37 MIN
3.23.38 MOD
3.23.39 NUMVAL
3.23.40 NUMVAL-C
3.23.41 ORD
3.23.42 ORD-MAX
3.23.43 ORD-MIN
3.23.44 PIx
3.23.45 PRESENT-VALUE
3.23.46 FUNCTION RANDOM
3.23.47 FUNCTION RANGE
3.23.48 REM
3.23.49 REVERSE
3.23.50 SECONDS-FROM-FORMATTED-TIME
3.23.51 SECONDS-PAST-MIDNIGHT
3.23.52 FUNCTION SIGN
3.23.53 SIN
3.23.54 SQRT
3.23.55 STANDARD-DEVIATION
3.23.56 STORED-CHAR-LENGTH
3.23.57 FUNCTION SUM
3.23.58 TAN
3.23.59 TEST-DATE-YYYYMMDD
3.23.60 TEST-DAY-YYYYMMDD
3.23.61 TRIM
3.23.62 UPPER-CASE
Returns a copy of the alphanumeric argument with any lower case letters
replaced by upper case letters.
3.23.63 VARIANCE
Returns the variance of a series of numbers. The variance is defined
as the square of the STANDARD-DEVIATION.
DISPLAY FUNCTION VARIANCE(1 2 3 4 5 6 7 8 9 100) END-DISPLAY.
+818.250000000000000
3.23.64 WHEN-COMPILED
Returns a 21 character alphanumeric field of the form
YYYYMMDDhhmmsscc±zzzz e.g. 2008070505152000-0400
representing when a module or executable is compiled. The
WHEN-COMPILED special register reflects when an object module was
compiled:
program-id. whenpart1. procedure division.
display "First part :" FUNCTION WHEN-COMPILED end-display.
program-id. whenpart2. procedure division.
display "Second part:" FUNCTION WHEN-COMPILED end-display.
program-id. whenshow. procedure division.
call "whenpart1" end-call.
call "whenpart2" end-call.
display "Main part :" FUNCTION WHEN-COMPILED end-display.
$ cobc -c whenpart1.cob && sleep 15 && cobc -c whenpart2.cob &&
> sleep 15 && cobc -x whenshow.cob whenpart1.o whenpart2.o
$ ./whenshow
First part :2008082721391500-0400
Second part:2008082721393000-0400
Main part :2008082721394500-0400
3.23.65 YEAR-TO-YYYY
Converts a two digit year to a sliding window four digit year.
The optional second argument (default 50) is added to the date
at execution time to determine the ending year of a 100 year
interval.
Yes. This information is from [Roger], posted to the opencobol forums.
Just to clarify the use of FUNCTION.
(Applies to 0.33)
FUNCTION (generally speaking, there are exceptions) can
be used anywhere where a source item is valid.
It always results in a new temporary field.
This will have the desired characteristics dependant
on the parameters.
eg. FUNCTION MIN (x, y, z)
with x PIC 99
y PIC 9(8) COMP
z PIC 9(6)V99
will result in returning a field that has
at least 8 positions before the (implied) decimal
point and 2 after.
It does NOT ever change the contents of parameters
to the function.
FUNCTION's are nestable.
eg.
DISPLAY FUNCTION REVERSE (FUNCTION UPPER-CASE (myfield)).
One clarification to the above quote was pointed out by Roger. The line:
be used anywhere where a source item is valid.
should be:
be used anywhere where a sending field is valid.
From [Roger]:
The standard only defines FUNCTION LENGTH.
The LENGTH OF phrase is an extension (from MF)
OpenCOBOL 1.0 ships with quite a few callable features. See CALL.
Looking through the source code, you'll find the current list of service
calls in:
libcob/system.def
With the 1.1 pre-release of July 2008, that list included:
/* COB_SYSTEM_GEN (external name, number of parameters, internal name) */
COB_SYSTEM_GEN ("SYSTEM", 1, SYSTEM)
COB_SYSTEM_GEN ("CBL_ERROR_PROC", 2, CBL_ERROR_PROC)
COB_SYSTEM_GEN ("CBL_EXIT_PROC", 2, CBL_EXIT_PROC)
COB_SYSTEM_GEN ("CBL_OPEN_FILE", 5, CBL_OPEN_FILE)
COB_SYSTEM_GEN ("CBL_CREATE_FILE", 5, CBL_CREATE_FILE)
COB_SYSTEM_GEN ("CBL_READ_FILE", 5, CBL_READ_FILE)
COB_SYSTEM_GEN ("CBL_WRITE_FILE", 5, CBL_WRITE_FILE)
COB_SYSTEM_GEN ("CBL_CLOSE_FILE", 1, CBL_CLOSE_FILE)
COB_SYSTEM_GEN ("CBL_FLUSH_FILE", 1, CBL_FLUSH_FILE)
COB_SYSTEM_GEN ("CBL_DELETE_FILE", 1, CBL_DELETE_FILE)
COB_SYSTEM_GEN ("CBL_COPY_FILE", 2, CBL_COPY_FILE)
COB_SYSTEM_GEN ("CBL_CHECK_FILE_EXIST", 2, CBL_CHECK_FILE_EXIST)
COB_SYSTEM_GEN ("CBL_RENAME_FILE", 2, CBL_RENAME_FILE)
COB_SYSTEM_GEN ("CBL_GET_CURRENT_DIR", 3, CBL_GET_CURRENT_DIR)
COB_SYSTEM_GEN ("CBL_CHANGE_DIR", 1, CBL_CHANGE_DIR)
COB_SYSTEM_GEN ("CBL_CREATE_DIR", 1, CBL_CREATE_DIR)
COB_SYSTEM_GEN ("CBL_DELETE_DIR", 1, CBL_DELETE_DIR)
COB_SYSTEM_GEN ("CBL_AND", 3, CBL_AND)
COB_SYSTEM_GEN ("CBL_OR", 3, CBL_OR)
COB_SYSTEM_GEN ("CBL_NOR", 3, CBL_NOR)
COB_SYSTEM_GEN ("CBL_XOR", 3, CBL_XOR)
COB_SYSTEM_GEN ("CBL_IMP", 3, CBL_IMP)
COB_SYSTEM_GEN ("CBL_NIMP", 3, CBL_NIMP)
COB_SYSTEM_GEN ("CBL_EQ", 3, CBL_EQ)
COB_SYSTEM_GEN ("CBL_NOT", 2, CBL_NOT)
COB_SYSTEM_GEN ("CBL_TOUPPER", 2, CBL_TOUPPER)
COB_SYSTEM_GEN ("CBL_TOLOWER", 2, CBL_TOLOWER)
COB_SYSTEM_GEN ("\364", 2, CBL_XF4)
COB_SYSTEM_GEN ("\365", 2, CBL_XF5)
COB_SYSTEM_GEN ("\221", 2, CBL_X91)
COB_SYSTEM_GEN ("C$NARG", 1, cob_return_args)
COB_SYSTEM_GEN ("C$PARAMSIZE", 1, cob_parameter_size)
COB_SYSTEM_GEN ("C$MAKEDIR", 1, cob_acuw_mkdir)
COB_SYSTEM_GEN ("C$CHDIR", 2, cob_acuw_chdir)
COB_SYSTEM_GEN ("C$SLEEP", 1, cob_acuw_sleep)
COB_SYSTEM_GEN ("C$COPY", 3, cob_acuw_copyfile)
COB_SYSTEM_GEN ("C$FILEINFO", 2, cob_acuw_file_info)
COB_SYSTEM_GEN ("C$DELETE", 2, cob_acuw_file_delete)
COB_SYSTEM_GEN ("C$TOUPPER", 2, CBL_TOUPPER)
COB_SYSTEM_GEN ("C$TOLOWER", 2, CBL_TOLOWER)
COB_SYSTEM_GEN ("C$JUSTIFY", 1, cob_acuw_justify)
COB_SYSTEM_GEN ("CBL_OC_NANOSLEEP", 1, cob_oc_nanosleep)
Note the "SYSTEM". This CALL sends a command string to the shell. It acts
as a wrapper to the standard C library "system" call. "SYSTEM" removes
any trailing spaces from the argument and appends the null terminator
required for the C library "system" call. While shell access opens yet
another powerful door for the OpenCOBOL programmer, diligent delevopers
will need to pay heed to cross platform issues when calling the operating
system.
From opencobol.org
The CALL's X"F4", X"F5", X"91" are from MF.
You can find them in the online MF doc under
Library Routines.
F4/F5 are for packing/unpacking bits from/to bytes.
91 is a multi-use call. Implemented are the subfunctions
get/set cobol switches (11, 12) and get number of call params (16).
Roger
Use
CALL X"F4" USING
BYTE-VAR
ARRAY-VAR
RETURNING STATUS-VAR
to pack the last bit of each byte in the 8 byte ARRAY-VAR into corresponding
bits of the 1 byte BYTE-VAR.
The X"F5" routine takes the eight bits of byte and moves them to the
corresponding occurrence within array.
X"91" is a multi-function routine.
CALL X"91" USING
RESULT-VAR
FUNCTION-NUM
PARAMETER-VAR
RETURNING STATUS-VAR
As mentioned by Roger, OpenCOBOL supports FUNCTION-NUM of 11, 12 and 16.
11 and 12 get and set the on off status of the 8 (eight) run-time OpenCOBOL
switches definable in the SPECIAL-NAMES paragraph.
CBL_OC_NANOSLEEP allows (upto) nanosecond sleep timing. It accepts a 64 bit
integer value which may be in character or numeric data forms.
CALL "CBL_OC_NANOSLEEP" USING 500000000
RETURNING STATUS
END-CALL
Would wait one-half second. It may be easier to grok if the source code
uses string catenation; "500" & "000000" for example.
OpenCOBOL internal runtime checks are enabled with -debug.
Support for tracing is enabled with -ftrace and -ftraceall.
Source line location is enabled with -fsource-location.
Activation of FIXED format D indicator debug lines is enabled with
-fdebugging-line.
-fstack-check will perform stack checking when -debug or -g is
used.
-fsyntax-only will ask the compiler to only check for syntax errors,
and not emit any output.
Support for gdb is enabled with -g.
$ gdb hello
GNU gdb 6.7.1-debian
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/i686/cmov/libthread_db.so.1".
(gdb) break 106
Breakpoint 1 at 0xOBFUSCA: file hello.c, line 106.
(gdb) break 109
Breakpoint 2 at 0xTETHESY: file hello.c, line 109.
(gdb) run
Starting program: /home/brian/writing/cobol/hello
[Thread debugging using libthread_db enabled]
[New Thread 0xSTEMADDR (LWP 5782)]
[Switching to Thread 0xESSES6b0 (LWP 5782)]
Breakpoint 1, hello_ (entry=0) at hello.c:106
106 cob_new_display (0, 1, 1, &c_1);
(gdb) cont
Continuing.
Hello World!
Breakpoint 2, hello_ (entry=0) at hello.c:109
109 cob_set_location ("hello", "hello.cob", 6, "MAIN SECTION", "MAIN PARAGRAPH", "STOP");
(gdb) cont
Continuing.
Program exited normally.
(gdb)
Setting a break at line 106 and 109 was found by a quick look through the C
code from $ cobc -C hello.cob and seeing where the DISPLAY call and
STOP RUN was located. Note: just because; the gdb displayed addresses were
obfuscated from this listing.
Thanks to Frank Swarbrick for pointing these idioms out
To add or remove a null terminator, use the STRING verb. For example:
* Add a null for calling C
STRING current-url
DELIMITED BY SPACE
X"00" DELIMITED BY SIZE
INTO display-url
MOVE display-url TO current-url
* Remove a null for display
STRING current-url
DELIMITED BY LOW-VALUE
INTO display-url.
Or to make changes in place:
* Change nulls to spaces
INSPECT current-url
REPLACING ALL X"00" WITH SPACE.
Or there is also modified references in OpenCOBOL:
* Assume IND is the first trailing space (or picture limit).
* Note: OpenCOBOL auto initializes working-storage to SPACES or ZEROES
* depending on numeric or non-numeric pictures.
* Remove null
MOVE SPACE TO current-url(IND:1).
* Add a zero terminator
MOVE X"00" TO current-url(IND:1).
[Roger] While points out:
X"00" is almost always interchangeable with LOW-VALUE.
In all of the above snippets, the source code X"00" can be replaced by the
COBOL noun LOW-VALUE or LOW-VALUES. Except when a program collating
sequence is active and where the first character is not X"00".
With the CALL verb, use ADDRESS OF and/or BY REFERENCE:
CALL "CFUNCTION" USING BY REFERENCE ADDRESS OF current-url.
The above being equivalent to char** in C.
COBOL, by it's nature, passes all arguments by reference. That can
be overridden with the BY VALUE clause and the BY CONTENT clause.
Yes. COPY is fully supported, all variations from the standards up to and
including the proposed 2008 standards.
The -I compiler option influences the copybook search path and
-E can be used to examine the after COPY preprocessor output.
There is also -ffold-copy-upper and -ffold-copy-lower compiler
controls.
Both as a noun and as an intrinsic function.
DISPLAY WHEN-COMPILED.
DISPLAY FUNCTION WHEN-COMPILED.
07/05/0805.15.20
2008070505152000-0400
Note: The noun WHEN-COMPILED is non-standard and was deemed obsolete in the
pre 85 standard.
With OpenCOBOL 1.1:
DISPLAY FUNCTION PI.
3.1415926535897932384626433832795029
DISPLAY FUNCTION E.
2.7182818284590452353602874713526625
Thats 34 digits after the decimal. Developers that need to know the
tolerances for use in calculations are directed to poke around the freely
available source code, and to read up on GMP.
Yes. PICTURE 78 clauses can be used for constants, translated at compile
time. This common non-standard extension is supported in OpenCOBOL.
Current OC 1.1 has preliminary support for a subset of the standard
conforming "CONSTANT" phrase. eg:
01 MYCONST CONSTANT AS 1.
Note: there is a syntax difference between 78 and CONSTANT.
Yes. A dash - in column 7 can be used for continuation lines. But, by
necessity continuation lines only apply in FIXED format source code. FREE
format COBOL does not support continuation as there is no real meaning to
column 7 in FREE form source.
Note that in this example there is no terminating quote on the string
continuations, but there is an extra starting quote following the dash:
123456789012345678901234567890123456789012345678901234567890123456789012
identification division.
program-id. longcont.
data division.
working-storage section.
01 longstr pic X(80)
value "This will all be one string in FIXED forma
-"t source code".
01 otherstr pic X(148) value "this
-"string will have spaces between the words THIS and STRING, as
-"continuation lines always fill to column 72.".
procedure division.
display longstr.
display length longstr.
display function length(function trim(longstr trailing)).
display otherstr(1:72).
display otherstr(73:75).
display length otherstr.
display function length(function trim(otherstr trailing)).
goback.
$ cobc longcont.cob
$ cobcrun longcont
This will all be one string in FIXED format source code
80
00000055
this string will have spaces between the words
THIS and STRING, as continuation lines always fill to column 72.
148
00000139
Note: The DISPLAY of otherstr was split to avoid any wide
browser scrolling, not for any COBOL reasons.
Also note that the rules for continuation lines are quite difficult to
describe simply and concerned OpenCOBOL programmers are urged to read
through the standards documents for full details.
Absolutely. Sources that need long strings, or those wishing to enhance
source code readability, can use the & operator:
identification division.
program-id. longstr.
data division.
working-storage section.
01 longstr pic X(80)
value "This " & "will " & "all " & "be " &
"one " &
"string " & "in both FIXED and FREE" &
" format source code".
procedure division.
display longstr.
goback.
Run this with:
$ cobc longstr.cob
$ cobcrun longstr
This will all be one string in both FIXED and FREE format source code
$ cobc -free longstr.cob
$ cobcrun longstr
This will all be one string in both FIXED and FREE format source code
Yes, but only for FIXED FORMAT sources. As for continuation lines, column
7 has no meaning for SOURCE FORMAT IS FREE source code. Use D lines as
a conditional include of a source code line. These debug lines will only
be compiled if the -fdebugging-line compiler switch is used.
From human on opencobol.org
If you put a D in column 7 OC handles this as a comment. These lines are
only compiled if you run cobc with -fdebugging-line.
By using this you can put some test messages etc. into your program that
are only used if necessary (and therefore build with -fdebugging-line).
Absolutely, kind of. Mixed case and mixed format, ASCII and EBCDIC. Most
COBOL compilers have not required uppercase only source code for quite a few
years now. Still, most COBOL compilers including OpenCOBOL folds parts of
the source to uppercase with certain rules before translating.
The compiler is case insensitive to names:
000100 identification division.
000200 program-id. mixcase.
000300 data division.
000400 working-storage section.
000500 01 SOMEUPPER pic x(9).
000600 01 SomeUpper pic x(9).
000700 01 someupper pic x(9).
000800
000900 procedure division.
001000 move "SOMEUPPER" to SOMEUPPER.
001100 move "SomeUpper" to SomeUpper.
001200 move "someupper" to someupper.
001300 display "SOMEUPPER: " SOMEUPPER end-display.
001400 display "SomeUpper: " SomeUpper end-display.
001500 display "someupper: " someupper end-display.
001600 stop run.
$ cobc -x mixcase.cob
mixcase.cob:10: Error: 'SOMEUPPER' ambiguous; need qualification
mixcase.cob:5: Error: 'SOMEUPPER' defined here
mixcase.cob:6: Error: 'SOMEUPPER' defined here
mixcase.cob:7: Error: 'SOMEUPPER' defined here
Note; that although the folded declarations conflict, the DISPLAY quoted
strings will NOT be folded, and would display as expected.
Case sensitivity is also at the mercy of operating system conventions.
Under GNU/Linux, OpenCOBOL's dynamic link loader is case sensitive.
CALL "C$JUSTIFY" USING center-string "C" END-CALL.
is not the same as:
CALL "c$justify" USING center-string "C" END-CALL.
In support of case folding and COPY libraries, OpenCOBOL supports
-ffold-copy-lower and -ffold-copy-upper. For mixing and matching legacy
sources.
- Trivia
- The expressions uppercase and lowercase date back to early moveable
type. Typographers would keep two cases of metal casted letters,
Capitalized and normal. Usually set on stacked shelves over the
workbench. The small letters, being used more frequently, ended up on the
lower shelf; the lower case letters.
All that is needed is a program-id. Doesn't do much.
program-id. a.
A short version of OpenCOBOL hello world, compiled -free:
program-id.hello.procedure division.display "Hello World!".
Thanks to human and the opencobol.org forums.
Please note: This is not good COBOL form, and is only shown as an
example of the possibilities.
FIXED format COBOL uses the first 6 positions of each line as a programmer
defined sequence field. This field is stripped as part of the
preprocessing and is not validated. Historically, the sequence numbers
were used to verify that card punch cards were read into a card reader in the
proper order. Many legacy COBOL programs have sequentially numbered sequence
values. Here is a little vi trick to renumber the sequence field by 100s.
Given
000005* HELLO.COB OpenCOBOL FAQ example
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. hello.
000030 PROCEDURE DIVISION.
000040 DISPLAY "Hello World!".
000100 STOP RUN.
Running the following ex filter
:%!perl -ne 'printf("\%06d\%s\n", $. * 100, substr($_, 6, -1));'
produces a nicely resequenced source file.
000100* HELLO.COB OpenCOBOL FAQ example
000200 IDENTIFICATION DIVISION.
000300 PROGRAM-ID. hello.
000400 PROCEDURE DIVISION.
000500 DISPLAY "Hello World!".
000600 STOP RUN.
- Note: Only use this on already FIXED form source. If used on any FREE format
COBOL, the first 6 columns will be damaged.
This has no effect on the compilation process, it only effects the appearance
of the sources.
- Vim: For users of the Vim editor, the command
:set number
will display the number of each source line. Many editors support the display
of line numbers. Even:
$ less -N
can be used to display line numbers of its input.
Yes. Quite a few. But instead of resorting to a PERFORM VARYING sequence
try:
01 B-COUNT PIC 999 VALUE 0.
01 TEST-CASE PIC X(80)
VALUE "This is my string.".
ONE-WAY.
INSPECT FUNCTION REVERSE(TEST-CASE)
TALLYING B-COUNT
FOR LEADING ' '.
DISPLAY B-COUNT.
TWO-WAY.
INSPECT TEST-CASE
TALLYING B-COUNT
FOR TRAILING SPACE.
DISPLAY B-COUNT.
THREE-WAY.
IF TEST-CASE EQUAL SPACES
COMPUTE B-COUNT = LENGTH OF TEST-CASE
ELSE
COMPUTE
B-COUNT = LENGTH TEST-CASE -
FUNCTION LENGTH(FUNCTION TRIM(TEST-CASE TRAILING))
END-COMPUTE
END-IF
DISPLAY B-COUNT.
produces:
062
124
062
The second value is 124 as TWO-WAY accumulates another 62 after ONE-WAY.
The INSPECT verb does not initialize a TALLYING variable.
Information modified from opencobol.org forum post.