Declaring host variable (The One without DCLGEN.)


DCLGEN (Declaration generator) is the utility/tool provided by IBM to create the Host Language (Cobol) compatible variable for columns in DB2 table.

It's simple ,you just provide the table name you are using in your program,DCLGEN will create the equivalent Host variable for you.

Can you, without the help of DCLGEN,create similar structure of host variable manually ??

Yes, off-course you can, Provided you are able to convert the data types and length from db2 column to that of cobol Program. For Ex. CHAR(10) to PIC X(10),SMALLINT to PIC S9(4) COMP etc.

Having said that, now consider the below scenario

I have created the host variable manually and used it in query which is embedded in my application Program.

Here it goes..

Declaration of Host variable:

01 WS-HOST
     05 WS-STAT-C  PIC X(1)

Usage in Query : (ACC_STAT_C is defined as CHAR(1) NOT NULL in RCAV0300)

SELECT ACC_STAT_C  INTO  :WS-STAT-C   FROM RCAV0300
WHERE ACC_N ='1234'

Now when i execute the Program (Containing above query),i am getting the below error.

"Undefined or Unusable Host Variable WS-STAT-C".


Can anyone one tell me what is the problem here?? Why am i getting this error??

Well i have spelled, defined and used the variable WS-STAT-C correctly in my Program still i am getting the above mentioned error.
Lesson Learnt :

Whenever you define the host variable in your program(the one without DCLGEN) ,define it at 01 Level.If you define it at any sub-level (05,10 etc), you will get the error at run time as "Undefined or Unusable Host Variable",  even though you have spelled,defined and used the host variable correctly in your program.

 
Needless to say now ,above  problem can be resolved by declaring your variable in working storage section as 

 
01 WS-STAT-C  PIC X(1).

2 comments:

Anonymous said...

Buddy we can declare host variable in 05, 10 or which ever level we want.. But it will not work if you have it in copybook.
This would work
01 WS-HOST.
05 WS-STAT-C PIC X(1).
This will not work
01 WS-HOST.
COPY WS-STAT.

Jennifer Tuffen said...

Well Explained. I am searching for the same. Thanks for sharing it here.
Also , checkout my website if you want to know about computer guides and reviews then you can checkout my website clickhere

Post a Comment