View previous topic :: View next topic |
Author |
Message |
mfuser Banned
Joined: 01 Mar 2005 Posts: 105 Topics: 58
|
Posted: Mon Jan 23, 2006 7:22 am Post subject: count of records in a file needed in PL/I program |
|
|
Hai All,
I am basically trying to count the total number of input records in a file as well display the count of records whose value lie below 50 and above 50 seperately.Here is what i have coded below and my input dataset looks like:
PROGRAM
-------
Code: |
TEST:PROCEDURE OPTIONS(MAIN);
DCL INP FILE STREAM INPUT;
DCL SYSPRINT FILE PRINT;
DCL MORE_RECORDS BIT (1);
DCL YES BIT (1) INITIAL('1'B);
DCL NO BIT (1) INITIAL('0'B);
DCL IN_CNT FIXED BINARY INIT(1);
DCL IN_CNT_LT50 FIXED BINARY INIT(0);
DCL IN_CNT_GT50 FIXED BINARY INIT(0);
DCL 1 IN_AREA,
2 IN_REC FIXED DECIMAL (02) INIT (0),
2 FILLER CHAR (78) INIT (' ');
DCL IN_TOT_LT50 FIXED DECIMAL (5,2) INIT (0);
DCL IN_TOT_GT50 FIXED DECIMAL (5,2) INIT (0);
ON ENDFILE(INP)
MORE_RECORDS = NO;
PUT SKIP(1) LIST('TOTAL NUMBER OF RECORDS ARE ',IN_CNT);
PUT SKIP(1) LIST('TOTAL NUMBER OF RECORDS LESS THAN 50 ',
IN_CNT_LT50);
PUT SKIP(1) LIST('TOTAL NUMBER OF RECORDS GREATER THAN 50 ',
IN_CNT_GT50);
CLOSE FILE(INP);
MORE_RECORDS = YES;
OPEN FILE(INP);
GET FILE (INP) LIST (IN_AREA);
DO WHILE(MORE_RECORDS);
IN_CNT = IN_CNT + 1;
IF IN_REC < 50 THEN
DO;
IN_CNT_LT50 = IN_CNT_LT50 + 1;
IN_TOT_LT50 = IN_TOT_LT50 + IN_REC;
PUT SKIP LIST('IN_CNT_LT50 ',IN_CNT_LT50);
PUT SKIP LIST('IN_TOT_LT50 ',IN_TOT_LT50);
END;
ELSE
DO;
IN_CNT_GT50 = IN_CNT_GT50 + 1;
IN_TOT_GT50 = IN_TOT_GT50 + IN_REC;
PUT SKIP LIST('IN_CNT_GT50 ',IN_CNT_GT50);
PUT SKIP LIST('IN_TOT_GT50 ',IN_TOT_GT50);
END;
GET FILE (INP) LIST (IN_AREA);
END;
END TEST;
|
INPUT DATASET
-------------
Code: |
10
20
50
70
25
55
15
78
82
60
|
OUTPUT
------
Code: |
TOTAL NUMBER OF RECORDS ARE 1
TOTAL NUMBER OF RECORDS LESS THAN 50 0
TOTAL NUMBER OF RECORDS GREATER THAN 50 0
IN_CNT_LT50 1
IN_TOT_LT50 10.00
IN_CNT_GT50 1
IN_TOT_GT50 50.00
IN_CNT_LT50 2
IN_TOT_LT50 35.00
IN_CNT_LT50 3
IN_TOT_LT50 50.00
IN_CNT_GT50 2
IN_TOT_GT50 132.00
|
DESIRED OUTPUT
-------------
Code: |
TOTAL NUMBER OF RECORDS ARE 10
TOTAL NUMBER OF RECORDS LESS THAN 50 4
TOTAL NUMBER OF RECORDS GREATER THAN 50 6
|
|
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Jan 23, 2006 8:29 am Post subject: |
|
|
mfuser,
You need to produce 2 output reports? Can you explain report 1 a little bit ? How did you arrive at the total no: records to be 1 ?
Btw you don't really need a program to produce this report. SORT can produce the report very easily
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
mfuser Banned
Joined: 01 Mar 2005 Posts: 105 Topics: 58
|
Posted: Mon Jan 23, 2006 12:17 pm Post subject: |
|
|
Kolusu,
I am basically trying out to code in PL/1 only as a learning excercise and i want to code by program only.The report should contain the total number of records in the file which is 10 and the count of records which are less than 50 as well as more than 50.I am getting the count total no: records to be 1 and i am not able to proceed further as why i am not getting the count to be 10.My run gives me the count to be 1 only .Please guide me further to get the desired results. |
|
Back to top |
|
 |
vst Beginner
Joined: 23 Jan 2006 Posts: 11 Topics: 0
|
Posted: Tue Jan 24, 2006 2:55 am Post subject: |
|
|
mfuser,
I believe you mean
Quote: |
ON ENDFILE(INP)
BEGIN /* we have to enclose code below to BEGIN...END */
MORE_RECORDS = NO;
PUT SKIP(1) LIST('TOTAL NUMBER OF RECORDS ARE ',IN_CNT);
PUT SKIP(1) LIST('TOTAL NUMBER OF RECORDS LESS THAN 50 ',
IN_CNT_LT50);
PUT SKIP(1) LIST('TOTAL NUMBER OF RECORDS GREATER THAN 50 ',
IN_CNT_GT50);
CLOSE FILE(INP);
END; /* close BEGIN group */
|
|
|
Back to top |
|
 |
|
|