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!
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.
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
****************************************************************
** 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.
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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.