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

Discrepancy between source code and output.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
I?aki Viggers

New User


Joined: 18 Jun 2005
Posts: 12

PostPosted: Wed Jun 22, 2022 6:22 am
Reply with quote

This is a follow-up of another question.

This simple program creates an output member, writes a record, and closes the member:

Code:
000001        IDENTIFICATION DIVISION.             
000002        PROGRAM-ID. 'IVCBL2'.                 
000003        ENVIRONMENT DIVISION.                 
000004        INPUT-OUTPUT SECTION.                 
000005        FILE-CONTROL.                         
000006            SELECT FHANDL ASSIGN TO UT-S-ODS1
000007              ACCESS MODE IS SEQUENTIAL.     
000008        DATA DIVISION.                       
000009        FILE SECTION.                         
000010        FD  FHANDL LABEL RECORDS ARE OMITTED.
000011        01  RECOR.                           
000012        05  FIELD1 PIC X(80).                 
000013        PROCEDURE DIVISION.                   
000014               MOVE SPACES TO FIELD1.         
000015               MOVE 'ASDFG' TO FIELD1.       
000016               OPEN OUTPUT FHANDL.           
000017               WRITE RECOR.                   
000018               CLOSE FHANDL.                 
000019               STOP RUN.                     

The program purports to run successfully, but the contents of the member are
Code:
****** ****ZAP****AUTOSAVE********** TOP OF DATA ******************************
000001   óÌ                                                                   
****** ****ZAP****AUTOSAVE********* BOTTOM OF DATA ****************************

which does not resemble at all what is coded on lines 14 & 15 of the COBOL source.

What am I doing wrong?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2011
Location: USA

PostPosted: Wed Jun 22, 2022 8:36 am
Reply with quote

Where is your JCL?


COBOL code itself cannot create a library member.

For COBOL, usually the member of a PDS dataset (a library) is defined in the corresponding DD statement.

Another way: using CALL to a specific (non-COBOL) function, or utility program, which are able to operate with PDS datasets, and "create new members".
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Wed Jun 22, 2022 10:09 am
Reply with quote

It's been a long time, but I think your problem is that you attempt to populate the output record before OPENing the file.

To do it this way, you would populate a WORKING-STORAGE field, OPEN the file, and then do a WRITE FROM the populated field.
Back to top
View user's profile Send private message
I?aki Viggers

New User


Joined: 18 Jun 2005
Posts: 12

PostPosted: Wed Jun 22, 2022 6:55 pm
Reply with quote

Phrzby Phil wrote:
It's been a long time, but I think your problem is that you attempt to populate the output record before OPENing the file.

Thank you! Yes, you're right. I got it now.

I am liking COBOL, but as a mainframe neophyte with a C/RPG/SQL/x86-asm background I'm noticing multiple counterintuitive minutiae about COBOL and mainframe.
Back to top
View user's profile Send private message
I?aki Viggers

New User


Joined: 18 Jun 2005
Posts: 12

PostPosted: Wed Jun 22, 2022 7:06 pm
Reply with quote

sergeyken wrote:
Where is your JCL?

COBOL code itself cannot create a library member.

For COBOL, usually the member of a PDS dataset (a library) is defined in the corresponding DD statement.

I omitted the JCL for brevity, but it is quite similar to the one I posted in the referenced question where you helped me. What Phrzby Phil pointed out helped me solve the particular issue that originated this post.

Quote:
Another way: using CALL to a specific (non-COBOL) function, or utility program, which are able to operate with PDS datasets, and "create new members".

Good to know, although I'm still much of a beginner to try this approach icon_lol.gif
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Wed Jun 22, 2022 7:15 pm
Reply with quote

The buffer(s) are allocated when the OPEN is executed.

I'm thinking that by trying to populate the FD record before the OPEN, you might sometimes get a protection error.

Anyone have an opinion on this?
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Thu Jun 23, 2022 10:18 pm
Reply with quote

I?aki Viggers -

One other thing I might as well mention since you are new to COBOL.

In COBOL and most languages, there is no need to space out a character field before moving a smaller length value to it. The move will fill the remaining bytes with spaces.

So your MOVE SPACES below is not needed:

Code:

MOVE SPACES TO FIELD1.         
MOVE 'ASDFG' TO FIELD1.


It does not hurt, but it is clutter.
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: Sat Jun 25, 2022 1:27 am
Reply with quote

Quote:
I'm thinking that by trying to populate the FD record before the OPEN, you might sometimes get a protection error.
For a batch job, I doubt a protection error could occur since the allocation occurs somewhere in the address space memory.

The COBOL Programming Guide manual specifically tells you not to do what you did:
Quote:
Data items defined in the FILE SECTION are not available to PROCEDURE DIVISION statements until
the file has been successfully opened.
And note the quote does not say that the OPEN statement was executed but that the file was successfully opened (so you need to check the FILE STATUS code to be 00).
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 run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
Search our Forums:

Back to Top