Logo
Back

◆ Reporting on defined Opals

A customer made the following request.

'Is there a quick way to get the total number of supervisor sequences that are present in our Schedule, other than doing a DEFINE ? DEFINE = and then counting them all. This is to answer the question 'how many supervisor sequences are there'.

This request prompted us to extend the TT SHOW command to provide this information. In the short term we provided an ODTSequence which would do the counting.

It was pretty much as the customer suggested 'do a TT DEFINE ? and count the responses, but we did it using Supervisor. Any Supervisor interrogation can be performed in OPAL using the KEYIN function. KEYIN("TT DEF ? ODTS") will return a string with the complete response to the DEF ? command. If we store the result in as string e.g. $LIST:=KEYIN("TT DEF ? ODTS") then each time we execute the command $Line:=$List.Split(/) we get the next line of the response. The response will contain heading lines which are always prefixed by "--" and may contain blank lines so the code:

   While $Tmp:=$Opals.Split(/) Neq Empty DO
     If Not ($Tmp Hdis "--" Or Trim($Tmp)=Empty) Then %ignore headings/blank lines
         #Cnt:=#Cnt+1;

will count the number of Opals found.

The final solution allows the type to be counted to be supplied as a parameter.

TT DEFINE + ODTSEQUENCE OPALS_COUNT(MSG):
$Param:=Trim(upper(text));
If $Param Neq {"ODTS","SITU","DISP"} Then
Abort("Parameter of ODTS,SITU or DISP required");
$Opals:=Keyin ("TT DEF ? "& $Param);
While $Tmp:=$Opals.Split(/) Neq Empty DO
If Not ($Tmp Hdis "--" Or Trim($Tmp)=Empty) Then %ignore headings/blank lines
#Cnt:=#Cnt+1; Show(#CNT,,$param,"s DEFINED")
So TT DO OPALS_COUNT SITU

will count all of the Situations defined.

This led us on to think finding which Opals have not been used in a specified time.

The responses to a DEF ? looks like:

TT DEF ? ODTS
AAAAA
SYSTEM
999.14
Never
15:50,21/10/02
ABC
MESSAGE
480.26
17:11,09/06/03
17:05,09/06/03
AC_CASE1
MESSAGE
999.14
Never
15:50,21/10/02
AC_CASE2
MESSAGE
999.14
Never
15:50,21/10/02
.
 
 
 
 
.
 
 
 
 
AC_TRICK1
MESSAGE
999.14
Never
15:50,21/10/02
AC_TRICK2
PER
999.14
Never
15:50,21/10/02

We want to determine the age of an Opal based on its date lasts used or if never used its creation date. If $Line held one line of the response then the date we want will always be the 8 characters after the first comma. So:

Take(Decat($line,",",1),8)

will give us the date, and therefore:

#Dt:=Julian(Take(Decat($line,",",1),8));

will store the date into #Dt in a form we can use for arithmetic.

#Age:=Days(#Dt,Today)

Will store the age of the Opal in days into #Age

The report will divide the Opals into those older than 365 days, those last used between 91 and 365 days, those used between 31 and 90 days and those used in the last 30 days.

If for each valid line of the response to a DEF ? we do:
#Dt:=Julian(Take(Decat($line,",",1),8));
If #Age:=Days(#Dt,Today)> 365 Then
Begin
  If $H365 Neq $Hd Then
    $L365:=&#(/,$H365:=$Hd,/);
    #A365:=#A365+1;
    $L365:=&#($Line,/,);
End
Else
If #Age > 90 Then
Begin
  If $H90 Neq $Hd Then
    $L90:=&#(/,$H90:=$Hd,/);
    #A90:=#A90+1;
    $L90:=&#($line,/,);
End
Else
   If #Age > 30 Then
Begin
   If $H30 Neq $Hd Then
   $L30:=&#(/,$H30:=$Hd,/);
   #A30:=#A30+1;
   $L30:=&#($Line,/,);
End
Else
Begin
If $H0 Neq $Hd Then
  $L0:=&#(/,$H0:=$Hd,/);
  #A0:=#A0+1;
  $L0:=&#($Line,/,)
End;
We will accumulate a count and a list of files for each range. A complication is that if any Opals are define for specific usercodes then an extra heading like:
ZZ       SYSTEM    480.18    14:15,20/11/02   14:14,20/11/02
ZZT      SYSTEM    480.18    12:40,14/11/02   12:40,14/11/02
-- ODTSEQUENCES for BOB -------------- Opal --- Last Used ----- Created ---- Ver
SWITCH   MESSAGE   999.14    Never           15:36,21/10/02

is produced. Whenever we see a new heading we store it in $Hd. The code

If $H0 Neq $Hd Then
  $L0:=&#(/,$H0:=$Hd,/);

repeated for each range, adds the heading to the list if required. If $H0 = $HD then this heading has already been seen and can be ignored. If not then we add the heading and update $H0 in the same expression: $L0:=&#(/,$H0:=$Hd,/);

Once we have scanned all of the line we can print the report:

Print(#A365,,$Type,If #A365 Neq 1 Then "s" Else "",,
    "not used in 365 days");Print(" ");
If #A365 > 0 Then
Begin
   Print($L365);
   Print(" ");
End;
Print(#A90,,$Type,If #A90 Neq 1 Then "s" Else "",,
  "last used in 91-365 days");Print(" "); 
  If #A90 > 0 Then
Begin
   Print($L90);
   Print(" ");
End;
Print(#A30,,$Type,If #A30 Neq 1 Then "s" Else "",,
  "last used in 31-90 days");Print(" ");
If #A30 > 0 Then
Begin
   Print($L30);
   Print(" ");
End;
   Print(#A0,,$Type,If #A0 Neq 1 Then "s" Else "",,
  " used in the past 30 days");Print(" ");
If #A0 > 0 Then
Begin
   Print($L0); Print(" ");
End;
$Type has been set earlier to "ODTS" or "SITU" or "DISP". Blank lines at the end of a string are ignored by the Print statement so we need to use PRINT(" "); to get a blank line.

We also accumulate summary information:

$Summary:=&#
   ($Type,,"Summary",/,
    ">365 ",#Tot.Accum(#A365) 6,/,
    "91-365 ",#Tot.Accum(#A90) 6,/,
    "31-90 ",#Tot.Accum(#A30) 6,/,
    "<31 ",#Tot.Accum(#A0) 6,/,
    "Total ",#Tot 6,//);

#Tot.Accum(#A365) returns the value stored in #A365 and adds that value to #Tot.

Finally our code would only report on one type of Opal so we wrap it in a loop:

$Request:="ODTSequence,SITUation,DISPlay";
While $Type:= $Request.Split Neq Empty Do
Begin
    %We use the following variables for each type so make sure
    %they are initialised
    #Tot:=#A365:=#A90:=#A30:=#A0:=0;
    $L365:=$L90:=$L30:=$L0:=Empty;
    $H365:=$H90:=$H30:=$H0:=Empty;
    $List:=Keyin("TT DEF ? "&$Type);
    While $Line:=$List.Split(/) Neq Empty Do
    If $Line HdIs "--" Then
      $Hd:=$Line
    Else
    If Trim($Line) Neq Empty Then %ignore blank lines before headings
    Begin
     .
     .
End

This will perform our report for each of ODTSequence,SITUation and DISPlay.

Note that we must be careful to initialise our variables for each cycle.

TT DO OPALS_REPORT will created a printed report (Mailed to you if you have set up a virtual print server for MAIL and have set your destination to MAIL).

The code for both ODTSequences can be downloaded here. Once downloaded unzip and transfer the file to the MCP system and enter 
UNWRAP *= OUTOF "OPALS_OPALS.CON".
This will unwrap the file *OPALS/OPALS. A Supervisor Enter from this fill will add the following Opal routines to your system
ODTSEQUENCE OPALS_COUNT
 and
ODTSEQUENCE OPALS_REPORT