INF: Data Conversion Sample Program in Embedded SQL for COBOL

Last reviewed: May 5, 1997
Article ID: Q66752
The information in this article applies to:

  - Microsoft Embedded SQL version 4.2 for COBOL

SUMMARY

The code listed below demonstrates several data conversion methods for bringing down SQL Server data and displaying it in a Microsoft Embedded SQL for COBOL program.

MORE INFORMATION

This example selects a varchar(80) field, a money field, an int field, and a datetime file into COBOL program variables and displays them.

The title field is straightforward. Price is brought down using a "v" in the picture clause representing the assumed decimal place, and is moved to a variable with a decimal point (.) to actually print the decimal point. The reason for this is that the decimal point is not accepted in the picture clause of a host variable.

Ytd-sales is also straightforward, except that it is moved into another program variable so that the plus (+) sign and preceding 0 (zero) would not be displayed. The pubdate field is converted on the SQL Server end and just returns the month, day, and year.

Sample Code

    WORKING-STORAGE SECTION.

    EXEC SQL INCLUDE SQLCA END-EXEC

    EXEC SQL BEGIN DECLARE SECTION END-EXEC
    01  title            pic x(80).
    01  price            pic s9(9)v9(9) comp-3.
    01  ytd-sales        pic s9(4) comp-3.
    01  pubdate          pic x(11).
    EXEC SQL END DECLARE SECTION END-EXEC

    01 price-convert     pic z(3).9(2).
    01 ytd-sales-convert pic z(4).

    PROCEDURE DIVISION.

    EXEC SQL
      select title, price, ytd_sales, convert(char(11),pubdate)
      into :title, :price, :ytd-sales, :pubdate
      from titles
      where title_id = "BU1111"
    END-EXEC
   * Ignore any warnings, sqlcode = 1. *
    if sqlcode = 0 or sqlcode = 1
      move price to price-convert
      move ytd-sales to ytd-sales-convert
    display title
      display "Has sold " ytd-sales-convert " copies this year, at
               $"price-convert " a copy."
      display "It was published on " pubdate
    else
      perform sql-error
    end-if
    stop run.

    sql-error.
    display "SQL error SQLCODE=" sqlcode.


Additional query words:
Keywords : kbprg SSrvCobol SSrvProg
Version : 4.2 | 4.2
Platform : MS-DOS OS/2


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.