Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Using the column name as the Host variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
padma_prakasam

New User


Joined: 06 Oct 2005
Posts: 31

PostPosted: Fri Dec 15, 2006 8:02 am    Post subject: Using the column name as the Host variable
Reply with quote

Hi,

I have cobol-Db2 program which has a select query that fetches values into host variables. Example i fetch EMPNAME into host variable WS-EMPNAME and want to move to another variable. I can use WS-EMPNAME to move. But is it possible to use EMPNAME itself (the coulmn name not host variable) in any MOVE statements?

Thanks
Padma
Back to top
View user's profile Send private message

guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Fri Dec 15, 2006 10:24 am    Post subject:
Reply with quote

Hi Padma,

I am not able to fully understand ur query but it look like

Code:
FETCH CURSOR_1
   INTO :WS-EMPNAME


then u want to move which is correct
Code:

MOVE WS-EMPNAME TO WS-OTHERVARIABLE


but u cant use
Code:
MOVE EMPNAME TO WS-OTHERVARIABLE
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Dec 15, 2006 10:45 am    Post subject: Re: Regarding Host variables
Reply with quote

Padma...

Host variables are nothing more than a COBOL Field declaration to map with a DB2 table field. They may have a similar nominclature as field name.
Thats why we put a colon ":" while using host variable in the SQL queries, so it is easy for compiler to understand which one of these is a host variable.
So you should be able to use something like this.
Code:
EXEC SQL
   SELECT EMPID INTO :EMPID
   FROM EMPLOYEES WHERE SALARY >= 1000000
END-EXEC.

MOVE EMPID TO WS-OTHER-VARIABLE

Ekta... Pls correct, if wrong... wanted to check it before, but couldn't.
Back to top
View user's profile Send private message
srinut123

New User


Joined: 11 Oct 2005
Posts: 62
Location: India

PostPosted: Fri Dec 15, 2006 10:45 am    Post subject:
Reply with quote

Hi Padma

The visibility of EMPNAME outside of the END-EXEC will be lost.. so u cant use the column name outside of the Embedded SQL statement. That is the reason we store the data from the query in a Host variable and will use this where ever we want in the program

Steve
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Fri Dec 15, 2006 11:37 am    Post subject:
Reply with quote

Hi There,

Just one more addition to whatever Priyesh said. In the following query
EMPID should be declare in working storage section if DCLGEN is not declare in the program otherwise EMPID which is the coloum of table ( Should be in dclgen). but if we are taking EMPID as working storage variable not the variable which is present in DCLGEN that better to use qualifier.Hope it make some sense

Code:
EXEC SQL
   SELECT EMPID INTO :EMPID
   FROM EMPLOYEES WHERE SALARY >= 1000000
END-EXEC.

MOVE EMPID TO WS-OTHER-VARIABLE
Back to top
View user's profile Send private message
Sarva_bubli

New User


Joined: 09 Aug 2006
Posts: 37
Location: Pune, India

PostPosted: Fri Dec 15, 2006 3:52 pm    Post subject:
Reply with quote

Hi,
EXEC SQL
SELECT EMPSAL
INTO :WS-EMPSAL
FROM EMP_TABLE
WHERE EMPNO = XXXXXX
END-EXEC


In the above u can
MOVE WS-EMPSAL TO WS-VARIABLE-SAL

Correct me if I'm wrong
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us