The real answer was given earlier in the chain, but then appears to have
gotten drown out in a flurry of alternatives. The problem is that the
storage for that variable does not exist in the running program. You need
to allocate the memory for the output parameter in program A, and then
pass that to program B. Otherwise you need to use some other form of
shared memory space like a user space. If you allocate program memory in
program B, then it may not be available due to program B shutting down.
If you do not shut down B by ending with LR off, what happens if the
activation group is reclaimed. Is program B running in a different
activation group? *New perhaps? Then the activation group and all the
program memory is going away when the program ends; not sure how LR
affects that.
If you need dynamically allocated memory in a case like this, it is safest
to use a user space. This object is not dependent on programs being
active. Otherwise allocate the memory in program A.
Mark Murphy
STAR BASE Consulting, Inc.
mmurphy@xxxxxxxxxxxxxxx
-----rpg400-l-bounces@xxxxxxxxxxxx wrote: -----
To: RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>
From: David FOXWELL <David.FOXWELL@xxxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
Date: 10/05/2009 08:59AM
Subject: RE: Pointer puzzle
Put a Watch on the pointer in called program program B. When the pointer
is changed, the pointer back in calling program A has the same value. But
in the router (between A and B).
As soon as router program goes past RETURN, the value of the pointer in
program A is lost.
> -----Message d'origine-----
> De : rpg400-l-bounces@xxxxxxxxxxxx
> [[1]mailto:rpg400-l-bounces@xxxxxxxxxxxx] De la part de David FOXWELL
> Envoy* : lundi 5 octobre 2009 13:42
> * : RPG programming on the IBM i / System i
> Objet : Pointer puzzle
>
> Hi, I thought I had pointers sussed, but it seems not. Hope
> someone can help.
>
> I'm calling program B from program A via a router program
> with a pointer in and out as parameters.
> I've debugged and I can see that program B receives a value
> *NULL for the output parameter pointer. It initialises the
> pointer, it is returned to the router OK, but once back in
> the calling program A, if I do EVAL on the pointer, I get
> CPF8E17, Pointeur non d*fini pour l'emplacement r*f*renc*. (
> would someone give me the English version of that message? ).
>
> Then, when I try and use the DS based on the pointer, it says
> I'm trying to access something that no longer exists
> (MCH3402). I wonder if the problem is not the pointer but the
> fact that the router program has ended?
>
> I've already successfully tested program B, using a test
> program to call it directly, now I'm testing with the router.
>
> Thanks.
>
>
> 1 .My Calling program (A)
> IF NOT ExcRouter (
> 'My program to call' :
> AnErrMg :
> wPtr_in :
> wPtr_out
> );
> RETURN *OFF;
>
> ENDIF;
>
> Procedure ExcRouter
> Callp routerpgm (
> APgmId :
> AnErrMg :
> Aptr_in :
> Aptr_out
> );
>
>
> 2 .Extract from routerpgm
> SELECT;
> WHEN %PARMS > 3;
> Trt03 (
> APtr_In :
> APtr_Out :
> AnErrMg
> );
>
> WHEN %PARMS > 2; .....etc
>
>
> D Trt03 PR EXTPGM ( APgmId )
> D APtr_In * OPTIONS ( *OMIT ) CONST
> D APtr_Out * OPTIONS ( *OMIT )
> D AnErrMg LIKE ( DFN_ERRMG )
>
>
> --
> This is the RPG programming on the IBM i / System i
> (RPG400-L) mailing list To post a message email:
> RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change
> list options,
> visit: [2]
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 [3]
http://archive.midrange.com/rpg400-l.
>
>
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing
list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: [4]
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 [5]
http://archive.midrange.com/rpg400-l.
References
Visible links
1. mailto:rpg400-l-bounces@xxxxxxxxxxxx
2.
http://lists.midrange.com/mailman/listinfo/rpg400-l
3.
http://archive.midrange.com/rpg400-l
4.
http://lists.midrange.com/mailman/listinfo/rpg400-l
5.
http://archive.midrange.com/rpg400-l
As an Amazon Associate we earn from qualifying purchases.