View previous topic :: View next topic
|
Author |
Message |
mflax
New User
Joined: 01 Sep 2006 Posts: 17 Location: Delhi
|
|
|
|
I have a input file as given and need to write output file with the records with different second column record. also zero is not considered as different it is same for all
I nto getting how to code, plz help.
INPUT
A 1
A 1
A 1
A 2
B 1
B 2
C 1
C 1
D 3
D 0
E 9
E 0
OUTPUT
A 1
A 1
A 1
A 2
B 1
B 2 |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
What happened to
C 1
C 1
D 3
D 0
E 9
E 0
and what does "also zero is not considered as different" mean? |
|
Back to top |
|
|
mflax
New User
Joined: 01 Sep 2006 Posts: 17 Location: Delhi
|
|
|
|
"also zero is not considered as different"
means, if first record is have a 3 and second is have a 0 then it is not different and is considered same. so along with record for C, D & E also did not go to output file.
all these records i write in another file. |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi Mflax,
Quote: |
means, if first record is have a 3 and second is have a 0 then it is not different and is considered same |
Then why following are not coming in to o/p file
C 1
C 1 |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
I still do not understand. The only logic I can see it read file, write file, do it six times and stop.
Is that what you want? |
|
Back to top |
|
|
Devzee
Active Member
Joined: 20 Jan 2007 Posts: 684 Location: Hollywood
|
|
|
|
By looking at your i/p and o/p, this is what i think you are looking for.
Starting with record type 1 followed by record type 2 is considered one group of records and written to output file?
Confirm this or give more details |
|
Back to top |
|
|
mahi
New User
Joined: 04 Apr 2006 Posts: 86 Location: Hyderabad
|
|
|
|
Wht I understtod from his I/P and O/P is:
He wants to write output when there are different second record fields like a 1 , a 2 so write all the records start with A. If the input is having only one like D3 it is not considerd as different and not to written to the Output. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
mflax,
Your example is not sufficient for us to understand your logic. ( I suppose there are some people with me )
If you could elaborate or post a different example, that would be great. |
|
Back to top |
|
|
mflax
New User
Joined: 01 Sep 2006 Posts: 17 Location: Delhi
|
|
|
|
Quote: |
I still do not understand. The only logic I can see it read file, write file, do it six times and stop.
Is that what you want? |
Okie, I try restating it in a better way.
One record in the I/p file is having many fields. I need to check for two of them. (lets say one record is a combination of field F1, F2, F3 & F4.
Now for all the records having similar value of F1, if value of F3 is same across then it goes to one file else other file. when checking for similarity of F3, 0 is exception and not considered different to any number.
I havent kept values of F2 & F4 in the example.
INPUT
A 1
A 1
A 1
A 2 (for all the recs of F1=A, F3 is not same across)
B 1
B 2 (for all the recs of F1=B, F3 is not same across)
C 1
C 1 (for all the recs of F1=C, F3 is same across)
D 3
D 0 (for all the recs of F1=D, F3 is not same across but 0 is exception)
E 9
E 0 (for all the recs of F1=E, F3 is not same across but 0 is exception)
So F1= A & F1=B goes one place, C D E goes another. |
|
Back to top |
|
|
mflax
New User
Joined: 01 Sep 2006 Posts: 17 Location: Delhi
|
|
|
|
Quote: |
Wht I understtod from his I/P and O/P is:
He wants to write output when there are different second record fields like a 1 , a 2 so write all the records start with A. If the input is having only one like D3 it is not considerd as different and not to written to the Output. |
This is SHE, not HE |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
Hi !
You say that Your file is composed of these records
a 1
a 1
a 1
a 2
and so on
I think that we all agree on saying that
f1 = a f2 = 1
then You start talking about f3 and f4
Now I start loosing You and Your way of describing things ...
also in Your first post You speak about differences
different from what ??
what are the two terms of the comparison
I might be dumb but I do not understand the logic
regards
e.s |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
Hi !
I just got some light ...
Quote: |
INPUT
A 1
A 1
A 1
A 2
B 1
B 2
C 1
C 1
D 3
D 0
E 9
E 0
|
The gentleman means
the first column is the key
write to file number 1 all the records where the second column is 0
---- /d 0/e 0/
write to file number 1 all the records where there is a single occurrence of the key ( because ... there is nothing to compare with)
---- /e 9/d 3/
write to file number 1 all the records where the second column has the same value for all the occurences of the same key
---- /c 1/c 1/
write to file number 2 all the records where for the same key there are different values of the second column
---- /a 1/a 1/a 1/a 2/
HOMEWORK AGAIN
regards
e.s |
|
Back to top |
|
|
mflax
New User
Joined: 01 Sep 2006 Posts: 17 Location: Delhi
|
|
|
|
Quote: |
I think that we all agree on saying that
f1 = a f2 = 1
then You start talking about f3 and f4
Now I start loosing You and Your way of describing things ... |
Sir, I am sorry to for the cofusion. but did u miss this line in my post earlier.
"I havent kept values of F2 & F4 in the example. "
Quote: |
write to file number 1 all the records where the second column is 0 |
No. record having 0 doesnt come in comparison, this record goes in the file where other record for that key is going.
Quote: |
write to file number 1 all the records where there is a single occurrence of the key ( because ... there is nothing to compare with) |
Yepp.
Quote: |
write to file number 1 all the records where the second column has the same value for all the occurences of the same key |
Yepp.
Quote: |
write to file number 2 all the records where for the same key there are different values of the second column |
Yepp.
Means what. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
It would be good if you start over with a more clear definition of your requirement. Do not use F1 and A and such. Use something that represents what is being processed - Order Items, or People, or whatever.
Make sure to have a good sample of the input and exactly what the output should be. Don't put anything extra in and please don't leave anything out. Whatever you post, it must demonstrate the rules you need to implement. It is sometimes tough to guess the rules from data - especially if there is data that doesn't demonstrate the "rules".
This
Quote: |
Quote:
HOMEWORK AGAIN
Means what. |
is because many students post class problems in the forums and the way this was presented it looks more like a school problem than a business requirement. |
|
Back to top |
|
|
mflax
New User
Joined: 01 Sep 2006 Posts: 17 Location: Delhi
|
|
|
|
Hi Dick, I try to make it more sensible. File is having records for Acct Numbers where there can be multiple records for a single Acct #.
Each Acct# is assigned to a name and I have to filter out all records for such Acct# which is assigned to more than one Name.
Exception here are the "0000" which doesnt mean Acct # is assign to a different person.
Thus from the file below, record for Acct# 1111 goes into filtering, others goes into a different file.
Code: |
Input
Acct# Acct Name
1111 John
1111 John
1111 John
1111 Dave
2222 Dick
2222 Dick
3333 Mflax
3333 0000 |
Please tell me, if it requires more clarity. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If i understand the requirement, i believe this is a better start, but i still have a question.
How many records of the 1111 Acct# should be in the output file (1, 2. or 4)? What is the maximum number of names a particular Acct might have?
For starters, your input needs to be in sequence by Acct# and Name.
If you write code that will read the Acct#/Name file, you could define an array in working-storage that has enough entries to handle the maximum number of names for one acct.
As each record is read, the Acct# is compared to the previous Acct#. If it the same as the previous, the name would be moved to the next entry in the array. If the Name is 0000, skip the record.
If the Acct# read is not the same as the previous, start at the brginning of the array check if any different names have been moved into the array for this Acct (i.e. more than one). If there is more than one name, start at the beginning of the array again and write the needed info to the "filtering" file - what is needed will depend on the answer to the question at the start of this reply. After each "set" is written to the output file, the array needs to be cleared for the next set.
Be sure to process the last set when end-of-file is reached. There may be a set in the array that needs to be written or if there is only one entry, it would be skipped.
Good luck |
|
Back to top |
|
|
mflax
New User
Joined: 01 Sep 2006 Posts: 17 Location: Delhi
|
|
|
|
Thank You so much Dick.
The problem I didnt go with array, was not being sure of number of entries for a perticular set of records for an Acct#. I found them a little tough to code anyway.
Wondering, Is there any other way, we can do this |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
mflax wrote: |
The problem I didnt go with array, was not being sure of number of entries for a perticular set of records for an Acct#. I found them a little tough to code anyway.
Wondering, Is there any other way, we can do this |
As for the number of entries, pick a number, make it big and every time you increment you subscript or counter or index, check it against the max value.
They, arrays, are very simple to code and easy to learn. Just picture each element as a cubby hole or file folder with a number on it. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
Just a thought - if you are going to work with computers for your career (doesn't really matter which platform(s)), arrays are a way of life. Bacically every application uses them in one way or another. Now is an excellent time to get familiar/comfortable with them.
If you begin to design/code, we can offer suggestions when you have questions. I'd suggest putting your thoughts on paper as some kind of diagram or flow-chart - a "picture" often is easier to "see" than words. With your diagram and some sample data (similar to what you posted originally - you will want some Acct#s that should be selected and some that should not), you could "play computer" and make sure your design will create the desired output.
If you have a couple of sets of data that in one case has the first Acct# selected and another that does not and sets of data where the last Acct# is selected and another where it is not, you will be ready to put your design into code and test it. This "play computer" data could also be your initial test data. Once the code tests correstly with your data, it is time to try a run with some of the "real" data.
There are other ways to do this, but they take more work and will most likely use much more machine resources. Besides, someday you will be faced with a situation that must be done with an array (i.e. existing code that must be modified due to a production abend).
If you begin now, you have us to help with the learning |
|
Back to top |
|
|
mflax
New User
Joined: 01 Sep 2006 Posts: 17 Location: Delhi
|
|
|
|
William/Dick, Thanks agian. You are right, need to join the mosters.
Could you give me a simple example of array handling in COBOL, and I'll try my best to explore it in my situation. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Sorry to be "gone" for so long - until this afternoon, i've not been able to connect to the forum since Sunday night. . .
If you post some new data and result you want the program to create, we can offer some suggestions.
It would be good for you to start your program and create the input and output file definitions as well as creating an 01 in working-storage that will be the "anchor" for your array. Inside your 01, you might use an 05 that is an item that occurs n times where n would be the max number of names you will ever have for a given acct#. The field would be as long as the name-field in the input file.
Once you get the data and start-up code posted, we will proceed from there |
|
Back to top |
|
|
|