Start Statement

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
AhmedHamesh
Member
Posts: 3
Joined: Thu Sep 04, 2014 5:16 pm

Start Statement

Post by AhmedHamesh » Thu Sep 04, 2014 5:28 pm

I was wondering how you go about using the Start statement in COBOL to position a file to find records in an input file that are duplicates/copies.

Im not sure if I am getting the syntax right. I'm trying to find all the duplicate records in an input file. I've tried several different ways, including putting an if statement, but nothing works

...also, I can't post code since the code is for an entity.

Any help appreciated

NicC
Active Member
Posts: 650
Joined: Sun Jul 24, 2011 5:27 pm
Location: Down on the pig farm

Post by NicC » Thu Sep 04, 2014 11:35 pm

Of course you can post some code - you can change anything that could identify your customer by using made up names and data. Without the code we have no real idea of what you are doing.
Regards
Nic

AhmedHamesh
Member
Posts: 3
Joined: Thu Sep 04, 2014 5:16 pm

Post by AhmedHamesh » Sun Sep 07, 2014 1:05 am

Ok I'll just make up code of what I want to do...

I'm trying to read in an input file. Ill read the input file, and be looking for duplicate values, in the input file, of what the current pointer is. Ill read it with a current, previous, and next pointer, like a linked list. Then keep doing this until I've read the whole file.

However, I cant use JCL or a sort. i have to use the start statement

This is what im trying to do:

Procedure:

Perform until eof
Move 1000 to current-pointer
Start input-file less than current-pointer
Read input-file
End-read

Start input-file equal to current-pointer
Read input-file
End-read
If previous-pointer or next-pointer equal to current-pointer
display "copy found"
End-if
end-perform

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Sun Sep 07, 2014 4:24 am

This is very confusing. You can only use START on a VSAM KSDS (which can have no duplicate keys) or on a VSAM Alternate Index file.

Never, and I repeat, NEVER, read the same record more than once. Your program will run like a dog with no legs.

If you are not reading an Alternate Index, forget START. If you are, tell us.

If you are reading an ordinary file, is it in key order? If it is, it is easy, you just read, store the key, read the next record, compare to the stored key, continue until end.

If it is not in key order, put it in key order. If for some really, really weird reason you are unable to use an external SORT (with which you can already identify duplicate keys anyway) then use the COBOL SORT verb to sort the file internally, then proceed as above. If you are not allowed to do even that, then you have to code your own sort and proceed as above.

AhmedHamesh
Member
Posts: 3
Joined: Thu Sep 04, 2014 5:16 pm

Post by AhmedHamesh » Mon Sep 08, 2014 8:09 am

Yes it is in key order. How do I go about writing the syntax for storing the key and then comparing to it? Nothing seems to work for me...

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Mon Sep 08, 2014 11:19 am

Code: Select all

Open Files
Priming Read
Loop til Eof
    If save key equal to key
        do duplicate stuff
    end
    save key
    read next
    loop
Priming Read
    read next

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others