...
Code Block |
---|
var command = "CRTDUPOBJ OBJ(ORDERSP) FROMLIB(DATALIB) OBJTYPE(*FILE) TOLIB(QTEMP) NEWOBJ(WORKFILE) DATA(*NO)";
pjs.runCommand(command); |
Examples for error-handling
No error-handling: run-time error is thrown if command has error
Code Block |
---|
pjs.runCommand(`CHKOBJ OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)`);
Error thrown:
Profound.js Error: Object MYFILE in library MYLIB not found. : CPF9801 - Cause . . . . . : The object MYFILE in library MYLIB type *FILE not found. The object name, library name, or the object type is not correct. If the library name is not specified, the object may be in a library that is not contained in the library list. Recovery . . . : Correct the object name, library name, or object type. If the library name was not specified, specify the library name and try the request again.
at profound.runCommand (c:\dev\profoundjs\profoundjs\api\runCommand.js:73:29)
at process.processTicksAndRejections (c:\dev\profoundjs\lib\internal\process\task_queues.js:95:5)
at async Object.app (c:\dev\profoundjs\modules\ado12345\mypgm_01.js:3:5)
at async profound.call (c:\dev\profoundjs\profoundjs\api\call.js:162:25)
at async profound.utils.<computed> [as handleExternalCall] (c:\dev\profoundjs\profoundjs\dat\bdba69cb3be3b6c.js:1:23224)
at async Strand._fn (c:\dev\profoundjs\profoundjs\server\controller.js:221:11)
at async C:\dev\profoundjs\node_modules\profoundjs-strands\index.js:29:18
at async Strand.run (C:\dev\profoundjs\node_modules\profoundjs-strands\index.js:28:16) {statusCode: 'CPF9801', name: 'Profound.js Error', appJob: undefined, currUser: undefined, stack: 'Profound.js Error: Object MYFILE in library M…_modules\\profoundjs-strands\\index.js:28:16)', …}
|
Use try/catch
Code Block |
---|
CL code:
CHKOBJ OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)
MONMSG MSGID(CPF0000)
PJS code:
try {
pjs.runCommand(`CHKOBJ OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)`);
} catch (error) {
console.log(`handle error here if needed`);
}
|
Specify 2nd optional parameter ignoreError as “true”
Code Block |
---|
CL code:
CHKOBJ OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)
MONMSG MSGID(CPF0000)
PJS code:
pjs.runCommand(`CHKOBJ OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)`, true); |
Specify 2nd optional parameter ignoreError as “true”, and specify a MsgId field to get error MsgId
Code Block |
---|
CL code:
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
CHKOBJ OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)
MONMSG MSGID(CPF0000) EXEC(DO)
RCVMSG MSGID(&MSGID)
/* handle error based on MsgId here */
ENDDO
PJS code:
pjs.define("msgId", {type: 'char', length: 7});
pjs.runCommand(`CHKOBJ OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)`, true, msgId);
if (msgId != "") {
console.log(`msgId = ${msgId}`);
// handle error based on msgId here
} |
Specify 2nd optional parameter ignoreError as “true”, specify a MsgId field to get error MsgId, and check return value
Code Block |
---|
CL code:
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
CHKOBJ OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)
MONMSG MSGID(CPF0000) EXEC(DO)
RCVMSG MSGID(&MSGID)
/* handle error based on MsgId here */
ENDDO
PJS code:
pjs.define("msgId", { type: 'char', length: 7});
if (pjs.runCommand(`CHKOBJ OBJ(MYLIB/MYFILE) OBJTYPE(*FILE)`, true, msgId) != 0) {
console.log(`msgId = ${msgId}`);
// handle error based on msgId here
}
|
Requirements
This API requires the Profound.js Connector module.
...