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

How to fetch the records based on current date in cobol


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

New User


Joined: 25 Jun 2006
Posts: 10
Location: Bangalore

PostPosted: Fri Aug 04, 2006 1:13 pm
Reply with quote

hi,
I was assigned a task in cobol which is related to date functions.
The task is to pick the records from previous quarter in the exististing file
depending up on the current date.

For example i am running the program in August then the program has to fetch records
from april,may,june months.If i run the program in jan 2007 then it has to fetch records from oct,nov,dec of 2006.


Thanq
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Fri Aug 04, 2006 4:03 pm
Reply with quote

Mercy,
Make a logic in the program such that when the current date is read ,the previous qtr date for the current date are assigned to the working-storage date fields.
If those working storage date field is matched with the date field of the record read from the file then move it to the output file.

Thanks,
Muthuvel.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Aug 05, 2006 7:53 pm
Reply with quote

Hi Mercy,

You can try something like this:
Code:

01  QTR-TBL-VALS.
    05  1ST-QTR-VALS.
        10  1ST-Q-NBR      PIC S99 VALUE +01 COMP.
        10  1ST-Q-ST-MM    PIC XX VALUE '01'.
        10  1ST-Q-EN-MM    PIC XX VALUE '03'.
    05  2ND-QTR-VALS.
         .
         .  repeat for each qtr
         .
01  QTR-TBL   REDEFINES QTR-TBL-VALS.
    05  QTR-ENTRY  OCCURS 4 TIMES
        10  QTR-NBR      PIC S99 COMP.
        10  QTR-ST-MM    PIC XX.
        10  QTR-EN-MM    PIC XX.

In the PD scan the QTR-TBL. If the run date falls between the start and end month of the table entry, compute the subscript value by subtracting 1 from the QTR-NBR. If the result is zero move 4 to the subscript.

Now use the subscript to access the start and end dates for the QTR you have to process.

I may have missed some exceptions, etc. but it should give you a lead to follow.

HTH
Back to top
View user's profile Send private message
mercy
Warnings : 1

New User


Joined: 25 Jun 2006
Posts: 10
Location: Bangalore

PostPosted: Sun Aug 06, 2006 7:45 pm
Reply with quote

Hi,
Thanq very much for ur reply.But i didnt get it properly as i am very new to mainframes.i need some more explanation.

mercy
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Mon Aug 07, 2006 2:03 am
Reply with quote

Quote:
i need some more explanation.

Explanation on what ?

OK... I assume there would be a DATE field on I/p file corresponding to every record, whwer you would compare and fetch the record and write to O/p file. Lets say DATE Field in I/p file is in YYYYMMDD format and starts from position 11 up to length 8.

Now see how can we make simple things comlicated icon_lol.gif

Code:
01 WS-DATE.
   05 WS-YYYY   PIC X(4).
   05 WS-MM   PIC X(2).
   05 WS-DD   PIC X(2).

01 WS-IN-REC.
   05 WS-IN-KEY   PIC........    X(10).
   05 WS-IN-YYYY   PIC X(8).
   05 WS-IN-MM   PIC X(2).
   05 WS-IN-DD   PIC X(2).
   05 WS-IN-REST   PIC........  X(62).

ACCEPT WS-DATE FROM DATE YYYYMMDD.

EVALUATE WS-MM.
   WHEN '01' OR '02' OR '03'
      MOVE '10' TO WS-MIN-TEMP
      MOVE '12' TO WS-MAX-TEMP
      SET SAME-YEAR TO FALSE.
   WHEN '04' OR '05' OR '06'
      MOVE '01' TO WS-MIN-TEMP
      MOVE '03' TO WS-MAX-TEMP
   WHEN '07' OR '08' OR '09'
      MOVE '04' TO WS-MIN-TEMP
      MOVE '06' TO WS-MAX-TEMP
   WHEN '10' OR '11' OR '12'
      MOVE '07' TO WS-MIN-TEMP
      MOVE '09' TO WS-MAX-TEMP
   WHEN OTHERS
      DISPLAY 'INVALID DATE... MONTH IS NOT BETWEEN 01 AND 12'
END-EVALUATE.

READ I/P FILE INTO WS-IN-REC
UNTIL END-OF-FILE.

PERFORM PROCESS UNTIL END-OF-FILE.

PROCESS.
   IF SAME-YEAR.
      IF WS-IN-YYYY = WS-YYYY.
         IF WS-IN-MM <= WS-MIN-TEMP OR
             WS-IN-MM <= WS-MIN-TEMP
            DISPLAY 'GOTCHA... OUTPUT RECORD'
         END-IF
      END-IF
   ELSE
      IF WS-IN-YYYY +1 = WS-YYYY
         IF WS-IN-MM <= WS-MIN-TEMP OR
             WS-IN-MM <= WS-MIN-TEMP
            DISPLAY 'GOTCHA... OUTPUT RECORD'
         END-IF
      END-IF
   END-IF.
EXIT.


If you I/p date is not in YYYYMMDD Format, a little modification would do.
Back to top
View user's profile Send private message
mercy
Warnings : 1

New User


Joined: 25 Jun 2006
Posts: 10
Location: Bangalore

PostPosted: Tue Aug 08, 2006 11:37 am
Reply with quote

Hi Priyesh.agarwal,

I have received ur explanation.Thanq very much for ur reply.As I am very new to Mainframes I need this much of explanation.Aby way thanx a lot.


Regards,
Mercy
Back to top
View user's profile Send private message
mercy
Warnings : 1

New User


Joined: 25 Jun 2006
Posts: 10
Location: Bangalore

PostPosted: Fri Aug 11, 2006 9:25 am
Reply with quote

Hi,
In the above can anybody tell me how can i increment year by 1 as it is pic x(8) field.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Aug 11, 2006 5:07 pm
Reply with quote

Hi Mercy,

Priyesh probably meant pix x(4) for the in-year. not pic x(8).
You can change all the pic x date fields to pic 9 to allow math to be performed.
Back to top
View user's profile Send private message
Archana_MF

New User


Joined: 21 Jul 2006
Posts: 49
Location: California

PostPosted: Sat Aug 19, 2006 2:47 am
Reply with quote

Hi,

For the Code Posted by Priyesh, I feel Mercy will get the records for all the months less than the current date.
For Ex:
If Mercy Ran his program on 200708 :
I will follow as per Priyesh code

Current Date : "200708"
INPUT REC DATE : "200703"
I am guessing he doesn't want this record to be pulled as it will not fall into the quarter condition

EVALUATE WS-MM.
WHEN '07' OR '08' OR '09' True
MOVE '04' TO WS-MIN-TEMP '04'
MOVE '06' TO WS-MAX-TEMP '06'
PERFORM PROCESS UNTIL END-OF-FILE.

PROCESS.
IF SAME-YEAR. TRUE again
IF WS-IN-YYYY = WS-YYYY. True again
IF WS-IN-MM <= WS-MIN-TEMP OR 03 < = 04 (True) OR
WS-IN-MM <= WS-MIN-TEMP(u mean WS-MAX-TEMP) 03 < = 06 (False)
DISPLAY 'GOTCHA... OUTPUT RECORD' <== The 200703 record is pulled

Also please check for " IF not SAME-YEAR " Logic too.
the Evaluate Logic will not work for 200702 & 200703 run months

If ur still looking for Cobol Code. See the attachment but my suggestion is Use Easytreive or SULP004T or some SORT utlities for working with such conditions. go thru the IBM Utilities Forum for more details.
I know SULP004T utility which can be used to get the records matching a condition, u can give the Dates in the coondition.

The attached logic is to get only the records falling in between the Past Quarter Close to Current Year.[right][/right]
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Sun Aug 27, 2006 4:13 am
Reply with quote

oops... I missed this thread completely in my previous visits...

Well, Archana... Thanks a lot for such a nice debugging of my screwed up code... it always happens with copy paste... atleast with me icon_mad.gif

Please consider below code for what I meant...

Code:
PROCESS.
   IF SAME-YEAR.
      IF WS-IN-YYYY = WS-YYYY.
         IF WS-IN-MM >= WS-MIN-TEMP AND
             WS-IN-MM <= WS-MAX-TEMP
            DISPLAY 'GOTCHA... OUTPUT RECORD'
         END-IF
      END-IF
   ELSE
      IF WS-IN-YYYY +1 = WS-YYYY
         IF WS-IN-MM >= WS-MIN-TEMP AND
             WS-IN-MM <= WS-MAX-TEMP
            DISPLAY 'GOTCHA... OUTPUT RECORD'
         END-IF
      END-IF
   END-IF.
EXIT.


And Jack... Thank You for pointing variable length... you are right there... as always... icon_smile.gif

P.S. Users posting their questions on Testing the code should take a note here on Archana's Debugging.

Regards,
Priyesh.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top