File Open/Close necessary?

jimmymac

Reputable Poster
This may be a common question, but couldn't find another thread for it. I'm looking at an existing custom UBE at my client. It does a F0411.Open in the Initialize Section, then in the Do section does a Select and FetchNext of the F0411. Then in the End section it does a F0411.Close.

My question, is it necessary really to do an explicit open/close? I thought that the Open would be done when the file is accessed and the Close would be done when the program ended. I was at JDE in the 90s and we were never told we needed to do explicit Opens/Closes in a UBE or NER or anywhere. Yet I do see this often in JDE custom code.

Any opinions as to whether this is really necessary?

Thanks
 
Hi jimmymac

I have found that in earlier releases that not using File Open/Close when using a Select and FetchNext can lead to memory leaks. I'm not entirely certain if this same technique is required in later releases, but I tend to use them anyway to make sure no problems arise.

Hope this helps
Aidy
 
Theoretically speaking they are not required UNLESS you are using a file handle(s).

However, like Aidy, I often use them anyway when doing table I/O that requires multiple calls like a select/fetch next. Too me it just makes the code easier to understand and less prone to logic errors.

One thing I have not done is do any tests to try and reverse engineer what happens when you don't use them. It is easy to see how ER code can simply do an implied open if there is not an open, internal handle, but what is the scope of this internal handle? When is it closed? In other words is it safe to do a select/fetch next in one section, then call another custom section that does a fetch keyed on the same table? Rather than figure all this out I have just explicitly used file open/close calls and use file handles if multiple events do multi-call table I/O statements against the same table... or just put it in a BSFN and eliminate all doubt.
 
Hi jimmymac,

An open close is done in UBe wherever transaction processing is done. That is manual rollback is necessary. In such report's you find a Open before the insert or update and close at the end section. Yes also a open close is needed for a handle based select fecth.

generally a Select event rule runs the JDB_Open table api.
 
I've just come across this thread when doing a review of some code at my new job.

I was led to believe, from a very trusted source and ex JDE employee, that are very useful and the right way to do things.

When you look at your jdedebug.log for the SQL commands etc, you can see the Select and Fetch next commands which relate to your ER code of:
SELECT then FETCH NEXT

But

If you change the ER code to a simple FETCH SINGLE you will see the following in your logs

OPEN TABLE
SELECT
FETCH NEXT
CLOSE TABLE

You didn't enter them, JDE did on your behalf.
So JDE will automatically add and insert these IO commands on a simple fetch next.

From that alone I am led to believe it is the right thing to do as JDE does it when you just want one record
 
Back
Top