× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hereby a procedure doing it.
Brgds
Helge

Usage:
GetCallerPgm = GetCaller();

Prototype:
*----------------------------------------------------------+
* Get Caller
*----------------------------------------------------------+
d GetCaller pr 10
d GetCallerPgm s 10
*----------------------------------------------------------+

Procedure:
*----------------------------------------------------------+
* Get Caller
*----------------------------------------------------------+
p GetCaller b
d pi 10

d ReturnCaller s 10

d QMHSNDPM pr extpgm('QMHSNDPM')
d MsgID 7A const
d MsgF 20A const
d MsgDta 32767A const options(*varsize)
d MsgDtaLen 10I 0 const
d MsgTyp 10A const
d MsgQ 10A const
d MsgStk 10I 0 const
d MsgKey 4A
d ApiErr 500A options(*varsize)
d QMHRCVPM PR extpgm('QMHRCVPM')
d Rcvr 32767A options(*varsize)
d RcvrLen 10I 0 const
d RcvrFormat 10A const
d MsgQ 10A const
d MsgStk 10I 0 const
d MsgTyp 10A const
d MsgKey 4A
d Wait 10I 0 const
d Action 10A const
d ApiErr 500A options(*varsize)

d ApiErrDs ds inz
d ApiErrSiz 10i 0 inz(%size(ApiErrDs))
d ApiErrLen 10I 0
d ApiErrId 7
d 1
d ApiErrDta 256

d MsgStk s 10I 0
d MsgKey s 4A inz(*BLANKS)

d Receiver ds based(pReceiver) qualified
d BytesRtn 1 4I 0
d BytesAvail 5 8I 0
d DtaAvailLen 85 88I 0
d MsgAvailLen 93 96I 0
d HlpAvailLen 101 104I 0
d SndAvailLen 109 112I 0
d InfoStart 113 113A

d ReceiverInfo ds based(pReceiverInfo) qualified
d Program 355 364
d Module 365 374
d Procedure 375 630
d Statement 645 654

d ReceiverLen s 10I 0
d pReceiver s * inz(%ADDR(InitReceiver))
d InitReceiver s like(Receiver)

/free

clear ReturnCaller;



MsgStk = 3; // very important setting the stack value



// Send a very short *INFO message to Caller

QMHSNDPM (*BLANKS : *BLANKS : '!' : 1

: '*INFO' : '*' : MsgStk : Msgkey : ApiErrDs );



// Receive it once to see how big the Receiver should be

QMHRCVPM (Receiver : %size(InitReceiver) : 'RCVM0300'

: '*' : MsgStk : '*INFO' : Msgkey : 0 : '*SAME' : ApiErrDs );



// Allocate the Receiver

ReceiverLen = Receiver.BytesAvail;

pReceiver = %alloc(ReceiverLen);



// receive the message again with into the allocated Receiver and Remove

QMHRCVPM (Receiver : ReceiverLen : 'RCVM0300'

: '*' : MsgStk : '*INFO' : Msgkey : 0 : '*REMOVE' : ApiErrDs );

// point to Receiver Info
pReceiverInfo = %ADDR(Receiver.InfoStart) + Receiver.DtaAvailLen
+ Receiver.MsgAvailLen
+ Receiver.HlpAvailLen;

// pull the Caller from Receiver Info
ReturnCaller = ReceiverInfo.Program;

// DeAllocate the Receiver
DeAlloc pReceiver;

return ReturnCaller;
/end-free
p e
*----------------------------------------------------------+
-----Oprindelig meddelelse-----
Fra: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] På vegne af Booth
Martin
Sendt: 11. maj 2014 22:26
Til: RPG programming on the IBM i / System i
Emne: How do I find the name of the calling program?

How do I find the name of the calling program? I have a program called from
several different programs. Is there a way to retrieve the name of the
calling program within the called program?

--
Booth Martin
www.martinvt.com
(802)461-5349
Skype: booth.martin

The computer can't tell you the emotional story. It can give you the exact
mathematical design, but what's missing is the eyebrows. -- Frank Zappa
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.