Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
Good morning. I'm really hoping someone might have some suggestions, because this issue has me baffled. I have an SQLRPGLE program that is running in batch, called by multiple programs simultaneously. There are a few fields in one of the output files that are randomly not being populated. It is very simple straight forward code, so it's driving me crazy.
Here's how it works:
There is a file that is being read as the driver file. I'm using a SELECT statement with the "FOR UPDATE OF' clause so that the record is locked to that instance of the program.
I have a procedure that is call and passed an order number. It retrieves customer information from 3 different files, populating a data structure (The reason I populate a data structure is because this customer information retrieval process is a copy module used by multiple different programs).
When the program returns from the call to the customer information procedure it populates fields in the output file from the data structure and writes the record. The fields that are randomly not being populated are in this output file.
Here's a snippet of the procedure code, below. You can assume that the key fields are correct. The issue is where I am trying to retrieve the SODZAD records. Those fields in the data structure are the ones that are randomly blank. Now, I know that if that record was locked by some other process, the chain may not work, but wouldn't I at least get an error on the chain? Should I change it to chain(e) and if an error, loop retrying the chain until it's successful? Or perhaps I missed something I should have selected in the compile?
Any help would be greatly appreciated. I'm going nuts here!! Thanks!!!
d*------------------------------------------------------------------------
d* rtvCustInfo - Customer Information Retrieval procedure
d*------------------------------------------------------------------------
prtvCustInfo b
drtvCustInfo pi
d pordno 8p 0
d* local variables definition
/free
resetcustInfoDS;
// retrieve SODA order header
chainpordno sodhdr;
if %found;
setllpordno sodadr;
readepordno sodadr;
dow not %eof(sodadr);
// B I L L - T O I N F O R M A T I O N P R O C E S S I N G
if oadlpt = ohbilp;
btadr1 = oaadr1;
btadr2 = oaadr2;
btadr3 = oaadr3;
btcity = oacity;
btcnty = oacnty;
btzip = oaptzc;
btstat = oaprst;
if oacntr = 'USA';
btctry = 'US ';
else;
btctry = oacntr;
endif;
// retrieve bill to name and phone number
chain(pordno:oadlpt) sodzad;
if %found(sodzad);
btphon = oatphn;
btfnam = oafnam;
btlnam = oalnam;
btemal = oaeml1;
endif;
// S H I P - T O I N F O R M A T I O N P R O C E S S I N G
else; <- This ELSE would skip the BTxxx fields assignment above.
stadr1 = oaadr1;
stadr2 = oaadr2;
stadr3 = oaadr2;
stcity = oacity;
stcnty = oacnty;
stzip = oaptzc;
ststat = oaprst;
if oacntr = 'USA';
stctry = 'US ';
else;
stctry = oacntr;
endif;
// retrieve ship to name
chain(oaohno:oadlpt) sodzad;
if %found;
stphon = oatphn;
stfnam = oafnam;
stlnam = oalnam;
stemal = oaeml1;
endif;
// retrieve shipping menthod
chain(pordno:2) sodadd;
if %found(sodadd);
shpmth = %trim(oacarr);
endif;
endif;
readepordno sodadr;
enddo;
endif;
/end-free
prtvCustInfo e
The only two things I would guess is either:
If the solution isn't clear, my guess would be that the section of code resulting in blanks (which I speculate isn't being called) should probably be moved to just under the DOW statement.
Hi Bob
You're right, I'm not passing the DS as a parm. It's just defined up in the D specs and cleared and populated in this procedure. As for the "else", there are two SODADR records per order. The first record has an OADLPT value of 1 (Billing info) and 2 (Shipping info). So each read populates a different part of the DS.
You are CHAINing to sodzad before the fields in question.
Yes, I am, Bob. The weird thing is, that sometimes it may even get the name, but leave the email address blank even tho both are populated in the SODZAD file. It really makes no sense.
// retrieve bill to name and phone number
chain(pordno:oadlpt) sodzad;
if %found(sodzad);
btphon = oatphn;
btfnam = oafnam;
btlnam = oalnam;
btemal = oaeml1;
endif;
Can you post your struct used for BTxxxx fields? Or do those field names come directly out of the file itself?