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

regarding COBOL WRITE verb (VB File Handling)


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
anonguy456

New User


Joined: 29 Jun 2021
Posts: 12
Location: India

PostPosted: Tue Jun 29, 2021 4:28 pm
Reply with quote

I have attached the code below. This is a small code which will copy contents of input file INPUT01 to output file OUTPUT01. Problem is blank characters at the end of every record is getting populated with HIGH-VALUE. I am able to populate blank characters at the end of every record with HIGH-VALUE/LOW-VALUE/SPACE but not with blank character at the end of record. I have also attached the snap of input file and output file after executing the below code.
Code:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.
           TST05.
      *PROGRAM THAT WILL COPY NORMAL PROD VB FILE AND INITIALIZE
      *BLANK CHARACTERS WITH HIGH VALUES
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT INPUT01 ASSIGN TO CHK01.
           SELECT OUTPUT01 ASSIGN TO CHK02.
      *
       DATA DIVISION.
       FILE SECTION.
       FD INPUT01
           BLOCK CONTAINS 0 RECORDS
           RECORD IS VARYING IN SIZE FROM 4 TO 24810
           DEPENDING ON REC-LEN.
       01 INPUTFILE01     PIC X(24810).
          88 ENDOFINPUTFILE01 VALUE HIGH-VALUES.
       01 FILLER          PIC X(4).
       FD OUTPUT01
           RECORDING MODE IS V.
       01 OUTPUTFILE01    PIC X(24810) VALUE HIGH-VALUES.
       WORKING-STORAGE SECTION.
       01 REC-LEN         PIC 9(5) COMP.
      *
       PROCEDURE DIVISION.
       MAINPROCEDURE.
           OPEN INPUT INPUT01
           OPEN OUTPUT OUTPUT01
           MOVE HIGH-VALUES TO OUTPUTFILE01
           READ INPUT01
             AT END SET ENDOFINPUTFILE01 TO TRUE
           END-READ
           PERFORM WRITEPOLICIES UNTIL ENDOFINPUTFILE01
           CLOSE INPUT01
           CLOSE OUTPUT01
           STOP RUN.
       WRITEPOLICIES.
           MOVE INPUTFILE01(1:REC-LEN) TO OUTPUTFILE01(1:REC-LEN)
           WRITE OUTPUTFILE01
           MOVE HIGH-VALUES TO OUTPUTFILE01
           READ INPUT01
             AT END SET ENDOFINPUTFILE01 TO TRUE
           END-READ.


Note: RESIZE the images before posting in the Forum.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10801
Location: italy

PostPosted: Tue Jun 29, 2021 5:37 pm
Reply with quote

do not post twice the same question ... icon_evil.gif
the peoplw answering here are the same answering there

and ... how many times do You have to be told not to post screenshots
when a plain TEXT cut and paste is more than enough ?
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 768
Location: Pennsylvania

PostPosted: Tue Jun 29, 2021 6:06 pm
Reply with quote

Try changing this:
Code:
MOVE INPUTFILE01(1:REC-LEN) TO OUTPUTFILE01(1:REC-LEN)
WRITE OUTPUTFILE01


To This:
Code:
WRITE OUTPUTFILE01 FROM INPUTFILE01(1:REC-LEN)
Back to top
View user's profile Send private message
anonguy456

New User


Joined: 29 Jun 2021
Posts: 12
Location: India

PostPosted: Tue Jun 29, 2021 7:52 pm
Reply with quote

nope i had tried this already, it fills space character. but thanks for your suggestion.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 768
Location: Pennsylvania

PostPosted: Tue Jun 29, 2021 7:56 pm
Reply with quote

How about removing the VALUE HIGH-VALUES from the 01 line.

Code:
 01 INPUTFILE01     PIC X(24810).
          88 ENDOFINPUTFILE01 VALUE HIGH-VALUES.
       01 FILLER          PIC X(4).
       FD OUTPUT01
           RECORDING MODE IS V.
 01 OUTPUTFILE01    PIC X(24810) VALUE HIGH-VALUES.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Tue Jun 29, 2021 11:31 pm
Reply with quote

As I anticipated from your comments on the other forum, you are doing precisely what I thought -- you are writing fixed length 24810 byte records to a variable length file. Your code needs to be something like:
Code:
       FD INPUT01
           BLOCK CONTAINS 0 RECORDS
           RECORD IS VARYING IN SIZE FROM 4 TO 24810
           DEPENDING ON REC-LEN.
       01 INPUTFILE01     PIC X(24810).
          88 ENDOFINPUTFILE01 VALUE HIGH-VALUES.
       01 FILLER          PIC X(4).
       FD OUTPUT01
           RECORDING MODE IS V
           RECORD IS VARYING IN SIZE FROM 4 TO 24810
           DEPENDING ON OUT-LEN.
       01 OUTPUTFILE01    PIC X(24810) VALUE HIGH-VALUES.
.
.
.
           MOVE REC-LEN TO OUT-LEN.
           WRITE OUTPUTFILE01.
This is untested code and may require some changes to get it to run properly, but this code indicates to COBOL to write only OUT-LEN bytes to the file (unlike your code which indicates to COBOL that every record you write to OUTPUT01 will be 24810 bytes and will have HIGH-VALUES for all bytes after the last byte of the input data).
Back to top
View user's profile Send private message
anonguy456

New User


Joined: 29 Jun 2021
Posts: 12
Location: India

PostPosted: Wed Jun 30, 2021 1:59 pm
Reply with quote

Thank You Robert, Finally it started to work the way I intended it to work
Back to top
View user's profile Send private message
anonguy456

New User


Joined: 29 Jun 2021
Posts: 12
Location: India

PostPosted: Wed Sep 08, 2021 4:16 pm
Reply with quote

Code:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.
           TST01.
      *PROGRAM THAT WILL COPY NORMAL PROD VB FILE
      *
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT INPUT01 ASSIGN TO CHK01.
           SELECT OUTPUT01 ASSIGN TO CHK02.
      *
       DATA DIVISION.
       FILE SECTION.
       FD INPUT01
           BLOCK CONTAINS 0 RECORDS
           RECORD IS VARYING IN SIZE FROM 4 TO 24810
           DEPENDING ON REC-LEN.
       01 INPUTFILE01     PIC X(24810).
          88 ENDOFINPUTFILE01 VALUE HIGH-VALUES.
       FD OUTPUT01
           BLOCK CONTAINS 0 RECORDS
           RECORD IS VARYING IN SIZE FROM 4 TO 24810
           DEPENDING ON REC-LEN2.
       01 OUTPUTFILE01    PIC X(24810).
       WORKING-STORAGE SECTION.
       01 REC-LEN         PIC 9(5) COMP.
       01 REC-LEN2        PIC 9(5) COMP.
      *
       PROCEDURE DIVISION.
       MAINPROCEDURE.
           OPEN INPUT INPUT01
           OPEN OUTPUT OUTPUT01
           READ INPUT01
             AT END SET ENDOFINPUTFILE01 TO TRUE
           END-READ
           PERFORM WRITEFILE UNTIL ENDOFINPUTFILE01
           CLOSE INPUT01
           CLOSE OUTPUT01
           STOP RUN.
       WRITEFILE.
           MOVE REC-LEN TO REC-LEN2
           MOVE INPUTFILE01(1:REC-LEN) TO OUTPUTFILE01
           WRITE OUTPUTFILE01
           READ INPUT01
             AT END SET ENDOFINPUTFILE01 TO TRUE
           END-READ.


The above code works most of the times, but in some instances it does not copy all records i.e., if there are 1000 records it will copy 996 records and then at 997th row displays error message " * I/O error detected, I/O terminated * ". I need help in fixing this.
NOTE: Its not an issue related with space since at times it is able to copy files bigger than this which has got more records.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2789
Location: NYC,USA

PostPosted: Fri Sep 10, 2021 7:12 pm
Reply with quote

Two points-
1. Please don't attach any screen shots or documents.
2. When you have an active post , please don't duplicate another new one.
ibmmainframes.com/viewtopic.php?p=353024#353024
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 768
Location: Pennsylvania

PostPosted: Fri Sep 10, 2021 7:18 pm
Reply with quote

Did you look in the JESMSGLG?

There should be System messages which provide more information.

One or more of them could be used to help you resolve your issue.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts IDCAMS listcat service using cobol JCL & VSAM 1
No new posts Convert PS to TXT file using jcl JCL & VSAM 7
No new posts Make cobol variable value a variable COBOL Programming 3
No new posts how to convert and use 1 bit hex-numb... COBOL Programming 10
This topic is locked: you cannot edit posts or make replies. Sort to include records of file 2 int... Java & MQSeries 1
Search our Forums:

Back to Top