This program is a wrapper for the QWVRCSTK API. It will retrieve all of the call stack information for the current job, and load the program names into an array data structure. The array data structure contains not only the program name, but also a pointer to the location in the heap containing the associated procedure name (for ILE programs) and the length of the associated procedure name.
The program is called from the command line with the no parameters.
The program call looks like this:
The generated loaded array looks like this:
> EVAL @prog @PROG.PROGNAME(1) = 'CP0210R ' @PROG.PROC@(1) = SPP:EEA410857A0023D0 @PROG.PROGNAME(2) = 'CP0210R ' @PROG.PROC@(2) = SPP:EEA410857A0023F0 @PROG.PROGNAME(3) = 'QCMDEXC ' @PROG.PROC@(3) = SPP:*NULL @PROG.PROGNAME(4) = 'CP0000 ' @PROG.PROC@(4) = SPP:*NULL
The 'D' Specs used to define the array look like this:
d prog ds Qualified d progname 10a d proc@ * Inz(*Null) d @prog ds LikeDS(prog) Dim(100) d Inz(*LikeDS)
The pointer @prog().proc@ points to allocated space in the heap. The first four (4) bytes contains the length of the procedure name. From there on is the procedure name itself.
d proc ds Based(proc@) Qualified d procNameLen Like(csProcLen) d procName 1a
Only one byte of the procedure name is defined because all access will be with the C function 'memcpy', which only needs to know the address of the first character:
A calculation using the array data structure looks like this:
det@ = hdr@ + detOSet; DoU ($I > count Or $I > 100); @prog($I).progName = csProg; If ( csProcOSet <> 0 ); proc@ = %Alloc(csProcLenLen + csProcLen); @prog($I).proc@ = proc@; proc.procNameLen = csProcLen; memcpy( %Addr(proc.procName) : det@ + csProcOset : csProcLen ); EndIf; $I = $I + 1; det@ = det@ + csLen; EndDo;
The following link takes you to the source code, written in beautiful /free ILE/RPG. The source is
distributed under a creative commons license.