ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

cobol & XML from:Four hundred Guru

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • cobol & XML from:Four hundred Guru

    I enjoyed the V5R4 RPG and CL enhancements articles. I can’t wait to use subroutines to clean up code in CL programs. Also, the RPG and SQL tips and techniques are great. But those of us who labor in the COBOL fields could use a little help. –Thom It’s taken me some time to get



    XML Support

    In V5R4, COBOL stays ahead of RPG in the area of XML support. COBOL learned
    to read XML in V5R3, but RPG had to wait until V5R4. Now COBOL learns to
    write XML.

    The command to write XML is called XML GENERATE. It has two forms,
    depending on whether you want to place the generated XML into a
    variable or an IFS file. Here's an untested example that gives an
    idea of how this works.

    First, consider the following source code from the data and procedure divisions.

    PHP Code:
     Data division.
     
    01  EmployeeRec.
         
    03  Name                pic X(25).
         
    03  Badge               pic S9(5).
         
    03  MailAddress.
             
    05  Street          pic X(20).
             
    05  City            pic X(12).
             
    05  State           pic X(2).
         
    03  Personal.
             
    05  MaritalStatus   pic X.
             
    05  BirthDate       pic X(8).

     
    01  XMLMsg    pic X(1000).
     
    01  IFSFile   pic x(50)   value "/home/mydir/SomeIFSFile.xml".

     
    Procedure division.
    Place the generated XML into a variable.
     
    XML GENERATE XMLMsg
         FROM EmployeeRec
     END
    -XML.

    Place the generated XML into an IFS file.
     
    XML GENERATE FILE-STREAM IFSFile
         FROM EmployeeRec
     END
    -XML
    Both commands generate XML from the data currently loaded in the
    EmployeeRec structure. The first XML GENERATE command stores the
    XML in the XMLMsg variable. The second stores the XML in IFS file
    SomeIFSFile.xml. In either case, the generated XML
    looks something like this:

    PHP Code:
    <EmployeeRec>
      <
    Name>Joe Smith</Name>
      <
    Badge>12345</Badge>
      <
    MailAddress>
        <
    Street>101 Main St</Street>
        <
    City>Lost Angeles</City>
        <
    State>NY</State>
      </
    MailAddress>
      <
    Personal>
        <
    MaritalStatus>M</MaritalStatus>
        <
    BirthDate>19010203</BirthDate>
      </
    Personal>
    </
    EmployeeRec
    XML GENERATE has some optional clauses you may be interested in.
    COUNT IN stores the number of generated XML characters in a variable.
    ON EXCEPTION and NOT ON EXCEPTION allow the programmer to include
    code that is to be executed if the XML generation fails or succeeds.

    After XML GENERATE executes, you may check the XML-CODE special
    register to determine failure or success. A value of zero means that the
    generation was successful.
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

  • #2
    Re: cobol &amp; XML from:Four hundred Guru

    Nice...I am writing a program now to create XML from RPGLe...this can't wait until V5R4 nor can I do Cobol...or can I?.....hmmmm. It looks so easy.

    Thnx
    Bill
    "A good friend will bail you out of jail,
    A true friend would be sitting beside you saying,
    'Wow, that was fun.'"

    Comment


    • #3
      Re: cobol &amp; XML from:Four hundred Guru

      should it coded in V5R4 or is it already in V5R3 ?
      and should it use CBLLE or can be used in CBL ?

      I am in V5R3, and trying to code using CBL (QLBLSRC), and failed :-(

      this is the code :
      PHP Code:
      IDENTIFICATION DIVISION.                                     
      PROGRAM-IDfdcxmlgen.                                       
      ENVIRONMENT DIVISION.                                        
      INPUT-OUTPUT SECTION.                                        
      FILE-CONTROL.                                                
          
      SELECT SRST-FILE ASSIGN TO DATABASE-PCPSRST0.            
      DATA DIVISION.                                               
      FILE SECTION.                                                
      FD  SRST-FILE  LABEL RECORDS ARE STANDARD.                   
      01  SRST-REC.  COPY DDS-ALL-FORMATS OF PCPSRST0.             
      WORKING-STORAGE SECTION.                                     
      01  IFSFILE  PIC X(50VALUE "/QDLS/YATNO/PCPSRST0.XML".     
      PROCEDURE DIVISION.                                          
      0000-OPEN-FILE.                                              
          
      OPEN INPUT SRST-FILE.                                    
      0000-READ-AND-CONVERT-TO-XML.                                
          
      READ SRST-FILE AT END GO TO 0000-END.                    
          
      XML GENERATE FILE-STREAM IFSFILE FROM SRST-REC           
          END
      -XML.                                                 
          
      GO TO 0000-READ-AND-CONVERT-TO-XML.                      
      0000-END.                                                    
          
      CLOSE SRST-FILE.                                         
          
      STOP RUN
      and this is compilation result :

      Code:
       5722WDS V5R3M0  030905            AS/400 COBOL Messages           LTUSR234/FDCXMLGEN    MASTER    07/09/07 16:18:15     
        STMT                                                                                                                   
      *   35  MSGID: LBL1325  SEVERITY: 30  SEQNBR:  000904                                                                    
              Message . . . . :   'XML' invalid and ignored, processing                                                        
                continues at next verb or procedure-name in Area A.                                                            
      *   35  MSGID: LBL0018  SEVERITY: 00  SEQNBR:  000904                                                                    
              Message . . . . :   Input ignored starting with 'XML'.                                                           
      *   36  MSGID: LBL0013  SEVERITY: 00  SEQNBR:  000906                                                                    
              Message . . . . :   Compilation continued starting with 'GO'.                                                    
                              * * * * *   E N D   O F   M E S S A G E S   * * * * *                                            
                                                Message Summary                                                                
        Total    Info(0-4)    Warning(5-19)    Error(20-29)    Severe(30-39)    Terminal(40-99)                                
            3          2             0                0                1                 0                                     
       Source records read . . . . . . . . :   23                                                                              
       Copy records read . . . . . . . . . :   38                                                                              
       Copy members processed  . . . . . . :   1                                                                               
       Sequence errors . . . . . . . . . . :   0                                                                               
       Highest severity message issued . . :   30                                                                              
      * LBL1903 40  Program FDCXMLGEN not created in library LTUSR234 because of source statement errors.                      
                             * * * * *   E N D   O F   C O M P I L A T I O N   * * * * *
      it even can not understand XML syntax.

      Comment


      • #4
        Re: cobol &amp; XML from:Four hundred Guru

        Originally posted by yatno View Post
        should it coded in V5R4 or is it already in V5R3 ?

        and should it use CBLLE or can be used in CBL ?
        This is a V5R4 ILE COBOL compiler feature - it will not work in V5R3 - only XML consumption is provided in the V5R3 release of ILE COBOL.

        Any compiler can handle any source type (CBL or CBLLE) - it is only the editors and PDM that care. So - just to be definitive - these features _only_ work in ILE COBOL - they do not work in COBOL/400 and never will. COBOL/400 (like RPG/400) is an obsolete compiler that has not been updated in over 10 years.

        Comment


        • #5
          Re: cobol &amp; XML from:Four hundred Guru

          Originally posted by Billw View Post
          Nice...I am writing a program now to create XML from RPGLe...this can't wait until V5R4 nor can I do Cobol...or can I?.....hmmmm. It looks so easy.

          Thnx
          Wish I'd seen this before Billw I might have been able to save you some time.

          For the future you might want to look at using CGIDEV2 for the XML generation - it is really easy to use and much more maintainable than a roll-your-own approach.

          I wrote an article on the topic that you might find useful http://www.mcpressonline.com/mc?1@25...m9.2@.6b50a11d

          Comment


          • #6
            Re: cobol &amp; XML from:Four hundred Guru

            happy friday to all...

            have a question and since you all have been so helpful in the past, i'm posing it here...i've read thru the info posted regarding COBOL and XML...

            we are getting ready to update our website here at my job...and will be needing to interface data with the as400...we are a cobol shop (not even ILE but regular old fashioned cobol)...

            first off...am i to understand that we cannot put xml into an old fashioned cobol program? that it must be ILE? if so, that's ok

            also...would it be better to write in rpgle or cblle? or either is fine?

            and a few more questions... is it better to use data queues for communicating the requests and responses or to use MQ Series? benefits/drawbacks for each?

            at my last job we sent XML via MQ Series using IFS but we were not sending the data to and from the web...in previous jobs we used data queues to send data to and from the web...just wondering which is best method to use now...

            oh...and btw...we're on latest version of as400 operating system

            we have very aggressive timeline on this project so any input is greatly appreciated!

            Comment


            • #7
              Re: cobol &amp; XML from:Four hundred Guru

              Originally posted by caren View Post
              happy friday to all...

              have a question and since you all have been so helpful in the past, i'm posing it here...i've read thru the info posted regarding COBOL and XML...

              we are getting ready to update our website here at my job...and will be needing to interface data with the as400...we are a cobol shop (not even ILE but regular old fashioned cobol)...

              first off...am i to understand that we cannot put xml into an old fashioned cobol program? that it must be ILE? if so, that's ok
              It depends what you mean by "put" - XML is just character data so ... but only ILE COBOL has built-in support for XML.

              To clarify - OPM COBOL has not been enhanced in over _10_ years! Only ILE COBOL has been enhanced since V3R1.

              also...would it be better to write in rpgle or cblle? or either is fine?
              The XML support is better in RPG than COBOL. RPG does everything that COBOL does and adds an extra layer.

              The one exception is in XML generation which is built-in to COBOL (V5R4) but not RPG. Hopefully they will never bother with it in RPG because it is so easy to do via simple string handling (although that is much better in RPG than COBOL for the most part) - but also using libraries like CGIDEV2 make creating XML a breeze and the COBOL support is very limited.

              Use RPG for web interfaces - COBOL is much harder to interface with the web APIs - its lack of prototyping support makes for real hard work to use C-style APIs

              and a few more questions... is it better to use data queues for communicating the requests and responses or to use MQ Series? benefits/drawbacks for each?
              It is not clear from your description why you would do either when you can communicate directly with the browser. MQ is used when communicating computer to computer - not to browser. Data Q is fine - but what reads it and displays it?

              It sounds as if maybe the web server is WAS and running on another box. If you can tell us exactly what your programs are supposed to be doing it would be easier to answer. For example if another platform is serving up the web pages, writing your programs as stored procedures is often a good way to go.

              Comment


              • #8
                Re: cobol &amp; XML from:Four hundred Guru

                thanks Jonboy for your quick response....i shared this information with my coworker as we will be working on this project together...

                as soon as i have more information...i.e., clarification for some of the points i raised...i will be back with more questions

                again thanks...

                have a great weekend!

                Comment


                • #9
                  Re: cobol &amp; XML from:Four hundred Guru

                  Well ... for me it easier to generate xml using sequel
                  It seems like 2 hop but simpler :

                  - generate ordinary physical file using cobol (filexx)
                  - execute it :
                  execute sql('select * from filexx') pcfmt(xml) toflr(yatno) tofile(fileyy)

                  just it

                  Comment

                  Working...
                  X