Highlighted
Absent Member.
Absent Member.
899 views

Cobol Code

Jump to solution

[Migrated content. Thread originally posted on 19 January 2012]

Hi All,

Does any one know how to COBOLIZE this?

http://support.microsoft.com/kb/301279

Many thanks

Neil.
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Cobol Code

Jump to solution
(To save everyone else from looking up the MSDN article, it shows how to write to a Windows event log.)

We've done this in managed COBOL. It's quite straightforward.

Here's a straight conversion of the VB.NET source from the article:

      $set sourceformat"variable"

      * COBOL version of MS KB 301279

      $set ilusing"System"
      $set ilusing"System.Diagnostics"

       class-id. Module1.
       method-id. Main static.
       01 sSource      string.
       01 sLog         string.
       01 sEvent       string.
       01 sMachine     string.
       01 eLog         type EventLog.
       
       procedure division.
           set sSource to "dotNET Sample App"
           set sLog to "Application"
           set sEvent to "Sample Event"
           set sMachine to "."

           if not type EventLog::SourceExists(sSource sMachine)
               invoke type EventLog::CreateEventSource(sSource sLog sMachine)
           end-if

           set eLog to new EventLog(sLog sMachine sSource)
           invoke eLog::WriteEntry(sEvent)
           invoke eLog::WriteEntry(sEvent, type EventLogEntryType::Warning, 234, 3 as binary-short)
       end method Main.
       end class Module1.


You can compile that right from the command line with "cobol filename.cbl ilgen ;".

View solution in original post

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Cobol Code

Jump to solution
(To save everyone else from looking up the MSDN article, it shows how to write to a Windows event log.)

We've done this in managed COBOL. It's quite straightforward.

Here's a straight conversion of the VB.NET source from the article:

      $set sourceformat"variable"

      * COBOL version of MS KB 301279

      $set ilusing"System"
      $set ilusing"System.Diagnostics"

       class-id. Module1.
       method-id. Main static.
       01 sSource      string.
       01 sLog         string.
       01 sEvent       string.
       01 sMachine     string.
       01 eLog         type EventLog.
       
       procedure division.
           set sSource to "dotNET Sample App"
           set sLog to "Application"
           set sEvent to "Sample Event"
           set sMachine to "."

           if not type EventLog::SourceExists(sSource sMachine)
               invoke type EventLog::CreateEventSource(sSource sLog sMachine)
           end-if

           set eLog to new EventLog(sLog sMachine sSource)
           invoke eLog::WriteEntry(sEvent)
           invoke eLog::WriteEntry(sEvent, type EventLogEntryType::Warning, 234, 3 as binary-short)
       end method Main.
       end class Module1.


You can compile that right from the command line with "cobol filename.cbl ilgen ;".

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.