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 

need to get the unique values through cobol pgm

 
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: Wed Mar 28, 2007 3:32 am    Post subject: need to get the unique values through cobol pgm Reply with quote

I have an input file which is having records in the fashion as below and the fields are Number,Name and Dept.
Code:

1   A   XXX
2   B   XXX
3   C   XXX
4   D   XXX
5   E   XXX
6   F   XXX
7   G   YYY
8   H   YYY
9   I   YYY

What i want in the output is all the depts as well as the input as it is:
Code:


DEPT
XXX
YYY

1   A   XXX
2   B   XXX
3   C   XXX
4   D   XXX
5   E   XXX
6   F   XXX
7   G   YYY
8   H   YYY
9   I   YYY
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Mar 28, 2007 4:05 am    Post subject: Reply with quote

yadav2005,

1. Define an Internal table to hold all the dept values
2. Read the file
3. search the internal for the dept . if found continue else load the dept into the internal table
4. repeat step 2 & 3 till the end of the file
5. write out all the depts from the internal table

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


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Wed Mar 28, 2007 4:35 am    Post subject: Reply with quote

Kolusu,

Thanks for your reply at the earliest.

There can be only two possible values for the dept which are XXX and YYY.Can there be some more simple logic instead of having an array and then using Search the internal table for the dept.I mean can we have a very simple code which will solve the purpose.

If possible can you please post a sample code which will make of the steps:
Code:

3. search the internal for the dept . if found continue else load the dept into the internal table
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Mar 28, 2007 7:28 am    Post subject: Reply with quote

yadav2005,
Quote:

There can be only two possible values for the dept which are XXX and YYY.Can there be some more simple logic instead of having an array and then using Search the internal table for the dept.I mean can we have a very simple code which will solve the purpose.


If you are sure that there are only 2 values then just 2 switches for each dept. If found just move 'y' to the switch and later on when writing the output check the switch and if it is 'y' then write that out.

The array concept comes into picture only when there are unknown no: of depts.check this

Code:

01  W-DEPTS-TABLE.                                     
    05    W-DEPTS-TBL    OCCURS 0 TO 30000 TIMES       
                        DEPENDING ON A-DEPTS-WRITTEN   
                        INDEXED BY W-DEPTS-NDX.       
        10 W-DEPTS-TBL-REC     PIC X(03) VALUE SPACES.

SEARCH W-DEPTS-TBL                                         
    AT END                                                 
       MOVE read-dept-from-file     TO W-DEPTS-TBL-REC(W-DEPTS-NDX)
    WHEN W-DEPTS-TBL-REC(W-DEPTS-NDX) = W-DEPTS-KEY       
       CONTINUE                                           
END-SEARCH                                                 


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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