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

Logic for this file handling


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Fri Apr 13, 2007 8:41 am
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Apr 13, 2007 9:49 am
Reply with quote

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
View user's profile Send private message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Fri Apr 13, 2007 10:04 am
Reply with quote

"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
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Fri Apr 13, 2007 10:19 am
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Apr 13, 2007 10:21 am
Reply with 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?
Back to top
View user's profile Send private message
Devzee

Active Member


Joined: 20 Jan 2007
Posts: 684
Location: Hollywood

PostPosted: Fri Apr 13, 2007 11:03 am
Reply with quote

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
View user's profile Send private message
mahi

New User


Joined: 04 Apr 2006
Posts: 86
Location: Hyderabad

PostPosted: Fri Apr 13, 2007 11:45 am
Reply with 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.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Apr 13, 2007 5:43 pm
Reply with quote

mflax,
Your example is not sufficient for us to understand your logic. ( I suppose there are some people with me icon_smile.gif )
If you could elaborate or post a different example, that would be great.
Back to top
View user's profile Send private message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Sun Apr 15, 2007 12:13 am
Reply with quote

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?

icon_sad.gif icon_sad.gif

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
View user's profile Send private message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Sun Apr 15, 2007 12:32 am
Reply with quote

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 icon_lol.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Sun Apr 15, 2007 12:32 am
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Sun Apr 15, 2007 12:44 am
Reply with quote

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
View user's profile Send private message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Sun Apr 15, 2007 1:34 am
Reply with quote

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.

Quote:
HOMEWORK AGAIN
Means what.
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: Sun Apr 15, 2007 2:04 am
Reply with quote

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
View user's profile Send private message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Sun Apr 15, 2007 2:43 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Sun Apr 15, 2007 3:10 pm
Reply with quote

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 icon_smile.gif
Back to top
View user's profile Send private message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Sun Apr 15, 2007 9:53 pm
Reply with quote

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 icon_question.gif
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sun Apr 15, 2007 10:14 pm
Reply with quote

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 icon_question.gif
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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Sun Apr 15, 2007 11:26 pm
Reply with quote

You're welcome icon_smile.gif

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 icon_smile.gif
Back to top
View user's profile Send private message
mflax

New User


Joined: 01 Sep 2006
Posts: 17
Location: Delhi

PostPosted: Mon Apr 16, 2007 11:25 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Apr 18, 2007 12:47 am
Reply with quote

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 icon_smile.gif
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
No new posts Need help for File Aid JCL to extract... Compuware & Other Tools 23
Search our Forums:

Back to Top