passing similar records of two files into third file.



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

passing similar records of two files into third file.

Postby VIJAY1 » Sun Oct 21, 2012 4:24 pm

I am a beginner in mainframes.I have started learning just a month back.I was asked to compare two files and pass the similar records into the third file.
I have sorted the files using jcl. The records in my file contain a single field. The field contains numbers.
HERE FILE-STAT11 AND FILE-STAT2 ARE FILE STATUS DATANAMES.
NUM1 ,NUM2,NUM3 ARE THE

PARA2.
 PERFORM UNTILL FILE-STAT1 NOT =10 OR FILE-STAT2 NOT=10
IF NUM1=NUM2
MOVE NUM1 TO NUM3
WRITE NUM3
END IF.
IF NUM1>NUM2
PERFORM UNTIL FILE-STAT2 NOT = 10
READ FILE2
IF NUM1 = NUM2
WRITE NUM3 FROM NUM1
GOTO PARA2
END IF.
END PERFORM
END IF
IF NUM1<NUM2
PERFORM UNTIL FILE-STAT1 NOT =10
READ FILE1
IF NUM1 = NUM2
WRITE NUM3 FROM NUM1
GOTO PARA2
END IF.
END PERFORM.
END IF.
END PERFORM.
VIJAY1
 
Posts: 26
Joined: Sun Oct 21, 2012 2:49 pm
Has thanked: 3 times
Been thanked: 0 time

Re: passing similar records of two files into third file.

 

Re: passing similar records of two files into third file.

Postby NicC » Sun Oct 21, 2012 4:43 pm

Welcome to the forum. There are a number of points to raise about your posts:
1) why the duplicate (which has been deleted)?
2) You did not sort the files using JCL. You used a sort program. Admittedly tou used to JCL to get the mainframe to execute the sort but you use JCL to execute any program
3) Please post your code and use the code tags. Your code has been coded for you this time. If you do not know how to use the code tags then search the forum for 'code tags'.
4) So what? - you have not actually asked a question and we do not do proof-reading - the compiler can do that much quicker.
5) at the top of the COBOL forum is a sticky on doing a 2 file match which is what you are doing.
6) Is this required to be done in COBOL or by any means? Your sort product can do this for you. Search the sort manuals and forum for JOINKEYS.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: passing similar records of two files into third file.

Postby VIJAY1 » Sun Oct 21, 2012 4:51 pm

Thank you Nic.
The query has been posted before completion due to some problem with my internet connection.
Thanks for the suggestion anyway.
VIJAY1
 
Posts: 26
Joined: Sun Oct 21, 2012 2:49 pm
Has thanked: 3 times
Been thanked: 0 time

Re: passing similar records of two files into third file.

Postby dick scherrer » Sun Oct 21, 2012 9:22 pm

Hello and welcome to the forum,

Suggest you download and review the "sticky" that Nic mentioned. It has been thoroughy tested and does what you want to do. The posted code will not.

Thank you for using the code tags (unless someone else later did this). However; it you intend to work with COBOL you need to learn to properly indent your code. The style you used is not maintainable / promotable.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: passing similar records of two files into third file.

Postby VIJAY1 » Sun Oct 21, 2012 9:37 pm

Thanks Dick.Its been just a week ,I started working on cobol. Looking forward to learning more from the forum..
VIJAY1
 
Posts: 26
Joined: Sun Oct 21, 2012 2:49 pm
Has thanked: 3 times
Been thanked: 0 time

Re: passing similar records of two files into third file.

Postby BillyBoyo » Mon Oct 22, 2012 4:32 am

PARA2.
 PERFORM UNTILL FILE-STAT1 NOT =10 OR FILE-STAT2 NOT=10
  IF NUM1=NUM2
    MOVE NUM1 TO NUM3
    WRITE NUM3
  END IF.
  IF NUM1>NUM2
    PERFORM UNTIL FILE-STAT2 NOT = 10
      READ FILE2
      IF NUM1 = NUM2
        WRITE NUM3 FROM NUM1
        GOTO PARA2
      END IF.
    END PERFORM
  END IF
  IF NUM1<NUM2
    PERFORM UNTIL FILE-STAT1 NOT =10
      READ FILE1
      IF NUM1 = NUM2
        WRITE NUM3 FROM NUM1
        GOTO PARA2
      END IF.
    END PERFORM.
  END IF.
END PERFORM.


I have attempted to "indent" you code.

There are many things wrong. This code will not compile. There are also mistakes which will not cause compile errors but which would make you program probably not work and certainly be difficult to understand.

When posting code here, we need to see the actual code you have attempted, unless you tell us it is "pseudo code".

You are missing hyphens in all your "end" constructs. Your fist UNTILL is not spelled correctly.

You are using full-stops/periods after your "end" constructs. It is best to leave them off.

You are using GO TO to leave your inline PERFORMs to restart from the top. This is a bad idea. If the code just naturally reaches the END-PERFORM, it will start at the top again all on its own with no extra code from you.

Study the program in the "sticky". As your mentor/trainer for some simple working programs to look at, to get an idea how code is used. Spend time thinking and writing out how you think something will work. Then go through it, on the paper, with test data. Have some columns for "variables" and note down the new values they have as you "go through" the code.

If you work out how to get the "simple" things going. then you'll have a technique to apply to more complex things. At some point, you won't need to write it out on paper, but you'll have trained yourself to "think" how it is working. You'll "think" as you are writing the code. You'll think "what will this loop do with the minimum value it can have? What will it do with the maxiumum value? What will it do with an "invalid" value?" and you'll code for all of those (even go back to the spec-writer, if they haven't covered something).

We can't train you here, but there is a lot of material for you to look at, and if you get stuck with something there'll be someone around.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post