Highlighted
Absent Member.
Absent Member.
926 views

[archive] precompiler

[Migrated content. Thread originally posted on 05 February 2003]

Has anyone had any success using/making the precompiler? I would like to conditionally compile certain files based on certain circumstances.

In particular, I am considering using the I$IO routine as a general replacement for all file actions. Using it is much less tedius than writing the select, file descriptor, etc. It would also provide the nice benefit of being able to access files by a variable filename (and with a little work, by field name via a special call) I would like to conditionally compile the .fd files (using C preprocessor syntax).

#ifdef _FILE-CONTROL
FD MY-FILE
LABEL RECORDS ARE STANDARD
RECORD CONTAINS 300 CHARACTERS
DATA RECORD IS MY-FILE-RECORD.

01 MY-FILE-RECORD.
05 MY-KEY-1.
...
#endif

In the file control section, I could

#define _FILE-CONTROL

In FILE-CONTROL, in front of the copy commands, I could
#define _FILE-CONTROL

In working storage, I could
#undef _FILE-CONTROL

This would allow fd files to be included as regular file descriptors or as working storage items based on the need. Unfortunately, as far as I can tell, conditional compilation is only possible in the following circumstances:
1. using -Si compile time switch. This is pretty much useless for this application because you can't change behavior at compilation time.
2. REPLACE command. The replace command has some crippling limitations, notably it does not apply to COPY'd files. It is also not switchable at compile time.
3. Custom preprocessor. AcuCorp has an interface for a custom preprocessor. This would easiest and most direct way to solve the problem, but experimentation with a quick and dirty processor (it just echoed the text to the compiler) showed that:
a. you lose ability to jump to compiler errors
b. compilation takes about 10 times as long
c. for some strange reason, sometimes when doing this compiler misses some copy books.

All togehter this makes a preprocessor option not usable.

If the compiler used stdin/stdout, the problem will be simple, as I could front end the compiler with a special program. Unfortuantely it doesn't...the filename is passed in as a compiler parameter. 😞

Any suggestions?
0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] precompiler

MerlinM said:

"1. using -Si compile time switch. This is pretty much useless for
this application because you can't change behavior at
compilation time."

I am not sure if I understand you right here, why is it that you cannot change behavior at compile time with this switch?

Assuming I wanted a different definition on Unix (UNX) and Windows (WIN) of a variable and I wanted this dynamically, what I would do was this:

77 DYNAMIC-VAR PIC 9(9) COMP-5 WIN
77 DYNAMIC-VAR UNSIGNED-INT UNX

To get Windows, I would:

ccbl32 -Si WIN mycode.cbl

To get Unix, I would:

ccbl32 -Si UNX mycode.cbl

Isn't this what you want?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] precompiler

I am not sure if I understand you right here, why is it that you cannot change behavior at compile time with this switch?


er, yes & no. I would like to be able to change compile flags during compilation, like in C with #define, ala

#define WIN
77 DYNAMIC-VAR PIC 9(9) COMP-5 WIN
77 DYNAMIC-VAR UNSIGNED-INT UNX

while the existing system works fine for global switches (file wide or larger), its not helpful for local ones. Its hard to show examples without posting a lot of code, which is not convenient here.

One of the points I raised in my previous post is incorrect: the REPLACE statement does recurse into copy files (there is a also a copy replacing). It would have given me what I wanted if I could comment a line or uncomment a line. Experimentation proved this is impossible.

I would like to point out my biggest reason for needing a precompiler has gone away: I simply split my FDs into two copy books, where one copies the other. This allows me to COPY the FD as a regular file descriptor or as working storage, depending on need (quite simple, really!).

What I'm doing is replacing the standard vision file handler such that the runtime simultaneously writes to the regular vision file system and to a SQL server, for which I've written a custom driver in cobol and C. I am very impressed to the extent that the file system behavior can be customized through I$IO and C$REDIRECT. It is even theoretically possible (and not that difficult, even) to write a .net data provider for cobol programs to use without recompilation.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.