IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Using the column name as the Host variable


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 1208
Location: Bangalore,India

PostPosted: Fri Dec 15, 2006 10:24 am
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: 1448
Location: Chicago, IL

PostPosted: Fri Dec 15, 2006 10:45 am
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
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: 1208
Location: Bangalore,India

PostPosted: Fri Dec 15, 2006 11:37 am
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts Variable Output file name DFSORT/ICETOOL 8
Search our Forums:

Back to Top