Showing posts with label Cobol. Show all posts
Showing posts with label Cobol. Show all posts

Thursday, March 09, 2006

Cobol : Conditional compile

This may apply only to Micro Focus.

Define a 78 level in Working Storage.

78 functionality value "yes".

Then use the $if .. $else .. $end construct,

$if functionality defined
* Conditional code xxx here.
$end

With this setup, xxx will be compiled. Now here's the trick. You would then expect that setting "functionality" to "no" would stop xxx from being compiled but no way!

You need to comment out the 78 line to achieve this.

You can also achieve this from the command line:

cob -C 'constant functionality "yes"' yyy.cbl

(Pay special attention to the use of ' and ").

Enjoy!

Tuesday, March 07, 2006

Cobol : Trimming a field

Cobol doesn't support a trim function but you can get by by using:

WORKING-STORAGE SECTION.

01 InputString Pic X(20).

01 TrimString Pic X(20).

01 TrimCount Pic 9(2).

PROCEDURE DIVISION.


move 'poiuytrewq ' to InputString

move zero to TrimCount
inspect function reverse (InputString) tallying TrimCount for leading space
compute TrimCount = (length of InputString) - TrimCount
move InputString (1:TrimCount) to TrimString


Enjoy!

Friday, February 24, 2006

Cobol : Net Express IDE comments

Ever noticed how the comments display as actual commands even though you have an "*" in column 7 and you chose a special colour for the comments under "Options / Customize IDE / Colors" ?

The solution is to go to "Options / Edit" and set the left margin to 7.

Now you have comments that actually look like comments!

Enjoy!

Friday, February 17, 2006

Cobol : Conditional compile / debug

DISPLAY messages are often useful in a development system but you most certainly don't want them in a production environment.

You can do this by setting a "D" in column 7. From the manual:

"A debugging line is any line with a "D" in column 7. It is only permitted in the program after the OBJECT-COMPUTER paragraph.

A debugging line will be considered to have all the characteristics of a comment line if the WITH DEBUGGING MODE clause is not specified in the SOURCE-COMPUTER paragraph."

e.g. SOURCE-COMPUTER. MainFrame WITH DEBUGGING MODE.

Enjoy!

Cobol : Creating a logging file for standard out and standard error

Often you want to send a log file to stdout so you can then redirect it to wherever.

In Cobol, you can use:

SELECT OUTPUT-LOG ASSIGN ':CO:'

where:

:CO: is standard output (stdout)

These can also be used:

:CI: is standard input (stdin)

and

:CE: is standard error (stderr)

Enjoy!