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

INITIALIZE Table - Alphanumeric & COMP-3


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

New User


Joined: 01 Feb 2006
Posts: 51
Location: India

PostPosted: Tue Jul 16, 2013 11:36 pm
Reply with quote

Dear Experts,

One of our COBOL programs failed due to Data Exception Error - COMP-3 variable contained non-numeric value.

Below is the Structure of the table where COMP-3 Variable is present

Code:
01  WS-TABLE.                                               
    05  WS-TABLE-ENTRIES  OCCURS 99 TIMES.                   
     10 WS-CASH-DISC-ACCT      PIC X(05)     VALUE  SPACES. 
     10 WS-CASH-DISC-AMT       PIC S9(07)V99 COMP-3 VALUE +0.
     10 WS-CASH-DISC-MEMO-ACCT PIC X(05)     VALUE  SPACES. 
     10 WS-CASH-DISC-MEMO-AMT  PIC S9(07)V99 COMP-3 VALUE +0.



I have coded INITIALIZE WS-TABLE statement but still when I checked the value of COMP-3 Variable (WS-CASH-DISC-AMT), the value was printed as SPACES (Hex value X'40404040'). By Initialization rule X should be replaced with spaces and 9 should be replaced with zeros. Will that be applicable for COMP-3 Numeric and COMP?

I searched the forum and found that in the discussion here, it is mentioned that COMP-3 will have issue if it is present in a table with the Alpha numeric variables.

Is this true and do we have any manuals where this has been mentioned as rule/limitation?

TIA


~Muru

Code'd and URL'd
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 17, 2013 12:10 am
Reply with quote

You set the initial values for your COMP-3 variables via the VALUE clause. You then turn around and use INITIALIZE on the group level, which totally destroys the VALUE clause values. If all of the table variables have VALUE clauses, why are you using the INITIALIZE statement at all?
Quote:
By Initialization rule X should be replaced with spaces and 9 should be replaced with zeros. Will that be applicable for COMP-3 Numeric and COMP?
Yes, this is true and applicable to COMP-3 and COMP variables. However, you are initializing the group, so every byte is considered PIC X.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 17, 2013 12:18 am
Reply with quote

Index/subscript incorrect
MOVE SPACE TO WS-TABLE
MOVE SPACE TO WS-TABLE-ENTRIES ( subscripting )
Field MOVEd to COMP-3 field already contains space

One of the above is likely your problem.

It is highly, highly, unlikely that, just for you, INITIALIZE has stopped working.

I'm not sure how you arrived at the conclusion you did from the link that you posted.

If you still have a problem, you're going to have to post relevant code, in the Code Tags, please.
Back to top
View user's profile Send private message
Gary McDowell

Active User


Joined: 15 Oct 2012
Posts: 139
Location: USA

PostPosted: Wed Jul 17, 2013 2:58 am
Reply with quote

I never trust INITIALIZE with tables so I do it "old" school. The following code is not tested.
Code:
           05  WS-TABLE-SUB    PIC  9(02)  VALUE ZEROS.                 
                                                                       
      *--- INITIALIZE WS-TABLE ---                                     
           MOVE 0     TO WS-TABLE-SUB                                   
           PERFORM 99 TIMES                                             
               ADD  1 TO WS-TABLE-SUB                                   
               MOVE SPACES     TO WS-CASH-DISC-ACCT      (WS-TABLE-SUB)
                                  WS-CASH-DISC-MEMO-ACCT (WS-TABLE-SUB)
               MOVE ZEROS      TO WS-CASH-DISC-AMT       (WS-TABLE-SUB)
                                  WS-CASH-DISC-MEMO-AMT  (WS-TABLE-SUB)
           END-PERFORM                                                 
      *---                                                             
           .                                                           
      *___/                                                             
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 Jul 17, 2013 3:10 am
Reply with quote

Hello,

The "old school" way i've used (especially when cpu cycles are to be spared) is to have one array for working and a duplicate for initializing. he initializing array has the initial values and then entire area is moved at one time saving considerable cpu time . . .

fwiw
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 Jul 17, 2013 4:06 am
Reply with quote

Change WS-TABLE-SUB to a binary-fullword.

Code:

05  WS-TABLE-SUB    PIC  9(08)  COMP VALUE ZERO.

and add -
Code:

05  WS-TABLE-MAX    PIC  9(08)  COMP.

Calculate the max-occurs and replace 99 (in the PERFORM) with WS-TABLE-MAX.
Code:

DIVIDE LENGTH OF WS-TABLE BY LENGTH OF WS-TABLE-ENTRIES (1)
                          GIVING WS-TABLE-MAX.
PERFORM WS-TABLE-MAX TIMES

You're done....
Back to top
View user's profile Send private message
mrgnndhmk

New User


Joined: 01 Feb 2006
Posts: 51
Location: India

PostPosted: Wed Jul 17, 2013 6:31 am
Reply with quote

Robert Sample wrote:
If all of the table variables have VALUE clauses, why are you using the INITIALIZE statement at all?


Thanks Robert for the explanation. The reason I use INITIALIZE is I relay records thru that table multiple times based on the input. Therefore, everytime I Initialize and then copy from input data.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 17, 2013 6:36 am
Reply with quote

Well, you've been given some approaches to prevent the S0C7 data exceptions; which one you use will depend upon your site and its standards.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 17, 2013 11:15 am
Reply with quote

mrgnndhmk wrote:

Thanks Robert for the explanation. The reason I use INITIALIZE is I relay records thru that table multiple times based on the input. Therefore, everytime I Initialize and then copy from input data.


Can you post the code, please?

I can guarantee* than your INITIALIZE is working. Rather than just picking on something unlikely, why don't you get some clues from the dump? Like the value of the subscript at the time, the contents of the current record, etc?

* Subject to code not being overwritten.
Back to top
View user's profile Send private message
mrgnndhmk

New User


Joined: 01 Feb 2006
Posts: 51
Location: India

PostPosted: Wed Jul 17, 2013 12:13 pm
Reply with quote

Hi Bill,
You are absolutely correct. The issue was with the subscript.

Due to a logic issue, the subscript was zero and the Table COMP-3 variable contained the Non-Numeric value for subscript zero.

I have clipped the program to provide the code below
Code:

       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID.    TESTPGM.                                         
       ENVIRONMENT DIVISION.                                           
       DATA DIVISION.                                                   
       WORKING-STORAGE SECTION.                                         
       01  WS-TABLE.                                                   
           05  WS-TABLE-ENTRIES          OCCURS 99 TIMES.               
               10 WS-CASH-DISC-ACCT      PIC X(05)     VALUE  SPACES.   
               10 WS-CASH-DISC-AMT       PIC S9(07)V99 COMP-3 VALUE +0.
               10 WS-CASH-MEMO-ACCT      PIC X(05)     VALUE  SPACES.   
               10 WS-CASH-MEMO-AMT       PIC S9(07)V99 COMP-3 VALUE +0.
               10 FILLER                 PIC X(05)     VALUE  SPACES.   
      *                                                                 
       01  WS-SUB                        PIC S9(04)    VALUE ZERO COMP.
      *                                                                 
       PROCEDURE DIVISION.                                             
       MAIN-PARA.                                                       
           INITIALIZE WS-TABLE                                         
                                                                       
           DISPLAY 'WS-CASH-DISC-AMT(00)-B: ' WS-CASH-DISC-AMT (WS-SUB)
           DISPLAY 'WS-CASH-MEMO-AMT(00)-B: ' WS-CASH-MEMO-AMT (WS-SUB)
                                                                       
          DISPLAY 'WS-CASH-DISC-AMT(01)-B: ' WS-CASH-DISC-AMT (01)
          DISPLAY 'WS-CASH-DISC-AMT(99)-B: ' WS-CASH-DISC-AMT (99)
          DISPLAY 'WS-CASH-MEMO-AMT(01)-B: ' WS-CASH-MEMO-AMT (01)
          DISPLAY 'WS-CASH-MEMO-AMT(99)-B: ' WS-CASH-MEMO-AMT (99)
          ADD 001 TO WS-CASH-DISC-AMT (01)                       
          ADD 099 TO WS-CASH-DISC-AMT (99)                       
          ADD WS-CASH-DISC-AMT (99) TO WS-CASH-MEMO-AMT (01)     
          ADD WS-CASH-DISC-AMT (01) TO WS-CASH-MEMO-AMT (99)     
          DISPLAY 'WS-CASH-DISC-AMT(01)-A: ' WS-CASH-DISC-AMT (01)
          DISPLAY 'WS-CASH-DISC-AMT(99)-A: ' WS-CASH-DISC-AMT (99)
          DISPLAY 'WS-CASH-MEMO-AMT(01)-A: ' WS-CASH-MEMO-AMT (01)
          DISPLAY 'WS-CASH-MEMO-AMT(99)-A: ' WS-CASH-MEMO-AMT (99)
          STOP RUN.                                               

Result:
WS-CASH-DISC-AMT(00)-B: 00000000\
WS-CASH-MEMO-AMT(00)-B: 00000?000
WS-CASH-DISC-AMT(01)-B: 000000000
WS-CASH-DISC-AMT(99)-B: 000000000
WS-CASH-MEMO-AMT(01)-B: 000000000
WS-CASH-MEMO-AMT(99)-B: 000000000
WS-CASH-DISC-AMT(01)-A: 000000100
WS-CASH-DISC-AMT(99)-A: 000009900
WS-CASH-MEMO-AMT(01)-A: 000009900
WS-CASH-MEMO-AMT(99)-A: 000000100
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 17, 2013 12:33 pm
Reply with quote

Thanks for letting us know.

99.82%* of all problems with data in a COBOL table are to do with "subscripting".

*Invented, but within 25% accuracy
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 Jul 25, 2013 2:48 am
Reply with quote

A bit off topic, but read up on the pitfalls of using STOP RUN instead of GOBACK.
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 Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top