Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Logic needed on Arrays
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
mehar asuri

New User


Joined: 10 May 2008
Posts: 8
Location: Mumbai

PostPosted: Mon May 19, 2008 8:57 pm    Post subject: Logic needed on Arrays
Reply with quote

Hi All,

My input file is a array of 100 occurences. I have 100 different products repeated many times in the table(Input File). I need to get the unique products into the output table which is defined as 100 occurences.

1) I dont want to hard code all the products in the program
2) The data is not sorted in a table.
3) The index is used in both the tables.

Ex:

Input file:
1st Record - 5 occurences
Products Count
AA 3
AA 4
AA 6
BB 1
BB 1

Output file:
1ST Record - 2 Occurance
Products Count Unique product codes
AA 13
BB 2

Can anyone helps me out to get the logic ....


Thanks.
Rajiv
Back to top
View user's profile Send private message

dick scherrer

Site Director


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

PostPosted: Mon May 19, 2008 9:06 pm    Post subject:
Reply with quote

Hello Rajiv and welcome to the forums,

Quote:
1st Record - 5 occurences
What does this mean? What you posted looks like 5 records. . . There are no occurrances. . .

So far, i do not know why arrays are referred to icon_confused.gif

To get what i believe you want as output (summary totals by product), you could read the input, "release" the records to an internal sort (sorting by product code), and summarize the totals as the records are "returned" from the sort.

Please clarify if i have misunderstood your requirement.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon May 19, 2008 9:23 pm    Post subject:
Reply with quote

Start with an empty table, as you read a product check to see if it is the table then just add to the count, if it is not in the table add it to the table with the count.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon May 19, 2008 9:28 pm    Post subject:
Reply with quote

Hello,

Quote:
if it is not in the table add it to the table with the count.
I suspect that the "output" is needed in product sequence. Adding it to the table "in sequence" will take a bit more work (if indeed, a table/array is needed at all).
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon May 19, 2008 9:30 pm    Post subject:
Reply with quote

A table with 100 occurences can be sort quickly.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Mon May 19, 2008 9:35 pm    Post subject:
Reply with quote

Hello,

Quote:
A table with 100 occurences can be sort quickly.
Yup, sure can; if a table is needed at all icon_smile.gif

It sounds like a simple read/sort the input and summarize. Still not sure that an array/table is needed. Possibly there is something i misunderstand icon_confused.gif
Back to top
View user's profile Send private message
mehar asuri

New User


Joined: 10 May 2008
Posts: 8
Location: Mumbai

PostPosted: Tue May 20, 2008 5:31 pm    Post subject: Reply to: Logic needed on Arrays
Reply with quote

Hi Craq, Dick,

Appreciate for your quick response.

Quote:
To get what i believe you want as output (summary totals by product), you could read the input, "release" the records to an internal sort (sorting by product code), and summarize the totals as the records are "returned" from the sort.


yes correct . but i need this into a output table.

For Ex:

Input Table
1st Record -
Product Count
AA 10
AA 12
CC 05
CC 10
AA 10
.
.
.
till Maximum 100 occurances

Similarly the second record also have the no. of occurences.

Output table:
1st record
Product Count
AA 32
CC 15

Which is the best method to do it......

[/quote]Start with an empty table, as you read a product check to see if it is the table then just add to the count, if it is not in the table add it to the table with the count.

How this logic works ? can you show some sample code..
Quote:
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue May 20, 2008 11:28 pm    Post subject:
Reply with quote

Hi Rajiv,

Questions:

Each rec contains a variable series of Prod/Count pairs, what is the max allowed in each rec?

If the # of variable pairs varies from rec to rec, are the recs variable length or just padded w/spaces.

What are the lengths of of the variables?

How many input recs do you expect - max?
Back to top
View user's profile Send private message
mehar asuri

New User


Joined: 10 May 2008
Posts: 8
Location: Mumbai

PostPosted: Wed May 21, 2008 10:35 am    Post subject: Reply to: Logic needed on Arrays
Reply with quote

Each rec contains a variable series of Prod/Count pairs, what is the max allowed in each rec?
Max 100 in each record

If the # of variable pairs varies from rec to rec, are the recs variable length or just padded w/spaces.
1) input variable in length
2) output is fixed in length padded with spaces

What are the lengths of of the variables?
2 and 4 bytes
How many input recs do you expect - max?
Around 90000 records
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed May 21, 2008 9:04 pm    Post subject:
Reply with quote

Rajiv,

I should have included this ques with the others:

What is the range of the product-variable values (e.g. lowest/highest val)? Are they contiguous? If you can, use actual values.
Back to top
View user's profile Send private message
mehar asuri

New User


Joined: 10 May 2008
Posts: 8
Location: Mumbai

PostPosted: Wed May 21, 2008 10:27 pm    Post subject: Reply to: Logic needed on Arrays
Reply with quote

lowest 1 highest around 40 ...Repeated many times in the table
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed May 21, 2008 11:17 pm    Post subject:
Reply with quote

...but the O/P table will never have more than 40 active occurences and each run of the pgm will produce one occurrence for each of the 40 (not 100) products and they will range from 01 to 40. Correct?

I'm trying to separate the "transaction" table from the "master" table. The trans table can contain 100 occurrences of the same product.
The mstr table can contain only one occurrence of each of the 40 products. Correct?
Back to top
View user's profile Send private message
mehar asuri

New User


Joined: 10 May 2008
Posts: 8
Location: Mumbai

PostPosted: Wed May 21, 2008 11:22 pm    Post subject: Reply to: Logic needed on Arrays
Reply with quote

Yes you are correct!!!!
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed May 21, 2008 11:55 pm    Post subject:
Reply with quote

Alleluia!!!!

Create your I/P rec description as a table w/100 occurances.
Create your O/P rec description as a table w/040 occurances.
read a rec
perform a loop until product = spaces (or whatever you use to indicate an empty product field) or sub > 100.

In the loop move the I/P product and add the I/P count (both subscripted by the sub) to the corresponing fields in the O/P rec subscripted by the count in the I/P rec.

At I/P EOF write your O/P rec, clean up and get out.

This is an overview of the central logic needed.

You can decide how to init the O/P table, construct the read loop, verify the I/P fields (crucial because you'll be using the product# as a subscript).

I probably forgot a few things, but this should get you started. If you get stuck show us what you've got and we'll continue from there.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu May 22, 2008 12:01 am    Post subject:
Reply with quote

Forgot. In the 1st loop mentioned in the prev post, add 1 to sub for each iteration.
Back to top
View user's profile Send private message
mehar asuri

New User


Joined: 10 May 2008
Posts: 8
Location: Mumbai

PostPosted: Thu May 22, 2008 5:47 pm    Post subject: Reply to: Logic needed on Arrays
Reply with quote

Thanks!! But How do I need to differentiate the products in the transaction table....

For Ex:
1ST record (transaction table)
AA,AA,AA, BB,BB....How to differentiate AA and BB to get the desired output results??
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu May 22, 2008 8:05 pm    Post subject:
Reply with quote

I'm assuming your rec layout is something like:

ppnnnn,ppnnnn,.... where pp is 01 - 40; nnnn the numeric product count.

You use the pp of the current occurrence of the I/P rec just read as the subscript into your O/P rec. For example, if pp = 23 and nnnn = 0036 the stmts:
Code:
MOVE IN-PP(IN-SUB)  TO OUT-SUB
ADD IN-NNNN(IN-SUB) TO OUT-NNNN(OUT-SUB)


result in the O/P count for product 23 to total 36, if the next I/P occurrence for prod 23 contained a count of 100, the O/P count resulting is 136. If the next occurrence of prod was 33 and the corresponding count was 14 those 2 same stmts would set the total of prod 33 to 14.
Back to top
View user's profile Send private message
mehar asuri

New User


Joined: 10 May 2008
Posts: 8
Location: Mumbai

PostPosted: Thu May 22, 2008 8:31 pm    Post subject: Reply to: Logic needed on Arrays
Reply with quote

Thanks...You mean to say..
Product Count
23 36 1st occurance
23 100 2nd occurance
33 14 3rd occurance

Output
23 136 1st occurance
33 14 2nd occurance

Am I correct....
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu May 22, 2008 9:33 pm    Post subject:
Reply with quote

That's correct.

One other thing to remind you:

Do the WRITE of the O/P as WRITE .... FROM. This allows you to create a WS rec description w/VALUEs for the prod number, then there's no need to MOVE it to the O/P rec.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu May 22, 2008 10:51 pm    Post subject:
Reply with quote

I just reread the O/P segment of your prev post. You said:
Quote:
Output
23 136 1st occurance
33 14 2nd occurance

The O/P rec will have as many occurrences as you have products (in one of your posts you mention 40). Given that, your 1st occurrence s/b 23rd occurrence; your 2nd occurrence s/b 33rd occurrence.

Remember the O/P table was constructed in a way to ease the placement of the transaction activity. There is no table search required, just a subscripted add.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Wildcard logic in COBOL dudenithy COBOL Programming 13 Thu Sep 01, 2016 7:36 pm
No new posts Help Needed with View Direct shailesh_do CA Products 2 Wed Jul 13, 2016 10:39 am
No new posts Sort Logic to extract data scorp_rahul23 DFSORT/ICETOOL 13 Tue Mar 01, 2016 1:22 am
No new posts Need a logic to validate the data in ... sandeep kumar302 COBOL Programming 17 Mon Feb 01, 2016 3:30 pm
No new posts Tricky sort logic required pgopi92 DFSORT/ICETOOL 3 Mon Jan 25, 2016 3:29 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us