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

2 DCLGEN's in the same program - duplicate variables


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
acrajesh

New User


Joined: 31 May 2007
Posts: 15
Location: Bangalore

PostPosted: Wed Aug 27, 2008 1:29 pm
Reply with quote

I am trying to use two DCLGEN's in the same program where two of the variables used is ambigous, ie; they are used in both the dclgen's. how to fix this issue?

Ex: The variable STL-CODE is used in both the DCLGEN's
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Wed Aug 27, 2008 1:52 pm
Reply with quote

acrajesh,

Quote:
am trying to use two DCLGEN's in the same program where two of the variables used is ambigous, ie; they are used in both the dclgen's.


Not a problem and you can use it even when the names are same.

Quote:
how to fix this issue?


Have both the dclgen's INCLUDEd in the program and when it comes to differentiate the variables code as shown below

Say if the field X is in DCLGEN Y and Z

Code:
MOVE X OF Y TO X OF Z
Back to top
View user's profile Send private message
acrajesh

New User


Joined: 31 May 2007
Posts: 15
Location: Bangalore

PostPosted: Wed Aug 27, 2008 2:09 pm
Reply with quote

Hi Aaru,

The code is as follows

EXEC SQL
INSERT INTO MTW.STK_MRKT_DTL(
STK_CODE,
DMAT_ACCT,
DMAT_ACCT_NAME,
DMAT_ACCT_ADDR,
STK_BUY_PRC,
STK_SELL_PRC,
TOT_STK_BOUGHT,
TOT_STK_SOLD,
STOP_LOSS_PRC,
STK_HLD_FROM,
LST_TXN_DATE,
CRT_USER_ID,
CRT_TMSTMP)
VALUES (
:STK-CODE,
:DMAT-ACCT,
:DMAT-ACCT-NAME,
:DMAT-ACCT-ADDR,
:STK-BUY-PRC,
:STK-SELL-PRC,
:TOT-STK-BOUGHT,
:TOT-STK-SOLD,
:STOP-LOSS-PRC,
:STK-HLD-FROM,
:LST-TXN-DATE,
CURRENT SQLID,
CURRENT TIMESTAMP)
END-EXEC

EXEC SQL
INSERT INTO MTW.STK_MRKT_HDR(
STK_CODE,
COMP_NAME,
COMP_ADDR,
CURR_STK_PRC,
CURR_YR_LOW,
CURR_YR_HIGH,
TOT_PUB_STK,
CRT_USER_ID,
CRT_TMSTMP )
VALUES (
:STK-CODE,
:COMP-NAME,
:COMP-ADDR,
:CURR-STK-PRC,
:CURR-YR-LOW,
:CURR-YR-HIGH,
:TOT-PUB-STK,
CURRENT SQLID,
CURRENT TIMESTAMP)
END-EXEC

where STK-CODE appears in both of the INSERT's. How to fix this issue as the compilation throws the following error:

DSNH314I E DSNHSMUD LINE 246 COL 0 REFERENCE TO HOST VARIABLE STK-CODE IS AMBIGUOUS
DSNH314I E DSNHSMUD LINE 300 COL 0 REFERENCE TO HOST VARIABLE STK-CODE IS AMBIGUOUS

I even tried like STK-CODE OF STK-MRKT-HDR and STK-MRKT-HDR.STK-CODE but both went in vain.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 27, 2008 2:23 pm
Reply with quote

reference qualification in COBOL is via the 'IN' or 'OF' keyword.

the format for qualifying columns in db2 is a little different.

it is either qualifier.column_name

or column_name.qualifier

i don't remember,
either refer to the documentation or try both ways and see which works
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 27, 2008 2:25 pm
Reply with quote

an amendment to the previous post.

it is host variable and not column that is qualified.
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Wed Aug 27, 2008 2:26 pm
Reply with quote

acrajesh,

This is how it should be done when the same field is there in 2 DCLGEN's.

Say the DCLGEN's are Y and Z

In the DCLGEN you would have 2 things

- DECLARE TABLE
- COBOL declaration for the TABLE

In the cobol declaration of the table make sure that the 01 level has the DCLGEN name.

Code:
01 X.
              10 field one  pic x(10)
              10 field two  pic x(20)


In the DCLGEN Y have it as

Code:
01 Y.
              10 field one pic x(10)


then in the query use as shown below

Code:
EXEC SQL
                  INSERT
                  INTO TABLE
                     ....
                      ....
                   VALUES(FIELD EIGHT
                             ,:X.FIELD ONE)
           END-EXEC   


Similarly in the next query use it with the prefix Y.

Hope this helps
Back to top
View user's profile Send private message
acrajesh

New User


Joined: 31 May 2007
Posts: 15
Location: Bangalore

PostPosted: Wed Aug 27, 2008 2:48 pm
Reply with quote

Not working icon_sad.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 27, 2008 2:55 pm
Reply with quote

only thing that is not working is you.

sorry if you are offended (yes the sarcasm was intended)
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Wed Aug 27, 2008 3:09 pm
Reply with quote

acrajesh,

Quote:
Not working


Which part of the code do you think is not working? Did you try ?
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Wed Aug 27, 2008 5:40 pm
Reply with quote

If nothing is working and standards permit , U may try this (not tested)

Move STK-CODE of STK-MRKT-DTL to WS-CODE-DTL
Move STK-CODE of STK-MRKT-HDR to WS-CODE-HDR

Make sure the data types exactly match and use these these variables in your SQl insert query.

Hope This helps.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Using API Gateway from CICS program CICS 0
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts DB2 Event passed to the Application P... DB2 1
No new posts How to pass the PARM value to my targ... COBOL Programming 8
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
Search our Forums:

Back to Top