MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

internal table logic needed

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Thu May 10, 2007 4:33 am    Post subject: internal table logic needed Reply with quote

I am using a CURSOR in my program and i am fetching records one by one and the way they are retreived is :
Code:

2007-01-01   ABC    100
2007-01-01   ABC    -50   
2007-01-01   ABC    200
2007-01-01   DEF    -10
2007-01-01   DEF    -20
2007-01-02   ABC      3
2007-01-02   ABC      6
2007-01-02   ABC      9
2007-01-02   ABC     12    
2007-01-02   ABC      1   
2007-01-02   ABC     -1
2007-01-02   ABC    -12
2007-01-02   ABC     20
2007-01-02   ABC     30
2007-01-02   ABC     -9
2007-01-02   PQR    100
2007-05-01   XYZ      1
2007-05-01   XYZ      2
2007-05-01   XYZ      3   
2007-05-01   XYZ     -6

I want to generate a report in this fashion:
Code:

DATE         DEPT   COUNT   PLUS     MINUS      DIFFERENCE       
                                                                 
2007-01-01   ABC        3    300       -50             250       
2007-01-01   DEF        2      0       -30             -30       
2007-01-02   ABC       10     81       -21              60       
2007-01-02   PQR        1    100         0             100       
2007-05-01   XYZ        4      6        -6               0       
                  -------   ----    ------    ------------       
TOTAL                 20     486      -105             381       

The date is sorted and then the dept while fetching as per the cursor ,Count is the number of records which has the same category ,plus indicates positive amount, minus indicates negative amount and difference is plus + minus.I want to make use of internal table (array) COBOL,please let me know how can i achieve it ?
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Thu May 10, 2007 5:09 am    Post subject: Reply with quote

sort your data in the required sequence, load it to the table and walk through the table accumulating your values as required and writing oout as required.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Thu May 10, 2007 5:38 am    Post subject: Reply with quote

I have been sort of a butt head last couple of days, so I will be nice.

yadav2005,

this unfortunately is a poor example of such a requirement. The data is already sorted:
Quote:
The date is sorted and then the dept while fetching as per the cursor

I assume you have an ORDER BY clause.

you only need 2 structures; DATE-DEPT and TOTALS.

you have an unknown number of DATE-DEPTs, which means you might fill your table. That means complex logic to handle dumping the table
outputing - and trying to keep track of what you printed last, where, are we at top of page etc....... -
initializing and starting again. really unnecessary since the input is sorted in report sequence.

and if you tell me ok, I just want the logic in case it was not sorted and I would tell you - Sort it!

In fact, DFSORT has a 'Report Writer' capability, you could code the ICETool Parms quicker than you could a program.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12382
Topics: 75
Location: San Jose

PostPosted: Thu May 10, 2007 5:43 am    Post subject: Reply with quote

yadav2005,


1. You don't need an Internal table.
Code:

01 ws-prev-key.
   05 ws-prev-date         pic x(10).
   05 ws-prev-dept         pic x(03).

01 ws-plus-qty             pic s9(09) comp-3.
01 ws-neg-qty              pic s9(09) comp-3.
01 ws-difference           pic s9(09) comp-3.

check for the key change and sum up of the values.

2. you can do all this in the sql itself

Code:

SELECT DATE_COL
      ,DEPT
      ,COUNT(*)
      ,SUM(CASE WHEN QTY < 0 THEN INT(0) ELSE QTY END)
      ,SUM(CASE WHEN QTY > 0 THEN INT(0) ELSE QTY END)
      ,SUM(QTY)
 FROM TABLE
GROUP BY DATE_COL
        ,DEPT



Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Thu May 10, 2007 5:52 am    Post subject: Reply with quote

Kolusu,

my, but you are quick. excellent solution.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Thu May 10, 2007 6:08 am    Post subject: Reply with quote

Kolusu,

Great Answer and it is so simple .But i want to implement the logic by using internal table , can u please help me out as the requirement is to implement by using Internal table.Thanks for your help.
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Thu May 10, 2007 6:11 am    Post subject: Reply with quote

change the requirement if it is less efficient. Why MUST you do it that way - because whoever wrote your spec didn't know any better? Just tell him there is a better way.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group