Switch Usage

Use a switch-var attribute instead of the value attribute when a tag expects a value with a compound string expression. The switch-var attribute contains a single variable name (which may be prefixed by %, but cannot be enclosed in curly brackets). Use <case>, <undef>, or <default> subtags to specify switch cases. These tags also expect the value attribute, so switches can be nested:

<name switch-var='%var'>
  <case eq='value1' value='...'/>
  <case eq='value2' switch-var='%var2'>
    <undef value='...'/>
  </case>
  <undef value='...'/>
  <default value='...'/>
</name>

When a switch is evaluated, the value of the variable specified using the switch-var attribute is matched against the literal specified in the <case> tags. The literal must be the same size as the variable. (The literals value1 and value2 in the example assume that var is defined as having six bytes.) If an appropriate case is found, the corresponding case value is evaluated.

Set the value and type of the variable to __fail__ (two underscores) if you do not want a relationship to be produced for the variable:

<progname switch-var="%fname">
  <case eq="LINKDATA" value="%pname" type="Calls" params="%3" /> 
  <case eq="LINK" value="%pname" type="Calls" params="%3" /> 
  <case eq="READQTS" value="__fail__" type="__fail__" /> 
  <default value="" /> 
  </progname>

If the variable is undefined, and the <undef> tag is specified, its value is used; if not, the switch fails. Otherwise, if the <default> case is specified, it is used; if not, the switch fails.

In cases where more than one switch variable is used, than the result will not be context dependent, this means that all possible combinations between possible values will be produced. The following example legacy.xml file demonstrates the behavior:

<Legacy>
  <Cobol>
    <MicroFocus>
      <GenericAPI>
        <APIEntry name='CALL XBASE'>
          <match stmt='CALL'>
            <name value='XBASE'/>
          </match>
          <flow halts='no'>
            <param index='1' usage='r'/>
            <param index='2' usage='r'/>
            <param index='3' usage='r'/>
            <param index='4' usage='r'/>
            <param index='5' usage='r'/>
            <param index='6' usage='r'/>
          </flow>
          <vars>
            <arg var='code'   param='1' type='data' offset='0' size='1'/>
            <arg var='filecode'  param='2' type='data' offset='0' size='1'/>
          </vars>
          <rep>
            <sql-database>
              <table switch-var = '%filecode'>
                <case eq='1' value='FILE1'/>
                <case eq='2' value='FILE2'/>
              </table>
              <column switch-var = '%filecode'>
                <case eq='1' value='FILE1'/>
                <case eq='2' value='FILE2'/>
              </column>
              <origin value='XBASE' />
              <action switch-var ='%code'>
                <case eq='1'  value='Inserts'/>
                <case eq='2'  value='Deletes'/>
              </action>
            </sql-database>
          </rep>
        </APIEntry>
      </GenericAPI>
    </MicroFocus>
  </Cobol>
</Legacy>

Using the following code:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.   test1.
       AUTHOR.
       ENVIRONMENT DIVISION.

       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       01 CODE1 PIC 9.
       01 FILECODE PIC 9.
       LINKAGE SECTION.

       PROCEDURE DIVISION.
       FIRST-SECTION SECTION.
       FIRST-PARAGRAPH.
           MOVE 1 TO CODE1.
           MOVE 1 TO FILECODE.
           PERFORM SECOND-PARAGRAPH.

           MOVE 2 TO CODE1.
           MOVE 2 TO FILECODE.
           PERFORM SECOND-PARAGRAPH.
           GOBACK. 

       SECOND-PARAGRAPH.
           CALL 'XBASE' USING CODE1 FILECODE.
           EXIT.

This results in the following relations being generated: