• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • What’s New in V5R4 COBOL?

    March 29, 2006 Hey, Ted

    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 to it, Thom, but thanks to Philip Mawby, of IBM‘s Toronto software labs, I have the information you need. I’ll hit the high points. Consult the V5R4 COBOL reference for more details.

    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.

     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:

    <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.

    Conversion of National Data

    IBM has added two new intrinsic functions to aid in translating national data.

    The NATIONAL-OF function converts alphabetic, alphanumeric, or DBCS to national data of CCSID 13488. NATIONAL-OF accepts one or two arguments. The first argument is the source string–the alphabetic, alphanumeric, or DBCS string that is to be translated.

    If the second argument is a one-character national literal or variable, this argument specifies the character to be substituted when a character in the source string cannot be translated into a national character. The default substitution character is X’FFFD’.

    If the second argument is an integer, this argument indicates the CCSID of the source string. If there is no second argument, the system assumes the source string is in the format of the CCSID in effect during compilation. If CCSID 65535 was in effect at compilation, CCSID 37 is used by default.

    The DISPLAY-OF function converts national to alphanumeric. It accepts one or two arguments. The first is the source string, which must be national data.

    If the second argument is a one-character alphabetic, alphanumeric, or DBCS literal or variable, this argument specifies the character to be substituted when a national character in the source string cannot be translated into a character of the target CCSID.

    If the second argument is an integer, this argument indicates the CCSID of the target string. If there is no second argument, the system assumes the target string is in the format of the CCSID in effect during compilation. If CCSID 65535 was in effect at compilation, CCSID 37 is used by default.

    The following example from the COBOL reference illustrates both functions. This example converts an EBCDIC string to ASCII in two steps. That is, first NATIONAL-OF converts EBCDIC data of CCSID 1140 to national. Then DISPLAY-OF converts national to ASCII (CCSID 819).

    77  EBCDIC-CCSID PIC 9(4) BINARY VALUE 1140. 
    77  ASCII-CCSID  PIC 9(4) BINARY VALUE 819. 
    77  Input-EBCDIC PIC X(80). 
    77  ASCII-Output PIC X(80). 
    
        Move Function
          Display-of
           (Function National-of
              (Input-EBCDIC EBCDIC-CCSID)
            ASCII-CCSID
           )
        to ASCII-output.
    

    Trimming Functions

    V5R4 introduces three functions that remove leading and/or trailing characters from strings. The TRIML (trim left) function removes leading characters, while TRIMR (trim right) removes trailing characters. TRIM removes both leading and trailing characters. The characters to be removed are typically blanks, but other characters may be stripped away as well. The source string is not affected by the operation.

    All of these functions take two arguments. The first is the source string, the one to be trimmed. The second argument lists the characters to be removed. If the second argument is not specified, the character list is assumed to consist of one blank. The system will remove characters from the beginning or end of the source string until it finds a character that is not in the character list.

    In the following example, TEXTF contains an edited numeric amount. The TRIML function removes leading blanks and dollar signs, storing the string 1,234.56 into PRICE.

    data division.
    working-storage section.
    01 TextF pic x(80).
    01 Price pic X(12).
    
    procedure division.
    main-logic.
        move " $1,234.56 " to TextF.
        move function TrimL(TextF, "$ ") to price.
    

    Null-Terminated Literals

    IBM has added COBOL support for null-terminated non-numeric literals in V5R4. A null-terminated literal looks like an alphanumeric literal with a leading Z prefix. Here’s an example that displays the value of environment variable XYZ_DATA.

    process nomonoprc
    
    identification division.
    program-id. cob02.
    
    environment division.
    
    data division.
    working-storage section.
    01  EnvVar    pic x(12)    value z"XYZ_DATA".
    01  EnvVarValue  pic X(50).
    01  ValuePtr  usage pointer.
    
    linkage section.
    01  EnvVarParm   pic X(50).
    
    procedure division.
    main-logic.
        call linkage type is procedure "getenv"
            using EnvVar
            returning ValuePtr.
        if ValuePtr = null
            move "*NONE" to EnvVarValue
        else
            set address of EnvVarParm to ValuePtr
            move EnvVarParm to EnvVarValue
        end-if.
        display EnvVarValue.
        goback.
    

    The getenv API requires that the name of the environment variable be passed as a null-terminated value. In this case, the VALUE clause of the definition of EnvVar stores the null-terminated name of the environment variable.

    New Compiler Option

    There is one new compiler option that may be used with the Create Bound COBOL Program (CRTBNDCBL) and Create COBOL Module (CRTCBLMOD) commands. You may specify *NOCOMPRESSDBG or *COMPRESSDBG to control the amount of information generated during compilation with DBGVIEW(*LIST) or DBGVIEW(*ALL) in effect.

    –Ted

    RELATED STORIES AND RESOURCES

    V5R4 RPG Enhancements

    V5R4 CL Enhancements, Revealed and Detailed

    V5R4 COBOL reference

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    SoftLanding Systems:  TurnOver Change Management for a more productive WDSc environment
    Computer Keyes:  Rapidly convert *SCS printer files into black and white or full color PDF documents
    Maximum Availability:  Secure, cost-effective, real-time iSeries replication software solutions

    Sam Palmisano Invites Me to India IBM Hints at Triple Redundancy in Power6

    Leave a Reply Cancel reply

Volume 6, Number 13 -- March 29, 2006
THIS ISSUE SPONSORED BY:

Advanced Systems Concepts
WorksRight Software
Bug Busters Software Engineering

Table of Contents

  • What’s New in V5R4 COBOL?
  • How Many Rows Did SQL Fetch?
  • Setting Up User Profiles Without Passwords

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle