support: Customer Portal
Focused on delivering choice, investment protection and flexibility to organizations with valuable COBOL assets
 

Veryant Knowledge Base
Home > All Categories > isCOBOL General > How do I use conditional compilation?
Question Title How do I use conditional compilation?
Question:

How do I use compiler directives to conditionally include or exclude sections of code?

Answer:

Here are some examples of conditional compilation: 

EVALUATE and WHEN in a bug test program:
       id division.
       program-id. chinese.
       data division.
       working-storage section.
      >> EVALUATE CASE
      >> WHEN "TEST-1"
       77 chinese-item pic n(2) value nx"4EAC".
      >> WHEN "TEST-2"
       77 chinese-item pic n(1) value nx"4EAC".
      >> WHEN "TEST-3"
       77 chinese-item pic n(1) usage national.
      >> END-EVALUATE
       procedure division.
       main-logic.
           display standard graphical window.
           display chinese-item.
           accept omitted.
Compile with:
java -Discobol.compiler.const.CASE=TEST-1 com.iscobol.compiler.Pcc chinese.cbl
to include the TEST-1 case.

An alternative would be to add the following to the top of chinese.cbl:
      >> DEFINE CASE AS "TEST-3"
and write the program as:
       id division.
       program-id. chinese.
       data division.
       working-storage section.
      >> IF CASE IS = "TEST-1"
       77 chinese-item pic n(2) value nx"4EAC".
      >> ELSE 
      >> IF CASE IS = "TEST-2"
       77 chinese-item pic n(1) value nx"4EAC".
      >> ELSE 
      >> IF CASE IS = "TEST-3"
       77 chinese-item pic n(1) usage national.
      >> END-IF
      >> END-IF
      >> END-IF
       procedure division.
       main-logic.
           display standard graphical window.
           display chinese-item.
           accept omitted.
In the above, CASE is a preprocessor constant set to either "TEST-1", "TEST-2" or "TEST-3". The program could also be written to just test whether a constant is defined, as follows:
       id division.
       program-id. chinese.
       data division.
       working-storage section.
      >> IF TEST-1 IS DEFINED
       77 chinese-item pic n(2) value nx"4EAC".
      >> ELSE 
      >> IF TEST-2 IS DEFINED
       77 chinese-item pic n(1) value nx"4EAC".
      >> ELSE 
      >> IF TEST-3 IS DEFINED
       77 chinese-item pic n(1) usage national.
      >> END-IF
      >> END-IF
      >> END-IF
       procedure division.
       main-logic.
           display standard graphical window.
           display chinese-item.
           accept omitted.
and then compiled with 
java -Discobol.compiler.const.TEST-1=1 com.iscobol.compiler.Pcc chinese.cbl
Here is an excerpt from the isCOBOL APS User Guide (which is available from the Windows Start menu or at this link).

Compiler directives 

The compiler directives can alter the behavior of the compiler.

DEFINE directive: 

The DEFINE directive allows to define a complier constant.
>> DEFINE ConstantName AS ContantValue [OVERRIDE]
Syntax

1. ConstantName is the name of the constant to be set. 
2. ConstantValue is the value of the constant. 

General rules

1. The Constant is defined and set to the ConstantValue. 
2. Use the OVERRIDE clause to re-define a previously set constant. 

ERROR Directive: 

When the ERROR directive is encountered, a message is written to the STDERR and the compiler exits.
>> ERROR String
Syntax

1. String is a text string delimited by quotes. 

EVALUATE directive: 

The EVALUATE directive allows to check the value of a constant to include or exclude fragments of source code.
>> EVALUATE ConstantName
  { >> WHEN String Statements-1 } ...
  [ >> WHEN OTHER Statements-2 ]
>> END-EVALUATE

Syntax

1. ConstantName is a constant defined in the configuration file as iscobol.compiler.ConstantName or using >> DEFINE compiler directive. 
2. String is a text string delimited by quotes. 
3. Statements-1 e Statements-2 are lines of COBOL code. 

General rules

1. When String matches the value of ConstantName, lines in Statements-1 are included. 
2. When no match is found, lines in Statements-2 are included. 

IF directive: 

The IF directive allows to check if a constant is set, to include or exclude fragments of source code. 
>> IF ConstantName IS [ NOT ] DEFINED Statements-1
                     {[ NOT ] = ConstantValue}
                     {[ NOT ] < ConstantValue}
                     {[ NOT ] > ConstantValue}
  [ >> ELSE Statements-2 ]
>> END-IF

Syntax

1. ConstantName is a constant defined in the configuration file as iscobol.compiler.ConstantName or using >> DEFINE compiler directive. 
2. Statements-1 e Statements-2 are lines of COBOL code. 

General rules

1. Testing IF DEFINED, when ConstantName is defined, no matter the value, lines in Statements-1 are included. Otherwise, lines in Statements-2 are included. 
2. Testing IF EQUAL, GREATER or LESS, when ConstantName is defined, and its value matches the IF condition, lines in Statements-1 are included. Otherwise, lines in Statements-2 are included. 
Authored by: Veryant Support This question has been viewed 10364 times so far.
Click Here to View all the questions in isCOBOL General category.
File Attachments File Attachments
There are no attachment file(s) related to this question.
How helpful was this article to you?
User Comments User Comments Add Comment
There are no user comments for this question. Be the first to post a comment. Click Here
Related Questions Related Questions
  1. How do I compile for compatibility with older versions of Java?
  2. When can I get the "java.net.SocketException: Permission denied:connect" message? And how can it be avoided?
  3. How do I resolve "code too large for try statement" errors?
  4. How do I migrate indexed files to a format that is supported by isCOBOL?
  5. How do I prevent hackers from decompiling Java class files to reverse engineer my COBOL application?
  6. How can I read an Excel spreadsheet from COBOL?
  7. Does SET ADDRESS OF X TO Y work?
  8. What Micro Focus library routines are supported?
  9. How do I create a desktop shortcut icon to launch my program?
  10. Do I need to worry about the compile warning "Note: MYPROG.java uses unchecked or unsafe operations?"
  11. What tools are available for automated functional (regression) testing of a COBOL application?
  12. Did you know you can create temporary files in memory?
  13. Where can I obtain a copy of the ANSI 2002 COBOL standard?
  14. Is there currently a way to debug COBOL and Java source together?
  15. How do I increase the maximum Java heap size when compiling?
  16. How do I turn on debug trace to produce a log file?
  17. How do I determine what properties are set?
  18. Should I use JISAM or Veryant's c-treeRTG?
  19. How would I create my own CBL_ALLOC_MEM and CBL_FREE_MEM routines?
  20. Why do I get a compile error "--S: Invalid open mode" on an OPEN I-O of an ORGANIZATION LINE SEQUENTIAL file?
  21. What is the best way to control Microsoft Word?
  22. How can I use the F10 key in my application without it changing the keyboard focus?
  23. How do I specify properties or a properties file on the command line?
  24. Where can I find more information on A$ENCRYPT and A$DECRYPT?
  25. How do I change the icon in the upper left corner of the Window?
  26. Does isCOBOL work with Flexus COBOL sp2?
  27. How does a program detect at runtime whether it is running standalone GUI, thin client or with Web Direct 2.0?
  28. What is the behavior difference of STOP THREAD?
  29. What are the defaults for the DATE-ENTRY control DISPLAY-FORMAT property and format styles?
  30. Sending SMTP mail
  31. How would I create my own CBL_CHECK_FILE_EXIST routine?
  32. Is the isCOBOL 2009 SP1 release intended to deploy mainframe applications over the cloud? Or is it an integration mechanism for bringing in cloud data and apps?
  33. How do I select 11x17 paper size using WIN$PRINTER?
  34. Where can I learn more about Classpath, the Java class loader, JDK tools and utilities?
  35. What are the key technical advantages of isCOBOL?
  36. Why do I get the error message "Native call not found" and how do I fix the problem?
  37. Why do I get the error java.lang.NoClassDefFoundError: com/iscobol/rts_n/StopRunException?
  38. Does isCOBOL run on Linux on System z?
  39. Can Veryant recommend a good Web site to find 3rd party JavaBeans?
  40. I still get the error : "Missing License: The license key is missing, invalid or has expired!" I can't figure out why
  41. What compile option should I use for ICOBOL compatibility?
  42. How do I compile fixed (ANSI) format source that COPYs terminal format source or vice versa?
  43. Can isCOBOL access a DLL or .so that is in a JAR file?
  44. Can I use directory paths in CALL names?
  45. How do I configure file locations with environment variables?
  46. What algorithm does isCOBOL use to load framework properties (runtime config variables)?
  47. Is your runtime library backward compatible?
  48. How can I make my isCOBOL program to be called instead of a C routine when both have the same name?
  49. How do I set iscobol.file.index.FileName with variable file name assignments?
  50. What is the easiest and/or best way to convert a legacy text-based user interface to a web front end?
  51. Does isCOBOL APS run on z/OS?
  52. How do I specify which file status codes I want to use?
  53. Is isCOBOL backward compatible?
  54. Is there any equivalent to COPY RESOURCE?
  55. Does isCOBOL support C$REDIRECT?
  56. Why do I get the error message “java.lang.UnsatisfiedLinkError: no ### in java.library.path?
  57. How do I write my own replacement for a C$ library routine?
  58. What is the best way to profile an isCOBOL program?
  59. What should I use for USAGE HANDLE items instead of NULL?
  60. How can I avoid the "java.lang.OutOfMemoryError: PermGen space" error?
  61. Can you derive isCOBOL object classes from Java and vice versa?
  62. Can the file system (iscobol.file.index) be set programmatically?
  63. How can I tell what changes were made in the isCOBOL latest update?
  64. Is there any way to use isCOBOL with SCO 5.0.6 (JDK 1.3)?
  65. I've heard there is a problem passing pointers to C functions. What is it?
  66. How can I monitor a jvm started on a remote computer box?
  67. How do I get more information when I get java.lang.reflect.InvocationTargetException?
  68. Does isCOBOL support Crystal Reports or other Report Writers?
  69. How do I suppress multiple reserved words with the -rw compiler option?
  70. Why do I get the error message "java.lang.ArrayIndexOutOfBoundsException" ?
  71. Why do I get the error message "java.lang.NullPointerException" ?
  72. Can I call an RMCobol program passing parameters to it?
  73. What does mean the error NO X11 DISPLAY?
  74. How can I encode a URL String?
  75. What can I use to perform an email validation during entry-field accept?
  76. Working with sequential files on Pipes
  77. How do I resolve the error "java.lang.NoClassDefFoundError" or "java.lang.ClassNotFoundException"?
  78. Does isCOBOL support C$XML or other XML interfaces?
  79. Is there any way to direct the output from the "Print Screen" keyboard key directly to a printer?
  80. Why do I get the error "Could not load the main class" ?
  81. Did you know isCOBOL IDE allows you to easily understand how to invoke a method in a Java Class?
  82. Did you know you could set a background image from isCOBOL IDE&#39;s painter?
  83. Did you know that in a string you can replace a text with a new one with a different length by using the C$REPLACE_ALL routine?
  84. Did you know how to write custom information inside isCOBOL log file?
  85. How to programmatically set the attributes for PDFs?
  86. How can I read data correctly from a line-sequential file that has a different encoding from the one used by isCOBOL?
  87. Did you know you can encrypt the communication with the isCOBOL Server?
  88. GIT Server (Linux) - Install and Configuration
  89. Did you know these two ways of finding out the working directory in use?
  90. Activating and Check the isCOBOL License
  91. How to search by key with case insensitive on ISAM files
  92. How can I read a data written with a different encoding?
  93. How do I point my installed isCOBOL to a different Java location?
  94. May I create my own type definitions and reuse them?
  95. How can I use the Call/Cancel custom HOOK program to get the start and end time of every CALLed program?
  96. How can I tell if my application is running in the WebClient environment or another environment?
  97. How can I generate QR codes from COBOL?
  98. Can I define one or more data items based on the definition of another one?
  99. How can you wait for several threads to finish?
Article Information Additional Information
Article Number: 27
Created: 2009-08-28 2:33 PM
Rating: 1 Star
 
Article Options Article Options
Print Question Print this Question
Email Question Email Question to Friend
Export to Adobe PDF Export to PDF File
Export to MS Word Export to MS Word
Bookmark Article
Subscribe to Article Subscribe to Article
 
Search Knowledge Base Search Knowledge Base



 
 

© Veryant - All Rights Reserved
Veryant and isCOBOL are trademarks or registered marks of Veryant in the United States and other countries. All other marks are the property of their respective owners.