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   Reply to topic
View previous topic :: View next topic  
Author Message
anonguy456

New User


Joined: 29 Jun 2021
Posts: 3
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: 10796
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: 762
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: 3
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: 762
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: 8578
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: 3
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
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 JSON PARSE in Enterprise COBOL COBOL Programming 2
No new posts Cobol code- to find a string in a str... COBOL Programming 3
No new posts To pull the file with Date and Time u... TSO/ISPF 17
No new posts COBOL Table data to a flat file with ... COBOL Programming 8
No new posts Write a current record plus previous ... DFSORT/ICETOOL 4
Search our Forums:

Back to Top