如何於應用軟體中建立類似系統的 Command line ?
File : QDDSSRC
Member: SHELL
Type : DSPF
Usage : CRTDSPF SHELL
A R LINE BLINK
A OVERLAY
A CF03(03 'exit')
A CF04(04 'prompt')
A CF08(08 'retrieve')
A CF09(09 'retrieve')
A CF12(12 'cancel')
A 1 32'Sample Command Line' DSPATR(HI)
A 20 2'Type command, press Enter.'
A 21 2'===>'
A COMMAND 153A B 21 7DSPATR(UL) CHECK(LC)
A 23 2'F3=Exit F4=Prompt -
A F8=RetrieveA F9=Retrieve -
A F12=Cancel'
A COLOR(BLU)
*
A R MSGSFL SFL
A SFLMSGRCD(24)
A MSGKEY SFLMSGKEY
A PROGRAM SFLPGMQ(10)
*
A R MSGCTL SFLCTL(MSGSFL)
A OVERLAY
A SFLDSP
A SFLDSPCTL
A SFLINZ
A SFLSIZ(25)
A SFLPAG(1)
*
A 99 SFLEND
A PROGRAM SFLPGMQ(10)
File : QCLSRC
Member: BLDCMDLINE
Type : CLP
Usage : CRTCLPGM BLDCMDLINE
CALL BLDCMDLINE
Pgm
Dclf File(Shell)
Dcl &ArchiveKey *char 4
Dcl &Big *char 6000
Dcl &BoundryKey *char 4
Dcl &Length *dec 5
Dcl &Sender *char 80
Dcl &TravelKey *char 4
Dcl &Type *char 10
Dcl &Option *char 20 -
value(X'0000000200000000000000000000000000000000')
Top: /* set new request message boundary */
SndPgmMsg MsgType(*Rqs) KeyVar(&BoundryKey) ToPgmq(*Same) Msg('/* */')
RcvMsg MsgType(*Rqs) MsgKey(&BoundryKey) Rmv(*No) Sender(&Sender)
ChgVar &Program %sst(&Sender 56 10)
ChgVar &IN99 '1'
Full: /* try to get full 6000-byte command */
ChgVar &Big &Command
If (&Big = ' ') (ChgVar &TravelKey ' ')
If (&IN04 = '1' *and &TravelKey *NE ' ') Do
RcvMsg MsgType(*Rqs) MsgKey(&TravelKey) Rmv(*No) Msg(&Big)
If (%sst(&Command 1 150) *NE %sst(&Big 1 150)) (Chgvar &Big &Command)
Enddo
F8_or_F9: /* retrieve prior requests */
If (&IN08 = '1' *and &TravelKey = ' ') (ChgVar &Type '*FIRST')
Else If (&IN08 = '1') (ChgVar &Type '*NEXT ')
Else If (&IN09 = '1' *and &TravelKey = ' ') (ChgVar &Type '*LAST ')
Else If (&IN09 = '1') (ChgVar &Type '*PRV ')
Else (Goto Archive)
Call QMHRTVRQ (&Big X'00001770' RTVQ0100 &Type &TravelKey X'00000000')
If (%bin(&Big 5 4) = 0 *and &TravelKey = ' ') (Goto Wait)
ChgVar &TravelKey ' '
If (%bin(&Big 5 4) = 0) (Goto F8_or_F9) /* now try *FIRST or *LAST */
ChgVar &TravelKey %sst(&Big 9 4)
ChgVar &Length %bin(&Big 33 4)
Chgvar &Big %sst(&Big 41 &Length)
Chgvar &Command &Big
If (%sst(&Command 1 2) = '/*') (Goto F8_or_F9) /* ignore comments */
If (&Length > 153) (ChgVar %sst(&Command 151 3) '...') /* ellipsis */
Goto Wait
Archive: /* archive command into job log */
If (&Big = ' ') (Goto Wait)
SndPgmMsg MsgType(*Rqs) KeyVar(&ArchiveKey) ToPgmq(*Same) Msg(&Big)
RcvMsg MsgType(*Rqs) MsgKey(&ArchiveKey) Rmv(*No)
Execute: /* execute command */
ChgVar &TravelKey ' '
ChgVar %sst(&Option 5 7) ('020' || &ArchiveKey)
If (&IN04 = '1') (ChgVar %sst(&Option 6 1) '1')
Call QCAPCMD (&Big X'00001770' &Option X'00000014' -
CPOP0100 ' ' X'00000000' ' ' X'00000000')
MonMsg CPF6801
MonMsg CPF0000 Exec(Goto Wait)
ChgVar &Command ' '
Wait: /* prompt for next command */
Sndf RcdFmt(MsgCtl)
SNDRcvf RcdFmt(Line)
RmvMsg MsgKey(&BoundryKey)
If (&IN03 *NE '1' *and &IN12 *NE '1') (Goto Top)
EndPgm
Process Command (QCAPCMD) API
Process Commands (QCAPCMD) API
此 API 做到下列事項
1. 在執行命令前,檢核命令語法
2. 顯示命令輔助畫面及接收命令參數(按F4 Prompt)
3. 執行指令
Process Command (QCAPCMD) API parameter list:
1 Source command string Input Char(*)
2 Length of source command string Input Binary(4)
3 Options control block Input Char(*)
The options control block is a QCAPCMD API parameter that lets you specify further options for how the command string is to be processed. This parameter is a character string that you must lay out according to API format CPOP0100 . Here are the possible values for each field of this format:
Type of Command Processing:
0 Command running: same function as QCMDEXC API
1 Command syntax check: same function as QCMDCHK API
2 Command line running: same as QCMDEXC with the addition of limited-user checking and prompting for missing required parameters
3 Command line syntax check: same as 2 except the command is not executed
4 CL program statement: the command string is checked for validity as a source code statement — the same checking that Source Entry Utility (SEU) provides for source-type CL programs
5 CL input stream: same type of checking as 4 for source-type CL job streams
6 Command definition statements: same type of checking as 4 for source-type command definitions
7 Binder definition statements: same type of checking as 4 for source-type binder definitions
8 User-defined option: checked for validity as a user-defined option for Programming Development Manager
Double-Byte Character Set (DBCS) Data Handling:
0 Ignore DBCS data
1 Handle DBCS data
Prompter Action:
0 Do not prompt even if selective prompting characters are present in the command string.
1 Prompt the command even if there are no selective prompting characters present.
2 Prompt the command only if selective prompting characters are present in the command string.
Command String Syntax:
0 AS/400 syntax
1 S/38 syntax
4 Options control block length Input Binary(4)
20 minimum value for CPOP0100 format
5 Options control block format Input Char(8)
CPOP0100 only valid value
6 Changed command string Output Char(*)
7 Length available for changed command string input Binary(4)
8 Length of changed command string available to return Output Binary(4)
9 Error code I/O Char(*)
==========================================================================================================
Retrieve Request Message (QMHRTVRQ) API
retrieves request messages from the current job's call message queue
parameter list:
1 Message information Output Char(*)
Offset Type RTVQ0100 Format
0 Binary(4) Bytes returned
4 Binary(4) Bytes available
8 Char(4) Message key
12 Char(20) Reserved
32 Binary(4) Length of request message text returned
36 Binary(4) Length of request message text available
40 Char(*) Request message text
Offset Type RTVQ0200 Format
0 Binary(4) Bytes returned
4 Binary(4) Bytes available
8 Char(4) Message key
12 Char(10) Program or service program name
22 Char(1) Receiving call stack entry type
0 OPM program
1 ILE procedure name
2 long ILE procedure name 23 Char(10) Module name
33 Char(256) Procedure name
289 Char(11) Reserved
300 Binary(4) Offset to long procedure name
304 Binary(4) Length of long procedure name
308 Binary(4) Length of request message returned
312 Binary(4) Length of request message text available
316 Char(*) Request message text
* Char(*) Long procedure name
2 Length of message information Input Binary(4)
3 Format name Input Char(8)
RTVQ0100 Basic request message information
RTVQ0200 All request message information
4 Message type Input Char(10)
*FIRST Retrieve the first request message in the current job *LAST Retrieve the last request message in the current job *NEXT Retrieve the request message after the message indicated by message key parameter *PRV Retrieve the request message before the message indicated by message key parameter
5 Message key Input Char(4)
6 Error code I/O Char(*)
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期三, 11月 01, 2023
2002-05-06 如何於應用軟體中建立類似系統的 Command line ?
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言