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

How to make the read statement to point to the first record?


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
HONEY LANGUAGE
Warnings : 2

New User


Joined: 27 Oct 2006
Posts: 17

PostPosted: Thu May 24, 2007 2:15 pm
Reply with quote

Hi,

Let me explain my problem clearly..

I have a two files-> file 1 and file 2.

In file 1,i have 10 records and in file 2,i have 30 records.I want to pick up the first record from file1 and search for a match record in file 2 and write the matched records in file 3.

This is how my entire program looks like..

/INCLUDE PLINC.MACROS
LOAD : PROC OPTIONS(MAIN);
DCL INFILE FILE RECORD INPUT;
DCL BKUPC FILE RECORD INPUT;
DCL OUTFILE FILE RECORD OUTPUT;
DCL EOF_IN BIT(1) INIT('0'B);
DCL EOF_BK BIT(1) INIT('0'B);
DCL LOOP_CNT FIXED BIN(31);
ON ENDFILE(INFILE) EOF_IN=TRUE;
ON ENDFILE(BKUPC) EOF_BK=TRUE;
DCL 1 INREC,
2 SYSTEM PIC'99',
2 GENERATION PIC'99',
2 VENDOR PIC'99999',
2 ITEM PIC'99999';
DCL 1 DICT,
/INCLUDE PLSTRUC.DICTRECL
DICT = '';

/****This is the logic of the program*********/
READ FILE(INFILE) INTO(INREC);-reading file1
PUT LIST('INFILE1 ITEM',INREC.ITEM);

READ FILE(BKUPC) INTO(DICT);-reading file2
PUT LIST('BKUPC ITEM',DICT.ITEM);

DO UNTIL(EOF_IN);
PUT LIST('INFILE2 ITEM',INREC.ITEM);

DO UNTIL(EOF_BK);
IF(INREC.SYSTEM = DICT.SYSTEM & INREC.GENERATION = DICT.
GENERATION & INREC.VENDOR = DICT.VENDOR &
INREC.ITEM = DICT.ITEM)
THEN DO;
WRITE FILE(OUTFILE) FROM(DICT);
PUT LIST('WRITTEN');
EOF_BK=TRUE;
END;
READ FILE(BKUPC) INTO(DICT);
PUT SKIP LIST('READING THE NEXT UPC FROM BKUPC');
END;

READ FILE(INFILE) INTO(INREC);
LOOP_CNT = LOOP_CNT + 1;
END;

PUT LIST('LOOP COUNT : ',LOOP_CNT);
END LOAD;

What it does is->it reads the first record form file1 and searches for the match record from file2 and writes the matched record in file3.After that it is reading the next record from file1 but it is not reading the first record from file 2 until the match record.

To be clear :

file 1 : file 2:

rec 1 rec5
rec 2 rec3
rec 3 rec1

It is reading the rec 1 from file 1 and search for a match rec in file 2 and writes the matched rec1 in file3.Again it started to read the next record rec 2 of file 1,but in file 2 the read statement points at the last record(since the previous read statement points to the matched record)
I wanted to read from the start of the file 2.

How can i do this..can anyone help me out...

Thanks in advance,
Thenmozhie.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri May 25, 2007 1:07 am
Reply with quote

Hello,

Is there some reason that the 2 files are not in the same sequence?

If the requirement is to match on the "keys" both files should be in key sequence.

Your problem is that you have reached end of file. The normal way to get back to the first record in a sequential file is to close the file and open it again - to do this for every record to be matched is a very bad way to implement. For testing with a tiny bit of data (30/10 records) it will not matter much, but let's say there were 1 million records in one file and 80thousand in the other. That would cost at least 80000 open/close actions (which are quite expensive) and 80,000,000,000 reads. I'm not sure how long that would run, but i can guarantee that it would not be acceptable.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri May 25, 2007 3:01 pm
Reply with quote

dick scherrer wrote:
Hello,
Is there some reason that the 2 files are not in the same sequence?



Yeah, I stand with Dick.

If your requirement is to match on the keys both files should be in key sequence & then It's a simple file-matching program.
And First prerequisite for such a matching-program is: i/p files must be in same sort order; if not your program'll stuck as stated in your problem.

Try out with sorted files, if you face some problem please let us know.
Back to top
View user's profile Send private message
HONEY LANGUAGE
Warnings : 2

New User


Joined: 27 Oct 2006
Posts: 17

PostPosted: Sat May 26, 2007 1:33 pm
Reply with quote

Hi,

Thanks for you reply.

i know if i sort both the files, i can get the output what i expected.But,i wanted to read it in a sequential manner without sorting both the files.

I have written a program...can you guys check out and let me know the mistake...

/****INCLUDE*******/
/INCLUDE PLINC.MACROS

/******DECLARATIONS********************/

TESTUPC : PROC OPTIONS(MAIN);
DCL INFILE FILE RECORD INPUT;
DCL BKUPC FILE RECORD INPUT;
DCL OUTFILE FILE RECORD OUTPUT;
DCL EOF_IN BIT(1) INIT('0'B);
DCL EOF_BK BIT(1) INIT('0'B);
DCL LOOP_CNT FIXED BIN(31);

/*******END OF FILE************/
ON ENDFILE(INFILE) EOF_IN=TRUE;
ON ENDFILE(BKUPC) EOF_BK=TRUE;

/******REC 1 STRUCTURE********/
DCL 1 INREC,
2 SYSTEM PIC'99',
2 GENERATION PIC'99',
2 VENDOR PIC'99999',
2 ITEM PIC'99999';

/*****REC 2 STRUCTURE**********/

DCL 1 OUTREC,
2 SYSTEM PIC'99',
2 GENERATION PIC'99',
2 VENDOR PIC'99999',
2 ITEM PIC'99999';

/*****LOGIC***************/

READ FILE(INFILE) INTO(INREC);
PUT LIST('INFILE FIRST REC',INREC.SYSTEM,INREC.GENERATION,
INREC.VENDOR,INREC.ITEM);

DO UNTIL(EOF_IN);

OPEN FILE(BKUPC);
READ FILE(BKUPC) INTO(OUTREC);
PUT LIST('BKUPCREC1',OUTREC.SYSTEM,OUTREC.GENERATION,
OUTREC.VENDOR,OUTREC.ITEM);
DO UNTIL(EOF_BK);
IF(INREC.SYSTEM = OUTREC.SYSTEM & INREC.GENERATION =
OUTREC.GENERATION & INREC.VENDOR =
OUTREC.VENDOR & INREC.ITEM = OUTREC.ITEM) THEN
DO;
WRITE FILE(OUTFILE) FROM(OUTREC);
PUT LIST('UPCWRITTEN',OUTREC.SYSTEM,
OUTREC.GENERATION,
OUTREC.VENDOR,OUTREC.ITEM);
EOF_BK=TRUE;
END;
ELSE
DO;
READ FILE(BKUPC) INTO(OUTREC);
PUT LIST('BKUPC NEXT REC',OUTREC.SYSTEM,
OUTREC.GENERATION,
OUTREC.VENDOR,OUTREC.ITEM);
END;
END;
READ FILE(INFILE) INTO(INREC);
PUT LIST('INFILE NEX REC',INREC.SYSTEM,INREC.GENERATION,
INREC.VENDOR,INREC.ITEM);
LOOP_CNT = LOOP_CNT + 1;
CLOSE FILE(BKUPC);
END;
PUT LIST('LOOP COUNT : ',LOOP_CNT);
END TESTUPC;

In file1 i have 3 records,In file2 i have 3 records.

rec1 rec1
rec2 rec3
rec3 rec2

It is reading the first rec(rec1) from file1 and reading the first rec(rec1) from file2 and writes the matched rec to file3(rec1).Again it reads the next record of file 1(rec2),but its not reading the next rec(rec3) from file 2.It comes out of the loop.

The output which i got was : In file 3->it has written only rec 1

I have used open and close statement over here,but eventhough i'm not getting the output properly..Please check out my Program and let me know the mistake.It will help me to learn my mistake.

Thanks in advance,
Thenmozhie.
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Sat May 26, 2007 11:48 pm
Reply with quote

Comparing 2 files and writing a 3rd one? Have a look at some old standards called 'balance line'. It's nearly pseudo code but it always works (after you sorted both input files).

Here
Back to top
View user's profile Send private message
HONEY LANGUAGE
Warnings : 2

New User


Joined: 27 Oct 2006
Posts: 17

PostPosted: Sun May 27, 2007 12:58 am
Reply with quote

Hi George,

Thanks for your reply.

Could you please tell me what does "balance line" mean? where should i find it out?
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Sun May 27, 2007 2:19 pm
Reply with quote

In my previous post follow the link, it is coloured blue.

Balance is a machine to compare two weights; left and right. The weights are the keys of two (or more) files. The lighter (smaller) one is the one to process. If they are the same they should both be processed.
Back to top
View user's profile Send private message
HONEY LANGUAGE
Warnings : 2

New User


Joined: 27 Oct 2006
Posts: 17

PostPosted: Tue May 29, 2007 12:51 pm
Reply with quote

Hi,

Thanks to all. I can sort out the two files and i can find out the match records.But,i don't want to do that.I just wanted to try it without sorting the files and with the sequential read.

I tried the above program but the second file is end up with the EOF problem. It is not resetting the read statement to point to the first record after the complete read of file 2.

I then resetted the EOF flag->as like this EOF_BK='FALSE'.Its working fine now.

Thanks for all of your support.

Thanks & Regards,
Thenmozhie.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue May 29, 2007 7:54 pm
Reply with quote

You're welcome.

Even though it is working, it would be a bad thing to ever have it used regularly. It would be ok for a learning experiment, but should not be used "for real".
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Tue May 29, 2007 9:18 pm
Reply with quote

Dick,

Absolutely right you are icon_lol.gif In my Vienna team there was a guy programming exactly like this one. Open/close all the way. I had him kicked out of my project icon_evil.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue May 29, 2007 11:26 pm
Reply with quote

Hi George,

Well, it is one way to make sure that the system has no spare cycles icon_smile.gif

Hardware sales people would be happy if more of this was implemented icon_wink.gif
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Tue May 29, 2007 11:58 pm
Reply with quote

Yeah Dick,

Remember the good old times where one was forced to program after good thinking. Worked on this one in the sixties. Nothing virtual to it; no air sold as virtual memory like IBM started to do early seventies.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed May 30, 2007 1:48 am
Reply with quote

Yup,

Surely do recall the days before virtual. Remember a friend back then saying he'd trust this "virtual memory stuff" as much as he'd trust a virtual sailboat.

My first assembler experiences were on machines that had about 4K of memory (nope, not meg, just k) icon_smile.gif . . . .

Wonder where we might post "remember when" stuff icon_smile.gif
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Thu May 31, 2007 1:51 am
Reply with quote

Programmed the Olivetti 523 with cassette deck and 7k octal onboard including the operating system. The bloody machine knew about overlay icon_exclaim.gif Programmed a complete insurance administration at it.
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 -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 7
No new posts Error to read log with rexx CLIST & REXX 11
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
Search our Forums:

Back to Top