Microsoft KB Archive/66752

= INF: Data Conversion Sample Program in Embedded SQL for COBOL =

PSS ID Number: 66752

Article Last Modified on 10/3/2003

-

The information in this article applies to:


 * Microsoft Embedded SQL for COBOL 4.2

-



This article was previously published under Q66752



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 &quot;v&quot; 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 = &quot;BU1111&quot; 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 &quot;Has sold &quot; ytd-sales-convert &quot; copies this year, at              $&quot;price-convert &quot; a copy.&quot; display &quot;It was published on &quot; pubdate else perform sql-error end-if stop run.

sql-error. display &quot;SQL error SQLCODE=&quot; sqlcode.

Keywords: kbprogramming KB66752

Technology: kbAudDeveloper kbSQLEmCOBOL kbSQLServSearch kbZNotKeyword3

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.