View previous topic :: View next topic
|
Author |
Message |
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
Hi i need to convert date in format (say) 01/01/09 (dd/mm/yy) to
01/Jan/09 using array/table in cobol. If there is any other way to do this that will be additional advantage. |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
Back to top |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
actually i dont want to use date function . want to write a code for that |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
want to write a code for that |
Ok. Go for it
Quote: |
If there is any other way to do this that will be additional advantage |
If you clarify this, someone may have a suggestion. It is not clear what you are asking.
To reformat dates, you may need an array or a series of IFs. . . |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Rupesh,
Here's a copybook I use for date processing. I have a leap year routine laying around somewhere. If you're interested I'll take a look.
Code: |
1 /
*===============================================================
*================== END OF MOMTH TABLE ===================
*===============================================================
* NOTE: THIS IS A GENERALIZED TABLE TO BE USED FOR DATE *
* MANIPULATION. EACH ENTRY CONTAINS THE NAME OF THE *
* MONTH AND THE NUMBER OF DAYS IN EACH MONTH AND ITS *
* IMMEDIATE NEIGHBORS. THE JAN-PREV-EOM FIELD CON- *
* TAINS THE NUMBER OF DAYS IN THE PREVIOUS DECEMBER. *
* THE DEC-NEXT-EOM FIELD CONTAINS THE NUMBER OF DAYS *
* IN THE NEXT JANUARY. *
*
* IN LEAP YEARS THE USER MUST INCREMENT THE FOLLOWING *
* FIELDS BY ONE: *
* JAN-NEXT-EOM-VAL *
* FEB-EOM-VAL *
* MAR-PREV-EOM-VAL *
*===============================================================
01 END-OF-MONTH-VALUES.
*========================
05 JAN-VALUES.
10 JAN-NAME PIC X(009) VALUE
'JANUARY'.
10 JAN-EOM-VAL PIC 9(002) VALUE 31.
10 JAN-PREV-EOM-VAL PIC 9(002) VALUE 31.
10 JAN-NEXT-EOM-VAL PIC 9(002) VALUE 28.
05 FEB-VALUES.
10 FEB-NAME PIC X(009) VALUE
'FEBRUARY'.
10 FEB-EOM-VAL PIC 9(002) VALUE 28.
10 FEB-PREV-EOM-VAL PIC 9(002) VALUE 31.
10 FEB-NEXT-EOM-VAL PIC 9(002) VALUE 31.
05 MAR-VALUES.
10 MAR-NAME PIC X(009) VALUE
'MARCH'.
10 MAR-EOM-VAL PIC 9(002) VALUE 31.
10 MAR-PREV-EOM-VAL PIC 9(002) VALUE 28.
10 MAR-NEXT-EOM-VAL PIC 9(002) VALUE 30.
05 APR-VALUES.
10 APR-NAME PIC X(009) VALUE
'APRIL'.
10 APR-EOM-VAL PIC 9(002) VALUE 30.
10 APR-PREV-EOM-VAL PIC 9(002) VALUE 31.
10 APR-NEXT-EOM-VAL PIC 9(002) VALUE 31.
05 MAY-VALUES.
10 MAY-NAME PIC X(009) VALUE
'MAY'.
10 MAY-EOM-VAL PIC 9(002) VALUE 31.
10 MAY-PREV-EOM-VAL PIC 9(002) VALUE 30.
10 MAY-NEXT-EOM-VAL PIC 9(002) VALUE 30.
05 JUN-VALUES.
10 JUN-NAME PIC X(009) VALUE
'JUNE'.
10 JUN-EOM-VAL PIC 9(002) VALUE 30.
10 JUN-PREV-EOM-VAL PIC 9(002) VALUE 31.
10 JUN-NEXT-EOM-VAL PIC 9(002) VALUE 31.
05 JUL-VALUES.
10 JUL-NAME PIC X(009) VALUE
'JULY'.
10 JUL-EOM-VAL PIC 9(002) VALUE 31.
10 JUL-PREV-EOM-VAL PIC 9(002) VALUE 30.
10 JUL-NEXT-EOM-VAL PIC 9(002) VALUE 31.
05 AUG-VALUES.
10 AUG-NAME PIC X(009) VALUE
'AUGUST'.
10 AUG-EOM-VAL PIC 9(002) VALUE 31.
10 AUG-PREV-EOM-VAL PIC 9(002) VALUE 31.
10 AUG-NEXT-EOM-VAL PIC 9(002) VALUE 30.
05 SEP-VALUES.
10 SEP-NAME PIC X(009) VALUE
'SEPTEMBER'.
10 SEP-EOM-VAL PIC 9(002) VALUE 30.
10 SEP-PREV-EOM-VAL PIC 9(002) VALUE 31.
10 SEP-NEXT-EOM-VAL PIC 9(002) VALUE 31.
05 OCT-VALUES.
10 OCT-NAME PIC X(009) VALUE
'OCTOBER'.
10 OCT-EOM-VAL PIC 9(002) VALUE 31.
10 OCT-PREV-EOM-VAL PIC 9(002) VALUE 30.
10 OCT-NEXT-EOM-VAL PIC 9(002) VALUE 30.
05 NOV-VALUES.
10 NOV-NAME PIC X(009) VALUE
'NOVEMBER'.
10 NOV-EOM-VAL PIC 9(002) VALUE 30.
10 NOV-PREV-EOM-VAL PIC 9(002) VALUE 31.
10 NOV-NEXT-EOM-VAL PIC 9(002) VALUE 31.
05 DEC-VALUES.
10 DEC-NAME PIC X(009) VALUE
'DECEMBER'.
10 DEC-EOM-VAL PIC 9(002) VALUE 31.
10 DEC-PREV-EOM-VAL PIC 9(002) VALUE 30.
10 DEC-NEXT-EOM-VAL PIC 9(002) VALUE 31.
01 EOM-TABLE REDEFINES
END-OF-MONTH-VALUES.
05 ET-MONTHLY-ENTRY OCCURS 012 TIMES.
10 ET-MONTH-NAME PIC X(009).
10 ET-EOM PIC 9(002).
10 ET-PREV-EOM PIC 9(002).
10 ET-NEXT-EOM PIC 9(002). |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
To reformat dates, you may need an array or a series of IFs. . . |
Dick: I'd probably use EVALUATE to simplify the logic. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hi Robert,
Quote: |
I'd probably use EVALUATE to simplify the logic. |
Yup, but if using a function was not acceptable, i wasn't sure if anything but the simplest instructions should be used. . . |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
I'd use a subscripted MOVE from the copybook using the MM as the subscript. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Works for me
i'm easy. . . |
|
Back to top |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
jack i got it .. can you provide me with subroutine for leap year as you have mentioned .. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Rupesh,
The code is listed below. You will probably have to make minor changes to fit your situation.
Code: |
05 WS-BIT-BUCKET PIC S9(04) COMP-3.
05 WS-LEAP-YR-IND-4 PIC S9(04) COMP-3.
88 DIVISIBLE-BY-4 VALUE +0.
05 WS-LEAP-YR-IND-100 PIC S9(04) COMP-3.
88 DIVISIBLE-BY-100 VALUE +0.
05 WS-LEAP-YR-IND-400 PIC S9(04) COMP-3.
88 DIVISIBLE-BY-400 VALUE +0.
05 WS-LEAP-YR-SW PIC X(01) VALUE 'N'.
88 ITS-A-LEAP-YR VALUE 'Y'.
05 WS-DATE-8.
10 WD8-CCYY.
20 WD8-CC PIC 9(02) VALUE 19.
20 WD8-YY PIC 9(02).
10 WD8-CCYY-NUM REDEFINES
WD8-CCYY PIC 9(04).
10 WD8-MM PIC 9(02).
10 WD8-DD PIC 9(02).
05 FILLER REDEFINES
WS-DATE-8.
10 FILLER PIC XX.
10 WS-DATE-6.
20 WD6-MM PIC 9(02).
20 WD6-DD PIC 9(02).
20 WD6-YY PIC 9(02).
COPY EOMLIST.
/*****************************************************************
1000-CALC-LEAP-YR.
******************************************************************
* THIS ROUTINE WILL:
* *> EXPAND YOUR DATE TO 8 POSITIONS.
* *> DETERMINE IF IT IS A LEAP YEAR.
* *> ADJUST THE EOMLIST TABLE TO REFLECT THE LEAP YEAR.
******************************************************************
MOVE YOUR DATE TO WS-DATE-6
IF WD6-YY < 90
ADD +1 TO WD8-CC
DIVIDE WD8-CCYY-NUM BY +4
GIVING WS-BIT-BUCKET
REMAINDER WS-LEAP-YR-IND-4
DIVIDE WD8-CCYY-NUM BY +100
GIVING WS-BIT-BUCKET
REMAINDER WS-LEAP-YR-IND-100
DIVIDE WD8-CCYY-NUM BY +400
GIVING WS-BIT-BUCKET
REMAINDER WS-LEAP-YR-IND-400
EVALUATE TRUE ALSO TRUE
WHEN DIVISIBLE-BY-400 ALSO ANY
WHEN DIVISIBLE-BY-4 ALSO NOT DIVISIBLE-BY-100
SET ITS-A-LEAP-YR TO TRUE
END-EVALUATE
IF ITS-A-LEAP-YR
ADD +1 TO ET-NEXT-EOM(1)
ET-EOM(2)
ET-PREV-EOM(3)
. |
|
|
Back to top |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
hi jack,
i ran this code with some modification and its wroking fine.
Regards,
Rupesh |
|
Back to top |
|
|
|