View previous topic :: View next topic |
Author |
Message |
yadav2005 Intermediate
Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Wed Mar 28, 2007 3:32 am Post subject: need to get the unique values through cobol pgm |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Wed Mar 28, 2007 4:05 am Post subject: |
|
|
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 |
|
|
yadav2005 Intermediate
Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Wed Mar 28, 2007 4:35 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Wed Mar 28, 2007 7:28 am Post subject: |
|
|
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 |
|
|
|
|