View previous topic :: View next topic
|
Author |
Message |
gprerna
New User
Joined: 21 Mar 2007 Posts: 38 Location: US
|
|
|
|
Hi,
I have the below requirement:
A
A
B
B
B
In the output i need as below:
A 2
B 3
Can any one assist me how this can be done thru Easytrieve? I have coded, but i am not getting the count for the last record i.e 'B'.
Thanks! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post your input, code and the output you get with that input & code.
If we can see your code and the data, maybe we can offer suggestions. |
|
Back to top |
|
|
gprerna
New User
Joined: 21 Mar 2007 Posts: 38 Location: US
|
|
|
|
Hi,
This is the code:
FILE INFILE FB(30 3000)
A-TYPE 1 30 A
*
FILE OUTFILE FB(40 4000)
B-TYPE 1 30 A
B-COUNT 31 9 N
*
W-FIRST-TIME W 9 N VALUE 1
W-REC W 40 A
W-PREV-TYPE W-REC 30 A
W-COUNT W-REC +30 9 N VALUE 0
*
JOB INPUT INFILE
IF NOT EOF INFILE
IF W-FIRST-TIME = 1
MOVE A-TYPE TO W-PREV-TYPE
W-FIRST-TIME = 2
END-IF
IF A-TYPE = W-PREV-TYPE
W-COUNT = W-COUNT + 1
ELSE
MOVE W-PREV-TYPE TO B-TYPE
MOVE W-COUNT TO B-COUNT
PUT OUTFILE
W-COUNT = 1
END-IF
MOVE A-TYPE TO W-PREV-TYPE
END-IF
IF EOF INFILE
STOP
END-IF
INFILE data:
A
A
B
B
B
OUTFILE expected o/p:
A 000000002
B 000000003
Thanks!! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
You are getting the proper count for type "A" but no count for type "B"?
If so, i'd suggest repeating these lines:
Code: |
MOVE W-PREV-TYPE TO B-TYPE
MOVE W-COUNT TO B-COUNT
PUT OUTFILE |
after the "IF EOF" and before the "STOP".
Code: |
IF EOF INFILE
<---- insert here
STOP
END-IF |
The way the posted code is structured, there is no code to print the last count. |
|
Back to top |
|
|
gprerna
New User
Joined: 21 Mar 2007 Posts: 38 Location: US
|
|
|
|
I tried this, but it doesnt work
Infact i had put a display statement, and noticed that its not going in the below if condition:
IF EOF INFILE
DISPLAY 'EOF'
STOP
END-IF
The code i used:
IF EOF INFILE
DISPLAY 'ITS END OF FILE'
MOVE W-PREV-TYPE TO B-TYPE
MOVE W-COUNT TO B-COUNT
PUT OUTFILE
STOP
END-IF
This didnt display anything in the spool. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
I'm away from most of my material, so i can't send good examples just now.
I suggested the earlier change because it fit your code. In the code we use, the "at end" is specified in the "JOB INPUT INFILE " statement. There are not checks for eof in the code at the read and "at the bottom". When the input raises eof, control is transferred to an end-of-file routine where the final totals are printed.
Let me know if this is not clear and i'll send a better example on Monday when i'm on a different computer. |
|
Back to top |
|
|
Devzee
Active Member
Joined: 20 Jan 2007 Posts: 684 Location: Hollywood
|
|
|
|
Change job statement as below and try this
Code: |
JOB INPUT NULL
GET INFILE
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
As i mentioned last night, following is an example of how many of our Easytrieve code that groups totals is coded.
After the working-storage items is
Code: |
JOB INPUT COOIN FINISH SHOW-TOTALS |
and this is at the end of the code:
Code: |
SHOW-TOTALS. PROC
code to print totals and/or output final record |
Code to show the last group of totals or output a summary record is included in the SHOW-TOTALS PROC. |
|
Back to top |
|
|
gprerna
New User
Joined: 21 Mar 2007 Posts: 38 Location: US
|
|
|
|
Hey,
Thanks a lot!!
I used the proc... that really worked!!
You are great |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome - glad we could help |
|
Back to top |
|
|
|