Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Comparing a flat file with VSAM file and updating VSAM File

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
pinchoo335

New User


Joined: 20 May 2008
Posts: 11
Location: Gurgaon

PostPosted: Thu May 22, 2008 11:38 am    Post subject: Comparing a flat file with VSAM file and updating VSAM File
Reply with quote

I have a flat file and based on some key i want to search the record in VSAM file and if found update some column in VSAM file.

Please help!!!!!!!!!!!
Back to top
View user's profile Send private message

the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Thu May 22, 2008 12:17 pm    Post subject:
Reply with quote


    1. OPEN INPUT FLAT-FILE
    2. OPEN I/O VSAM-FILE
    3. READ FLAT-FILE (to get the data to be searched)
    4. MOVE FLAT-FILE-KEY TO VSAM-FILE-KEY
    5. READ VSAM-FILE (with the key data)
    6. POPULATE THE NEW VALUES IN VSAM-FILE-DATA
    7. REWRITE THE VSAM-FILE-DATA
    8. CLOSE FLAT-FILE, VSAM-FILE
Back to top
View user's profile Send private message
pinchoo335

New User


Joined: 20 May 2008
Posts: 11
Location: Gurgaon

PostPosted: Thu May 22, 2008 12:35 pm    Post subject: Reply to: Comparing a flat file with VSAM file and updating
Reply with quote

Thanks!! for the quick reply

As i am a new programmer for Cobol.
Can you please give me some more details with some actual code
so that i can have some idea

flat file length is x(35)
key is first six characters.

and if matches i have to update rest of the data in VSAM file
Back to top
View user's profile Send private message
mytags

New User


Joined: 28 Apr 2008
Posts: 63
Location: US

PostPosted: Thu May 22, 2008 12:48 pm    Post subject:
Reply with quote

Hi Pinchoo,
Read Flat file and move the required field to a working storage variable and compare it with the VSAM file by reading it based on the key and rewrite it.I think you got stuck due to logic?You need code to solve it?
Thanks
Hari
Back to top
View user's profile Send private message
pinchoo335

New User


Joined: 20 May 2008
Posts: 11
Location: Gurgaon

PostPosted: Thu May 22, 2008 2:03 pm    Post subject: Reply to: Comparing a flat file with VSAM file and updating
Reply with quote

i am clear with the Logic but i am stuck while coding it...
Can you provide me some sample code.... of reading and writing a flat file and a VSAM file.

Thanks!!!!
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu May 22, 2008 2:10 pm    Post subject: Re: Reply to: Comparing a flat file with VSAM file and updat
Reply with quote

pinchoo335 wrote:
i am clear with the Logic but i am stuck while coding it...
Can you provide me some sample code.... of reading and writing a flat file and a VSAM file.

No, you first....
Start with Processing QSAM files and Processing VSAM files
Back to top
View user's profile Send private message
pinchoo335

New User


Joined: 20 May 2008
Posts: 11
Location: Gurgaon

PostPosted: Thu May 22, 2008 3:09 pm    Post subject: Reply to: Comparing a flat file with VSAM file and updating
Reply with quote

Can i load my flat file to a internal table.
It's a huge file, so is there some way i can automatically pick the recors from flat file and load it to a table.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu May 22, 2008 3:23 pm    Post subject:
Reply with quote

Pinchoo,

from what I gather,
LOOP:
you need to read a qsam record,
attempt to find matching vsam
when match update vsam
goto loop


why complicate the programming with an internal COBOL table?
Back to top
View user's profile Send private message
pinchoo335

New User


Joined: 20 May 2008
Posts: 11
Location: Gurgaon

PostPosted: Thu May 22, 2008 3:29 pm    Post subject: Reply to: Comparing a flat file with VSAM file and updating
Reply with quote

Yaa you ar right....

But i need to perform some other functions also that's why i need to do some searching in flat file also.

That's why i want to load it in a table.

please let me know how to load a flat file to a table.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu May 22, 2008 11:53 pm    Post subject:
Reply with quote

Hello,

Each time you post, you add more to what you are looking for.

I'd suggest you take some time and post your complete requirement, not bits and pieces. You need to post some sample data from both of the input files as well as what the output should be when the sample input is processed.

If you believe you need an array, post how it will be used. "Some other functions" is not what is needed. You need to explain these functions.

If the file is very large, you will not be able to load it into an array. If your requirement is like most similar requests, you do not need an array. We will know better when you clarify your requirement.
Back to top
View user's profile Send private message
pinchoo335

New User


Joined: 20 May 2008
Posts: 11
Location: Gurgaon

PostPosted: Fri May 23, 2008 8:59 am    Post subject: Reply to: Comparing a flat file with VSAM file and updating
Reply with quote

My Flat file contains data like

abcdef 12345 98734567 34512356
anghty 36785 98354687 15347859

Now i have the VSAM file.

abcdef 12345 67837502 45678903
fgejsjk 87452 missing missing

The first column value abcdef is the key.

Now i have to pick the first key value from flat file
search it in VSAM file.
if found then match the values for other columns
if different in VSAM file
Then update the values from Flat file.

I hope this would help you i understanding the problem better and helping me in a better manner

thanks!
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri May 23, 2008 9:33 am    Post subject:
Reply with quote

Hello,

Quote:
I hope this would help you i understanding the problem better and helping me in a better manner
Yes, it does.

From your explanation, i suggest you follow Gautam's suggestion - it is just what you need. You should not need to create an array.

If there are questions/problems when you code, post what you have and the question about it.
Back to top
View user's profile Send private message
pinchoo335

New User


Joined: 20 May 2008
Posts: 11
Location: Gurgaon

PostPosted: Fri May 23, 2008 2:51 pm    Post subject:
Reply with quote

Code:
4000-EXTRA-RECORDS.                           
                                               
     OPEN INPUT FILE-NEW                   
              INPUT FILE-OLD.               
                                               
      READ FILE-OLD NEXT AT END               
               SET OLD-EOF TO TRUE             
          MOVE OLD-KEY       TO WS-KEY         
          MOVE OLD-MANAGER   TO WS-MANAGER     
          MOVE OLD-FAMILY    TO WS-FAMILY     
          MOVE OLD-CALENDER  TO WS-CALENDER   
                                               
          PERFORM UNTIL WS-FOUND OR NEW-EOF   
            READ FILE-NEW AT END               
                      SET  NEW-EOF TO TRUE     
             IF WS-KEY = NEW-KEY               
                SET WS-FOUND TO TRUE           
             END-IF                           
            END-READ                           
       END-PERFORM                                 
                                                   
       IF  WS-NOT-FOUND                           
          DISPLAY ' EXTRA RECORD IN PRODUCTION'   
       END-IF                                     
       CLOSE FILE-NEW                             
   END-READ.       

I have written the code for extracting the records which are there in VSAM file but not in Flat file.
FILE-OLD is VSAM file with extra records.
FILE-NEW is Flat file.

I am picking up a single record from VSAM file and the comparing it with whole flat file by matching the key.
If it is found it's ok, If not found the i have put a display

Please let me know if i am wrong somewhere.
Thanks!
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri May 23, 2008 10:15 pm    Post subject:
Reply with quote

Hello,

The code posted does not work the same as the description posted previously.

Please review your requirement and post some sample data for both files that includes all of the conditions the code must handle. Also post what the output should be when the sample data is processed.

It is beginning to look like you need a match process rather than a random read process. If you are not familiar with matching 2 files, ther is a "Sticky" near the top of the COBOL section of the forum that contains sample code for matching 2 files. Save the sample code to your pc and review the code.
Back to top
View user's profile Send private message
salehi

New User


Joined: 30 Sep 2006
Posts: 14
Location: Iran

PostPosted: Sun May 25, 2008 5:32 pm    Post subject: Reply to: Comparing a flat file with VSAM file and updating
Reply with quote

Here is a sample program ...
Code:
       ID DIVISION.
       PROGRAM-ID. PGM001.
      *THIS PROGRAM WOULD READ A QSAM FILE AND FIND THE KEYS IN
      *VSAM FILE,IF FOUNDED IT WOULD UPDATE THE ROW WITH NEW
      *QSAM FILE VALUES
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
           CONSOLE  IS INP.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
             SELECT VSM
             ASSIGN TO INDD1
             ORGANIZATION IS INDEXED
             ACCESS MODE IS DYNAMIC
             RECORD KEY IS INFILE-RECORD-KEY
             FILE STATUS   IS INFILE-STATUS INVSAM-STATUS.

             SELECT QSM
             ASSIGN TO INDD2
             ORGANIZATION IS SEQUENTIAL
             ACCESS MODE IS SEQUENTIAL
             FILE STATUS   IS INFILE2-STATUS.
        DATA DIVISION.
        FILE SECTION.
        FD VSM.
      *       RECORDING IS VARYING FROM 80 TO 80.
        01  STUDENT.
            03 ST-ID  PIC X(10).
            03 NAME   PIC X(30).
            03 FAMILY PIC X(30).
            03 AGE    PIC 9(2).
            03 GENDER PIC X(1).
            03 FILLER PIC X(7).
        01  INFILE-RECORD-KEY PIC  X(10).
        FD QSM
             RECORDING MODE IS F
             BLOCK CONTAINS 0 CHARACTERS
             RECORD CONTAINS 80 CHARACTERS.
      *       RECORDING IS VARYING FROM 80 TO 80.
        01  STUDENT2.
            03 ST-ID2  PIC X(10).
            03 NAME2   PIC X(30).
            03 FAMILY2 PIC X(30).
            03 AGE2    PIC 9(2).
            03 GENDER2 PIC X(1).
            03 FILLER  PIC X(7).
        01  INFILE2-RECORD-KEY PIC  X(10).
        WORKING-STORAGE SECTION.
        01  STID PIC  X(10) VALUE '0000000000'.
        01  INFILE-STATUS PIC X(2).
        01  INFILE2-STATUS PIC X(2).
        01  INFILE-EOF PIC X(1) VALUE 'N'.
        01  INFILE2-EOF PIC X(1) VALUE 'N'.
        01  REC-FOUND  PIC X(1) VALUE 'N'.
        01  INVSAM-STATUS.
            03 VSAM-CODE1 PIC X(2).
            03 VSAM-CODE2 PIC X(1).
            03 VSAM-CODE3 PIC X(3).
        PROCEDURE DIVISION.
        0001-MAIN.
            DISPLAY "*****************************"  UPON INP.
            OPEN I-O VSM
            IF  (INFILE-STATUS NOT = 00)
                DISPLAY "ERROR OPENING VSAM FILE - " UPON INP
                DISPLAY  "INFILE  STATUS=" INFILE-STATUS UPON INP
                DISPLAY  "VSAM    CODE1 =" VSAM-CODE1 UPON INP
                DISPLAY  "VSAM    CODE2 =" VSAM-CODE2 UPON INP
                DISPLAY  "VSAM    CODE3 =" VSAM-CODE3 UPON INP
                GOBACK
            END-IF
             DISPLAY "VSAM FILES SUCCESSFULLY OPENED ...." UPON INP
            OPEN I-O QSM
            IF  (INFILE2-STATUS NOT = 00)
                DISPLAY "ERROR OPENING QSAM FILE - " UPON INP
                DISPLAY  "INFILE  STATUS=" INFILE2-STATUS UPON INP
                GOBACK
            END-IF
            DISPLAY "QSAM FILES SUCCESSFULLY OPENED ...." UPON INP
             INITIALIZE INFILE-EOF
             PERFORM UNTIL INFILE2-EOF = 'Y'
             READ QSM
                  AT END MOVE 'Y' TO INFILE2-EOF
             END-READ
            IF (INFILE2-STATUS NOT = '00')
             DISPLAY "ERROR READING QSM-STATUS=" INFILE2-STATUS UPON INP
             GOBACK
            END-IF
             DISPLAY "QSAM REC IS :" STUDENT2 UPON INP
             DISPLAY "QSAM KEY IS :" INFILE2-RECORD-KEY UPON INP
             DISPLAY "READING VSAM..."  UPON INP
             MOVE INFILE2-RECORD-KEY TO INFILE-RECORD-KEY
             START VSM
                KEY IS EQUAL TO INFILE-RECORD-KEY
                INVALID KEY MOVE "I" TO INFILE-EOF
             END-START
             IF (INFILE-EOF = 'I')
              DISPLAY "INVALID KEY :" INFILE2-RECORD-KEY UPON INP
             ELSE
              DISPLAY "KEY FOUNDED :" INFILE2-RECORD-KEY UPON INP
              MOVE NAME2 TO NAME
              MOVE FAMILY2 TO FAMILY
              MOVE AGE2 TO AGE
              MOVE GENDER2 TO GENDER
              REWRITE STUDENT
              IF (INFILE-STATUS NOT = '00')AND(INFILE-STATUS NOT = '10')
               DISPLAY "ERROR WRITING ,STATUS=" INFILE-STATUS UPON INP
               GOBACK
              END-IF
             DISPLAY "UPDATE DONE FOR KEY:" INFILE2-RECORD-KEY  UPON INP
             END-IF
            END-PERFORM.
            DISPLAY "*****************************"  UPON INP.
            CLOSE VSM
            CLOSE QSM
            STOP RUN.
        END PROGRAM PGM001.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun May 25, 2008 7:24 pm    Post subject:
Reply with quote

Hello salehi,

A couple of things.

1. as posted, your sample program will not work - it will probably have compile problems - if not, it will abend.

2. as posted, your sample program does not conform to the posted rules (for which we are waiting clarification).
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Sun May 25, 2008 8:01 pm    Post subject: Reply to: Comparing a flat file with VSAM file and updating
Reply with quote

here is a pointer to a well documented cobol sample
for a master file update
http://www.simotime.com/itmast01.htm
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun May 25, 2008 9:17 pm    Post subject:
Reply with quote

Hello,

Until Pinchoo takes the time to properly explain the requirement, we are only guessing at which type of process is needed. One way to read the requirement is to read the qsam file and perform updates to the corresponding vsam record. Another way the requirement was posted was to read the vsam file, "search" the qsam file for any match(es?) and make the appropriate updsate(s). Somehow, using array(s) got into the discussion. So far we have not seen sample data in the 2 files and what should be the result of the process using the sample data.

I suspect we should stop offering ways to answer the question until the question has actually been defined.
Back to top
View user's profile Send private message
pinchoo335

New User


Joined: 20 May 2008
Posts: 11
Location: Gurgaon

PostPosted: Mon May 26, 2008 3:30 pm    Post subject: Reply to: Comparing a flat file with VSAM file and updating
Reply with quote

Thanks!!! salehi

This is what i was looking for...

Thanks everybody for your help...and sorry i wasn't able to make my requirement clear to you guys :-(

Thanks!!
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon May 26, 2008 7:33 pm    Post subject: Reply to: Comparing a flat file with VSAM file and updating
Reply with quote

Good to hear that you have something . . .

Quote:
This is what i was looking for...

You did fix the code?

d
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 Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Updating the counters after eliminati... PANDU1 DFSORT/ICETOOL 12 Mon Nov 21, 2016 9:47 am
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us