Source Code for Open Access Handler Template | |||||||||||
This is a basic template for an Open Access handler program. I developed it after I had written a number of other examples which is why you will find some of the techniques used slightly different and, hopefully, easier to follow. | |||||||||||
|
H DftActGrp(*No) Option(*SrcStmt) // User Data - normally in a copy source - modify as required D userData_T ds D userParm 10a // Standard IBM supplied Open Access definitions /Copy QRNOPENACC // Copy constants for all RPG status codes - write your own or use mine // email me at Contact at Partner400 dot com if you would like a copy /Copy MonStatCds // Protos for program and local procedures - not needed v7+ D OpenFile Pr D CloseFile Pr // Change to ExtProc etc. if required D HandlerName Pr ExtPgm('HANDLERNM') D info likeds(QrnOpenAccess_T) d userData ds Based(info.userArea) // Add fields as required - normally this is in a /Copy // Remove input and output buffer definitions if not needed d inputBuffer s 64512a Based(info.inputBuffer) d outputBuffer s 64512a Based(info.outputBuffer) // Field Names/Values structures if required D nvInput ds likeds(QrnNamesValues_T) D based(info.NamesValues) // State info d stateInfo DS Based(info.stateInfo) Qualified // Add the data defintions for whatever fields you need preserve for a specific file D RcvDQHand1 PI D info likeds(QrnOpenAccess_T) /Free Select; // Add When clauses here for all required operations // READ, CHAIN, SETLL, etc. - Whatever you need When (info.rpgOperation = QrnOperation_OPEN); OpenFile(); When (info.rpgOperation = QrnOperation_CLOSE); CloseFile(); Other; // We don't know how to do this operation Dsply ('Unsupported function ' + %Char(info.rpgOperation) + ' on queue ' + info.externalFile.name ); info.rpgStatus = errIO; EndSl; Return; /End-Free // Basic outline logic for Open function P OpenFile B D PI /Free // If no state info area yet allocate now and initialize If info.stateInfo = *null; info.stateInfo = %Alloc( %Size(stateInfo)); Clear stateInfo; EndIf; // Check if user parm was supplied and any set defaults if needed // Store the values in the state info area oitherwise if values change // in the user parm it migth really mess us up If info.userArea = *Null; // Set any default values required by handler Else; // Copy user supplied data into state info area to preserve EndIf; Return; /End-Free P OpenFile E P CloseFile B D PI /Free // Release storage holding state information and set pointer to null. // That way we can't ever reference it by mistake. Dealloc info.stateInfo; info.stateInfo = *null; info.rpgStatus = stsOK; Return; /End-Free P CloseFile E |
||||||||||
Return to Home Page |
Want
more information? |