I’m working on an assignment and I’ve sort of hit a wall. I’m going to make the question very generic as I’m mainly looking for some tips and a shove in the right direction. I am to take two input files who’s records are in no particular sequence, sort both of them into one output file while excluding certain entries. So far I’ve figured out that I need to code the sort statements like:
SORT ORDERS-FILE-SORT
ON ASCENDING REQUEST-DATE-S
ASCENDING CUST-NUMBER-S
ASCENDING CUST-ORDER-NUMBER-S
ASCENDING PART-NUMBER-S
USING INPUT PROCEDURE 200-SORT-AND-MERGE
GIVING ORDERS-OUT
I haven’t figured out what to code in the input procedure.
P.S. There is one other thing I haven’t figured out. This is kind of a side notE and I don’t want anything specific with this particular question, just a tip. We’re supposed to exclude records with a REQUEST-DATE that is not within 6 months. At first I was thinking it was as simple as:
01 WS-DATE
05 RUN-YEAR PIC 99.
05 RUN-MONTH PIC 99.
05 RUN-DAY PIC 99.
300-TEST-DATE
ADD 6 TO RUN-MONTH
IF REQUEST-DATE > WS-DATE
However in the event that adding 6 to the month causes it to go over 12 this will not work. I’ve been getting a headache over this one. Thanks for any help I will really appreciate it.
Check out this link. It gives several examples illustrating how to use the COBOL sort verb. This link should give you plenty of hints. As for testing date ranges, consider doing it within the INPUT PROCEDURE. See the MaleSort.cbl example from the link where records are included/excluded based on having a specific gender code.
Adding 6 months to a date can be a bit of a trick. There are a number of intrinsic date manipulation functions in COBOL but using them may be a bit beyond where you are at right now, but have a look at: date-of-integer and integer-of-date and maybe dateval. On the other hand, you might find it just a easy to do the arithmetic yourself.
If you choose to do your own date math, try something along the lines of:
ADD 6 TO RUN-MONTH DIVIDE RUN-MONTH BY 12 GIVING WS-YEAR-ROLLOVER REMAINDER IN RUN-MONTH END-DIVIDE COMPUTE RUN-YEAR = RUN-YEAR + WS-YEAR-ROLLOVERSince your RUN-YEAR is only 2 digits long, you might have to deal with century rollover if WS-DATE is prior to year 2000 (I can’t believe that anybody would still be using 2 digit dates in this day and age). Another thing to watch out for are the number of days – August 31 plus 6 months gets you to… February which only has 28 or 29 days.
Have fun.