Over the last couple of days I have been enhancing the EDI 816 Organization document automation for NanjingUSA. Last week I added an enhancement to process the Wal-Mart document by Global Location Number and send E-mail with the update statistics.
The Organizational Relationships (EDI 816) document is used to communicate location address and relationship information. On the most frequently exchanged EDI documents (the PO, ASN, and invoice) locations are most often identified only by codes in order to avoid the cost of transmitting full addresses. Location codes are unique to a specific trading partner. The 816 document tells trading partners the address to associate with a particular location code. The trading partner receiving the 816 can use it to maintain a list of the sender's location codes and associated addresses. An alternate format of the 816 is used to show organizational relationships, such as stores serviced by a specific Distribution Center or warehouse. Trading of 816's begins with a full set of the trading partner's addresses, after which changes may be sent on a weekly or monthly basis, or as needed.
My new challenge is due to the capability of receiving different GLN number for the same store. This is a normal situation as the first record received has a delete code and the second record is the add to replace the previous recorded deleted. The VAI ship to master file is uniquely keyed by company, customer # and ship to #. The deficiency here is that VAI does not have the record status as part of the unique key. This file is way to integrated to change the physical file key at this point. With this scenario the program will halt with a duplicate record key when the record is written to the file.
If NanjingUSA was a bigger operation and I had access to Hawkeye cross reference I would change the DDS and add the status field to the unique key. But for now I will just code around the deficiency.
So now it is time to look into the new MONITOR operation code that I have never used before. I want to be able to avoid the program halting and waiting for someone to answer the program error message. The EDI 816 process is automated thru the job scheduler .
I also want to be able to call the VAI SNDMAIL program from the RPGLE to send E-mail with the failing store and GLN numbers. I could have created a couple of parameters and pass parameters back to the calling CL program to send the E-mail but I wanted to also practice with Prototypes and QCMDEXEC.
* Add shipvia record */
C Addrec BEGSR
C kshp CHAIN varshp2
C IF NOT %FOUND
C ….Populate fields …..
* Determine is store or DC
* …End populate fields
C write arshipr
C eval recadd = recadd + 1
C exsr Chgrec found then chg
@RecipFull = %trim(userid) + ' ' + %trim(emaddr);
@msg = 'Possible duplicate store, check EDI816H2 +
errors. Store ' + BHDSNB + ' and GLN ' +
BHGLN + '.';
Cmd_Str = 'sndmail recipient((' + %trim(@Recipfull) + ')) +
sender(' + %trim(@SendFull) + ') +
ExcCmd (Cmd_Str: %len(Cmd_Str));
recerr = recerr + 1;
$pos2 = 1;
The real trick here is creating the command string and overcoming the short comings of the SNDMAIL program. The Subject and Message will not accept variables. So I added a new member to the QHTMLSRC source file and added some embedded SQL to a subroutine to update the file with the error information. This enables me to send a HTML message using the SNDMAIL.
* Change file path in source file to send in E-mail
C+ Create alias qtemp/errormsg for r37nan/qhtmlsrc(errormsg)
C+ update qtemp/errormsg
C+ set srcdta = :@msg
C+ where RRN(errormsg)=2
C+ Drop alias qtemp/errormsg
One thing that I should change is hardcoding the library. I also could monitor for the exact error for duplicate key message but it is adequate to just capture any error when writing the new record. Also if the record is in error the input record status code is change to 'X' and logical file has select of status of blank or 'X'. This file quickly identifies records not processed and / or in error.
All in all this is really cool stuff, they really made coding for program and file errors very easy. You may also notice that there is a mix of free and legacy code, I wrote this program four years ago and currently there is no need the rewrite the program.