This program illustrates how to use APIs to create and manipulate a *DTAQ.
Refer to Example in ILE C: Data queue for the original example.
F*************************************************************** F*************************************************************** F* F* Program Name: DQUEUEX F* F* Programming Language: OPM RPG F* F* Description: This program illustrates how to use APIs to F* create and manipulate a *DTAQ. F* F* Header Files Included: QUSEC - Error Code Parameter F* QCAPCMD - Process Command API F* F*************************************************************** F* FQPRINT O F 132 PRINTER UC F*************************************************************** I* I* Error Code parameter include I* I/COPY QSYSINC/QRPGSRC,QUSEC I* I* Process Command API Include I* I/COPY QSYSINC/QRPGSRC,QCAPCMD I* I* Command strings I* I DS I I 'CRTLIB LIB(QUEUELIB)' 1 20 CRTLIB I I 'DLTLIB LIB(QUEUELIB)' 21 40 DLTLIB I I 'CRTDTAQ DTAQ(QUEUELI- 41 82 CRTDQ I 'B/EXAMPLEQ) MAXLEN(1- I '0)' I I 'DLTDTAQ DTAQ(QUEUELI- 83 113 DLTDQ I 'B/EXAMPLEQ)' I* I* Miscellaneous data structure I* I DS I 1 100 CMDSTR I B 101 1040LENSTR I I 20 B 105 1080SIZE I I 0 B 10901120RCVSIZ I I '0' 113 113 FSTERR I 114 123 APINAM C* C* Beginning of mainline C* C* Initialize the error code parameter. To signal exceptions to C* this program by the API, you need to set the bytes provided C* field of the error code to zero. Because this program has C* exceptions sent back through the error code parameter, it sets C* the bytes provided field to the number of bytes it gives the C* API for the parameter. C* C Z-ADD16 QUSBNB C* C* Initialize QCAPCMD options control block for CL processing C* C Z-ADD0 QCABCB C MOVE '0' QCABCC C MOVE '0' QCABCD C MOVE '0' QCABCF C MOVE *BLANKS QCABCG C MOVE *LOVAL QCABCH C* C* Create library QUEUELIB C* C MOVELCRTLIB CMDSTR C Z-ADD20 LENSTR C* C EXSR EXCCMD C* C* Create a data queue called EXAMPLEQ in library QUEUELIB. The C* queue will have a maximum entry length set at 10, and will be C* FIFO (first-in first-out). C* C MOVELCRTDQ CMDSTR C Z-ADD42 LENSTR C* C EXSR EXCCMD C* C* Send information to the data queue. C* C CALL 'QSNDDTAQ' C PARM 'EXAMPLEQ'QUENAM 10 C PARM 'QUEUELIB'LIBNAM 10 C PARM 10 MSGSZ 50 C PARM 'EXAMPLE' MSG 10 C* C* Retrieve information from the data queue. C* C CALL 'QRCVDTAQ' C PARM 'EXAMPLEQ'QUENAM 10 C PARM 'QUEUELIB'LIBNAM 10 C PARM 10 MSGSZ 50 C PARM MSGBCK 10 C PARM 0 WAITTM 50 C* C* Display the returned message C* C DSPLY MSGBCK C* C* Delete the data queue C* C MOVELDLTDQ CMDSTR C Z-ADD31 LENSTR C* C EXSR EXCCMD C* C* Delete the library C* C MOVELDLTLIB CMDSTR C Z-ADD20 LENSTR C* C EXSR EXCCMD C* C SETON LR C RETRN C* C* End of MAINLINE C* C***************************************************************** C* C EXCCMD BEGSR C* C* Process requested CL command C* C CALL 'QCAPCMD' C PARM CMDSTR C PARM LENSTR C PARM QCABC C PARM SIZE C PARM 'CPOP0100'FORMAT 8 C PARM RCVVAR 1 C PARM 0 RCVSIZ C PARM RCVSIZ C PARM QUSBN C* C* If an exception occurs, the API returns the exception in the C* error code parameter. The bytes available field is set to C* zero if no exception occurs and greater than zero if an C* exception does occur. C* C QUSBNC IFGT 0 C MOVEL'QCAPCMD' APINAM C EXSR ERRCOD C ENDIF C ENDSR C* C***************************************************************** C* C ERRCOD BEGSR C* C* Process errors returned from the API. C* C* If first error found, then open QPRINT *PRTF C* C FSTERR IFEQ '0' C OPEN QPRINT C MOVEL'1' FSTERR C ENDIF C* C* Print the error and the API that received the error C* C EXCPTBADNEW C* C ENDSR OQPRINT E 106 BADNEW O 'Failed in API ' O APINAM O 'with error ' O QUSBND