×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Specifying copybook name on the command line

Specifying copybook name on the command line

Specifying copybook name on the command line

(OP)
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

RE: Specifying copybook name on the command line

Which compiler on which operating plaftorm?

RE: Specifying copybook name on the command line

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
www.syssoft-int.com

FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

RE: Specifying copybook name on the command line

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.

RE: Specifying copybook name on the command line

(OP)
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.

RE: Specifying copybook name on the command line

(OP)
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.

RE: Specifying copybook name on the command line

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
www.syssoft-int.com

FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

RE: Specifying copybook name on the command line

(OP)
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.

RE: Specifying copybook name on the command line

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?

RE: Specifying copybook name on the command line

(OP)
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.

RE: Specifying copybook name on the command line

Easy enough to get Rexx for windows - or almost any other platform. And it is free.


Nic

RE: Specifying copybook name on the command line

(OP)
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.

RE: Specifying copybook name on the command line

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

RE: Specifying copybook name on the command line

(OP)
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.

RE: Specifying copybook name on the command line

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
http://tubularity.com

RE: Specifying copybook name on the command line

(OP)
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.

RE: Specifying copybook name on the command line

For modifying sources I'm using a simple utility called sed.

For example for this source
xyz.cbl

CODE

IDENTIFICATION DIVISION.
PROGRAM-ID. XYZ.  
DATA DIVISION.
WORKING-STORAGE SECTION.
COPY {COPYBOOK}.
PROCEDURE DIVISION.
DISPLAY "HELLO WORLD".
GOBACK. 

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

@ECHO OFF
IF  %1x==x    GOTO help

REM -- Copy original xyz.cbl source file replacing {COPYBOOK} 
REM --  into temporary source file xyz_01.cbl
sed s/{COPYBOOK}/%1/g xyz.cbl > xyz_01.cbl

REM -- Compile temporary source xyz_01.cbl creating xyz.exe 
REM -- e.g.: cobol xyz_01.cbl -o xyz.exe
goto end

:help
ECHO Usage:
ECHO     %0 copybook_name

:end
echo done. 

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

IDENTIFICATION DIVISION.
PROGRAM-ID. XYZ.  
DATA DIVISION.
WORKING-STORAGE SECTION.
COPY MYCOPYBOOK1.
PROCEDURE DIVISION.
DISPLAY "HELLO WORLD".
GOBACK. 

and then compiles it

RE: Specifying copybook name on the command line

(OP)
sed is cool, but I don't have it and have never used it. Perhaps if I had it and knew how to use it, I could do lots of cool things like that.

Anyway, I've solved the problem by overlaying the copybook rather than changing the source prograom. Came through the back door because the front door was locked.

RE: Specifying copybook name on the command line

(OP)
Neither link worked for me.

RE: Specifying copybook name on the command line

Strange, now the link doen't work for me, but it worked today when I tried it.
Then try to downolad it from here: http://sourceforge.net/projects/gnuwin32/files/sed...
Download the package sed-3.02-bin.zip. I have still this older version 3.02, which is standalone executable /Some of the newer versions I tried needs additional files to run maybe libraries/

I downloaded it now again, and it works for me.

RE: Specifying copybook name on the command line

(OP)
Well, according to my security software, both links contain an active virus.

RE: Specifying copybook name on the command line

Cannot believe it.
I have on my notebook Microsoft Security Essentials and on my workstation Kasperski AV and neither reported something like this.

RE: Specifying copybook name on the command line

I downloaded the EXE once again from the link above, scanned it with Kasperski AV and evrything is OK.

RE: Specifying copybook name on the command line

(OP)
I'm using ESET.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close