× 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.




On 23/08/2008, at 5:19 AM, Mike Cunningham wrote:

No service program in use, it is bound by copy. The module has a NO MAIN clause on the H: spec and only has one procedure. There is no SQL involved. The module opens one of two files depending on what was passed and does one chain operation and then returns

Let's see: You have:
o module A declares file X
o module B declares file X USROPN
o module A opens file X
o module A reads file X in a loop
o module A calls module B for each record read
o module B opens file X if not already open
o module B returns a result to module A
o module A and module B are bound-by-copy into program K
o program K has a *NEW activation group

If that's an accurate description of your code then you should see TWO full opens of file X: one from module A and one from the first call to module B but you should NOT see additional opens for subsequent calls to module B.

Given that it is highly unlikely for %OPEN to be broken the problem must be in your code. Create a cut-down version that manifests the problem and show us the code.

Here is some example code for you to play with.

* Module A : Change XXXXXXXX to any file that exists on your system
FXXXXXXXX UF E DISK USROPN
D result S 50
D B PR 50
C IF NOT( %OPEN( XXXXXXXX ) )
C OPEN XXXXXXXX
C 'Opened by A' DSPLY
C ENDIF
C READ(E) XXXXXXXX
C DOW NOT( %EOF( XXXXXXXX ) )
C EVAL result = B()
C result DSPLY
C READ(E) XXXXXXXX
C ENDDO
C SETON LR
C RETURN

* Module B: Change XXXXXXXX to the same file in module A
H NOMAIN

FXXXXXXXX UF E DISK USROPN
D B PR 50
P B B EXPORT
D B PI 50
D result S 50
C IF NOT( %OPEN( XXXXXXXX ) )
C OPEN XXXXXXXX
C EVAL result = 'Opened by B'
C ELSE
C EVAL result = 'Already open'
C ENDIF
C RETURN result
P B E

Compile each module with system-supplied defaults. Create program with:
CRTPGM PGM(K) MODULE(A B)

Running:
CALL K
gives:

DSPLY Opened by A
DSPLY Opened by B
DSPLY Already open
DSPLY Already open
DSPLY Already open
DSPLY Already open

Files (and therefore %OPEN status) are global to the MODULE not the PROGRAM which explains the 2 opens. I think VRM610 has support for passing files between modules (and maybe programs) but I've not experimented with that feature.


Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.