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
 

 

Removing duplicates before write to output file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Removing duplicates before write to output file
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    Post subject: Reply to: Removing duplicates before write to output file
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORTJOIN - Copy Matched and Unmatched... Steve Ironmonger DFSORT/ICETOOL 5 Tue Jan 17, 2017 4:26 pm
No new posts Incorrect output when trying to add n... monica1 PL/I & Assembler 10 Fri Jan 13, 2017 5:02 pm
No new posts Copy RECFM =VB TO FB file with RECL =... sahil41352 DFSORT/ICETOOL 3 Wed Dec 28, 2016 11:29 pm
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm


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