You are on page 1of 9

Using IBM-Supplied APIs

Part 19

Presentation Copyright 2008, Bryan Meyers, www.bmeyers.net


Introduction to APIs

Application programming interfaces


Enable access low-level machine functions or
secured system data
Usually callable programs
Documented interface remains constant between
IBM i releases
Using QCMD

Executes CL command requests


Displays full command entry screen
CALL QCMD
Using QUSCMDLN

Displays command line window


CALL QUSCMDLN
Using QCMDCHK

Checks syntax of single CL command


Optionally prompts for command
Does not execute command
Returns CPF0006 error if command is incorrect
Returns correct command string to program
PGM
DCL &cmdstr *CHAR 3000 VALUE('?DSPLIB ??LIB() ?-OUTPUT(*PRINT)')

PROMPT:
CALL QCMDCHK PARM(&cmdstr 3000)
MONMSG MSGID(CPF6801 CPF0006) EXEC(GOTO PROMPT)
SBMJOB JOB(DISPLAY) RQSDTA(&cmdstr)

RETURN
ENDPGM
Using QCMDEXC

Executes a single command


Command executes at same call stack level as
API call
PGM
DCL &cmdstr *CHAR 3000 VALUE('?DSPLIB ??LIB() ?-OUTPUT(*PRINT)')

PROMPT:
CALL QCMDCHK PARM(&cmdstr 3000)
MONMSG MSGID(CPF6801 CPF0006) EXEC(GOTO PROMPT)
CALL QCMDEXC PARM(&cmdstr 3000)
MONMSG CPF0000

RETURN
ENDPGM
Other APIs
QCLSCAN scans character string
QDCXLATE translates characters
E.g., lowercase to uppercase
Data queue APIs
QSNDDTAQ sends entry to data queue
QRCVDTAQ reads entry from data queue
User space APIs
QUSCRTUS creates user space
QUSPTRUS retrieves pointer to user space
QUSCHGUS changes contents of user space
QUSRTVUS retrieves contents of user space
Other APIs

List APIs
QUSLFLD lists record layout into user space
QUSLJOB lists jobs into user space
QUSLMBR lists database file members into user
space
QUSLOBJ lists objects into user space
QUSLRCD lists record formats into user space
QUSLSPL lists spooled files into user space
ILE Bindable APIs

Common Execution Environment (CEE) APIs


are ILE procedures, not programs
Call using CALLPRC (Call Procedure) command
PGM PARM(&days &startdate)
DCL &days *DEC (15 5)
DCL &startdate *CHAR 8
DCL &ldateint *INT 4
DCL &message *CHAR 50
DCL &newdate *CHAR 10
/* Get Lilian date for date parameter */
CALLPRC CEEDAYS PARM(&startdate 'MMDDYYYY' &ldateint *OMIT)
/* Add the number of days (first parameter) */
CHGVAR &ldateint (&ldateint + &days)
/* Get the calculated date in MM/DD/YYYY format */
CALLPRC CEEDATE PARM(&ldateint 'MM/DD/YYYY' &newdate *OMIT)
/* Build the message and send it */
CHGVAR &message ('The new date is ' *CAT &newdate)
SNDPGMMSG MSG(&message) TOPGMQ(*EXT)
ENDPGM

You might also like