View previous topic :: View next topic
|
Author |
Message |
I?aki Viggers
New User
Joined: 18 Jun 2005 Posts: 13
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2145 Location: USA
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
I?aki Viggers
New User
Joined: 18 Jun 2005 Posts: 13
|
|
|
|
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 |
|
|
I?aki Viggers
New User
Joined: 18 Jun 2005 Posts: 13
|
|
|
|
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 |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
|