Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

RE: Get the date and time the local server

$
0
0

You can use the NetRemoteTOD WINAPI function to do this.

The docs can be found here:

A COBOL example of this would be:

       identification division.
       program-id. Program1.

       environment division.
       configuration section.
       special-names.
          call-convention 66 is winapi.
       data division.
       working-storage section.
       01 pp procedure-pointer.
       01 UncServerName pic x(100)
          value z"myservername".
       01 pBuffer       pointer.
       01 net-api-status  pic x(4) comp-5 value 0.
       01 format-date-time.
          05 format-year  pic 9(4).
          05              pic x value "/".
          05 format-month pic 9(2).
          05              pic x value "/".
          05 format-day   pic 9(2).
          05              pic x value space.
          05 format-hours pic 9(2).
          05              pic x value ":".
          05 format-minutes pic 9(2).
          05              pic x value ":".
          05 format-seconds pic 9(2).
          
       linkage section.
       01 Buffer.
          05 tod_elapsedt pic x(4) comp-5.
          05 tod_msecs    pic x(4) comp-5.
          05 tod_hours    pic x(4) comp-5.
          05 tod_mins     pic x(4) comp-5.
          05 tod_secs     pic x(4) comp-5.
          05 tod_hunds    pic x(4) comp-5.
          05 tod_timezone pic s9(9) comp-5.
          05 tod_tinterval pic x(4) comp-5.
          05 tod_day      pic x(4) comp-5.
          05 tod_month    pic x(4) comp-5.
          05 tod_year     pic x(4) comp-5.
          05 tod_weekday  pic x(4) comp-5.
       
       procedure division.

           
           set pp to entry "netapi32"
           call winapi "NetRemoteTOD"
              using function national-of(uncservername)
                    pBuffer
              returning net-api-status
           end-call
           if net-api-status not = 0
              display "error = " net-api-status
              goback
           end-if
           
           set address of buffer to pBuffer
           
           move tod_year to format-year
           move tod_month to format-month
           move tod_day to format-day
           move tod_hours to format-hours
           move tod_mins to format-minutes
           move tod_secs to format-seconds
           display format-date-time
           
           if pBuffer not = null
              call winapi "NetApiBufferFree"
                 using pBuffer
              end-call
           end-if
           goback.

       end program Program1.

Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>