Rules definition

Top  Previous  Next

Once the converter has been generated, the programmer must code the rules to choose the correct structure and branches for those files that requires it.

These rules must be coded in COBOL and stored in a copybook that is automatically referenced, with a COPY statement, at generation time by xmlconverter.

With this code the programmer must identify each record and instructs the converter on which structure to use and, within the structure itself, which branch to follow.

The programmer code is invoked for each record red, and it must identify the structure to use and, within the structure itself, which branch to follow. Of course if only one record structure is defined or if there are no redefines branches there is no need to identify them.

The field RECORD-TYPE identifies the structure to use: the programmer must set this filed to the correct structure number (starting from zero).

Each redefines branch is identified by a field name RDFBRCH-field where field is a the redefined field name. Its value must be set to the corresponding branch to use (starting from zero).

To simplify programmer's life, xmlconverter may generate a skeleton for the rules copybook: the programmer will only have to define the recognization code.

Remember that, for EBCDIC to ASCII conversions, the content of the record red is code in EBCDIC.

Rules samples

Multiple structure without critical redefines

The source copybook (employee.cpy):

    01  EMPLOYEE.
          03  INFO        PIC X.
              88  TYPE-1         VALUE '1'.
              88  TYPE-2         VALUE '2'.
          03  ANAG-INFO.
              05  SURNAME        PIC X(20).
              05  NAME           PIC X(20).
          03  SALARY-INFO REDEFINES ANAG-INFO.
              05  HOUR-PRICE     PIC S9(8) COMP-3.
              05  TAX-RATE       PIC S9(8) COMP-3.

 

The copybook after structure manual separation (employee_split.cpy):

     01  EMPLOYEE-1.
          03  INFO        PIC X.
          03  ANAG-INFO.
              05  SURNAME        PIC X(20).
              05  NAME           PIC X(20).
      01  EMPLOYEE-2.
          03  INFO        PIC X.
          03  SALARY-INFO.
              05  HOUR-PRICE     PIC S9(8) COMP-3.
              05  TAX-RATE       PIC S9(8) COMP-3.

 

Commands:

# cpy2xml -o employee.xml employee_split.cpy
# xmlconverter -o employee.cbl -c employee_rules.cpy -t employee_rules.cpy employee.xml

 

The rules copybook (employee_rules.cpy) obtained editing manually (bold text) the template generated by xmlconverter:

     *
     * template rule for
     *
          EVALUATE TRUE
     *
     * record type: EMPLOYEE-1
     *
          WHEN INFO OF EMPLOYEE-1 = X"F1"
              MOVE 0 TO RECORD-TYPE
     *
     * record type: EMPLOYEE-2
     *
          WHEN INFO OF EMPLOYEE-1 = X"F2"
              MOVE 1 TO RECORD-TYPE
          WHEN OTHER
              PERFORM ERROR-MSG
          END-EVALUATE
          CONTINUE.

 

Single structure with critical redefines

The source copybook (employee.cpy):

      01  EMPLOYEE.
          03  SURNAME        PIC X(20).
          03  NAME           PIC X(20).
          03  CALC-CLASS     PIC X(2).
          03  HOUR-PRICE     PIC S9(8) COMP.
          03  BILL-RATE REDEFINES HOUR-PRICEx  PIC X(4).

 

Commands:

# cpy2xml -o employee.xml employee.cpy
# xmlconverter -R -o employee.cbl -c employee_rules.cpy -t employee_rules.cpy employee.xml

 

The rules copybook (employee_rules.cpy) obtained editing manually (bold text) the template generated by xmlconverter:

    

     EVALUATE TRUE
        WHEN CALC-CLASS = LOW-VALUES
            MOVE 0 TO RDFBRCH-HOUR-PRICE
        WHEN CALC-CLASS = X"F0F0"
            MOVE 1 TO RDFBRCH-HOUR-PRICE
        WHEN OTHER
             PERFORM ERROR-MSG
        END-EVALUATE
        CONTINUE.

 

Multiple structure with critical redefines

The source copybook (employee.cpy):

      01  EMPLOYEE.
          03  SURNAME        PIC X(20).
          03  NAME           PIC X(20).
          03  CALC-CLASS     PIC X(2).
          03  HOUR-PRICE     PIC S9(8) COMP.
          03  BILL-RATE REDEFINES HOUR-PRICEx  PIC X(4).

 

The copybook after structure manual separation (employee_split.cpy):

   01  EMPLOYEE-1.
          03  RECORD-TYPE     PIC X.
          03  ANAG-INFO.
            05  SURNAME        PIC X(20).
            05  NAME           PIC X(20).
   01  EMPLOYEE-2.
          03  RECORD-TYPE     PIC X.
          03  BILLING-INFO.
            05  CALC-CLASS     PIC X(2).
            05  ADDR    PIC X(40).
            05  BILL-RATE      REDEFINES ADDR.
                07  IND        PIC X.
                07  HOUR-PRICE PIC S9(8) COMP.
                07  DISC-RATE REDEFINES HOUR-PRICE PIC X(4).

Commands:

# cpy2xml -o employee.xml employee_split.cpy
# xmlconverter -R -o employee.cbl -c employee_rules.cpy -t employee_rules.cpy employee.xml

 

The rules copybook (employee_rules.cpy) obtained editing manually (bold text) the template generated by xmlconverter:

    

         EVALUATE TRUE
     *
     * record type: EMPLOYEE-1
     *
          WHEN INFO OF EMPLOYEE-1 = X"F1"
            MOVE 0 TO RECORD-TYPE
     *
     * record type: EMPLOYEE-2
     *
          WHEN INFO OF EMPLOYEE-1 = X"F2"
            MOVE 1 TO RECORD-TYPE
     * redefines for field: ADDR
            EVALUATE TRUE
            WHEN CALC-CLASS = LOW-VALUES
              MOVE 0 TO RDFBRCH-BILLING-INFO
            WHEN CALC-CLASS = X"F0F0"
              MOVE 1 TO RDFBRCH-BILLING-INFO
     * redefines for field: HOUR-PRICE
              EVALUATE TRUE
              WHEN IND NOT = X"00"
                MOVE 0 TO RDFBRCH-BILL-RATE
              WHEN IND = X"00"
                MOVE 1 TO RDFBRCH-BILL-RATE
              WHEN OTHER
                PERFORM ERROR-MSG
              END-EVALUATE
            WHEN OTHER
              PERFORM ERROR-MSG
            END-EVALUATE
          WHEN OTHER
              PERFORM ERROR-MSG
          END-EVALUATE
          CONTINUE.