Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

trouble with dates... (INSPECT, REDEFINES, ETC...)

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Damire

New User


Joined: 25 Aug 2006
Posts: 6

PostPosted: Tue Aug 29, 2006 1:58 pm    Post subject: trouble with dates... (INSPECT, REDEFINES, ETC...)
Reply with quote

guys i have this problem with my assignment...

i need to print out a date in proper format...

it's like dis...

my program accepts date from the DATE

these are the code

WORKING-STORAGE SECTION.

03 TABLE-MONTH-NAME PIC X(36) VALUE
'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'.
03 TABLE-MONTH REDEFINES TABLE-MONTH-NAME
OCCURS 12 PIC X(3).

03 WS-DATER.

05 WS-YEAR PIC 99.
05 WS-MONTH PIC 99.
05 WS-DAY PIC 99.

PROCEDURE DIVISION.

ACCEPT WS-DATER FROM DATE.


ex: the date is Aug. 25, 2006

my WS-DATER will now contain 060825...

now, it will be easy to output the date, as the specification indicate that the date need to be at MMM DD, YYYY.

the code would probably like this using STRING

STRING
TABLE-MONTH(WS-MONTH) DELIMITED BY SIZE,
' ' DELIMITED BY SIZE,
WS-DAY-ALPHA DELIMITED SIZE,
', 20' DELIMITED BY SIZE,
WS-YEAR DELIMITED BY SIZE
INTO DTL-DATE
END-STRING.

displaying the output will give me

AUG 25, 2006

that's correct, but here's the problem...

for example the date is Aug. 5, 2006 or Aug. 20, 2006...

i need to display it like: AUG 5, 2006 AUG 20, 2006

notice that there are only 1 space between the 'AUG' and '5'.
i cant correctly find a way to remove the spaces between them, i always
end up having an output of AUG 5, 2006 (with two spaces).

i tried truncating the zero, but when i encounter days with zero, the program also removes them like the one above, i displayed it like
AUG 2 , 2006

now, can anyone please help me... i will really appreciate anything that you can tell me, ideas and everything... tnx guys!
Back to top
View user's profile Send private message

surya_pathaus

Active User


Joined: 28 Aug 2006
Posts: 110

PostPosted: Tue Aug 29, 2006 3:00 pm    Post subject:
Reply with quote

Hi,

Quote:

STRING
TABLE-MONTH(WS-MONTH) DELIMITED BY SIZE,
' ' DELIMITED BY SIZE,
WS-DAY-ALPHA DELIMITED SIZE,
', 20' DELIMITED BY SIZE,
WS-YEAR DELIMITED BY SIZE
INTO DTL-DATE
END-STRING.


In this string WS-DAY-ALPHA is used to display day (i.e, 5 or 20).
Declare this as WS-DAY-ALPHA pic x(2).
then AUG 5, 2006 will be displayed as AUG 05, 2006.
Back to top
View user's profile Send private message
Damire

New User


Joined: 25 Aug 2006
Posts: 6

PostPosted: Tue Aug 29, 2006 3:03 pm    Post subject:
Reply with quote

i actually tried doing that but wat is required of me is to display it like
AUG 5, 2006 (single space between AUG and 5, and without the zero)...

tnx for the reply...
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Aug 30, 2006 2:40 am    Post subject: Re: trouble with dates... (INSPECT, REDEFINES, ETC...)
Reply with quote

Hi Damire,

What is you coding requirement (not the result requirement), Do you have to use the STRING statement or are you open as to how you can code this?

One way, after you use the STRING statement to create a date like "AUG 05, 2006" would be to say

Code:

    IF DTL-DATE(5:1) = '0'
    THEN
        MOVE DTL-DATE(6:7) TO DTL-DATE(5:8)
    END-IF.


crude, but effective

Other techniques are also available

Dave
Back to top
View user's profile Send private message
Damire

New User


Joined: 25 Aug 2006
Posts: 6

PostPosted: Wed Aug 30, 2006 5:25 am    Post subject:
Reply with quote

@David I was required to use STRING statement... but i will try your suggestion, dat statement is kinda new to me, never seen statement like that before... correct me if i'm wrong, bout DTL-DATE(5:1) = '0'
do the 5 points to the 5th character, ryt? and the 1 indicates the length?

tnx...
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Aug 30, 2006 7:47 pm    Post subject: Re: trouble with dates... (INSPECT, REDEFINES, ETC...)
Reply with quote

Yes, check the link to REFERENCE MODIFICATION

Dave
Back to top
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Thu Aug 31, 2006 2:33 pm    Post subject:
Reply with quote

Hi
Please find the code below.

WORKING-STORAGE SECTION.
01 TABLE-MONTH-NAME PIC X(36) VALUE
'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'.
01 TABLE-MONTH REDEFINES TABLE-MONTH-NAME
OCCURS 12 PIC X(3).
01 ws-dater.
02 yy pic 99.
02 mm pic 99.
02 dd pic 99.
01 WS-DATE.
02 yy1 pic 9(4).
02 mm1 pic 99.
02 dd1 pic 99.
02 e-dd redefines dd1.
03 a-dd1 pic 9.
03 a-dd2 pic 9.

01 WS-YEAR PIC 99.
01 WS-MONTH PIC x(3).
01 WS-DAY PIC 99.
01 ws-day-alpha pic x(10).
01 dtl-date pic x(12).
PROCEDURE DIVISION.

ACCEPT WS-DATER FROM DATE.
compute yy1 = yy + 2000.
move mm to mm1.
move dd to dd1.
display ws-date.
move table-month(mm1) to ws-month.
move dd1 to e-dd.

if a-dd1 not = 0
STRING
WS-MONTH DELIMITED BY SIZE,
' ' DELIMITED BY SIZE,
e-dd DELIMITED by size,
', ' DELIMITED BY SIZE,
yy1 DELIMITED BY SIZE
INTO DTL-DATE
END-STRING.

if a-dd1 = 0
STRING
WS-MONTH DELIMITED BY SIZE,
' ' DELIMITED BY SIZE,
a-dd2 DELIMITED by size,
', ' DELIMITED BY SIZE,
yy1 DELIMITED BY SIZE
INTO DTL-DATE
END-STRING.
display dtl-date.

stop run.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Sep 03, 2006 9:05 pm    Post subject:
Reply with quote

Hi Damire,

If you're limited to STRING you can modify Dave's solution by:

Adding
Code:
 05 pos pic s9(002) comp value 1. 
05 len pic s9(002) comp value 2.

to your WS, then code:
Code:

if ws-day  < 10
   move 2 to pos
   move 1 to len
end-if


Then change
Code:

WS-DAY-ALPHA DELIMITED SIZE,  to
ws-day(pos:len) delimited by size

Haven't tested it (there may be some caveats I'm not aware of) and as Dave said: "crude", but then, it wouldn't be COBOL. icon_smile.gif

BTW, where did -ALPHA come from? Typo or did I miss something?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Inspect statement spoorni COBOL Programming 5 Mon Jun 06, 2016 9:53 pm
No new posts Sort Card : To get the records with ... pecsakthivel123 DFSORT/ICETOOL 7 Thu Dec 10, 2015 11:54 pm
No new posts Using Inspect in cobol Ajay Dwivedi COBOL Programming 8 Sat Sep 26, 2015 11:33 pm
No new posts DATEADD query trouble Shripad AVhad DB2 8 Tue Sep 15, 2015 11:57 am
No new posts Another redefines in COBOL RahulG31 COBOL Programming 1 Fri Mar 20, 2015 4:09 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us