Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

TIME in free-form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • G.Gaunt
    Guest replied
    TIME in free-form

    Thanks!

    Leave a comment:


  • G.Gaunt
    Guest replied
    TIME in free-form

    Is this the right way to get current time into a numeric variable in free-form RPG?
     Time=%subdt(%time:*h)*10000+%subdt(%time:*mn)*100+  %subdt(%time:*s);

    Leave a comment:


  • Guest.Visitor
    Guest replied
    TIME in free-form

    Let's take the expression atoi(%char(%time():*iso0)) step by step: 1) %time() returns the current time as datatype time. 2) %char(%time():*iso0) converts the value from datatype time to datatype character, converting to time format *iso0, which is the time without any separators. You get a string of six digits this way. 3) atoi() converts the character value to numeric. Option options(*string) on the prototype converts an RPG character value to a pointer. The pointer points to a temporary variable containing the string value with null terminator. Got it?

    Leave a comment:


  • Guest.Visitor
    Guest replied
    TIME in free-form

    I wouldn't have used atoi() in that example if it weren't possible. You just need to code two other things in your RPG IV program. First, code bnddir('QC2LE') on your H-Spec. Second, you need to code a prototype for atoi(). The prototype looks like:
     D atoi pr 10i 0 extproc('atoi') D str * value options(*string) 
    Any function in the C run-time library is at your disposal, whether or not you have a C compiler installed on your system. To determine how to write the prototype in RPG, refer to the information at Converting from C prototypes to RPG prototypes.

    Leave a comment:


  • G.Gaunt
    Guest replied
    TIME in free-form

    Hans, will that get HHMMSS or just HH into TIME? How did you get the address of %CHAR(%TIME()) into the ATOI argument? What is *IS0O ?

    Leave a comment:


  • B.Wahl
    replied
    TIME in free-form

    Hans, forgive the newbie question, but are you able to use the atoi function in an rpg pgm? ... if not, how would you use access the function from an rpg pgm?

    Leave a comment:


  • Guest.Visitor
    Guest started a topic TIME in free-form

    TIME in free-form

    That's one way of doing it. But that involves calling %time() three times. If you're unlucky, the time returned each time may be different. For example, the first call might return 12.59.59, the second and third might give you 13.00.00, resulting in a value of 120000. Probably not what you'd want. I'd prefer coding something like this: time = atoi(%char(%time():*iso0));
Working...
X