September 11

1 comments

RPG program to retrieve the current job call stack

By NickLitten

September 11, 2013

callstack, rpgle

Retrieve the Jobs Program Call Stack – RPGLE Example

The RPG IV provided in this tip uses a simpler method to provide this function.

The program sends messages up the call stack one at a time (to a maximum of 10 entries) until the top is reached. For each send, a retrieve is also performed and the receiving program name is captured. The program has three parameters: PStack (call stack returned), PStartPoint (relative starting point), and PEntries (number of entries returned).

When you call the program, set the PStartPoint parameter to the call stack entry at which you want to start. Entries are returned starting with the latest entry in the first array element. You can easily modify the program to include more or fewer call stack entries.

  *****************************************************************
  * Retrieve last 10 entries in the call stack excluding the current program **
  * 
  * This program accepts three parameters. **
  * Stack (Array of 10 x 10) entries **
  * Relative starting position (3,0 P) **
  * No of Entries to return. **
  *****************************************************************
  *Data Definitions
  *****************************************************************
  * Call Stack
 D DSStack ds
 D @Stack 10 Dim(10)
 D* Stack counter
 D #PCounter s 9b 0
 D* Wait time on receive message
 D #PWait s 9b 0
 D* Type Definition for the RCVM0200 format.
 D RCVM0200 DS
 D RCVPgm 111 120
 D RCVM0200Len s 9b 0 INZ(%Size(RCVM0200))
 D*****
 D* API Error Data structure
 D*****
 D DSERR DS 256
 D ERBYTP 1 4B 0 INZ(256)
 D ERBYTA 5 8B 0
 D ERMSID 9 15
 D ERMSDT 17 256
 D*****************************************************************
 D* Calc Specs
 D*****************************************************************
 C* Entry parameters
 C *Entry Plist
 C Parm PStack 100
 C Parm PStartPoint 3 0
 C Parm PEntries 3 0
 C*****
 C* Initialize parameters
 C*****
 C Move *Blanks PStack
 C Z-Add *Zero PEntries
 C Z-Add PStartPoint StartPoint 3 0
 C StartPoint IfLt 1
 C Z-Add 1 StartPoint
 C EndIf
 C Z-Add *Zero S 3 0
 C*****
 C* Loop around for maximum of 10 entries
 C*****
 C S DOUEQ 10
 C ERBYTA ORGT *ZERO
 C Add 1 S
 C StartPoint Add S #PCounter
 D*****
 D* Send A message to specified queue
 D*****
 C Call 'QMHSNDPM'
 C Parm #PMsId 7
 C Parm #PMsgf 20
 C Parm 'SLIC' #PMSDT 4
 C Parm X'00000004' #PLen 4
 C Parm '*INFO' #PType 10
 C Parm '*' #PMSGQ 10
 C Parm #PCounter
 C Parm #PKey 4
 C Parm DSERR
 D*****
 D* Receive the message
 D*****
 C Call 'QMHRCVPM'
 C Parm RCVM0200
 C Parm RCVM0200Len
 C Parm 'RCVM0200' #PFormat 8
 C Parm '*' #PMSGQ
 C Parm *ZERO #PCounter
 C Parm '*ANY ' #PType
 C Parm #PKey
 C Parm *Zero #PWait
 C Parm '*REMOVE' #PAction 10
 C Parm DSERR
 C*****
 C* If no error, return stack entry
 C*****
 C ERBYTA IFeq *ZERO
 C MOVE RCVPgm @Stack(S)
 C EndIf
 C*
 C ENDDO
 C*****
 C* Put data structure back into parameter and
 C* return no of entries processed
 C*****
 C Move DSSTack PStack
 C S Sub 1 PEntries
 C*
 C RETURN
  • Hi Nick,
    Trying to get into the API world. Like the pgm for call stack. I wrote a CL to traverse up the call stack using SNDPGMMSG. I use it in my trigger pgm to see who fired the trigger. It works really well except for the embedded SQL updates. I get an error.
    CPF2479
    Message . . . . : Call stack entry not found.
    Cause . . . . . : Call stack entry QSQRUN3, specified for the send, receive,
    move or delete message operation, could not be found in the call stack.

    1. Does your pgm work on embedded SQL updates?

    2. IBM suggested I use the QWVRCSTK API to work the call stack but it is fairly complicated to figure out. Have you ever used it?

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

    >