0 pts.
 ILE sub-procedure does not return data from a ReadE operation
Sub-procedure is directly bound to pgm and has f-spec to read a file based on incoming keys. Handles the keys correctly and sets conditions based on found/not found in the file but the input buffer never loads into the field names for the file. Object is to return entire found record as a data-structure (externally defined) to caller through Procedure Interface, eliminating need for file in application pgm. The only DS fields that ever get loaded are fields expressly loaded in calcs from input parameters. I set a break-point immediately after the READE, pgm reads a record but the fields do not contain any data. Does this issue ring any bells with anyone?

Software/Hardware used:
ASKED: March 16, 2005  6:29 PM
UPDATED: April 1, 2005  8:10 AM
  Help
 Approved Answer - Chosen by TomLiotta

You probably defined the externally defined data structure within the procedure, thereby inadvertently creating two sets of fields: the global ones that are automatically created by the RPG compiler and the local ones you defined within your procedure. When you read a record, the global fields are filled with the input data; the local fields stay empty.

Remember:
- all file data is global
- local fields effectively hide global fields with the same names.

ANSWERED:  Mar 29, 2005  1:35 AM (GMT)  by TomLiotta

 
Other Answers:

I suggest you define the data structure in both the program AND the subprocedure. Define the structure in the subprocedure as “based” on a pointer and pass the pointer instead of the datastructure into the procedure. When you define the structure in the program, define a separate pointer field and initialize it to the %addr of the data structure. This is the pointer that you would pass.

Last Wiki Answer Submitted:  March 17, 2005  7:59 am  by  mygoodname   0 pts.
Latest Answer Wiki Contributors:  mygoodname   0 pts.
To see other answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

The contents of the datastructure pass back ok. I’m not getting any of the fields loaded from READE within the sub-procedure. The sub-proc is in its own nomain module and bound at compile-time. After the Read operation (in the proc) the fields coming from the file are all initialized as either blanks or zeros. Anything I load into the DS fields directly stays & gets passed back to the caller of the proc. I’m thinking this may have something to do with activation group and scope, the file/field data has to go somewhere… The Chain or ReadE finds the correct record but everything but the key fields remains initialized (in the sub-proc, immediately after the operation).

 0 pts.

 

If you are not specifying INFSR on the F-spec, try placing it, along with the data structure, after the PI so that all of the variables are local to the subprocedure.

 0 pts.

 

After the Reade operation, try this in the procedure.

Move the Ds loaded to the Ds to be Returned.

eg.
F Customer
D CustomerDs E ds
P pCustomerDs like(CustomerDs)

SetLL….
Reade E…
pCustomerDs = CustomerDs;

 0 pts.

 

Have you tried to read a record into data structure?

d PI likeds(datastructure)

c key chain fileformat datastructurname
return datastructurename

The data structure could be defined as:
d datastructurename ds LIKEREC fileformat:*INPUT)

 0 pts.

 

Try not to use %found, use the old indicator way of read and chain. I know it is starnge but I have found a few situations that %found doesn’t work properly.

 0 pts.

 

If you could post some code it would help a great deal. While the previous suggestions have been good, without seeing what your procedure is doing we are shooting in the dark.

Using %FOUND isn’t related to your issue so don’t worry about that.

One thing not yet mentioned is that depending on how you defined your data structure in the subprocedure it my be a qualified data structure even though you don’t use the QUALIFIED keyword. If so, you will need to explicitly move each field from the file into the corresponding data structure field. Alternatively, you can read directly into the data structure as mentioned in a previous post. If I understand your situation correctly that is how I would do it. Even if the DS isn’t qualified.

 0 pts.

 

Thanks to all. Number 8 wins the prize though. The external DS was defined inside the proc instead of above it with the file spec.

Dave

 0 pts.

 

Even though %Found is not part of the problem remember that with READE it is not a Found or not found condition that gets set. Instead you will get an %EOF rather than Not %Found. Just as with obsolute indicators you had a Error or End of File, Now you have a %Error or %EOF. Do not use %Found with READE the %Found will never get set.

Remember: Chain = %Found

 0 pts.