× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



We do know that in OS/400 V4R2 IBM added Date and Time support to display
files, right?
You can specify a T or L data type for Time or Date field on the screen.
Then, workstation management automatically takes care of the user-input
(forcing them to enter a valid date/time value) 
-Bob


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Carmen Nuland
Sent: Thursday, August 19, 2004 9:51 AM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: Display field conversion to Time field

Thanks Scott!  This is just what I was looking for!
Carmen

-----Original Message-----
date: Wed, 18 Aug 2004 17:16:35 -0500 (CDT)
from: Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>
subject: Re: Display field conversion to Time field


Hi Carmen,

> We want to have a character time field on a screen, which will then have
to
> be converted to a Time datatype within the RPG program.  We were trying to
> come up with all of the different possibilities they could enter, just
using
> a pseudo-*USA format:  10:30 AM, 10 AM, 2 PM, etc.  Has anyone else worked
> with this scenario?  Trying to code for all or most of the possibilities
> seems overwhelming.  Thanks.

I wrote a subprocedure that looks through the character string byte by
byte...  if it's a number, it saves it into a field, if it's a colon it
moves on to the next field, if it's an 'A' or 'P' it figures out the AM/PM
logic, it ignores spaces and/or the letter 'M' (from "PM").

I'm not sure why you'd need this in a display file application (since, in
that scenario, you can just tell the user how to key the time info!) but
here it is, in case it's useful:

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * ParseTime():  Parse a time field entered by the user
      *
      *     Input = (input) character field containing time
      *    Output = (output) Time field containing results
      *
      * Returns *ON if successful, *OFF otherwise
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P ParseTime       B
     D ParseTime       PI             1N
     D  Input                        50A   varying const
     D  Output                         T

     D f               s             10I 0
     D x               s             10I 0
     D field           s             10A   varying dim(3)
     D c               s              1A
     D pm              s              1N
     D hh              s              2P 0
     D mm              s              2P 0
     D ss              s              2P 0
     D temp            s              8A

      /free

        field(1) = '';
        field(2) = '0';
        field(3) = '0';
        output = t'00.00.00';
        pm = *off;
        f = 1;

        for x = 1 to %len(input);

           c = %subst(input: x: 1);

           select;
           when c=' ' or c='a' or c='A' or c='a' or c='M';
             // ignore spaces and the letters 'AM'

           when c = ':';

             f = f + 1;

             if (f > %elem(field));
                return *OFF;
             endif;

           when c = 'p' or c = 'P';
             pm = *on;

           other;
             field(f) = field(f) + c;

           endsl;

        endfor;

        // Make sure user at least supplied the hour

        if (Field(1) = '');
           return *OFF;
        endif;

        // make sure that hr/min/sec can convert to numbers

        monitor;
           hh = %int(field(1));
           mm = %int(field(2));
           ss = %int(field(3));
        on-error;
           return *OFF;
        endmon;

        // if PM is specified, it's 12 hours later.

        if (pm);
           hh = hh + 12;
        endif;

        // try to build a time field

        temp = %editc(hh:'X') + ':'
             + %editc(mm:'X') + ':'
             + %editc(ss:'X');

        monitor;
          output = %time(temp:*HMS);
        on-error;
          return *OFF;
        endmon;

         return *ON;

      /end-free
     P                 E

--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.