![]() |
Display and Write to Log File SimoLOGS - The COBOL Source Code http://www.simotime.com |
| When technology complements business | Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
This document provides a listing of the COBOL source code for viewing. Additional information about this program may be obtained by sending an e-mail to: helpdesk@simotime.com
The SimoLOGS routine (or callable program) will display and/or write a buffer of information to the screen and a log file. The display and/or logging is optional.
The following will cause the SimoLOGS routine to display "Hello World" to the screen and write an entry to the log file..
MOVE 'Hello World' to SIMOLOGS-MESSAGE
MOVE 'BOTH' to SIMOLOGS-REQUEST
CALL 'SIMOLOGS' using SIMOLOGS-PASS-AREA
In the preceding example the text "Hello World" will be displayed on the screen and written to the log file..
A copy file is provided to define the pass area to be used when calling SimoLOGS. The following statement is required in the WORKING STORAGE section of the calling program.
COPY PASSLOGS.
The following is the source code for the copy file that defines the pass area for calling SimoLOGS.
*****************************************************************
* Data Structure or Pass Area used for calling SIMOLOGS. *
*****************************************************************
* Copyright (C) 1987-2005 SimoTime Enterprises *
* All Rights Reserved *
*****************************************************************
* Provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
* SIMOLOGS-REQUEST Type of request, must be one of the *
* following values. *
* BOTH - Display message on the console, *
* Write message to the SYSLOG file. *
* FILE - Write message to the SYSLOG file. *
* NOTE - Display message on the console, *
* Write message to the SYSLOG file. *
* SHOW - Display message on the console. *
* SIMOLOGS-STATUS This is an indicator as to the success *
* or failure of the request. A value of *
* zero (0000) indicates the routine was *
* successful. A non-zero value indicates *
* a failure. *
* SIMOLOGS-MESSAGE Contains the message text. *
*****************************************************************
01 SIMOLOGS-PASS-AREA.
05 SIMOLOGS-REQUEST pic X(4).
05 SIMOLOGS-STATUS pic 9999.
05 SIMOLOGS-MESSAGE pic X(1024).
*! PASSLOGS - End-of-Copy File...
Note: The maximum length for the message text is 1,024 characters.
The following is the COBOL Source Code.
*set ASSIGN(EXTERNAL) NOOPTIONAL-FILE SEQUENTIAL(LINE)
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMOLOGS.
AUTHOR. SIMOTIME ENTERPRISES.
*****************************************************************
* Copyright (C) 1987-2009 SimoTime Enterprises, LLC. *
* *
* All rights reserved. Unpublished, all rights reserved under *
* copyright law and international treaty. Use of a copyright *
* notice is precautionary only and does not imply publication *
* or disclosure. *
* *
* Permission to use, copy, modify and distribute this software *
* for any non-commercial purpose and without fee is hereby *
* granted, provided the SimoTime copyright notice appear on all *
* copies of the software. The SimoTime name or Logo may not be *
* used in any advertising or publicity pertaining to the use *
* of the software without the written permission of SimoTime *
* Enterprises. *
* *
* Permission to use, copy, modify and distribute this software *
* for any commercial purpose requires a fee to be paid to *
* SimoTime Enterprises. Once the fee is received by SimoTime *
* the latest version of the software will be delivered and a *
* license will be granted for use within an enterprise, *
* provided the SimoTime copyright notice appear on all copies *
* of the software. The SimoTime name or Logo may not be used *
* in any advertising or publicity pertaining to the use of the *
* software without the written permission of SimoTime *
* Enterprises. *
* *
* SimoTime Enterprises makes no warranty or representations *
* about the suitability of the software for any purpose. It is *
* provided "AS IS" without any express or implied warranty, *
* including the implied warranties of merchantability, fitness *
* for a particular purpose and non-infringement. SimoTime *
* Enterprises shall not be liable for any direct, indirect, *
* special or consequential damages resulting from the loss of *
* use, data or projects, whether in an action of contract or *
* tort, arising out of or in connection with the use or *
* performance of this software *
* *
* SimoTime Enterprises *
* 15 Carnoustie Drive *
* Novato, CA 94949-5849 *
* 415.883.6565 *
* *
* RESTRICTED RIGHTS LEGEND *
* Use, duplication, or disclosure by the Government is subject *
* to restrictions as set forth in subparagraph (c)(1)(ii) of *
* the Rights in Technical Data and Computer Software clause at *
* DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of *
* Commercial Computer Software - Restricted Rights at 48 *
* CFR 52.227-19, as applicable. Contact SimoTime Enterprises, *
* 15 Carnoustie Drive, Novato, CA 94949-5849. *
* *
*****************************************************************
* This program is provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
* *
*****************************************************************
* Source Member: SIMOLOGS.CBL
*****************************************************************
*
* SIMOLOGS - Call SIMOLOGS to write record to the Message file.
*
* CALLING PROTOCOL
* ----------------
* Use standard procedure to EXECUTE, RUN or ANIMATE.
*
* DESCRIPTION
* -----------
* This program will write a message to the SYSLOG file.
*
* REQUIREMENTS
* ------------
* The COBOL/390 dialect is required for Y2K date processing.
* The following directives are required for Micro Focus.
* ASSIGN(EXTERNAL) Map COBOL file name to externally defined name
* SEQUENTIAL(LINE) Treat COBOL SEQUENTIAL as a LINE SEQUENTIAL
* NOOPTIONAL-FILE The OPEN EXTEND file must exist or post error
*
*****************************************************************
*
* MAINTENANCE
* -----------
* 1997/12/18 Simmons, Created program.
* 1997/12/18 Simmons, No changes to date.
*
*****************************************************************
*
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
*****************************************************************
SELECT SYSLOG-FILE
ASSIGN to SYSLOG
ORGANIZATION is SEQUENTIAL
ACCESS MODE is SEQUENTIAL
FILE STATUS is SYSLOG-LOG-STATUS.
*****************************************************************
*
DATA DIVISION.
FILE SECTION.
*
*****************************************************************
FD SYSLOG-FILE
DATA RECORD IS SYSLOG-RECORD
RECORDING MODE is V
RECORD is VARYING in SIZE from 64 to 1051
DEPENDING ON MESSAGE-LENGTH.
01 SYSLOG-RECORD.
05 SYSLOG-DAY pic X(3).
05 filler pic X.
05 SYSLOG-DATE pic X(10).
05 filler pic X.
05 SYSLOG-TIME pic X(11).
05 filler pic X.
05 SYSLOG-DATA pic X(1024).
*****************************************************************
WORKING-STORAGE SECTION.
01 SYSLOG-LOG-STATUS.
05 SYSLOG-LOG-STAT1 pic X.
05 SYSLOG-LOG-STAT2 pic X.
01 IO-STATUS.
05 IO-STAT1 pic X.
05 IO-STAT2 pic X.
01 TWO-BYTES.
05 TWO-BYTES-LEFT pic X.
05 TWO-BYTES-RIGHT pic X.
01 TWO-BYTES-BINARY redefines TWO-BYTES pic 9(4) comp.
01 SYSLOG-OPEN-FLAG pic X value 'N'.
01 FIRST-TIME pic X value 'Y'.
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* SIMOLOGS '.
05 MESSAGE-TEXT pic X(68).
01 APPL-RESULT pic S9(9) comp.
88 APPL-AOK value 0.
88 APPL-EOF value 16.
01 WORK-04 pic X(4).
01 ASC-EBC-FLAG pic X value 'A'.
01 WORK-DATE.
05 WORK-DATE-08 pic X(8).
01 WORK-TIME pic X(8).
01 MESSAGE-LENGTH pic 9(5) value 1024.
01 LOG-DATE pic X(10) value 'yyyy/nn/nn'.
01 LOG-TIME pic X(11) value 'nn:nn:nn:nn'.
COPY ASCEBCB1.
*****************************************************************
LINKAGE SECTION.
COPY PASSLOGS.
*****************************************************************
PROCEDURE DIVISION using SIMOLOGS-PASS-AREA.
add 8 to ZERO giving SIMOLOGS-STATUS
move 'A' to ASC-EBC-FLAG
* if SIMOLOGS-REQUEST not = 'BOTH'
* and SIMOLOGS-REQUEST not = 'FILE'
* and SIMOLOGS-REQUEST not = 'NOTE'
* and SIMOLOGS-REQUEST not = 'SHOW'
* move 'NOTE' to SIMOLOGS-REQUEST
* end-if
move SIMOLOGS-REQUEST to WORK-04
evaluate WORK-04
when 'BOTH' perform DETERMINE-LENGTH-OF-MESSAGE
perform WRITE-TO-LOG
perform DISPLAY-SIMOLOGS-MESSAGE
when 'FILE' perform DETERMINE-LENGTH-OF-MESSAGE
perform WRITE-TO-LOG
when 'NOTE' perform DETERMINE-LENGTH-OF-MESSAGE
perform WRITE-TO-LOG
perform DISPLAY-SIMOLOGS-MESSAGE
when 'SHOW' perform DETERMINE-LENGTH-OF-MESSAGE
perform DISPLAY-SIMOLOGS-MESSAGE
when 'DUMP' perform DUMP-BUFFER
when OTHER perform TRY-EBCDIC
end-evaluate
if APPL-AOK
subtract SIMOLOGS-STATUS from SIMOLOGS-STATUS
end-if
if ASC-EBC-FLAG = 'E'
inspect SIMOLOGS-STATUS converting A-INFO to E-INFO
move 'A' to ASC-EBC-FLAG
end-if
GOBACK.
*****************************************************************
TRY-EBCDIC.
inspect WORK-04 converting E-INFO to A-INFO
evaluate WORK-04
when 'BOTH' perform DETERMINE-LENGTH-OF-MESSAGE
move 'E' to ASC-EBC-FLAG
perform WRITE-TO-LOG
perform DISPLAY-SIMOLOGS-MESSAGE
when 'FILE' perform DETERMINE-LENGTH-OF-MESSAGE
move 'E' to ASC-EBC-FLAG
perform WRITE-TO-LOG
move 'E' to ASC-EBC-FLAG
when 'NOTE' perform DETERMINE-LENGTH-OF-MESSAGE
perform WRITE-TO-LOG
perform DISPLAY-SIMOLOGS-MESSAGE
when 'SHOW' perform DETERMINE-LENGTH-OF-MESSAGE
move 'E' to ASC-EBC-FLAG
perform DISPLAY-SIMOLOGS-MESSAGE
when 'DUMP' perform DUMP-BUFFER
move 'E' to ASC-EBC-FLAG
end-evaluate
exit.
*****************************************************************
DUMP-BUFFER.
perform DETERMINE-LENGTH-OF-MESSAGE
exit.
*****************************************************************
DETERMINE-LENGTH-OF-MESSAGE.
add 1024 to ZERO giving MESSAGE-LENGTH
if SIMOLOGS-MESSAGE(513:512) = SPACES
add 512 to ZERO giving MESSAGE-LENGTH
if SIMOLOGS-MESSAGE(257:256) = SPACES
add 256 to ZERO giving MESSAGE-LENGTH
if SIMOLOGS-MESSAGE(129:128) = SPACES
add 128 to ZERO giving MESSAGE-LENGTH
if SIMOLOGS-MESSAGE(65:64) = SPACES
add 64 to ZERO giving MESSAGE-LENGTH
end-if
end-if
else
if SIMOLOGS-MESSAGE(385:128) = SPACES
add 384 to ZERO giving MESSAGE-LENGTH
end-if
end-if
else
if SIMOLOGS-MESSAGE(769:256) = SPACES
add 768 to ZERO giving MESSAGE-LENGTH
else
if SIMOLOGS-MESSAGE(897:128) = SPACES
add 896 to ZERO giving MESSAGE-LENGTH
end-if
end-if
end-if
perform
until MESSAGE-LENGTH = 0
or SIMOLOGS-MESSAGE(MESSAGE-LENGTH:1) not = SPACE
if SIMOLOGS-MESSAGE(MESSAGE-LENGTH:1) = SPACE
subtract 1 from MESSAGE-LENGTH
end-if
end-perform
add 27 to MESSAGE-LENGTH
exit.
*****************************************************************
* I/O ROUTINE TO DISPLAY MESSAGES TO THE CONSOLE... *
*****************************************************************
DISPLAY-SIMOLOGS-MESSAGE.
if SIMOLOGS-MESSAGE(80:1) = ' '
display SIMOLOGS-MESSAGE(1:79) upon console
else
display SIMOLOGS-MESSAGE(1:80) upon console
end-if
exit.
*****************************************************************
GET-DATE-AND-TIME.
accept WORK-DATE from DATE YYYYMMDD
accept WORK-TIME from TIME
move WORK-DATE(1:4) to LOG-DATE(1:4)
move WORK-DATE(5:2) to LOG-DATE(6:2)
move WORK-DATE(7:2) to LOG-DATE(9:2)
move WORK-TIME(1:2) to LOG-TIME(1:2)
move WORK-TIME(3:2) to LOG-TIME(4:2)
move WORK-TIME(5:2) to LOG-TIME(7:2)
move WORK-TIME(7:2) to LOG-TIME(10:2)
exit.
*****************************************************************
WRITE-TO-LOG.
perform SIMOLOGS-OPEN
if SYSLOG-OPEN-FLAG = 'Y'
perform GET-DATE-AND-TIME
move all SPACES to SYSLOG-RECORD
move '***' to SYSLOG-DAY
move LOG-DATE to SYSLOG-DATE
move LOG-TIME to SYSLOG-TIME
move SIMOLOGS-MESSAGE to SYSLOG-DATA
if ASC-EBC-FLAG = 'E'
inspect SYSLOG-DATA converting E-INFO to A-INFO
end-if
perform SIMOLOGS-WRITE
perform SIMOLOGS-CLOSE
move 'N' to SYSLOG-OPEN-FLAG
else
move 'SHOW' to SIMOLOGS-REQUEST
end-if
exit.
*****************************************************************
* I/O ROUTINES TO CREATE THE MESSAGE FILE, SIMOLOGS...
*****************************************************************
SIMOLOGS-WRITE.
if MESSAGE-LENGTH > 1051
add 1051 to MESSAGE-LENGTH giving MESSAGE-LENGTH
end-if
if MESSAGE-LENGTH < 64
add 64 to MESSAGE-LENGTH giving MESSAGE-LENGTH
end-if
write SYSLOG-RECORD.
if SYSLOG-LOG-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
if SYSLOG-LOG-STATUS = '10'
add 16 to ZERO giving APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
end-if.
if APPL-AOK
CONTINUE
else
move 'FAILED-WRITE, Log file, SYSLOG' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
move SYSLOG-LOG-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
* perform Z-ABEND-PROGRAM
end-if
exit.
*---------------------------------------------------------------*
SIMOLOGS-OPEN.
add 8 to ZERO giving APPL-RESULT.
open EXTEND SYSLOG-FILE
if SYSLOG-LOG-STATUS = '00'
* move 'SYSLOG, Open as EXTEND file' to MESSAGE-TEXT
* perform Z-DISPLAY-CONSOLE-MESSAGE
subtract APPL-RESULT from APPL-RESULT
move 'Y' to SYSLOG-OPEN-FLAG
else
close SYSLOG-FILE
* move 'SYSLOG, Open as OUTPUT file' to MESSAGE-TEXT
* perform Z-DISPLAY-CONSOLE-MESSAGE
open output SYSLOG-FILE
if SYSLOG-LOG-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
move 'Y' to SYSLOG-OPEN-FLAG
end-if
end-if
if APPL-AOK
CONTINUE
else
move 'FAILED-OPEN, Log file, SYSLOG' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
move SYSLOG-LOG-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
* perform Z-ABEND-PROGRAM
end-if
exit.
*---------------------------------------------------------------*
SIMOLOGS-CLOSE.
add 8 to ZERO giving APPL-RESULT.
close SYSLOG-FILE
if SYSLOG-LOG-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'FAILED-CLOSE, Log file, SYSLOG' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
move SYSLOG-LOG-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
* perform Z-ABEND-PROGRAM
end-if
exit.
*****************************************************************
* The following Z-Routines perform administrative functions *
* for this program. *
*****************************************************************
*****************************************************************
* ABEND the program and return to caller... *
*****************************************************************
Z-ABEND-PROGRAM.
if MESSAGE-TEXT not = SPACES
perform Z-DISPLAY-CONSOLE-MESSAGE
end-if
move 'Writing to log file is ABENDING...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add 12 to ZERO giving RETURN-CODE
GOBACK.
*****************************************************************
* Display the file status bytes. This routine will display as *
* two digits if the full two byte file status is numeric. If *
* second byte is non-numeric then it will be treated as a *
* binary number. *
*****************************************************************
Z-DISPLAY-IO-STATUS.
if IO-STATUS NUMERIC
display '* SIMOLOGS FILE-STATUS-' IO-STATUS upon console
else
subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
move IO-STAT2 to TWO-BYTES-RIGHT
display '* SIMOLOGS FILE-STATUS-'
IO-STAT1 '/' TWO-BYTES-BINARY upon console
end-if
exit.
*****************************************************************
* Display a message generated by this program. *
*****************************************************************
Z-DISPLAY-CONSOLE-MESSAGE.
display MESSAGE-BUFFER upon console
move SPACES to MESSAGE-TEXT
exit.
*****************************************************************
* This example is provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
The purpose of this document is to provide a COBOL Source member for viewing.
Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to Simotime Enterprises. Once the fee is received by SimoTime the latest version of the software will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
Permission to use, copy, modify and distribute this software for a non-commercial purpose and without fee is hereby granted, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.
You may view the complete list of SimoTime callable Modules or Driver Programs at http://www.simotime.com/simomods.htm.
The SimoZAPS Utility Program has the capability of generating a COBOL program that will do the conversion of sequential and VSAM (KSDS) files between EBCDIC and ASCII. SimoZAPS can also read a sequential file in EBCDIC format and create an ASCII/CRLF file or VSAM KSDS file in ASCII format. The conversion tables may be viewed or modified to meet unique requirements. The Hexcess/2 function provides the capability of viewing, finding or patching the contents of a file in hexadecimal.
This item will provide a link to an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.
This document provides a quick summary of the File Status Key for VSAM data sets and QSAM files.
Check out The SimoTime Library for a wide range of topics for Programmers, Project Managers and Software Developers.
To review all the information available on this site start at The SimoTime Home Page .
Check out The SimoTime Glossary for a list of terms and definitions used in the documents provided by SimoTime.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
We appreciate your comments and feedback.
Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |