×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

Need Help converting XML to COBOL for integration

Need Help converting XML to COBOL for integration

Need Help converting XML to COBOL for integration

(OP)
I am needing assistance in converting an XML output from a program into our software that is written in COBOL.  Problem is that I don't know XML.  Help in doing the crossover would be appreciated.  Can give some reimbursement for hands-on expertise.  Thanks!

RE: Need Help converting XML to COBOL for integration

Which COBOL are you using?
I'm using ILE COBOL on iSeries, which supports a XML PARSE statement for parsing XML input. I thing this statement is available for all IBM's COBOL - i.e. on zSeries and pSeries too.
Similarly there is a XML GENERATE statement for writing XML output.      

RE: Need Help converting XML to COBOL for integration

You must find an element within the xml record that is unique.
This will be the key to determine when to write a record.
A sample follows.
I use violation-reference to determine whether I have a record

Bill Dougherty

       cbl codepage(1140)
       IDENTIFICATION DIVISION.
       PROGRAM-ID.      DCCS46N.
      *AUTHOR.          W. DOUGHERTY.
      *DATE-WRITTEN.    10/26/2009

      ****************************************************************
      **  CONVERT PROGRAM TO PARSE XML DOCUMENTS                    **
      ****************************************************************
      **  LINK WITH AMODE 31                                        **
      ****************************************************************
      *   DATE    WHO               PROJECT / DESCRIPTION            *
      * --------- ---  ----------------------------------------------*
      *                                                              *
      ****************************************************************

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.  ES9000.
       OBJECT-COMPUTER.  ES9000.
       SPECIAL-NAMES.
            C01 IS HOF.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT XML-IN           ASSIGN XMLIN
               STATUS IS XML-STATUS.
           SELECT DAT-OT           ASSIGN DATOT
               STATUS IS DAT-STATUS.

       DATA DIVISION.
       FILE SECTION.

       FD  XML-IN
           RECORDING MODE F
           BLOCK COntains 0 RECORDS.
       01  XML-IN-REC.
           05  FILLER          PIC X(80).

       FD  DAT-OT
           RECORDING MODE F
           BLOCK COntains 0 RECORDS.
       01  DAT-OT-REC.
           05  FILLER          PIC X(9421).

       WORKING-STORAGE SECTION.

       01  WS-START-TIME           PIC 9(08) VALUE ZEROS.
       01  CTL-ERROR               PIC X(01) VALUE SPACES.
       01  EOF-SW                  PIC X(01) VALUE SPACES.
       01  XML-DOC.
           05  FILLER              PIC X(80).
       01  XML-DOC-LENGTH   COMP   PIC 999   VALUE 80.

       01  REC-CNT                 PIC 9(04) VALUE ZERO.
       01  WRI-CTR                 PIC 9(04) VALUE ZERO.
       01  DUP-CTR                 PIC 9(04) VALUE ZERO.
       01  V-SUB                   pic 9(02) value 0.
       01  XML-STATUS              PIC 9(02) VALUE ZERO.
       01  DAT-STATUS              PIC 9(02) VALUE ZERO.

           COPY DATEFUNC.

           COPY PERMIT01.

       01  HOLD-CURR-DATE.
           05  HOLD-CURR-CC    PIC 9(02) VALUE ZEROS.
           05  HOLD-CURR-YY    PIC 9(02) VALUE ZEROS.
           05  HOLD-CURR-MM    PIC 9(02) VALUE ZEROS.
           05  HOLD-CURR-DD    PIC 9(02) VALUE ZEROS.
       01  CTR-DATA.
           05  EOE-CTR            PIC 9(04) VALUE ZERO.
           05  EOD-CTR            PIC 9(04) VALUE ZERO.
           05  VI-CTR             PIC 9(04) VALUE ZERO.
           05  ENC-CTR            PIC 9(04) VALUE ZERO.
           05  STD-CTR            PIC 9(04) VALUE ZERO.
           05  ATN-CTR            PIC 9(04) VALUE ZERO.
           05  ATC-CTR            PIC 9(04) VALUE ZERO.
           05  ATCH-CTR           PIC 9(04) VALUE ZERO.
           05  STC-CTR            PIC 9(04) VALUE ZERO.
           05  ETC-CTR            PIC 9(04) VALUE ZERO.
           05  CC-CTR             PIC 9(04) VALUE ZERO.
           05  CCS-CTR            PIC 9(04) VALUE ZERO.
           05  PIT-CTR            PIC 9(04) VALUE ZERO.
           05  PID-CTR            PIC 9(04) VALUE ZERO.
           05  COM-CTR            PIC 9(04) VALUE ZERO.
      *** XML PROCESSING FIELDS                              ****
       01  XML-DATA.
           05  CURRENT-ELEMENT     PIC X(30).
           05  XFR-CH4             PIC X(04).
           05  XFR-CH5             PIC X(05).
           05  XFR-CH9             PIC X(09).
           05  XFR-CH20            PIC X(20).
           05  XFR-CH30            PIC X(30).
           05  XFR-CH35            PIC X(35).
           05  XFR-CH40            PIC X(40).
           05  XFR-CH75            PIC X(75).
           05  XFR-ED              PIC X(09) JUSTIFIED.
           05  XFR-ED-I REDEFINES XFR-ED PIC 999999.99.
           05  XFR-DATE.
               10  XFR-DATE-MM    PIC X(02).
               10  FILL1          PIC X(01).
               10  XFR-DATE-DD    PIC X(02).
               10  FILL2          PIC X(01).
               10  XFR-DATE-YYYY  PIC X(04).
           05  OT-DATE.
               10  OT-DATE-YYYY  PIC X(04).
               10  OT-DATE-MM    PIC X(02).
               10  OT-DATE-DD    PIC X(02).
           05  LIST-PRICE   COMP  PIC 9V99 VALUE 0.
           05  DISCOUNT     COMP  PIC 9V99 VALUE 0.
           05  DISPLAY-PRICE      PIC $$9.99.
           05  XML-DOCUMENT-LENGTH COMP PIC 999.

       PROCEDURE DIVISION.
       MAINLINE SECTION.
           MOVE ZEROS              TO RETURN-CODE.
           OPEN INPUT XML-IN.
           IF  XML-STATUS NOT = 00
               MOVE 88             TO RETURN-CODE
               DISPLAY
               'PROGRAM ENDING  INVALID OPEN ON XMLIN        '
               DISPLAY
               'XMLIN STATUS IS ' XML-STATUS
               GO TO 0500-EOJ.
           OPEN OUTPUT DAT-OT.

           MOVE FUNCTION CURRENT-DATE TO WS-FUNCTION-DATE.
           MOVE WS-FUNCTION-CYMD      TO HOLD-CURR-DATE.
           ACCEPT WS-START-TIME FROM TIME.

           INITIALIZE MUNIS-NOTICE-RECORD.
           DISPLAY 'BEGIN DCCS46  '
           DISPLAY WS-START-TIME.

           PERFORM READ-XMLIN
             UNTIL EOF-SW = 'Y'.

            IF VIOLATION-REFERENCE NOT = SPACES
               WRITE DAT-OT-REC FROM MUNIS-NOTICE-RECORD
               ADD 1 TO WRI-CTR.

           DISPLAY 'WRITE COUNT    '
           DISPLAY WRI-CTR.
           DISPLAY 'REC   COUNT    '
           DISPLAY REC-CNT.

       0500-EOJ.
           CLOSE XML-IN.
           CLOSE DAT-OT.
           STOP RUN.

       READ-XMLIN.
           READ XML-IN INTO XML-DOC
              AT END
                 MOVE 'Y' TO EOF-SW.

           IF XML-STATUS = '00'
             PERFORM PROCESS-XML-DOC.

       PROCESS-XML-DOC.
           XML PARSE XML-DOC PROCESSING PROCEDURE XML-HANDLER
             ON EXCEPTION
                PERFORM DOC-ERROR
           END-XML.

       DOC-ERROR   SECTION.
            IF XML-CODE = 2
            OR XML-CODE = 102
            OR XML-CODE = 114
            OR XML-CODE = 115
               CONTINUE
            ELSE
                DISPLAY 'XML DOCUMENT ERROR ' XML-CODE.

       XML-HANDLER SECTION.
           EVALUATE XML-EVENT
              WHEN 'START-OF-ELEMENT'
                MOVE XML-TEXT TO CURRENT-ELEMENT
                PERFORM CHECK-ELEMENT
              WHEN 'CONTENT-CHARACTERS'
                ADD 1 TO CCS-CTR
                PERFORM EVAL-CONTENT
              WHEN 'END-OF-ELEMENT'
                MOVE SPACES TO CURRENT-ELEMENT
              WHEN 'START-OF-DOCUMENT'
                COMPUTE XML-DOCUMENT-LENGTH =
                   FUNCTION LENGTH(XML-TEXT)
      **        DISPLAY 'Start of document LEN='
      **            XML-DOCUMENT-LENGTH 'Characters'
              WHEN 'END-OF-DOCUMENT'
                ADD 1 TO EOD-CTR
      **        DISPLAY 'End of document'
              WHEN 'VERSION-INFORMATION'
                ADD 1 TO VI-CTR
              WHEN 'ENCODING-DECLARATION'
                ADD 1 TO ENC-CTR
              WHEN 'STANDALONE-DECLARATION'
                ADD 1 TO STD-CTR
              WHEN 'ATTRIBUTE-NAME'
                ADD 1 TO ATN-CTR
              WHEN 'ATTRIBUTE-CHARACTERS'
                ADD 1 TO ATC-CTR
              WHEN 'ATTRIBUTE-CHARACTER'
                ADD 1 TO ATCH-CTR
              WHEN 'START-OF-CDATA-SECTION'
                ADD 1 TO STC-CTR
              WHEN 'END-OF-CDATA-SECTION'
                ADD 1 TO ETC-CTR
              WHEN 'CONTENT-CHARACTER'
                ADD 1 TO CC-CTR
              WHEN 'PROCESSING-INSTRUCTION-TARGET'
                ADD 1 TO PIT-CTR
              WHEN 'PROCESSING-INSTRUCTION-DATA'
                ADD 1 TO PID-CTR
              WHEN 'COMMENT'
                ADD 1 TO COM-CTR
              WHEN 'EXCEPTION'
                COMPUTE XML-DOCUMENT-LENGTH =
                   FUNCTION LENGTH (XML-TEXT)
      **        DISPLAY 'Exception ' XML-CODE ' at offset '
      **           XML-DOCUMENT-LENGTH '.'
              WHEN OTHER
                DISPLAY 'Unexpected XML Event ' XML-EVENT '.'
           END-EVALUATE.

       EVAL-CONTENT SECTION.
           EVALUATE CURRENT-ELEMENT
              WHEN 'LISTPRICE'
               COMPUTE LIST-PRICE = FUNCTION NUMVAL-C(XML-TEXT)
              WHEN 'FormCode'
               MOVE XML-TEXT TO XFR-CH4
               MOVE XFR-CH4  TO FORM-CODE
              WHEN 'ViolationReference'
               MOVE XML-TEXT TO XFR-CH9
               MOVE XFR-CH9  TO  VIOLATION-REFERENCE
               ADD 1 TO REC-CNT
              WHEN 'ResponsibleDepartmentCode'
               MOVE XML-TEXT TO XFR-CH5
               MOVE XFR-CH5  TO RESPONSIBLE-DEPT-CODE
              WHEN 'ResponsibleDepartmentDesc'
               MOVE XML-TEXT TO XFR-CH20
               MOVE XFR-CH20 TO RESPONSIBLE-DEPT-DESC
              WHEN 'ComplaintDate'
               MOVE XML-TEXT TO XFR-DATE
               MOVE XFR-DATE-MM TO  OT-DATE-MM
               MOVE XFR-DATE-DD TO  OT-DATE-DD
               MOVE XFR-DATE-YYYY TO  OT-DATE-YYYY
               MOVE OT-DATE       TO  COMPLAINT-DATE
              WHEN 'CorrectByDate'
               MOVE XML-TEXT TO XFR-DATE
               MOVE XFR-DATE-MM TO  OT-DATE-MM
               MOVE XFR-DATE-DD TO  OT-DATE-DD
               MOVE XFR-DATE-YYYY TO  OT-DATE-YYYY
               MOVE OT-DATE       TO  CORRECT-BY-DATE
              WHEN 'ParcelID'
               MOVE XML-TEXT TO XFR-CH9
               MOVE XFR-CH9  TO PARCEL-ID
              WHEN 'PropertyLocation'
               MOVE XML-TEXT TO XFR-CH40
               MOVE XFR-CH40 TO LOCATION
              WHEN 'PropertySubdivisionDesc'
               MOVE XML-TEXT TO XFR-CH30
               MOVE XFR-CH30 TO SUBDIVISION-DESCRIPTION
              WHEN 'PropertySubdivisionCode'
               MOVE XML-TEXT TO XFR-CH4
               MOVE XFR-CH4  TO SUBDIVISION-CODE
              WHEN 'MunicipalityCode'
               MOVE XML-TEXT TO XFR-CH4
               MOVE XFR-CH4  TO CITY-TOWN-CODE
              WHEN 'MunicipalityName'
               MOVE XML-TEXT TO XFR-CH40
               MOVE XFR-CH40 TO TOWN-PRECINCT
              WHEN 'ViolationOwnerName'
               MOVE XML-TEXT TO XFR-CH40
               MOVE XFR-CH40 TO OWNER-NAME
              WHEN 'ViolationOwnerAddr01'
               MOVE XML-TEXT TO XFR-CH35
               MOVE XFR-CH35 TO OWNER-ADDRESS-LINE-1
              WHEN 'ViolationOwnerAddr02'
               MOVE XML-TEXT TO XFR-CH35
               MOVE XFR-CH35 TO OWNER-ADDRESS-LINE-2
              WHEN 'ViolationCode'
               MOVE XML-TEXT TO XFR-CH4
               ADD 1 TO V-SUB
               PERFORM EVAL-VIOLATION-CD
              WHEN 'ViolationDescription'
               MOVE XML-TEXT TO XFR-CH30
               PERFORM EVAL-VIOLATION-DESC
              WHEN 'ViolationDetailComment'
               MOVE XML-TEXT TO XFR-CH75
               PERFORM EVAL-VIOLATION-COMMENT
           END-EVALUATE.

       EVAL-VIOLATION-CD SECTION.
           EVALUATE V-SUB
              WHEN 1
               MOVE XFR-CH4  TO VIOLATION-CODE-1
              WHEN 2
               MOVE XFR-CH4  TO VIOLATION-CODE-2
              WHEN 3
               MOVE XFR-CH4  TO VIOLATION-CODE-3
              WHEN 4
               MOVE XFR-CH4  TO VIOLATION-CODE-4
              WHEN 5
               MOVE XFR-CH4  TO VIOLATION-CODE-5
              WHEN 6
               MOVE XFR-CH4  TO VIOLATION-CODE-6
              WHEN 7
               MOVE XFR-CH4  TO VIOLATION-CODE-7
              WHEN 8
               MOVE XFR-CH4  TO VIOLATION-CODE-8
              WHEN 9
               MOVE XFR-CH4  TO VIOLATION-CODE-9
              WHEN 10
               MOVE XFR-CH4  TO VIOLATION-CODE-10
              WHEN 11
               MOVE XFR-CH4  TO VIOLATION-CODE-11
              WHEN 12
               MOVE XFR-CH4  TO VIOLATION-CODE-12
              WHEN OTHER
                 DISPLAY 'VIOLATE CODE ERROR ' V-SUB
                 MOVE 88 TO RETURN-CODE
              END-EVALUATE.

       EVAL-VIOLATION-DESC SECTION.
           EVALUATE V-SUB
              WHEN 1
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-1
              WHEN 2
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-2
              WHEN 3
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-3
              WHEN 4
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-4
              WHEN 5
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-5
              WHEN 6
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-6
              WHEN 7
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-7
              WHEN 8
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-8
              WHEN 9
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-9
              WHEN 10
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-10
              WHEN 11
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-11
              WHEN 12
               MOVE XFR-CH30 TO VIOLATION-DESCRIPTION-12
              WHEN OTHER
                 DISPLAY 'VIOLATE CODE DESC ERROR ' V-SUB
                 MOVE 88 TO RETURN-CODE
              END-EVALUATE.

       EVAL-VIOLATION-COMMENT SECTION.
           EVALUATE V-SUB
              WHEN 1
               MOVE XFR-CH75 TO VIOLATION-COMMENT-1
              WHEN 2
               MOVE XFR-CH75 TO VIOLATION-COMMENT-2
              WHEN 3
               MOVE XFR-CH75 TO VIOLATION-COMMENT-3
              WHEN 4
               MOVE XFR-CH75 TO VIOLATION-COMMENT-4
              WHEN 5
               MOVE XFR-CH75 TO VIOLATION-COMMENT-5
              WHEN 6
               MOVE XFR-CH75 TO VIOLATION-COMMENT-6
              WHEN 7
               MOVE XFR-CH75 TO VIOLATION-COMMENT-7
              WHEN 8
               MOVE XFR-CH75 TO VIOLATION-COMMENT-8
              WHEN 9
               MOVE XFR-CH75 TO VIOLATION-COMMENT-9
              WHEN 10
               MOVE XFR-CH75 TO VIOLATION-COMMENT-10
              WHEN 11
               MOVE XFR-CH75 TO VIOLATION-COMMENT-11
              WHEN 12
               MOVE XFR-CH75 TO VIOLATION-COMMENT-12
              WHEN OTHER
                 DISPLAY 'VIOLATE CODE DESC ERROR ' V-SUB
                 MOVE 88 TO RETURN-CODE
              END-EVALUATE.

       CHECK-ELEMENT SECTION.
           IF CURRENT-ELEMENT = 'ViolationNotice'
           AND VIOLATION-REFERENCE NOT = SPACES
               WRITE DAT-OT-REC FROM MUNIS-NOTICE-RECORD
               ADD 1 TO WRI-CTR
               MOVE 0 TO V-SUB
               INITIALIZE MUNIS-NOTICE-RECORD.
       END PROGRAM DCCS46N.
 

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