msgproc: PROCEDURE /* zex1717n */ /* MSGPROC to trap all messages sent to an OCS window */ /* and selectively log messages to a file. */ /* You turn on logging by typing AAAAA at the OCS */ /* command input line. You turn off logging by typing */ /* ZZZZZ at the OCS command input line. */ ON ERROR FLUSH /* Error handler */ SAY MSGPROC starting CALL create_file /* Create log file */ &log = "" DO FOREVER /* Trap messages */ MSGREAD VARS=&word* /* Put text to words*/ &log = &word&(SYS.VARCNT) /* Get last word */ IF &log = AAAAA THEN DO /* Begin logging if */ SAY "Logging enabled" /* AAAAA is last on */ CALL log SHARE &$msg. /* line and open log*/ END /*do*/ END /*do forever*/ /* Get next message */ /* ==================== CREATE FILE ===================== */ create_file: PROCEDURE /* Use FUP to try and create new entry-sequenced file. */ /* Set a large record length because MDO variables with*/ /* messages contain lots of attribute information. */ INTCMD "OPSYS SEND FUP CREATE $DATA2.JOHNNCLS.MSGLOG,", "TYPE E, REC 4072" DO UNTIL &msgno = "NNM0999" INTREAD VARS=(&msgno(7),*,&text) TYPE=ANY PARSE=NO /* Check if file was created */ IF POS("ERR 10",&text) > 0 THEN DO /* File exists, so purge data, and leave DO UNTIL */ /* Typing UDBCTL RESET=$DATA2.JOHNNCLS.MSGLOG */ /* before activating this MSGPROC does the same */ INTCMD "OPSYS SEND FUP PURGEDATA $DATA2.JOHNNCLS.MSGLOG" END /*do*/ ELSE NOP END /*do until*/ INTCMD "OPSYS KILL FUP" INTREAD END create_file /* ==================== LOG RECORDS ====================== */ log: PROCEDURE SHARE &$msg. /* Open private log. You can specify another filename. */ /* You could modify the procedure so that the 1st */ /* parameter you enter is the file name. If so, don't */ /* forget to share it to this LOG procedure. */ INTCMD 'UDBCTL OPEN=$DATA2.JOHNNCLS.MSGLOG ID=MSGLOG' INTREAD /* Wait for message */ FILE OPEN ID=MSGLOG FORMAT=MAPPED, /* Must be mapped */ MAP=$MSG /* with $MSG */ DO WHILE &log \= ZZZZZ /* Stop logging if */ MSGREAD VARS=&word* /* ZZZZZ is last on */ FILE ADD MDO=&$msg. /* line. */ &log = &word&(SYS.VARCNT) /* Get last word */ END /*do until*/ SAY "Logging disabled" FILE CLOSE ID=MSGLOG /* Close log */ INTCMD 'UDBCTL CLOSE=$DATA2.JOHNNCLS.MSGLOG' END log END msgproc