For Programmers: Free Programming Magazines  


Home > Archive > Cobol > October 2005 > How to accept date in particular format









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to accept date in particular format
PradeepR

2005-10-31, 7:55 am

Hello,

I am looking for accepting a date in format mm/dd/yyyy. The initial
screen should show current date in this format, for eg.
10/31/2005.
I am working on ACU COBOL.
The date should be accepted at a particular line and column, say line
4. I have to default it with current date
and allow the user to edit.

I have tried
working-storage section.
01 in-date pic x(10) value " / / ".

procedure division.
move "10/31/2005" to in-date.
accept in-date line 4 prompt.

The problem with above is that neither the date gets defaulted, nor
does it force the user to enter it in proper format. Excuse me if this
is a newbie question. Any help is appreciated.
Thanks for your attention.

PradeepR

Frederico Fonseca

2005-10-31, 7:55 am

On 31 Oct 2005 04:14:25 -0800, "PradeepR" <pradeep.ravle@gmail.com>
wrote:

>Hello,
>
>I am looking for accepting a date in format mm/dd/yyyy. The initial
>screen should show current date in this format, for eg.
>10/31/2005.
>I am working on ACU COBOL.
>The date should be accepted at a particular line and column, say line
>4. I have to default it with current date
>and allow the user to edit.
>
>I have tried
>working-storage section.
>01 in-date pic x(10) value " / / ".
>
>procedure division.
>move "10/31/2005" to in-date.
>accept in-date line 4 prompt.

A common way, and one that prevents all possible problems with change
in locales/countries, is to have 3 fields, properly identified as day,
month and year.

Apart from that you need to perform validation within your code to
verify that your users have entered the correct information.


>
>The problem with above is that neither the date gets defaulted, nor
>does it force the user to enter it in proper format. Excuse me if this
>is a newbie question. Any help is appreciated.
>Thanks for your attention.
>
>PradeepR



Frederico Fonseca
ema il: frederico_fonseca at syssoft-int.com
HeyBub

2005-10-31, 6:55 pm

PradeepR wrote:
> Hello,
>
> I am looking for accepting a date in format mm/dd/yyyy. The initial
> screen should show current date in this format, for eg.
> 10/31/2005.
> I am working on ACU COBOL.
> The date should be accepted at a particular line and column, say line
> 4. I have to default it with current date
> and allow the user to edit.
>
> I have tried
> working-storage section.
> 01 in-date pic x(10) value " / / ".
>
> procedure division.
> move "10/31/2005" to in-date.
> accept in-date line 4 prompt.
>
> The problem with above is that neither the date gets defaulted, nor
> does it force the user to enter it in proper format. Excuse me if this
> is a newbie question. Any help is appreciated.
> Thanks for your attention.
>
> PradeepR


Consider:

01 InDate.
02 InDateMM PIC XX.
02 filler PIC X value '/'.
02 InDateDD PIC XX.
02 filler PIC X value '/'.
02 InDateYYYY PIC X(4).

Then accept each of the three fields separately.

Of course in a Windows rendition of a compiler, you could use an Active-X
popup calendar....


Chuck Stevens

2005-10-31, 6:55 pm


"HeyBub" <heybubNOSPAM@gmail.com> wrote in message
news:11mcfl757ne15f6@news.supernews.com...

>
> Consider:
>
> 01 InDate.
> 02 InDateMM PIC XX.
> 02 filler PIC X value '/'.
> 02 InDateDD PIC XX.
> 02 filler PIC X value '/'.
> 02 InDateYYYY PIC X(4).
>
> Then accept each of the three fields separately.


Just out of curiosity, how does one accept the three fields separately?

I can see something like
01 AccDate.
02 AccDateYYYY PIC X(4).
02 AccDateMM PIC XX.
02 AccDateDD Pic XX.

with code like

ACCEPT AccDate FROM DATE YYYYMMDD.
MOVE CORRESPONDING AccDate TO InDate.

presuming, that is, that the COBOL implementation is compliant with ISO/IEC
1989:2002, or includes the YYYYMMDD feature as an extension if it's
compliant with a prior standard.

MOVE FUNCTION CURRENT-DATE TO AccDate
would also serve the function of the ACCEPT, and could be followed by the
same MOVE CORRESPONDING, if your compiler includes support for the Intrinsic
Function Amendment of 1989. But that's not, strictly speaking, ACCEPT.

-Chuck Stevens


Richard

2005-10-31, 6:56 pm

>> Then accept each of the three fields separately.

> Just out of curiosity, how does one accept the three fields separately?


Using the ANS 'ACCEPT InDateMM [FROM CONSOLE]' or the X/Open ACCEPT xxx
FROM CRT AT llcc, or ...

> 01 InDate.
> 02 InDateMM PIC XX.
> 02 filler PIC X value '/'.
> 02 InDateDD PIC XX.
> 02 filler PIC X value '/'.
> 02 InDateYYYY PIC X(4).


In fact an X/Open 'ACCEPT InDate AT llcc FROM CRT' will accept the
three non-filler fields and skip over the fillers.

However a DISPLAY InDate will also skip the fillers and not show the
'/'s so you may need to redefine this as a named PIC X(10) and display
that.

Chuck Stevens

2005-10-31, 6:56 pm

Yes, you're right; I completely misunderstood the original request.

What I thought was being asked for was acceptance of *system* date/time
information, not keyed-in user input as specified.

-Chuck Stevens


"Richard" <riplin@Azonic.co.nz> wrote in message
news:1130787278.595288.122950@f14g2000cwb.googlegroups.com...
>
>
> Using the ANS 'ACCEPT InDateMM [FROM CONSOLE]' or the X/Open ACCEPT xxx
> FROM CRT AT llcc, or ...
>
>
> In fact an X/Open 'ACCEPT InDate AT llcc FROM CRT' will accept the
> three non-filler fields and skip over the fillers.
>
> However a DISPLAY InDate will also skip the fillers and not show the
> '/'s so you may need to redefine this as a named PIC X(10) and display
> that.
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com