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

Removing duplicates before write to output file


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

New User


Joined: 20 May 2010
Posts: 75
Location: India

PostPosted: Wed Jul 07, 2010 11:18 am
Reply with quote

Hello

I have a table like this
05 ws-var1 pic x(8) occurs 10 times
aaaaaaaabbbbbbbbaaaaaaaacccccccccbbbbbbbb


am expecting a result like this

aaaaaaaaa 2
bbbbbbbbb 2
cccccccccc 1
I want to get the count of the occurences from the table and to write to a out put file

i was trying to do like this

Code:
PROCESS-PARA.                                               
     PERFORM VARYING WS-INDEX  FROM 1 BY 1 UNTIL           
                 WS-CNT = 50 OR WS-VAR1(WS-INDEX) = SPACES 
     ADD +1 TO WS-CNT                                       
     MOVE 1 TO WS-INDEX1                                   
     PERFORM VARYING WS-INDEX1 FROM 1 BY 1 UNTIL           
               WS-CNT2 =  50 OR WS-VAR1(WS-INDEX1) = SPACES
     ADD +1 TO WS-CNT2                                     
      DISPLAY WS-VAR1(WS-INDEX) '  = ' WS-VAR1(WS-INDEX1)   
     IF  WS-VAR1(WS-INDEX) = WS-VAR1(WS-INDEX1)             
     COMPUTE WS-COUNT = WS-COUNT + 1                       
     END-IF                                                 
     END-PERFORM                                           
     MOVE WS-VAR1(WS-INDEX) TO WS-TAG                       
     PERFORM WRITE-PARA THRU WRITE-EXIT                     
     END-PERFORM.                                           



but am getting duplicates as
aaaaaaaaa 2
bbbbbbbbb 2
aaaaaaaaa 2
bbbbbbbbb 2
cccccccccc 1

please advise how i can overcome this
Back to top
View user's profile Send private message
lakshmikondur

New User


Joined: 05 Jan 2006
Posts: 9
Location: hyderabad

PostPosted: Wed Jul 07, 2010 12:40 pm
Reply with quote

I believe it will work with the higlited conditon.Please try

Note :I have not tested his one as i don't have the mainframe access.


PROCESS-PARA.
PERFORM VARYING WS-INDEX FROM 1 BY 1 UNTIL
WS-CNT = 50 OR WS-VAR1(WS-INDEX) = SPACES
ADD +1 TO WS-CNT
MOVE 1 TO S-INDEX1
PERFORM VARYING S-INDEX1 FROM 1 BY 1 UNTIL
S-CNT2 = 50 OR WS-VAR1(S-INDEX1) = SPACES
ADD +1 TO S-CNT2
DISPLAY WS-VAR1(WS-INDEX) ' = ' WS-VAR1(S-INDEX1)
IF S-VAR1(S-INDEX) = S-VAR1(S-INDEX1)
COMPUTE S-COUNT = S-COUNT + 1
END-IF
END-PERFORM
IF S-VAR1(S-INDEX) not = S-VAR1(S- INDEX1)
MOVE S-VAR1(S-INDEX) TO WS-TAG
PERFORM WRITE-PARA THRU WRITE-EXIT
END-IF
END-PERFORM.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jul 07, 2010 1:46 pm
Reply with quote

what is the 50 represent? you only have 8 occurances,
where did you get 50????? (don't answer, I can guess)

learn to code for the data defintions,
and not the one time values.

since your table/item description is:
05 ws-var1 pic x(8) occurs 10 times

the ws-index and s-index are subscripts.

suggest you amend your naming conventions,
and use descriptive names like:
ws-sub1
ws-sub2

THE FOLLOWING IS UNTESTED, BUT THE RESULTS MAY BE A LITTLE MORE ACCURATE

Code:
MOVE ZERO TO DUP-COUNT

PERFORM VARYING WS-SUB1
        FROM 1
        BY   1
        UNTIL WS-SUB1 > 10
        PERFORM  VARYING WS-SUB2
                 FROM WS-SUB1 + 1
                 UNTIL WS-SUB2 > 9
            IF WS-VAR1(WS-SUB1) = SPACES
              OR
               WS-VAR1(WS-SUB2) = SPACES
            THEN
               CONTINUE
            ELSE
               IF WS-VAR1(WS-SUB1) = WS-VAR1(WS-SUB2)
               THEN
                  ADD 1 TO DUP-COUNT
                  MOVE SPACES TO WS-VAR1(WS-SUB2)
               END-IF
            END-IF
       END-PERFORM
       IF WS-VAR1(WS-SUB1) > SPACES
       THEN
          MOVE WS-VAR1(WS-SUB1) TO DISPLAY-VARIABLE
          MOVE DUP-COUNT        TO DISPLAY-DUPCOUNT
          PERFORM WRITE-PARAGRAPH
          MOVE ZERO             TO DUP-COUNT
       END-IF
END-PERFORM
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 Write line by line from two files DFSORT/ICETOOL 7
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top