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

How to retain a value in first record of a file


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

New User


Joined: 03 Feb 2006
Posts: 11

PostPosted: Fri Feb 03, 2006 9:09 pm
Reply with quote

I am reading file A and writing to file B.

I need to write file A to file B But in file B I need to see
a constant value which appears in file A first 5 chars of First record.

Rest of all the file B and file A should be same.

Please let me know if I need to declare some variable as GLOBAL or anything to retain same value.

I tried moving to temp field when I read first rec of A.
But its is diplaying spaces when coming to 2nd record of file B.
I am not at all intializing the temp field.

Eg.,

File A
---------------
123 afdsfdsfdsfd
567 fdsfdsfdsfdsf
678 gfdgfdgfdgfd


Expected File B
------------------
123 afdsfdsfdsfd
123 fdsfdsfdsfdsf
123 gfdgfdgfdgfd

Thanks
Suresh
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri Feb 03, 2006 9:37 pm
Reply with quote

I'm not a programmer, but this seems like a rather simplistic task:

Code:

       IDENTIFICATION DIVISION.                         
       PROGRAM-ID. PROGxx.                             
       INSTALLATION.                                   
       AUTHOR. SUPERK.                                 
       DATE-WRITTEN. 02/03/2006.                       
                                                       
       ENVIRONMENT DIVISION.                           
       INPUT-OUTPUT SECTION.                           
                                                       
         FILE-CONTROL.                                 
           SELECT A ASSIGN TO FILEA                     
             ORGANIZATION IS SEQUENTIAL.               
           SELECT B ASSIGN TO FILEB                     
             ORGANIZATION IS SEQUENTIAL.               
                                                       
       DATA DIVISION.                                   
       FILE SECTION.                                   
                                                       
       FD  A                                           
           LABEL RECORD STANDARD                       
           BLOCK 0 RECORDS                             
           RECORDING MODE F                                 
           RECORD CONTAINS 80 CHARACTERS.                   
                                                           
       01 A-REC.                                           
          03 A-FIRST-FIVE              PIC X(05).           
          03 FILLER                    PIC X(75).           
                                                           
       FD  B                                               
           LABEL RECORD STANDARD                           
           BLOCK 0 RECORDS                                 
           RECORDING MODE F                                 
           RECORD CONTAINS 80 CHARACTERS.                   
                                                           
       01 B-REC.                                           
          03 B-FIRST-FIVE              PIC X(05).           
          03 FILLER                    PIC X(75).           
                                                           
       WORKING-STORAGE SECTION.                             
       01  WS-FIRST-FIVE        PIC X(05) VALUE SPACES.     
       01  EOF                  PIC X VALUE 'N'.           
                                                           
       PROCEDURE DIVISION.                                 
       MAIN-PARA.                                             
           OPEN INPUT A, OUTPUT B.                           
           MOVE SPACES TO B-REC.                             
           READ A AT END MOVE 'Y' TO EOF.                     
           MOVE A-FIRST-FIVE TO WS-FIRST-FIVE.               
           PERFORM READ-PARA UNTIL EOF = 'Y'.                 
           CLOSE A, B.                                       
           MOVE ZEROS TO RETURN-CODE.                         
           STOP RUN.                                         
                                                             
       READ-PARA.                                             
           MOVE A-REC TO B-REC.                               
           MOVE WS-FIRST-FIVE TO B-FIRST-FIVE.               
           WRITE B-REC.                                       
           READ A AT END MOVE 'Y' TO EOF. 


Input:
Code:

123   afdsfdsfdsfd         
567   fdsfdsfdsfdsf       
678   gfdgfdgfdgfd         

Output:
Code:

123   afdsfdsfdsfd 
123   fdsfdsfdsfdsf
123   gfdgfdgfdgfd 
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Feb 04, 2006 7:25 am
Reply with quote

Or you can do something like this (no better or wose than K's):

Do the 1st read outside the loop and save "123" as suggested.

In the loop, move "123" to the A rec.
Write the B rec from the A rec.

Just another way to do it.
Back to top
View user's profile Send private message
sure116

New User


Joined: 03 Feb 2006
Posts: 11

PostPosted: Mon Feb 06, 2006 2:16 pm
Reply with quote

Thank you very much for your kind responses.


Now am able to get the results. The worng thing I have done is
I am moving to the WS field after a statement where spaces were moved to CARD-IN so I am not getting the result.

But after the reply from K and mm I am reviewing the code and
cought myself where I have coded wrong location of move stmt.
Now I have changed the move prior to the initialize.


Thank you very much for your suggestions.


I really appreciate it.......................
suresh
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Mon Feb 06, 2006 3:23 pm
Reply with quote

sure116,

No chance you would be waiting for any suggestion now, after two super suggestions above...

One thing I would like to add, If 123 is constant for each & every record of output file....

Code:
01 A-REC.                                           
          03 A-FIRST-FIVE              PIC X(05).           
          03 A-REST                      PIC X(75). 

01 B-REC.                                           
          03 B-FIRST-FIVE              PIC X(05) VALUE '123  '.           
          03 B-REST                    PIC X(75).           
         
       PROCEDURE DIVISION.                                 
       MAIN-PARA.                                             
           OPEN INPUT A, OUTPUT B.                           
           PERFORM READ-PARA UNTIL EOF = 'Y'.                 
           CLOSE A, B.                                       
           STOP RUN.                                         
                                                             
       READ-PARA.                                             
           READ A INTO A-REC AT END MOVE 'Y' TO EOF.                     
           MOVE A-REST TO B-REST.                               
           WRITE B-REC.       


Regards,

Priyesh.
Back to top
View user's profile Send private message
mijanurit
Currently Banned

New User


Joined: 26 Aug 2005
Posts: 33
Location: bangalore

PostPosted: Mon Feb 06, 2006 3:41 pm
Reply with quote

hi all,

whatever is given by superk, is right. i want to modify procedure division then it will be more easy to understand.

Code:
 PROCEDURE DIVISION.
          MAIN-PARA.
                MOVE SPACE TO B-REC.
                OPEN INPUT A, OPEN OUTPUT B.
                PERFORM READ-PARA UNTIL EOF='Y'.
                CLOSE A,B.
                STOP RUN.

         READ-PARA.
                READ A  INTO W-REC AT END MOVE 'Y' TO EOF.
                IF EOF='N'
                MOVE W-REC TO B-REC
                WRITE B-REC.
               
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top