Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specifying copybook name on the command line

Status
Not open for further replies.

webrabbit

MIS
Jan 31, 2003
1,059
US
I have a program which can be compiled with many different copybooks. I would like to specify the copybook name on the command line. That is, I have the source code line

COPY COPYBOOK.

and would like to replace the word COPYBOOK with a string from the command line. Is there any way to do this?

Windows XP Pro; Micro Focus COBOL Version 3.2.46
 
Not sure if you can do it directly but see if the use of the CONSTANT directive can be of use.

If your compiler supports it you can at least surround your copy statement with a $IF/$END based on the constant value

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
My bad . . . Didn't see the last part of the initial post :(

And we can't edit here. . .

I might have a suggestion if this was a UNIX or Mainframe compile, but my clients are not currently using COBOL on Win-based systems. Sorry.
 
I tried the CONSTANT directive. It doesn't work for the COPY statement. I ended up having the driving .BAT file copy the requested copybook to "COPYBOOK" with the /Y switch. The program calculates the compiled length of the copybook using 78-level "constants" (well, they are constant during execution), then displaying the results.
 
Oh yeah. The $IF would work if there were a defined set of copybooks. But it could be any copybook containing a single 01-level with its subordinates.
 
Can't you use an environment variable in your COPY instruction ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
if PHV suggestion doesn't work you can always write a preprocessor - or use a quick and dirty program to replace the copybook name by the one supplied on command line and then invoke the compiler.


with the version I have of mf the following works

$if book1 = "book3"
copy copybook1.
$else
copy copybook2.
$end

where book1 is defined as a CONSTANT on the directives file or on the compiler command line

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Well, fredrico, I guess you didn't read my comment on the $IF statement.

And PMV, the probmlem is getting the compiler to process a variable.
 
You might consider a "pre-process" that will change the source so that compile time, all is resolved. Say a little REXX code to change from one value to another?

This would place an additional step before the compile, but hopefully, that would not be too much?
 
Well, as Windows does not have REXX as a command language, I must resort to either batch commands or CMD commands. I am not familiar with CMD commands, which are an extension of batch commands. But as I mentioned above, I have essentially solved the problem with a batch file. Note also that Microfocus COBOL has native support for a preprocesser, but that is a bit of overkill.
 
Easy enough to get Rexx for windows - or almost any other platform. And it is free.


Nic
 
So REXX free? Where can I get it, and how does it integrate with Windows and COBOL? I somewhere have a copy of PC-DOS 2000, which came with REXX. Unfortunately, it was not well inegrated with the o/s: for instance, it could not put environment variables where COBOL programss could find them, which batch files did.
 
I am pretty darned sure that the version of rexx you used would have integrated seamlessly with the OS - that is one of its strengths - if it does not understand a command it passes it on. To help, put your system command in quotes and specifically send it to the system ADDRESS WIN or what ever the documentation says.


Nic
 
The problem was that REXX created its own "protected" environment, and any changes to it were "protected" from access by COBOL. This "protected" environment was the one updated by any system commands when REXX was running.
 
XYZ.BAT
**********
@ECHO OFF
IF "%1"=="" GOTO ERROR
ECHO IDENTIFICATION DIVISION. > XYZ.CBL
ECHO PROGRAM-ID. XYZ. >> XYZ.CBL
ECHO DATA DIVISION. >> XYZ.CBL
ECHO WORKING-STORAGE SECTION. >> XYZ.CBL
ECHO COPY %1.CPY. >> XYZ.CBL
ECHO PROCEDURE DIVISION. >> XYZ.CBL
ECHO DISPLAY "HELLO WORLD". >> XYZ.CBL
ECHO GOBACK. >> XYZ.CBL
TYPE XYZ.CBL
***COMPILE LOGIC***
GOTO END
:ERROR
ECHO ****************************************
ECHO Generates and compiles a program
ECHO passing copybook name
ECHO ****************************************
ECHO Parameter(s)...
ECHO 1 = COPYNAME
:END

Clive
 
Yes, Clive, this is essentially what I did, except I made the source program static and copyied the copybook I wanted to test into the one referenced by that program. A whole lot less batch code.

I extended the batch file to put the name of the copybook, the content of the copybook, and the documentation from the test program into a file (named COPYBOOK.TXT).
Then the batch file starts Word with this file, so I can print out reference cards with the name of the copybook, its contents, and the documentation.
 
For modifying sources I'm using a simple utility called sed.

For example for this source
xyz.cbl
Code:
[COLOR=#804040][b]IDENTIFICATION[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
[COLOR=#804040][b]PROGRAM-ID[/b][/color]. XYZ.  
[COLOR=#804040][b]DATA[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
[COLOR=#804040][b]WORKING-STORAGE[/b][/color][COLOR=#804040][b] SECTION[/b][/color].
[COLOR=#a020f0]COPY[/color] {COPYBOOK}.
[COLOR=#804040][b]PROCEDURE[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
[COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"HELLO WORLD"[/color].
[COLOR=#804040][b]GOBACK[/b][/color].

I would create a BAT-file which replaces the pattern {COPYBOOK} with the an copybook name from command line argument (using sed), for example:
replace_and_compile.bat
Code:
@[COLOR=#008080]ECHO[/color][COLOR=#804040][b] OFF[/b][/color]
[COLOR=#804040][b]IF[/b][/color][COLOR=#804040][b]  [/b][/color][COLOR=#008080]%1[/color]x[COLOR=#804040][b]==[/b][/color]x    [COLOR=#804040][b]GOTO[/b][/color][COLOR=#804040][b] help[/b][/color]

[COLOR=#008080]REM[/color][COLOR=#0000ff] -- Copy original xyz.cbl source file replacing {COPYBOOK} [/color]
[COLOR=#008080]REM[/color][COLOR=#0000ff] --  into temporary source file xyz_01.cbl[/color]
sed s/{COPYBOOK}/[COLOR=#008080]%1[/color][COLOR=#6a5acd]/g[/color] xyz.cbl > xyz_01.cbl

[COLOR=#008080]REM[/color][COLOR=#0000ff] -- Compile temporary source xyz_01.cbl creating xyz.exe [/color]
[COLOR=#008080]REM[/color][COLOR=#0000ff] -- e.g.: cobol xyz_01.cbl -o xyz.exe[/color]
[COLOR=#804040][b]goto[/b][/color][COLOR=#804040][b] end[/b][/color]

[COLOR=#804040][b]:help[/b][/color]
[COLOR=#008080]ECHO[/color][COLOR=#ff00ff] Usage:[/color]
[COLOR=#008080]ECHO[/color][COLOR=#ff00ff]     [/color][COLOR=#008080]%0[/color][COLOR=#ff00ff] copybook_name[/color]

[COLOR=#804040][b]:end[/b][/color]
[COLOR=#008080]echo[/color][COLOR=#ff00ff] done.[/color]

Then after running the BAT file
Code:
c:\_mikrom\Work\COBOL\copybook>replace_and_compile.bat MYCOPYBOOK1
done.
it creates first the modified source
xyz_01.cbl
Code:
[COLOR=#804040][b]IDENTIFICATION[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
[COLOR=#804040][b]PROGRAM-ID[/b][/color]. XYZ.  
[COLOR=#804040][b]DATA[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
[COLOR=#804040][b]WORKING-STORAGE[/b][/color][COLOR=#804040][b] SECTION[/b][/color].
[COLOR=#a020f0]COPY[/color] MYCOPYBOOK1.
[COLOR=#804040][b]PROCEDURE[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
[COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"HELLO WORLD"[/color].
[COLOR=#804040][b]GOBACK[/b][/color].

and then compiles it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top