Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

DB2 handelling XML programs through Cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
kgumraj2

New User


Joined: 01 Aug 2007
Posts: 42
Location: Hyderabad

PostPosted: Mon Aug 27, 2007 6:46 pm    Post subject: DB2 handelling XML programs through Cobol
Reply with quote

Hi,

Does Anyone have a sample program or some reference, for DB2 handelling XML programs through Cobol?
Do share

Thanks Much for your help again !!!
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Aug 27, 2007 7:33 pm    Post subject:
Reply with quote

Hello,

You might want to clarify this
Quote:
for DB2 handelling XML programs through Cobol
Start with DB2 as a database engine, XML as a data handling convention, and COBOL as a procedural programming language.

Are you asking about COBOL code that will parse XML data and put the results into DB2 tables? Something else?

If you provide small examples of what data you have and what you want to do with it, we may have suggestions.
Back to top
View user's profile Send private message
dr_te_z

New User


Joined: 08 Jun 2007
Posts: 71
Location: Zoetermeer, the Netherlands

PostPosted: Tue Aug 28, 2007 2:03 am    Post subject:
Reply with quote

Well, that's the power of DB2 V9. You do not need to 'handle XML'. DB2 does it for you.
When you insert a row with a XML-column, the parsing thing is taken care of. When you want to query the content, just "embedd" your xpath in your "already embedded" SQL.

Yes: it's gonna be as easy as this sounds.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 28, 2007 2:39 am    Post subject:
Reply with quote

xquery is also available in DB2 V9
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Aug 28, 2007 3:10 am    Post subject:
Reply with quote

Hello,

What if the requirement will be implemented on a version earlier than 9?
Back to top
View user's profile Send private message
dr_te_z

New User


Joined: 08 Jun 2007
Posts: 71
Location: Zoetermeer, the Netherlands

PostPosted: Tue Aug 28, 2007 3:36 am    Post subject:
Reply with quote

dick scherrer wrote:
What if the requirement will be implemented on a version earlier than 9?
Well, then the above is not true. Parsing XML yourself in COBOL: great fun. You can store the XML file as a BLOB or CLOB or whatever, you still got to parse and interpred the content yourself.

When your business requires you to process XML and you're already a DB2 user... I'd like to see your shortlist of PRO's & CON's whether to upgrade to V9 or not.

You could install DB2 V9 LUW for your XML files and leave your relational data on the mainframe. As an incremental approach.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Aug 28, 2007 4:38 am    Post subject:
Reply with quote

Hello Kiran,

Is your system running V9 yet?

If not, Enterprise COBOL has XML support (if you are using Enterprise COBOL, your compiles will show something like "PP 5655-G53 IBM ENTERPRISE COBOL FOR Z/OS").
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Aug 28, 2007 5:33 am    Post subject:
Reply with quote

The XML support in Cobol is very straight forward and easy to work with even. It is a little lacking when creating "standard" XML, but it can parse with no problems that I have found.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Aug 28, 2007 6:40 am    Post subject:
Reply with quote

Hello Steve,

Depending on what we hear from Kiran, have you any working code that could be posted or genericized?

Ok, regardless of Kiran's specific requirements - i'm sure there others going down the same path "as we speak".
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Aug 28, 2007 6:59 am    Post subject:
Reply with quote

Here is a basic parse. I am reading a record from a file. Each record is a complete XML doc not formatted to be pretty. The document is then parsed looking for only the EMPLOYEE_NUM element and the FIRST_NM element. It can get somewhat cumbersome, but it is pretty easy to use.

Code:

4000-PROCESS-XML-FILE.                                     
     PERFORM 4300-READ-INPUT THRU 4300-EXIT.               
     IF INPUT-EOF                                           
        GO TO 4000-EXIT                                     
     ELSE                                                   
         IF XML-CNT    = 1                                 
            GO TO 4000-EXIT                                 
         ELSE                                               
            XML PARSE INBOUND-RECORD                           
               PROCESSING PROCEDURE 4010-XML-PARSE THRU
                  4010-EXIT                                 
               ON EXCEPTION PERFORM 8000-XML-ERROR THRU     
                  8000-EXIT                                 
            END-XML                                         
         END-IF                                             
         If TXN-RT-CD-Found                                 
            If DTL-ERROR-CD NOT EQUAL '00000'               
               Perform 4200-Format-Rpt thru 4200-Exit       
            End-If                                         
         End-If                                             
         Set TXN-RT-CD-Not-Found to True     
         Set INBOUND-ID-Not-Found to True       
     END-IF.                                                             
4000-EXIT. EXIT. 

4010-XML-PARSE.                                             
                                                           
        DISPLAY 'PARSER READ IN: '                         
        DISPLAY '  XML-CODE     = ' XML-CODE               
        DISPLAY '  XML-EVENT    = ' XML-EVENT               
        DISPLAY '  XML-TEXT     = ' XML-TEXT               
        DISPLAY '  XML-TEXT LEN = ' LENGTH OF XML-TEXT.     
                                                           
    Move XML-CODE  to HOLD-XML-CODE.                       
    Move XML-EVENT to NEW-XML-EVENT.                       
    Move LENGTH OF XML-TEXT to XML-LEN-IN.                 
                                                           
    Evaluate NEW-XML-EVENT                                 
      When 'START-OF-ELEMENT'                               
        Perform 4020-Process-Start-Tag thru 4020-Exit       
      When 'CONTENT-CHARACTER'                             
      When 'CONTENT-CHARACTERS'                             
        Move XML-TEXT(1:XML-LEN-IN) to                     
             HOLD-XML-TEXT(CHAR-SUB:XML-LEN-IN)             
        Add XML-LEN-IN to CHAR-SUB                         
      When 'END-OF-ELEMENT'                                 
        If CHAR-SUB > 1                                     
           Perform 4030-Process-Tag-Data Thru 4030-Exit         
        End-if                                                   
        Perform 4040-Process-End-Tag thru 4040-Exit             
     When 'Exception'                                           
***  Err 12: A processing instruction target name was 'xml'     
***  in lowercase, uppercase, or mixed case.                     
        If XML-CODE = 12                                         
           Move 0 to XML-CODE                                   
        Else                                                     
           Display 'XML Exception ' XML-CODE ' Set XML-CODE = 0'
           Move 0 to XML-CODE                                   
        End-if                                                   
     End-Evaluate.                                               
4010-EXIT. EXIT.                                                 


4020-Process-Start-Tag.                               
    Move XML-TEXT to HOLD-CURRENT-TAG.                 
    Move 1 to CHAR-SUB.                               
    Move Spaces to HOLD-XML-TEXT.                     
    Evaluate HOLD-CURRENT-TAG                         
       WHEN 'EMPLOYEE_NUM'                               
          Set EMP_NO-Found to True                 
       WHEN 'FIRST_NM'                                   
          Set INBOUND-ID-Found to True                     
    End-Evaluate.                                     
4020-Exit. Exit.                                       

4030-Process-Tag-Data.                                 
    Subtract 1 from CHAR-SUB.                         
    Evaluate HOLD-CURRENT-TAG                         
       WHEN 'EMPLOYEE_NUM'                               
          Move HOLD-XML-TEXT(1:5) TO WS-EMP-NUM
       WHEN 'FIRST_NM'                                   
          Move HOLD-XML-TEXT(1:18) TO WS-FIRST-NM
    End-Evaluate.                                     
4030-Exit. Exit.                                       

4040-Process-End-Tag.                       
    Subtract 1 from CHAR-SUB.               
    Move Spaces to HOLD-XML-TEXT.           
    Move Spaces to HOLD-CURRENT-TAG.       
4040-Exit. Exit.                           
icon_evil.gif
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Aug 28, 2007 7:14 am    Post subject:
Reply with quote

Basic XML generation. I would post the reformatter, but that is too much work to genericize unless someone really wants to see it.

Standard XML calls for underscores in the XML. The reformater replaces the '-' from the COBOL working storage fields '_'. I modified some code from IBM's website to take care of this work.
It takes this:
<MQ-RECORD>
<COBOL-DATA>some data record</COBOL-DATA>
</MQ-RECORD>

And changes it to this:
<MQ_RECORD>
<FIELD name="COBOL_DATA" type="text">some data record</FIELD>
</MQ_RECORD>

Code:

 Identification Division.
 PROGRAM-ID. XMLGENR.

*Other standard program stuff

 Data Division.
 Working-storage Section.
  copy MQCPYBK.
  01 xml-response.                               
     05  return-cd            pic s9(9) binary.   
     05  XML-count            PIC 9(9) comp.     
     05  xmla-count           pic 9(9) comp.     
     05  XMLa                 PIC X(1000000).     
     05  XML-OUTPUT           PIC X(800000).       

 PROCEDURE DIVISION.
 000-Main.

 Move
 XML GENERATE XML-OUTPUT FROM  MQ-RECORD
     COUNT IN xml-count                               
    ON EXCEPTION                                       
       DISPLAY 'XML generation error ' xml-code         
       DISPLAY 'XML count            ' xml-count         
*       GOBACK                                                                                           
    NOT ON EXCEPTION                                   
       display 'XML generation success. ' xml-count     
       CALL XML-REFMT-PGM using xml-response                 
       display 'cincom xml convert success. ' xml-count 
       display xmla(1:xmla-count)                       
 END-XML.                                             

 GOBACK.

 End program 'XMLGENR'.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Aug 28, 2007 7:22 am    Post subject:
Reply with quote

The parser may have some typos in it. I used EMP_NO-Found when it should be EMP-NO-Found
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Aug 28, 2007 8:36 am    Post subject:
Reply with quote

We just did our v8 upgrade this year...
Back to top
View user's profile Send private message
kgumraj2

New User


Joined: 01 Aug 2007
Posts: 42
Location: Hyderabad

PostPosted: Tue Aug 28, 2007 12:21 pm    Post subject:
Reply with quote

Hi,

Thanks All for your Suggestion.
I have written XML-DB2 program that reads data from table and passes similar to above example.

This is fine when I read into Working storage varaible of datatype VARCHAR or any other type.
But I need to declare the variable as CLOB.

Code:
01 WS-STRUCTURE USAGE IS SQL TYPE IS CLOB(1K).


As CLOB can store 1020 KB and working storage varibles can store 327607(~32KB).

Can any one please Me khow how to handle CLOB variables ?
Thanks once again.[/code]
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Aug 28, 2007 5:17 pm    Post subject:
Reply with quote

No, working storage can hold variables of huge sizes. I have one declared 16000 KB in a program.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Aug 28, 2007 5:38 pm    Post subject:
Reply with quote

kgumraj2 wrote:
As CLOB can store 1020 KB and working storage varibles can store 327607(~32KB).
Feel free to visit Appendix B. Compiler limits where you can see for yourself that 01 levels can be bigger than ~32KB: "01-49 data-names | 16,777,215 bytes"
Back to top
View user's profile Send private message
dr_te_z

New User


Joined: 08 Jun 2007
Posts: 71
Location: Zoetermeer, the Netherlands

PostPosted: Tue Aug 28, 2007 5:58 pm    Post subject:
Reply with quote

I was told by IBM-mers that DB2V9 can handle XML's up to 2Gb.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Aug 28, 2007 6:23 pm    Post subject:
Reply with quote

Hello,

Steve, Thanks for the code icon_smile.gif

Kiran, What version of COBOL is used on your system?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us