View previous topic :: View next topic
|
Author |
Message |
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
Hi,
I want to initialize an array. This array contains comp and packed data and is part of a record structure..Explained below:
Code: |
01 WS-REC-7382.
05 TS-NBR PIC S9(4) USAGE IS COMP.
05 TS-RAN-NBR PIC S9(4) USAGE IS COMP.
05 WS-ARRAY1 OCCURS 50 TIMES.
10 WS-TS-CODE-ST PIC S9(4) COMP.
10 WS-T6-PL-COUNT PIC S9(9) COMP-3.
05 FILLER PIC X(48). |
( The filler part I have declared because I don't need this part of the data)
Now I am dumping the data from a table into this structure WS-REC-7382. But getting some unpredictable values in few places like in field WS-TS-CODE-ST. Although I have used an initialize before every fetch from the table.
For initializing I have used the following statement
Initialize WS-REC-7382.
I am not sure if it will initialize the whole strucure including the array correctly. Please advise. When I am displaying the following fields
WS-TS-CODE-ST (wk_nbr) --> I am not getting the expected values
Can anyone suggest if I am going wrong somewhere! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
Are you finding the "unexpected" values immediately after initialization, or only following one or more FETCHes?
If after a FETCH, it would help to see the CURSOR declaration along with the table structure (DCLGEN). |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Beginning with VS/COBOL II, if you add VALUE clauses to all array elementary items, they will be initialized during program prologue.
Otherwise, there's INITIALIZE (as Dick has pointed out) which is used during execution.
Bill |
|
Back to top |
|
|
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
Ronald Burr wrote: |
Are you finding the "unexpected" values immediately after initialization, or only following one or more FETCHes?
If after a FETCH, it would help to see the CURSOR declaration along with the table structure (DCLGEN). |
I am getting the unexpected values after the fetch..And particularly I am cocerned with only the array part of the structure..
Actually this structure I have declared in my program.. |
|
Back to top |
|
|
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
Refering to my first post...
WS-REC-7382 is the structure which I have declared in my pgm..
WS-T7382........is the DCLGEN structure which I have copied in my program
before fetch I am initializing both the structures::
INITIALIZE WS-REC-7382
WS-T7382.
The fetching data into the DCLGEN structure WS-T7382
Then finally MOVE WS-T7382 TO WS-REC-7382.
AND I am getting some unexpected values fter this move statement. |
|
Back to top |
|
|
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
Dick,
I was reading..I found this
All elementary receiving fields, including all occurrences of table items within the group, are initialized, with the following exceptions:
* Items that are subordinate to identifier-1 and contain a REDEFINES clause, or any items subordinate to such an item. (However, identifier-1 can contain a REDEFINES clause or be subordinate to a redefining item.)
My array is subordinate here is it? That is why is it not getting initialized as I have initialized the main group variable..I am am little puzzled with the language..
Can you elaborate a bit.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
The fetching data into the DCLGEN structure WS-T7382 |
It may help if you post the definition of WS-T7382 and the code that does the FETCH.
If there is data in the table that is not as expected, it will go into the array with unexpected values. . . |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
deleted by poster |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
You can first move LOW-VALUES to WS-REC-7382 (will generate an MVCL Assembler instruction), then followed by -
Code: |
MOVE 1 TO TALLY.
PERFORM UNTIL TALLY > 50
MOVE ZERO TO WS-T6-PL-COUNT (TALLY)
ADD 1 TO TALLY
END-PERFORM.
|
Because WS-REC-7382 contains COMP items, when you move LOW-VALUES to the GROUP level, this is the same as if you had moved ZERO to an elementary COMP item.
Then, all you need to ensure is packed-zero in the fifty occurrences of WS-T6-PL-COUNT and you're done.
I'm using TALLY Special-Register as a subscript but you can define a WS subscript and use that.
Bill |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
Rijit wrote: |
I was reading..I found this
All elementary receiving fields, including all occurrences of table items within the group, are initialized, with the following exceptions:
* Items that are subordinate to identifier-1 AND contain a REDEFINES clause, or any items subordinate to such an item. (However, identifier-1 can contain a REDEFINES clause or be subordinate to a redefining item.)
My array is subordinate here is it? |
Subordinate to identifier-1, yes. Subordinate to identifier-1 AND contains a REDEFINES clause, or subordinate to an identifier that contains the REDEFINES clause, No (unless the code segment you posted is not an accurate representation of the actual code ). |
|
Back to top |
|
|
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
Well, WS-T7382 has the same structure as I had posted in my first post except the array part
01 WS-T7382.
05 TS-NBR PIC S9(4) USAGE IS COMP.
05 TS-RAN-NBR PIC S9(4) USAGE IS COMP.
05 WS-TS-CODE-ST-1 PIC S9(4) COMP.
05 WS-T6-PL-COUNT-1 PIC S9(9) COMP-3.
.......
.......
.......
05 WS-TS-CODE-ST-50 PIC S9(4) COMP.
05 WS-T6-PL-COUNT-50 PIC S9(9) COMP-3.
05 WS-ADD-UPD PIC X(08).
05 WS-CD-ENT PIC X(06).
.........
.........
My objective to define my own structure is to get the field WS-TS-CODE-ST-1 depending upon some subscript, so I have declared the array structure in pgm.
And regarding the data fetch it is no cursor but a simple select query fetching all columns of the table.
It is happening in a perform loop:
----------------------------------------
PERFORM UNTIL EOF
***
Initialize WS-T7382
WS-REC-7382
SELECT * into WS-T7382
from table
where..............
If success
MOVE WS-T7382 to WS-REC-7382
and do further processing.
endif
end-perform.. |
|
Back to top |
|
|
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
for each iteration of the perform the where cond will change and a single row from the table will be retrieved..more than one rows shall not be retrieved for sure so I have used no cursor.. |
|
Back to top |
|
|
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
Bill O'Boyle wrote: |
You can first move LOW-VALUES to WS-REC-7382 (will generate an MVCL Assembler instruction), then followed by -
Code: |
MOVE 1 TO TALLY.
PERFORM UNTIL TALLY > 50
MOVE ZERO TO WS-T6-PL-COUNT (TALLY)
ADD 1 TO TALLY
END-PERFORM.
|
Because WS-REC-7382 contains COMP items, when you move LOW-VALUES to the GROUP level, this is the same as if you had moved ZERO to an elementary COMP item.
Then, all you need to ensure is packed-zero in the fifty occurrences of WS-T6-PL-COUNT and you're done.
I'm using TALLY Special-Register as a subscript but you can define a WS subscript and use that.
Bill |
Bill,
I am a bit worried about moving low values to the muneric field..becoz sometimes it may cause abend.
Can we move zeros to both the array elements in the perform loop to initialize the packed data you mentioned? and before fetching the data from the table just call this para each time
Pls correct me if I am wrong. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Well, WS-T7382 has the same structure as I had posted in my first post except the array part |
Rather significant is it not?
What you appear to be doing is reading a bit of data and moving it over the entire array. . .
Maybe i am missing something. . . |
|
Back to top |
|
|
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
Yes, you are right to an extent..
I don't want to use dynamic sql that is the reason I am using this array structure in my program..I only need the field WS-TS-CODE-ST. And the subscript for this I will get dynamically whwn I run by reading another table.
So instead of putting 50 evaluates or dynamic sql I am trying the array approach..so that when I get the subscript value dynamically I can only retrieve the required information... WS-TS-CODE-ST (subscript)
In the DCLGEN I did not have a array structure so had to define it in my program and hence I am moving MOVE WS-T7382 to WS-REC-7382 |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
There is no way that performing a query 40 or 50 times with different predicate values is going to populate 40 or 50 DIFFERENT elements in an array ( Hint - there is no subscript/index on your host-variable name(s)) to show which array element(s) to put the results into.
1) Never a good idea to code SELECT * in a static SQL ( i.e. in a program ). One simple change to the table and you will blow up.
Try something like this (note: NOT tested):
Code: |
01 WS-STRUCTURE.
05 WSS-NBR PIC S9(4) COMP.
05 WSS-RAN-NBR PIC S9(4) COMP.
05 WSS-ARRAY-DATA.
10 WSS-TS-CODE-ST PIC S9(4) COMP.
10 WSS-T6-PL-COUNT PIC S9(9) COMP-3.
05 WSS-ADD-UPD PIC X(08).
05 WSS-CD-ENT PIC X(06).
ETC.
01 TS-REC-7382.
05 TS-NBR PIC S9(4) USAGE IS COMP.
05 TS-RAN-NBR PIC S9(4) USAGE IS COMP.
05 WS-ARRAY1 OCCURS 50 TIMES
INDEXED BY ARRAY-INDEX.
10 WS-TS-CODE-ST PIC S9(4) COMP.
10 WS-T6-PL-COUNT PIC S9(9) COMP-3.
05 TS-ADD-UPD PIC X(08).
05 TS-CD-END PIC X(06).
ETC.
SET ARRAY-INDEX TO 1
PERFORM UNTIL SQLCODE = +100
EXEC SQL
SELECT NBR
,RAN_NBR
,TS_CODE_ST
,T6_PL_COUNT
,ADD_UPD
,CD_ENT
,ETC.
FROM TABLE_?????
INTO :WSS-NBR
,:WSS-RAN-NBR
,:WSS-TS-CODE-ST
,:WSS-T6-PL-COUNT
,:WSS-ADD-UPD
,:WSS-CD-ENT
,ETC.
WHERE ???
END-SQL
IF SQLCODE = ZERO
IF ARRAY-INDEX = 1
MOVE WSS-NBR TO TS-NBR
MOVE WSS-RAN-NBR TO TS-RAN-NBR
MOVE WSS-ADD-UPD TO TS-ADD-UPD
MOVE WSS-CD-ENT TO TS-CD-ENT
ETC.
END-IF
MOVE WSS-ARRAY-DATA TO TS-ARRAY-1(ARRAY-INDEX)
SET ARRAY-INDEX UP BY 1
END-IF
END-PERFORM |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
You have majorly confused yourself. . .
How did dynamic sql get into the picture? Nothing appears to be dynamic. . .
Why might you want 50 evaluates?
The only way to successfully move some data to an array item is to move the data to that particular item (using a subscript or index).
Suggest you forget about all of the complexities that have been introduced and create a little bit of test code that reads some instream data and moves it to an array. At the end of the input, display all of the entries in this array. This has nothing to do with dynamic, or comp/comp-3 data but rather how to load individual data items into an array.
Once you have the experiment working correctly, then go back to the code that gets the input from the database.
Again, there may be something i misunderstand. . . But i believe the whole topic has gone in the wrong direction for what you are stuck on. |
|
Back to top |
|
|
Rijit
Active User
Joined: 15 Apr 2010 Posts: 168 Location: Pune
|
|
|
|
Ronald,
You made avalid point regarding usage of 'select *'. I was aware of it and in my code I have coded all the columns insead of *. But since the number of columns was around 100 so tats why just I used * to denote it here..But good catch |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Roland has provided a very good example of how you avoid
wasting machine time initializing a cobol internal table
only thing I would comment on is
SET ARRAY-INDEX TO 1
MOVE ZERO TO SQLCODE
PERFORM UNTIL SQLCODE NOT = 0 |
|
Back to top |
|
|
|