Kbase 21943: Sample Program to Trace an ADM2 Super Procedure and Includes
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  04/04/2002 |
|
SUMMARY:
This Knowledge Base Solution applies to Progress Version 9.1x and higher.
The sample program below will help you to trace and report the super procedures and include files instantiated by an ADM2 procedure. This is especially useful if you are trying to debug an ADM2 procedure or if you want to learn more about how the ADM2 works.
This example does not replace the Utility provided by Progress Software with ProTools, that is, PROSPY.
SOLUTION:
/* program: proceduretree.p Author: pmartine
Date: 04/04/02
Description: This procedure will trace any ADM2 procedure and will
report the list of ADM2 Super Procedures instantiated at Run-TIME */
def var PROGR as char format "x(50)" no-undo.
def var LEVELMAX as int init 2 no-undo.
def var PROGRAMPATH as char no-undo.
def var PROGRAMCOUNT as int no-undo.
def var LEVELCOUNT as int no-undo.
def var STR as char format "x(200)" no-undo.
def var TARGETFILE as char init "proceduretree.txt" format "x(40)" no-undo.
def var OFFSET as int no-undo.
def temp-table PROGRAMLIST no-undo
field PROGRAMNAME as char FORMAT "x(70)" LABEL "Name"
field FULLPATH as char format "x(70)" LABEL "Path"
field LEVEL as int LABEL "Level"
field PROGRAMNUMBER as int LABEL "Number"
field PARENTNUMBER as int LABEL "Parent"
field PROCESSED as log
index PRI as primary PROGRAMNUMBER
index SEC PARENTNUMBER
index FPATH FULLPATH.
def var SAV-NUM like PROGRAMLIST.PROGRAMNUMBER no-undo.
def stream MYSTREAM.
def buffer PROGRAM-LIST for PROGRAMLIST.
DEFINE VAR wWin AS WIDGET-HANDLE NO-UNDO.
DEFINE QUERY q1 FOR programlist.
DEFINE BROWSE b1 QUERY q1
DISPLAY programnumber level parentnumber programname fullpath
WITH 17 DOWN.
DEFINE BUTTON BQuit LABEL " &Quit " AUTO-ENDKEY.
DEFINE FRAME f1
SKIP(1)
PROGR LABEL "Procedure" TO 70 SKIP
LEVELMAX label "Maximum level of nested programs" TO 70
help "Usually more than 3 makes no sense, you can try more later" SKIP
TARGETFILE label "Send Output to File" TO 70
help "File name where output 'tree' will be sent" BQuit SKIP(2)
b1 SKIP(2)
with SIDE-LABELS THREE-D WIDTH 200.
CREATE WINDOW wWin ASSIGN
HIDDEN = YES
TITLE = "ADM2 ProcedureTree Tracer"
HEIGHT = 23
WIDTH = 185
MAX-HEIGHT = 35.81
MAX-WIDTH = 200.2
VIRTUAL-HEIGHT = 35.81
VIRTUAL-WIDTH = 200.2
RESIZE = YES
SCROLL-BARS = NO
STATUS-AREA = NO
BGCOLOR = ?
FGCOLOR = ?
THREE-D = yes
MESSAGE-AREA = no
SENSITIVE = yes.
VIEW FRAME f1 IN WINDOW wWin.
VIEW wWin.
wwin:SENSITIVE = YES.
ENABLE ALL WITH FRAME f1.
update
PROGR
validate(search(PROGR) <> ?,"Procedure not found, please try again")
LEVELMAX
TARGETFILE with FRAME f1.
assign
PROGRAMCOUNT = PROGRAMCOUNT + 1
OFFSET = min(int(40 / LEVELMAX),4).
create PROGRAMLIST.
assign PROGRAMNAME = PROGR
FULLPATH = search(PROGR)
LEVEL = LEVELCOUNT
PROGRAMNUMBER = PROGRAMCOUNT
PARENTNUMBER = 0.
MAIN-LOOP:
do while true on error undo, LEAVE on end-key undo, leave:
find first PROGRAMLIST where PROGRAMLIST.PROCESSED = no no-error.
if not avail PROGRAMLIST then leave MAIN-LOOP.
if PROGRAMLIST.LEVEL >= LEVELMAX
or PROGRAMLIST.PROGRAMNAME matches "applhelp.p"
or PROGRAMLIST.PROGRAMNAME = "RUN VALUE ?"
then do:
PROGRAMLIST.PROCESSED = yes.
next MAIN-LOOP.
end.
input stream MYSTREAM from value(PROGRAMLIST.FULLPATH).
LEVELCOUNT = PROGRAMLIST.LEVEL + 1.
repeat:
import stream MYSTREAM unformatted str.
if index(str,"run ") > 0 and
( index(str," value(") > 0 or
index(str," value ") > 0 )
then do:
PROGRAMCOUNT = PROGRAMCOUNT + 1.
create PROGRAM-LIST.
assign PROGRAM-LIST.PROGRAMNAME = "RUN VALUE ?"
PROGRAM-LIST.FULLPATH = "RUN " + str
PROGRAM-LIST.LEVEL = LEVELCOUNT
PROGRAM-LIST.PROGRAMNUMBER = PROGRAMCOUNT
PROGRAM-LIST.PARENTNUMBER = PROGRAMLIST.PROGRAMNUMBER.
next.
end.
if index(str,"run") > 0 and ( index(str,".p") > 0 or index(str,".w") > 0 ) then do:
str = substr(str,index(str,"run") + 4).
if index(str,".p") > 0 then
str = substr(str,1,index(str,".p") + 1).
else
str = substr(str,1,index(str,".w") + 1).
if search(str) ne ? and not can-find(PROGRAM-LIST where
PROGRAM-LIST.FULLPATH = search(str)
and PROGRAM-LIST.PARENTNUMBER = PROGRAMLIST.PROGRAMNUMBER)
then do:
PROGRAMCOUNT = PROGRAMCOUNT + 1.
create PROGRAM-LIST.
assign PROGRAM-LIST.PROGRAMNAME = str
PROGRAM-LIST.FULLPATH = search(str)
PROGRAM-LIST.LEVEL = LEVELCOUNT
PROGRAM-LIST.PROGRAMNUMBER = PROGRAMCOUNT
PROGRAM-LIST.PARENTNUMBER = PROGRAMLIST.PROGRAMNUMBER
.
end.
end. /* if index(str,"run") */
if index(str,chr(123)) > 0 then do:
str = trim(substr(str,index(str,chr(123)) + 1)).
if index(str," ") > 0 then str = trim(substr(str,1,index(str," "))).
if index(str,chr(125)) > 0
then str = trim(substr(str,1,index(str,chr(125)) - 1)).
if search(str) ne ? and not can-find(PROGRAM-LIST where
PROGRAM-LIST.FULLPATH = search(str)
and PROGRAM-LIST.PARENTNUMBER = PROGRAMLIST.PROGRAMNUMBER)
then do:
PROGRAMCOUNT = PROGRAMCOUNT + 1.
create PROGRAM-LIST.
assign PROGRAM-LIST.PROGRAMNAME = str
PROGRAM-LIST.FULLPATH = search(str)
PROGRAM-LIST.LEVEL = LEVELCOUNT
PROGRAM-LIST.PROGRAMNUMBER = PROGRAMCOUNT
PROGRAM-LIST.PARENTNUMBER = PROGRAMLIST.PROGRAMNUMBER.
end.
end.
end.
input stream MYSTREAM close.
PROGRAMLIST.PROCESSED = yes.
end. /* MAIN-LOOP */
OPEN QUERY q1 FOR EACH programlist.
output stream MYSTREAM to value(TARGETFILE).
find PROGRAMLIST where PROGRAMLIST.PROGRAMNUMBER = 1.
put stream MYSTREAM PROGRAMLIST.FULLPATH skip.
PROGRAMLIST.PROCESSED = no.
PRINT-BLOCK:
do while LEVELCOUNT >= 0:
LEVELCOUNT = 0.
find first PROGRAM-LIST where PROGRAM-LIST.PARENTNUMBER = PROGRAMLIST.PROGRAMNUMBER
and PROGRAM-LIST.PROCESSED = yes
no-error.
if avail PROGRAM-LIST then do:
assign
PROGRAM-LIST.PROCESSED = no
LEVELCOUNT = PROGRAM-LIST.LEVEL.
put stream MYSTREAM space(LEVELCOUNT * OFFSET) PROGRAM-LIST.FULLPATH skip.
find PROGRAMLIST where recid(PROGRAMLIST) = recid(PROGRAM-LIST).
end.
else do:
find first PROGRAM-LIST where PROGRAM-LIST.LEVEL = LEVELCOUNT
and PROGRAM-LIST.PARENTNUMBER = PROGRAMLIST.PARENTNUMBER
and PROGRAM-LIST.PROCESSED = yes
no-error.
if avail PROGRAM-LIST then do:
assign PROGRAM-LIST.PROCESSED = no.
put stream MYSTREAM space(LEVELCOUNT * OFFSET) PROGRAM-LIST.FULLPATH skip.
find PROGRAMLIST where recid(PROGRAMLIST) = recid(PROGRAM-LIST).
end.
else do:
assign SAV-NUM = PROGRAMLIST.PARENTNUMBER.
if SAV-NUM = 0 then leave PRINT-BLOCK.
find PROGRAMLIST where PROGRAMLIST.PROGRAMNUMBER = SAV-NUM.
LEVELCOUNT = PROGRAMLIST.LEVEL.
end.
end. /* not avail PROGRAM-LIST*/
end. /* PRINT-BLOCK */
WAIT-FOR WINDOW-CLOSE OF wwin.
output stream MYSTREAM close.