Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

INITIALIZE Table - Alphanumeric & COMP-3

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
mrgnndhmk

New User


Joined: 01 Feb 2006
Posts: 46
Location: India

PostPosted: Tue Jul 16, 2013 11:36 pm    Post subject: INITIALIZE Table - Alphanumeric & COMP-3
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: 7910
Location: Bellevue, IA

PostPosted: Wed Jul 17, 2013 12:10 am    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Wed Jul 17, 2013 12:18 am    Post subject: Reply to: Initialization of Table - Alphanumeric & COMP-
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    Post subject:
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

Site Director


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

PostPosted: Wed Jul 17, 2013 3:10 am    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Jul 17, 2013 4:06 am    Post subject: Reply to: Initialization of Table - Alphanumeric & COMP-
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: 46
Location: India

PostPosted: Wed Jul 17, 2013 6:31 am    Post subject: Reply to: Initialization of Table - Alphanumeric & COMP-
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: 7910
Location: Bellevue, IA

PostPosted: Wed Jul 17, 2013 6:36 am    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Wed Jul 17, 2013 11:15 am    Post subject: Re: Reply to: Initialization of Table - Alphanumeric & C
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: 46
Location: India

PostPosted: Wed Jul 17, 2013 12:13 pm    Post subject: Reply to: Initialization of Table - Alphanumeric & COMP-
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Wed Jul 17, 2013 12:33 pm    Post subject: Reply to: Initialization of Table - Alphanumeric & COMP-
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: 1238
Location: Richfield, MN, USA

PostPosted: Thu Jul 25, 2013 2:48 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to move a long alphanumeric data ... lind sh COBOL Programming 6 Mon Dec 05, 2016 7:51 pm
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Command UNIQUE CONSTRAINT on any tabl... rohanthengal DB2 2 Thu Aug 18, 2016 3:48 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us