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: ILE 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 OFLIND(*INOF) USROPN F*************************************************************** D* D* Error Code parameter include D* D/COPY QSYSINC/QRPGLESRC,QUSEC D* D* Process Command API Include D* D/COPY QSYSINC/QRPGLESRC,QCAPCMD D* D* Command strings D* D DCRTLIB C 'CRTLIB LIB(QUEUELIB)' DDLTLIB C 'DLTLIB LIB(QUEUELIB)' DCRTDQ C 'CRTDTAQ DTAQ(QUEUELIB/+ D EXAMPLEQ) MAXLEN(10)' DDLTDQ C 'DLTDTAQ DTAQ(QUEUELIB/EXAMPLEQ)' D* D* Miscellaneous data structure D* DCMD_STR S 100 DLEN_STR S 9B 0 DCAP0100_SZ S 9B 0 INZ(%SIZE(QCAP0100)) DRCVVAR_SZ S 9B 0 INZ(0) DAPI_NAME S 10 DFIRST_ERR S 1 INZ('0') 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 EVAL QUSBPRV = %SIZE(QUSEC) C* C* Initialize QCAPCMD options control block for CL processing C* C EVAL QCACMDPT = 0 C EVAL QCABCSDH = '0' C EVAL QCAPA = '0' C EVAL QCACMDSS = '0' C EVAL QCAMK = *BLANKS C EVAL QCAERVED = *LOVAL C* C* Create library QUEUELIB C* C EVAL CMD_STR = CRTLIB C EVAL LEN_STR = %SIZE(CRTLIB) C* C EXSR EXEC_CMD 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 EVAL CMD_STR = CRTDQ C EVAL LEN_STR = %SIZE(CRTDQ) C* C EXSR EXEC_CMD C* C* Send information to the data queue. C* C CALL 'QSNDDTAQ' C PARM 'EXAMPLEQ ' NAME_OF_Q 10 C PARM 'QUEUELIB ' NAME_OF_LB 10 C PARM 10 MSG_SZ 5 0 C PARM 'EXAMPLE ' MSG 10 C* C* Retrieve information from the data queue. C* C CALL 'QRCVDTAQ' C PARM 'EXAMPLEQ ' NAME_OF_Q C PARM 'QUEUELIB ' NAME_OF_LB C PARM 10 MSG_SZ C PARM MSG_BACK 10 C PARM 0 WAIT_TIME 5 0 C* C* Display the returned message C* C DSPLY MSG_BACK C* C* Delete the data queue C* C EVAL CMD_STR = DLTDQ C EVAL LEN_STR = %SIZE(DLTDQ) C* C EXSR EXEC_CMD C* C* Delete the library C* C EVAL CMD_STR = DLTLIB C EVAL LEN_STR = %SIZE(DLTLIB) C* C EXSR EXEC_CMD C* C EVAL *INLR = '1' C RETURN C* C* End of MAINLINE C* C***************************************************************** C* C EXEC_CMD BEGSR C* C* Process the requested CL command C* C CALL 'QCAPCMD' C PARM CMD_STR C PARM LEN_STR C PARM QCAP0100 C PARM CAP0100_SZ C PARM 'CPOP0100' FORMAT 8 C PARM RCVVAR 1 C PARM 0 RCVVAR_SZ C PARM RCVVAR_SZ C PARM QUSEC 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 IF QUSBAVL > 0 C EVAL API_NAME = 'QCAPCMD' 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 IF FIRST_ERR = '0' C OPEN QPRINT C EVAL FIRST_ERR = '1' C ENDIF C* C* Print the error and the API that received the error C* C EXCEPT BAD_NEWS C* C ENDSR OQPRINT E BAD_NEWS 1 O 'Failed in API ' O API_NAME O 'with error ' O QUSEI