Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to retain a value in first record of a file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to retain a value in first record of a file
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

Moderator Team Head


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

PostPosted: Fri Feb 03, 2006 9:37 pm    Post subject: Re: How to retain a value in first record of a file
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    Post subject:
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Mon Feb 06, 2006 3:23 pm    Post subject: Re: How to retain a value in first record of a file
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    Post subject: Re: How to retain a value in first record of a file
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORT BUT RETAIN HIGHEST VALUE ON NON-... leondan22 DFSORT/ICETOOL 2 Thu Dec 14, 2017 8:13 pm
No new posts ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts File Tailoring -- Temporary dataset i... samzee71 CLIST & REXX 3 Fri Dec 01, 2017 3:12 am
No new posts Rexx - File tailoring samzee71 CLIST & REXX 10 Thu Nov 30, 2017 10:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us