• No results found

Declaring host variables in PL/I applications that use SQL

ThePL/Iprecompileronlyrecognizesa subsetofvalidPL/Ideclarationsasvalidhostvariable declarations.

Onlythenamesanddataattributesofthevariablesareusedbytheprecompilers;thealignment,scope, andstorageattributes areignored.Even thoughalignment,scope,and storageareignored,therearesome restrictionsontheirusethat,if ignored,mayresultinproblemswhen compilingPL/Isourcecodethatis createdbytheprecompiler.Theserestrictionsare:

v Adeclarationwith theEXTERNALscope attributeandtheSTATICstorageattributemustalso havethe

INITIALstorageattribute.

v IftheBASEDstorageattributeiscoded,itmust befollowedbya PL/Ielement-locator-expression.

Numeric-hostvariablesinPL/IapplicationsthatuseSQL:

Thisfigure showsthesyntaxforvalidscalarnumeric-hostvariable declarations.

Numeric  DECLARE DCL  variable-name , ( variable-name )   BINARY FIXED BIN ( precision ) FLOAT ( precision ) DECIMAL FIXED DEC ( precision ) ,scale FLOAT ( precision ) PICTURE picture-string   ;

Alignment and/or Scope and/or Storage



Notes:

1. (BINARY,BIN, DECIMAL,orDEC)and(FIXED orFLOAT)and(precision,scale)canbe

2. Apicture-string intheform ’9...9V9...R’indicatesanumerichostvariable. TheRisrequired.

TheoptionalVindicatestheimplieddecimalpoint.

3. Apicture-string intheform ’S9...9V9...9’indicatesa signleadingseparatehostvariable. TheS

isrequired. TheoptionalVindicates theimplieddecimalpoint.

Character-hostvariables inPL/IapplicationsthatuseSQL:

Thisfigure showsthesyntaxforvalidscalarcharacter-hostvariables.

Character  DECLARE DCL  variable-name , ( variable-name ) CHARACTER

CHAR ( length ) VARYING

VAR





;

Alignment and/or Scope and/or Storage



Notes:

1. Lengthmustbe anintegerconstantnotgreaterthan32766 ifVARYINGorVARisnot

specified.

2. IfVARYINGorVARisspecified,lengthmust bea constantnogreaterthan32740.

Binaryhost variablesinPL/IapplicationsthatuseSQL:

PL/IdoesnothavevariablesthatcorrespondtotheSQLbinarydatatypes. Tocreatehost variablesthat canbeusedwiththesedatatypes, usetheSQLTYPE ISclause.TheSQLprecompilerreplacesthis declarationwitha PL/Ilanguagestructurein theoutputsourcemember.

BINARYandVARBINARY  DECLARE DCL  variable-name , ( variable-name ) SQL TYPE IS BINARY VARBINARY BINARY VARYING ( length ) ;  Notes:

1. ForBINARYhostvariables,thelengthmustbe intherange1 to32766.

2. ForVARBINARYand BINARYVARYINGhostvariables,thelength mustbeintherange1to

32740.

3. SQLTYPEIS,BINARY,VARBINARY,BINARYVARYING canbe inmixedcase.

BINARYexample

Thefollowingdeclaration:

DCL MY_BINARY SQL TYPE IS BINARY(100);

Resultsinthegenerationofthefollowingcode:

VARBINARYexample

Thefollowingdeclaration:

DCL MY_VARBINARY SQL TYPE IS VARBINARY(250);

Resultsinthegenerationofthefollowingcode:

DCL MY_VARBINARY CHARACTER(250) VARYING;

LOBhostvariables inPL/IapplicationsthatuseSQL:

PL/IdoesnothavevariablesthatcorrespondtotheSQLdatatypesforLOBs(largeobjects).Tocreate hostvariablesthatcanbe usedwiththesedatatypes, usetheSQLTYPEISclause.TheSQLprecompiler replacesthisdeclarationwith aPL/Ilanguagestructure intheoutputsourcemember.

Thefollowingfigureshowsthesyntaxfor validLOBhostvariables.

LOB  DECLARE DCL  variable-name , ( variable-name ) SQL TYPE IS CLOB BLOB ( lob-length ) ; K  Notes:

1. ForBLOBand CLOB,1≤ lob-length≤32,766

2. SQLTYPEIS,BLOB,CLOBcanbe inmixedcase.

CLOBexample

Thefollowingdeclaration:

DCL MY_CLOB SQL TYPE IS CLOB(16384);

Resultsinthegenerationofthefollowingstructure:

DCL 1 MY_CLOB,

3 MY_CLOB_LENGTH BINARY FIXED (31) UNALIGNED,

3 MY_CLOB_DATA CHARACTER (16384);

BLOBexample

Thefollowingdeclaration:

DCL MY_BLOB SQL TYPE IS BLOB(16384);

Resultsinthegenerationofthefollowingstructure:

DCL 1 MY_BLOB,

3 MY_BLOB_LENGTH BINARY FIXED (31) UNALIGNED,

3 MY_BLOB_DATA CHARACTER (16384);

LOBlocator  DECLARE DCL  variable-name , ( variable-name ) SQL TYPE IS CLOB_LOCATOR ; DBCLOB_LOCATOR BLOB_LOCATOR 

Note: SQLTYPE IS,BLOB_LOCATOR, CLOB_LOCATOR,DBCLOB_LOCATORcanbeinmixedcase.

CLOBlocatorexample

Thefollowingdeclaration:

DCL MY_LOCATOR SQL TYPE IS CLOB_LOCATOR;

Resultsinthefollowinggeneration:

DCL MY_LOCATOR BINARY FIXED(31) UNALIGNED;

BLOBandDBCLOB locatorshavesimilarsyntax.

ThefollowingfigureshowsthesyntaxforvalidLOBfilereferencevariables.

LOBfile referencevariable  DECLARE DCL  variable-name , ( variable-name ) SQL TYPE IS CLOB_FILE ; DBCLOB_FILE BLOB_FILE 

Note: SQLTYPE IS,BLOB_FILE,CLOB_FILE,andDBCLOB_FILEcanbeinmixedcase.

CLOBfilereferenceexample

Thefollowingdeclaration:

DCL MY_FILE SQL TYPE IS CLOB_FILE;

Resultsinthegenerationofthefollowingstructure:

DCL 1 MY_FILE,

3 MY_FILE_NAME_LENGTH BINARY FIXED(31) UNALIGNED,

3 MY_FILE_DATA_LENGTH BINARY FIXED(31) UNALIGNED,

3 MY_FILE_FILE_OPTIONS BINARY FIXED(31) UNALIGNED,

3 MY_FILE_NAME CHAR(255);

BLOBandDBCLOB filereference variableshavesimilarsyntax.

Thepre-compilerwillgeneratedeclarationsforthefollowingfileoptionconstants: v SQL_FILE_READ(2) v SQL_FILE_CREATE(8) v SQL_FILE_OVERWRITE(16) v SQL_FILE_APPEND(32) Related reference

LOBfilereferencevariables

PL/Idoesnothavea variablethatcorresponds totheSQLdatatypeROWID.Tocreatehostvariables thatcanbeusedwiththisdatatype,usetheSQLTYPEISclause.TheSQLprecompilerreplacesthis declarationwith aPL/Ilanguagestructure intheoutputsourcemember.

ROWID  DECLARE DCL  variable-name , ( variable-name ) SQL TYPE IS ROWID 

Note: SQLTYPE ISROWIDcanbeinmixedcase.

ROWIDexample

Thefollowingdeclaration:

DCL MY_ROWID SQL TYPE IS ROWID;

Resultsinthefollowinggeneration:

DCL MY_ROWID CHARACTER(40) VARYING;