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

Variable initialization error


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

New User


Joined: 17 Sep 2008
Posts: 41
Location: Chennai

PostPosted: Mon Feb 21, 2011 5:58 pm
Reply with quote

Hi,

I had written a program to read a VB file of length 2056 and format and write onto a FB file. the code is as below,

Code:
FD INP-VB-FILE             
    RECORDING MODE IS V         
    DATA RECORD IS VU-REC-INP.   
01  VU-REC-INP.
   05 FILLER                PIC X(02).                 
   05 USRID                    PIC X(10).
   05 PG-NUM             PIC PIC 9(08) COMP.
   05 FILLER                   PIC X(2040)

FD OUT-FILE1                                       
    DATA RECORD IS OUT-REC1                         
    BLOCK CONTAINS 0 RECORDS.                             
01 OUT-REC1.                                       
   05 O-USRID             PIC X(10).                 
   05 FILLER                   PIC X(01) VALUE ';'.       
   05 O-PART-ID                PIC X(03).                 
   05 FILLER                   PIC X(01) VALUE ';'.       
   05 O-PG-NUM            PIC 9(08).                 
                                                         
FD OUT-FILE2                                       
    DATA RECORD IS OUT-REC2                         
    BLOCK CONTAINS 0 RECORDS.                             
01 OUT-REC2.                                       
   05 A-PART-ID                PIC X(03) VALUE SPACES.   
   05 FILLER                   PIC X(04) VALUE SPACES.   
   05 A-COUNT                  PIC ZZZZZZZZZZZ VALUE ZERO.

PROCEDURE DIVISION.                               
                                                 
000-INITIALIZE.                                   
                                                 
     OPEN INPUT INP-VB-FILE.                 
     OPEN OUTPUT OUT-FILE1                 
                 OUT-FILE2.                 
     INITIALIZE VB-REC-INP                         
                OUT-REC1.                   
                                                 
     PERFORM 100-READ-INPUT UNTIL EOF-FILE = 'Y' 
     PERFORM 400-CLOSE-FILES THRU 400-EXIT       
     
     STOP RUN.                                   

000-EXIT.                                         
    EXIT.       

100-READ-INPUT.                               
     READ INP-VB-FILE                     
      AT END MOVE 'Y' TO EOF-FILE.             
                                               
     IF EOF-FILE = 'N'                         
     PERFORM 200-PROCESS-REC THRU 200-EXIT.   
                                               
100-EXIT.                                     
    EXIT.     
   
200-PROCESS-REC.                           
                                           
     MOVE USRID TO O-USRID.           
     MOVE PG-NUM TO O-PG-NUM.     
                                           
     IF USRID(3:1) IS NUMERIC           
        MOVE USRID(1:2) TO O-PART-ID     
        DISPLAY 'PARTID-INSIDEIF:' O-PART-ID 
     ELSE                                   
        MOVE USRID(1:3) TO O-PART-ID   
     END-IF                                 
     
     WRITE OUT-REC1   
     MOVE O-PART-ID TO WS-PART-ID           
     PERFORM 300-CHECK-PARTID THRU 300-EXIT               
     DISPLAY 'O-PART-ID:' O-PART-ID   
     ADD  1 TO WS-COUNT                     

     IF EOF-FILE = 'N'                     
     PERFORM 100-READ-INPUT THRU 100-EXIT.
200-EXIT.                                   
    EXIT.                                   
                                                 
300-CHECK-PARTID.                           
                                                                                                   
     INITIALIZE PART-COUNT-REC.             
                                             
     IF (O-PART-ID = WS-PART-ID)             
        ADD PG-NUM TO TOT-PAGE         
     ELSE                                   
        IF WS-COUNT = 0                     
          ADD PG-NUM TO TOT-PAGE       
          WRITE OUT-REC2 FROM WS-HEADER
          CONTINUE                           
        ELSE                                 
          MOVE WS-PART-ID TO A-PART-ID       
          MOVE TOT-PAGE TO A-COUNT           
          WRITE OUT-REC2               
          DISPLAY 'O-PART-ID:' O-PART-ID     
          ADD 1 TO WS-NO-OF-PART             
          MOVE ZERO TO TOT-PAGE             
          ADD PG-NUM TO TOT-PAGE       
        END-IF                               
     END-IF                       
     MOVE O-PART-ID TO WS-PART-ID.
                                 
300-EXIT.                         
    EXIT.       
"Code'd"

The problem is that the in para 200-PROCESS-REC the USRID value gets moved to O-PART-ID. But after the output record is written the value is
getting moved as junk or spaces.Can anyone please help me to understand how it is happening? My code works fine when i place the IF loop in 200- para in the
300- para as well.

P.S I do not get any error in both the scenarios. But the total pg-num value reflects wrong.

Thanks very much for your time,
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Feb 21, 2011 6:14 pm
Reply with quote

if you want to have access to data values in a 'written' record,
use the work-area option with your write.

sounds as if you need to re-read the application programmers guide concerning writing files and accessing data in the FD record area.

and do you have the ';' (semi-colons) in all of your outfile1 records.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Mon Feb 21, 2011 6:45 pm
Reply with quote

From the COBOL Language Reference manual, section 6.2.40.7 on the WRITE statement:
Quote:
After the WRITE statement is executed, the logical record is no longer available in record-name-1 unless either:


The associated file is named in a SAME RECORD AREA clause (in which case, the record is also available as a record of the other files named in the SAME RECORD AREA clause)

The WRITE statement is unsuccessful because of a boundary violation.
So after you do WRITE OUT-REC1, you cannot reference O-USRID, O-PART-ID, or O-PG-NUM until you've moved data into the output record again. And you certainly cannot expect to have the same values you just wrote available.
Back to top
View user's profile Send private message
Vidya Bhama

New User


Joined: 17 Sep 2008
Posts: 41
Location: Chennai

PostPosted: Tue Feb 22, 2011 5:12 pm
Reply with quote

Thanks for the explanation. I was wondering where my logic was wrong in such a simple program.

@Dick: No the semicolon was not displayed even in one of the records of OUTIFLE1. As it was of less importance i omitted that in my output verification. I moved the layout to the working storage and gave "write from " and it worked. Good that you pointed out. Thanks.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Feb 22, 2011 5:23 pm
Reply with quote

i was suprised that the compiler did not flag the 'value in the fd record def' with at least a warning.
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: Tue Feb 22, 2011 5:33 pm
Reply with quote

Dick,

Although not recommended, maybe the compiler option FLAG(E) is being specified?

Bill
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Feb 22, 2011 5:35 pm
Reply with quote

since 'warnings' can be ignored and the object built,
the user probably also ignored the warnings in the compiler output.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Tue Feb 22, 2011 6:48 pm
Reply with quote

The code posted obviously does not accurately represent the actual code. For example, the word PIC occurs twice for the PG-NUM data element in the input file's Record Description, there is a period missing after the "PIC X(2040)" in the input file's Record Description, and the input file's FD claims to have a record format of V, but only contains one Record Description entry that defines a fixed-length record. Any one of these conditions would result in an error that would prevent a successful compile, and hence no executable code generation.
Back to top
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Tue Feb 22, 2011 11:49 pm
Reply with quote

I may be missing the point. But in looking at your program -- I give a SNAPSHOT (with only the code that I feel is important for my point).

It appears that you are skipping over a record. From paragraph 000-INITIALIZE:
1. You PERFORM 100-READ-INPUT until ---- end of file
2. from within 100-READ-INPUT you perform 200-PROCESS-REC
3. from within 200-PROCESS-REC you:
a. process the record and then
b. PERFORM 100-READ-INPUT which:
1) Perform 200-PROCESS-REC
I AM TOTALLY LOST???

PROCEDURE DIVISION.

000-INITIALIZE.

PERFORM 100-READ-INPUT UNTIL EOF-FILE = 'Y'
PERFORM 400-CLOSE-FILES THRU 400-EXIT
STOP RUN.

000-EXIT.
EXIT.

100-READ-INPUT.
READ INP-VB-FILE
AT END MOVE 'Y' TO EOF-FILE.
IF EOF-FILE = 'N'
PERFORM 200-PROCESS-REC THRU 200-EXIT.

100-EXIT.
EXIT.

200-PROCESS-REC.
| your code
|
|
IF EOF-FILE = 'N'
PERFORM 100-READ-INPUT THRU 100-EXIT.
200-EXIT.
EXIT.
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 Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Error when install DB2 DB2 2
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts Variable Output file name DFSORT/ICETOOL 8
Search our Forums:

Back to Top