cleancut-fluent

(Answer) (Category) iSeries / AS400 FAQ : (Category) Programming :
How can I identify the name of the program that called this one?
Here it goes, This is a low tech solution and can be made into Procedures using Message API's if you want to make it real fancy. But as is, it will also work for the average Joe/Jane programmer too.

For trigger's, in your *INZSR subroutine repeatedly call a CLP to retrieve the program name of the caller. You can "walk up the Stack" past the programs(OS/400's that begin with "Q") to the program you're looking for.


Just call the below program repeatedly(in a loop in your *INZSR), First time pass your trigger program name(the program who's *inzsr you are currently in that is) as the &CALLED, and who ever called your trigger will be returned in the &CALLER variable. This will undoubtedly be a "Q" OS/400 program. Call the CLP again this time pass what was returned the first time to find out who called him, and so on up the stack till *EXT.

Stop at the first program name(&CALLER) doesn't begin with a "Q". That's the application program that kicked off the trigger..


PGM    &CALLER &CALLED

DCL   &CALLER  *CHAR  10  
DCL   &CALLED  *CHAR  10
DCL   &M1KEY   *CHAR   4
DCL   &M1MDTA  *CHAR  80

SNDPGMMSG  MSG('TEST')  TOPGMQ(*PRV &CALLED) MSGTYPE(*RQS) KEYVAR(&M1KEY)

RCVMSG   PGMQ(*PRV &CALLED)  MSGKEY(&M1KEY)  SENDER(&M1MDTA)

CHGVAR   &CALLER    %SST(&M1MDTA  56 10)

ENDPGM

So, just call it with a program name(&CALLED) and it will tell you who called that program (&CALLER) , next time pass it what was returned the previous time to find out who called him, and so on up the stack. Look at the name returned (&CALLER). If the first position of the name is a "Q" it's an OS/400 program. (Unless you start your program names with the letter Q ?)

Answer courtesy John Carr via MIDRANGE-L 17 Sep 1999

A search through the archives at http://archive.midrange.com using "call stack" reveals several other good answers as well.


Also, the QWVRCSTK API is available on V5R1 systems and beyond.
ans-ins-part
Append to This Answer
buck.calabro, david
Previous: (Answer) How do I determine if a specific spool file exists?
Next: (Answer) How can I print barcodes on an HP printer?
This document is: http://faq.midrange.com/index.pl?file=95
[Search] [Appearance]
This is a Faq-O-Matic 2.721.