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

Initializing comp-3 fields in an array


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

New User


Joined: 12 Dec 2005
Posts: 31
Location: bangalore

PostPosted: Wed Mar 11, 2009 11:39 am
Reply with quote

Hi,

I want to initialize a record in a file of variable record length, & maximum record length can be 28356.

the record structure has picture clause of X as well as comp-3 for few fields. there are few array fields in the structure.
I am able to initialize the entire lenth of record using below array:
Code:
01  WS-INIT-ARRY.                             
    05  WS-INIT-REC    OCCURS 28356 TIMES.
        10  WS-INIT-FIELD       PIC 9(01).     
01  WS-COUNTER                  PIC 9(05).

ans the following code used for initialization:
Code:
PERFORM VARYING WS-COUNTER FROM 1 BY 1                   
                UNTIL WS-COUNTER > 28356                 
   MOVE ZEROS         TO WS-INIT-FIELD(WS-COUNTER) 
END-PERFORM                                             


When i open the file with initialized record (with above logic) in INSYNC tool mapped with copybook layout, all comp-3 fields show a value of X'F0F0F0' which is not a valid one.

How can i initialize the record so that i get comp-3 as 0000.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 11, 2009 12:23 pm
Reply with quote

Hello,

Quote:
How can i initialize the record so that i get comp-3 as 0000
You cannot - 0000 is not a valid comp-3 (packed-decimal) value.

Your array shows no comp-3 fields in the definition.
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Wed Mar 11, 2009 2:22 pm
Reply with quote

Yes Dick.

The last byte will be '0C' for a packed decimal.

But still 'move zeros' statement should work for a packed decimal too.

Can you please give us the exact variable definition.
Back to top
View user's profile Send private message
sampathkmn
Warnings : 1

New User


Joined: 12 Dec 2005
Posts: 31
Location: bangalore

PostPosted: Wed Mar 11, 2009 3:03 pm
Reply with quote

I have one the arrays like mentioned below:

10 WS-SUMM-DATA
OCCURS 0 TO 1 TIMES
DEPENDING ON WS-TEST-SUMM.


15 B PIC 9(09) COMP-3.
15 C PIC 9(03) COMP-3.

I have initialized the above group using below code:

MOVE ZEROS TO B C


I am getting value when i write above group into a file as follows:
B ---> X'000F000000' ---> is this ok?
C ---> 0
Back to top
View user's profile Send private message
sampathkmn
Warnings : 1

New User


Joined: 12 Dec 2005
Posts: 31
Location: bangalore

PostPosted: Wed Mar 11, 2009 3:04 pm
Reply with quote

Please ignore the array declaration above...


15 B PIC 9(09) COMP-3.
15 C PIC 9(03) COMP-3.

I have initialized the above variable using below code:

MOVE ZEROS TO B C


I am getting value when i write above group into a file as follows:
B ---> X'000F000000' ---> is this ok?
C ---> 0
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Wed Mar 11, 2009 3:27 pm
Reply with quote

No.

If you move zeros to B and C,

B should be X'000000000F' and displayed as '0'.

C should be X'000F' and displayed as '0'.

i think storage overlapping occurs in your wroking storage. Please check.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Mar 11, 2009 7:16 pm
Reply with quote

sampathkmn wrote:
I am getting value when i write above group into a file as follows:
B ---> X'000F000000' ---> is this ok?
C ---> 0
What proof can you offer that what you say is the values in B & C are the actual values? After the MOVE, add a line of:
DISPLAY "*" b "*" c "*"
and then HEX display the output.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed Mar 11, 2009 9:58 pm
Reply with quote

Mathiv Anan wrote:
But still 'move zeros' statement should work for a packed decimal too.
Code:
01  WS-INIT-ARRAY.
    05  WS-INIT-REC    OCCURS 28356 TIMES.
        10  WS-INIT-FIELD       PIC 9(01).
01  WS-COUNTER                  PIC 9(05).

It works, but there is no packed decimal in your receiving array.

Mathiv Anan wrote:
and the following code used for initialization:
Code:
PERFORM VARYING WS-COUNTER FROM 1 BY 1
                UNTIL WS-COUNTER > 28356
   MOVE ZEROS         TO WS-INIT-FIELD(WS-COUNTER)
END-PERFORM

you could as well have done MOVE ALL ZERO TO WS-INIT-ARRAY. It would give the same wrong result, but much faster!

Mathiv Anan wrote:
the record structure has picture clause of X as well as comp-3 for few fields. there are few array fields in the structure.

Do you really want to move zeroes into your X fields as well ?

Can you please show us the REAL array, the one with X fields and COMP-3 fields and arrays ???
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Mar 11, 2009 11:48 pm
Reply with quote

Once you've properly defined all the elementary items (assuming they are of mixed-data types) associated with each table-entry group-level (WS-INIT-REC) -

Code:

03  WS-MAX-SUB PIC S9(08) BINARY.
03  WS-SUB     PIC S9(08) BINARY.

DIVIDE LENGTH OF WS-INIT-ARRAY BY LENGTH OF WS-INIT-REC (1)
                               GIVING WS-MAX-SUB.

INITIALIZE WS-INIT-REC (WS-MAX-SUB).

ADD -1 TO WS-MAX-SUB GIVING WS-SUB.

PERFORM UNTIL WS-SUB < 1
    MOVE WS-INIT-REC (WS-MAX-SUB) TO WS-INIT-REC (WS-SUB)
    ADD -1 TO WS-SUB
END-PERFORM.

Because your initialization begins at the calculated last table-entry, if the OCCURS is altered, the value in WS-MAX-SUB will always be correct.

But, Marso's assessment points out a better initialization method. If the entire array is defined as display-numeric -

Code:

MOVE ZERO TO WS-INIT-ARRAY.

will initialize the entire array to all EBCDIC ZEROS (most likely via an MVCL) and will be much faster than a loop.

Regards,
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Mar 12, 2009 2:57 am
Reply with quote

If you show us the exact definition of the array you want initialized, we can show you at least 2 different ways of accomplishing what you want with very little coding and one of the methods doesn't even involve procedure division statements.
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 COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts Concatenate 2 fields (usage national)... COBOL Programming 2
Search our Forums:

Back to Top