01 DATE-IN-9 PIC 9(009).
01 DATE-WORK REDEFINES DATE-IN-9.
05 FILLER PIC X(001).
05 DW-CCYY PIC 9(004).
05 DW-MONTH PIC 9(002).
05 DW-DAY PIC 9(002).
01 DATE-OUT.
05 DO-DAY PIC X(002).
05 FILLER PIC X(001) VALUE "-".
05 DO-MONTH PIC X(003).
05 FILLER PIC X(001) VALUE "-".
05 DO-CCYY PIC X(004).
01 MONTH-TABLE.
05 FILLER PIC X(003) VALUE "Jan".
05 FILLER PIC X(003) VALUE "Feb".
.
.
.
05 FILLER PIC X(003) VALUE "Dec".
01 MONTH-NAME REDEFINES MONTH-TABLE
OCCURS 12 TIMES PIC X(003).
In the procedure division, move your input field to DATE-IN-9, then move
DW-CCYY to DO-CCYY, DW-DAY to DO-DAY and use DW-MONTH as a subscript
to the MONTH-NAME to move into DO-MONTH. The move DATE-OUT to your DOC1 field.
------------------------------------
another approach.
I like to put the work in the SQL and let DB2 do the work. Here is a sample (not exactly what you want, but I am sure you will get the idea and be able to tailor it for your use.)
SELECT
A.D ,
CASE MONTH(A.D)
WHEN 1 THEN 'JAN '
WHEN 2 THEN 'FEB '
WHEN 3 THEN 'MAR '
WHEN 4 THEN 'APR '
WHEN 5 THEN 'MAY '
WHEN 6 THEN 'JUN '
WHEN 7 THEN 'JUL '
WHEN 8 THEN 'AUG '
WHEN 9 THEN 'SEP '
WHEN 10 THEN 'OCT '
WHEN 11 THEN 'NOV '
WHEN 12 THEN 'DEC '
END
Steve
================================================================
<i>If I have a string that looks like '019970711'...</i>
First, I have to assume that that value is Jul 11, 1997. And by "string", you mean a character variable -- e.g., PIC X(9). And since you don't say what platform, I'll supply this example code:<pre>
PROCESS APOST
NOMONOPRC
Identification Division.
Program-ID. CVTDATE.
/
Environment Division.
Configuration Section.
Source-computer. IBM-AS400.
Object-computer. IBM-AS400.
Special-names.
Linkage type is prc
for 'CEESECS'
using
all DESCRIBED
Linkage type is prc
for 'CEEDATM'
using
all DESCRIBED
.
Data Division.
Working-storage Section.
77 Xmpl-Date pic x(9)
value '019970711'.
01 WS-PicStr1 pic x(32)
value '9YYYYMMDD'.
01 WS-PicStr2 pic x(32)
value 'ZD-Mmm-YYYY'.
01 WS-OutSecs pic x(8).
01 WS-NewDate pic x(32).
Procedure Division
.
0000-Main Section.
0010-MainLine.
call 'CEESECS'
using
Xmpl-Date
WS-PicStr1
WS-OutSecs
OMITTED
.
call 'CEEDATM'
using
WS-OutSecs
WS-PicStr2
WS-NewDate
OMITTED
.
goback
.</pre>
The CEESECS API takes your input string value and converts it to the number of seconds since 00:00:00 14 Oct 1582, using WS-PicStr1 to parse out the year, month and day values. I didn't need hours, minutes or seconds; but they're available if you need them. The number of seconds is stored in WS-OutSecs.
The CEEDATM API converts that value into a string formatted according to WS-PicStr2. I used "ZD" for the day number for zero-suppression, but you might use "DD" instead. Same consideration for hours/minutes/seconds (and fractions).
I compiled and ran under debug, and WS-NewDate contained '11-Jul-1997'. Note that "Mmm" resulted in "Jul" rather than "JUL".
You can rearrange the WS-PicStrX characters to get just about any date, time or timestamp format you can imagine on both the input and output ends.
Tom
Thanks!
actually you cannot have a value on a filler, so i just gave it a name