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

Tables in cobol


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

New User


Joined: 11 Feb 2008
Posts: 53
Location: NJ

PostPosted: Fri Mar 07, 2008 5:37 am
Reply with quote

I am not sure if what I want to do is possible or not...but here it goes....

I have 3 work areas with fields that has following characteristics

1st area has fields with XXXX-WS
2nd area has fields with SCA-XXXXX
3rd area has fields with IND-XXXXX

Now, field lengths are the same across -WS and -SCA area. IND- are indicators being populated with either -1 or 0 when I do SELECT from DB2.

Right now, I have individual checks to say that

IF IND-XXXX = 0 then
move XXXXX-WS to SCA-XXXXX
end-if


And then I have

If SCA-XXXX-R not = high-values
move SCA-XXXXX to XXXXX-WS
else
move -1 to IND-XXXX
end-if

Now, I am wondering if there is a way I can make a table that would have 3 columns and X number of rows where X would equal number of fields so that I do not have to do in excess of 100 if statements?

If this is not clear, please excuse me. I will try to explain it better...


Thanks!!
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Mar 07, 2008 6:19 am
Reply with quote

Jeez, if this was much more unclear, you would have won the 'Huh?' award.....
Back to top
View user's profile Send private message
Nirav721

New User


Joined: 11 Feb 2008
Posts: 53
Location: NJ

PostPosted: Fri Mar 07, 2008 6:50 am
Reply with quote

Lets try it this way...

I have a WS area as follows...

10 FIELD-WS.
15 PART-NUMBER-WS PIC X(2).
15 PURE-NIRAV-AMT-WS PIC S9(5)V USAGE COMP-3.
15 CURR-CICS-GUY-AMT-WS PIC S9(3)V USAGE COMP-3.


Then, I have the Indicator area...

10 INDICATOR-WS.
15 IND-PURE-NIRAV-AMT PIC S9(4) COMP.
15 IND-CURR-CICS-GUY-AMT PIC S9(4) COMP.


Then I have the SCA area....

01 SCA-BUILD-AREA.
05 SCA-PURE-NIRAV-AMT PIC S9(5)V USAGE COMP-3.
05 SCA-PURE-NIRAV-AMT-R
REDEFINES SCA-PURE-NIRAV-AMT.
10 FILLER PIC X(3).
05 SCA-CURR-CICS-GUY-AMT PIC S9(3)V USAGE COMP-3.
05 SCA-CURR-CICS-GUY-AMT-R
REDEFINES SCA-CURR-CICS-GUY-AMT.
10 FILLER PIC X(2).




Then I perform a select...

SELECT PURE_NIRAV_AMT,
CURR_CICS_GUY_AMT
INTO :PURE-NIRAV-AMT-WS:IND-PURE-NIRAV-AMT,
:CURR-CICS-GUY-AMT-WS:IND-CURR-CICS-GUY-AMT


IF SQLCODE = 0

IF IND-PURE-NIRAV-AMT = 0 THEN
MOVE PURE-NIRAV-AMT-WS TO SCA-PURE-NIRAV-AMT
END-IF

IF IND-CURR-CICS-GUY-AMT = 0
MOVE CURR-CICS-GUY-AMT-WS TO SCA-CURR-CICS-GUY-AMT
END-IF

END-IF.



Note that in this example, I am only using two fields, we could potentially have up to 150 fields...so I am trying to find a way to avoid typing in 150 if-end-if statements....I thought that table might be a way to do this, but I am not too savy with cobol yet, so needed little nudge in the right direction....?

Thanks!!
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Mar 07, 2008 10:42 am
Reply with quote

If you are using DB2 you can not select into a table item!
Back to top
View user's profile Send private message
Nirav721

New User


Joined: 11 Feb 2008
Posts: 53
Location: NJ

PostPosted: Fri Mar 07, 2008 4:28 pm
Reply with quote

Hmm, I thought it would be possible if I specify each index individually. I just want to get rid of the if statements....?

Something similar to...

10 FIELD-WS-TABLE occurs 3 times indexed by Index-ws
15 PART-NUMBER-WS PIC X(2).
15 PURE-NIRAV-AMT-WS PIC S9(5)V USAGE COMP-3.
15 CURR-CICS-GUY-AMT-WS PIC S9(3)V USAGE COMP-3.

10 INDICATOR-WS-TAble occurs 2 times indexed by Index-ind
15 IND-PURE-NIRAV-AMT PIC S9(4) COMP.
15 IND-CURR-CICS-GUY-AMT PIC S9(4) COMP.


01 SCA-BUILD-AREA occurs 2 times indexed by Index-SCA
05 SCA-PURE-NIRAV-AMT PIC S9(5)V USAGE COMP-3.
05 SCA-PURE-NIRAV-AMT-R
REDEFINES SCA-PURE-NIRAV-AMT.
10 FILLER PIC X(3).
05 SCA-CURR-CICS-GUY-AMT PIC S9(3)V USAGE COMP-3.
05 SCA-CURR-CICS-GUY-AMT-R
REDEFINES SCA-CURR-CICS-GUY-AMT.
10 FILLER PIC X(2).


Then I suppose I should be able to

SELECT PURE_NIRAV_AMT,
CURR_CICS_GUY_AMT
INTO :FIELD-WS-TABLE(2):INDICATOR-WS-TABLE(1),
:FIELD-WS-TABLE(3):INDICATOR-WS-TABLE(2)



Is this possible to do? If yes, then is there a way to incorporate the whole logic into If? sorry, little confused
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Mar 07, 2008 4:57 pm
Reply with quote

if your db2 vsn supports rowS select - can'T remember the techi name, but you can select multiple rows into a cobol table if you have set it up correctly.

but, you are still (and always will be) stuck with providing a host variable for every column that you retrieve.
Back to top
View user's profile Send private message
Nirav721

New User


Joined: 11 Feb 2008
Posts: 53
Location: NJ

PostPosted: Fri Mar 07, 2008 6:05 pm
Reply with quote

Yes, I am fine with having to specify each column for the select, and the host variables for them...I just don't want to write out 150 if statements...So anyone think its possible?
Back to top
View user's profile Send private message
Pcrummey

New User


Joined: 26 Feb 2008
Posts: 4
Location: Van Wert, OH

PostPosted: Sat Mar 08, 2008 1:25 am
Reply with quote

Your occurs clause specifies the number of rows in your table not the number of columns, those are defined by the level 15 items. Why can't you select to a Working Storage item and then load that to your occurs table like this.

SELECT PURE_NIRAV_AMT,
CURR_CICS_GUY_AMT
INTO :PURE-NIRAV-AMT-WS:IND-PURE-NIRAV-AMT,
:CURR-CICS-GUY-AMT-WS:IND-CURR-CICS-GUY-AMT

Then after the select

MOVE PURE-NIRAV-AMT-WS TO WS-PURE-NIRAV-AMT(Index-ws)
MOVE IND-PURE-NIRAV-AMT TO WS-IND-PURE-NIRAV-AMT(Index-ind)
MOVE CURR-CICS-GUY-AMT-WS TO WS-CURR-CICS-GUY-AMT(Index-ws)
MOVE IND-CURR-CICS-GUY-AMT TO WS-IND-CURR-CICS-GUY-AM(Index-ind)

SET INDEX-WS UP BY 1
SET INDEX-IND UP BY 1

Then you do a PERFORM later in your code

SET INDEX-WS TO 1
SET INDEX-IND TO 1
PERFORM UNTIL END-OF-TABLE-WS
IF WS-IND-PURE-NIRAV-AMT(Index-ind) = 0
MOVE WS-PURE-NIRAV-AMT(Index-ws) TO SCA-PURE-NIRAV-AMT (INDEX-SCA)
END-IF
SET INDEX-IND UP BY 1
SET INDEX-WS UP BY 1
SET INDEX-SCA UP BY 1
IF INDEX-WS > OCCURS AMOUNT
MOVE 'Y' TO END-OF-TABLE-WS-SW
END-IF
END-PERFORM

Or the Mutli Row Fetch mentioned above would work as well. Only for Version 8 of DB2 I think.
Back to top
View user's profile Send private message
Nirav721

New User


Joined: 11 Feb 2008
Posts: 53
Location: NJ

PostPosted: Sat Mar 08, 2008 1:41 am
Reply with quote

Thanks all, I think this helps me go in right direction...
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top