INFORMIX 4GL 的程式架構
<語法格式>
#===========================
DATABASE database-name
#---------------------------
GLOBAL
...
END GLOBALS
#---------------------------
MAIN
...
END MAIN
#---------------------------
FUNCTION function-name()
...
END FUNCTION
#---------------------------
REPORT report-name()
...
END REPORT
#===========================
IF 敘述
<語法格式>
IF boolean-exp THEN
...
ELSE
...
END IF
FOR 敘述
<語法格式>
FOR varibale = integer_exp TO integer_exp
...
[CONTINUE FOR]
...
[EXIT FOR]
...
END FOR
WHILE 敘述
<語法格式>
WHILE boolean-exp
...
[CONTINUE WHILE]
...
[EXIT WHILE]
...
END WHILE
CASE 敘述
<語法格式>
CASE [(exp)]
WHEN {exp|boolean}
...
[exit case]
...
WHEN {exp|boolean}
...
[exit case]
...
OTHERWISE
...
[exit case]
...
END CASE
GOTO 敘述
無條件跳至標記處(同一函數、報表、MAIN之中)執行命令。
<語法格式>
GOTO 標記名稱
LABEL 敘述
標記GOTO跳到的位址。
<語法格式>
LABEL 標記名稱
標記GOTO跳到的位址。
<語法格式>
LABEL 標記名稱
例:
if status != 0 then
goto stop_run
end if
statement
...
label stop_run: statement
if status != 0 then
goto stop_run
end if
statement
...
label stop_run: statement
SLEEP 敘述
使程式暫停幾秒。
<語法格式>
SLEEP 整數咚闶?hr />WHENEVER 敘述
當錯誤或警告發生時執行 ...
<語法格式>
WHENEVER {ERROR|WARNING}
{GOTO 標計|CALL 函數|CONTINUE|STOP}
例:
whenever error continue
whenever error stop
SET LOCK MODE TO WAIT
FOREACH 敘述
相當於 WHILE 迴圈半和 FETCH 的組合。
<語法格式>
FOREACH 指標名稱 [INTO 變數串列]
...
[CONTINUE FOREACH]
...
[EXIT FOREACH]
END FOREACH
CALL 敘述
<語法格式>
CALL 函數([參數串列]) [RETURNING 變數串列]
例:
call sample_function(parm1,parm2) returning variable
call sample_function(parm)
call sample_function()
call sample_function(parm1,parm2) returning variable
call sample_function(parm)
call sample_function()
DEFER 敘述
阻止使用者中斷程式執行
<語法格式>
DEFER INTERRUPT
一旦宣告,無法改變。
RUN 敘述
執行作業系統下的可執行檔
<語法格式>
RUN 可執行檔名稱
例:
LET l_cmd=" echo '",str CLIPPED," '> cmsr350.out"
RUN l_cmd
LET l_cmd=" echo '",str CLIPPED," '> cmsr350.out"
RUN l_cmd
PROMPT 敘述
PROMPT 敘述可以從使用者處,交談式的接受所輸入之資料
<語法格式>
PROMPT display_list FOR variable
PROMPT 敘述可以從使用者處,交談式的接受所輸入之資料
<語法格式>
PROMPT display_list FOR variable
例:
define stuff_num char(7)
prompt "請輸入員工編號" for stuff_num
define stuff_num char(7)
prompt "請輸入員工編號" for stuff_num
DISPLAY 敘述
<語法格式>
DISPLAY display_list [USING|CLIPPED] AT ROW,COLUMN
MESSAGE 敘述
用來顯示訊息至螢幕的訊息行(default 第二行)
<語法格式>
MESSAGE display_list
5-19 ERROR 敘述
用來顯示錯誤訊息至螢幕的錯誤行(default 第 24 行)
<語法格式>
ERROR display_list
5-20 CLEAR 敘述
<語法格式一>
CLEAR SCREEN
此敘述用來清除整個螢幕,包刮訊息行、錯誤行
<語法格式二>
CLEAR FORM
此敘述用來清除所有的螢幕欄位資料值。
<語法格式三>
CLEAR VARIABLE_LIST
此敘述用來清除 field_list 所包含的一個或一個以上的螢幕欄位資料值。
INITIALIZE 敘述
通常變數可以用LET 設定,但若要設定為 NULL 時,必須使用 INITIALIZE。
INITIALIZE l_bmd04 TO null
LET lsql='database dsb'
PREPARE chgdsb FROM lsql
EXECUTE chgdsb
LET l_sql=" SELECT DISTINCT xhb11 FROM ",l_azp03 CLIPPED,":xha_file,",l_azp03 CLIPPED,":xhb_file",
" WHERE xha01=xhb01",
" AND xha20=Today - 186",
" AND xhaconf<>'X'"
PREPARE xha_pre FROM l_sql
DECLARE xha_cur CURSOR FOR xha_pre
FOREACH xha_cur INTO l_xhb11
LET l_sql=" SELECT xfb11 FROM ",l_azp03 clipped,":xfb_file",
" WHERE xfb01='",l_xhb11 clipped,"' and xfb09='Y' "
PREPARE xfc_pre FROM l_sql
DECLARE xfc_cus CURSOR FOR xfc_pre
OPEN xfc_cus
FETCH xfc_cus INTO l_xhb11
CLOSE xfc_cus
IF not (l_xhb11 is NULL or l_xhb11=' ') THEN
INSERT INTO cmsp350_temp2(azp01,azp03,xfb01) VALUES(l_azp01,l_azp03,l_xhb11)
END IF
END FOREACH
END FOREACH
" WHERE xha01=xhb01",
" AND xha20=Today - 186",
" AND xhaconf<>'X'"
PREPARE xha_pre FROM l_sql
DECLARE xha_cur CURSOR FOR xha_pre
FOREACH xha_cur INTO l_xhb11
LET l_sql=" SELECT xfb11 FROM ",l_azp03 clipped,":xfb_file",
" WHERE xfb01='",l_xhb11 clipped,"' and xfb09='Y' "
PREPARE xfc_pre FROM l_sql
DECLARE xfc_cus CURSOR FOR xfc_pre
OPEN xfc_cus
FETCH xfc_cus INTO l_xhb11
CLOSE xfc_cus
IF not (l_xhb11 is NULL or l_xhb11=' ') THEN
INSERT INTO cmsp350_temp2(azp01,azp03,xfb01) VALUES(l_azp01,l_azp03,l_xhb11)
END IF
END FOREACH
END FOREACH
{r1} LET l_sql = " SELECT azj03 from azj_file",
{r1} " WHERE azj01 = 'USD' and azjacti='Y' ",
{r1} " order by azj02 desc"
{r1}
{r1} PREPARE sel_zu0_pre FROM l_sql
{r1} DECLARE sel_zu0_cus CURSOR FOR sel_zu0_pre
{r1} OPEN sel_zu0_cus
{r1} FETCH sel_zu0_cus INTO l_azj03
{r1} CLOSE sel_zu0_cus
{r1} " WHERE azj01 = 'USD' and azjacti='Y' ",
{r1} " order by azj02 desc"
{r1}
{r1} PREPARE sel_zu0_pre FROM l_sql
{r1} DECLARE sel_zu0_cus CURSOR FOR sel_zu0_pre
{r1} OPEN sel_zu0_cus
{r1} FETCH sel_zu0_cus INTO l_azj03
{r1} CLOSE sel_zu0_cus
LET g_sql="SELECT omaconf,oma54t,oma56t FROM ",g_dbs_new,"oma_file",
" WHERE oma01=?"
PREPARE t400_bu_13_p1 FROM g_sql
DECLARE t400_bu_13_c1 CURSOR FOR t400_bu_13_p1
OPEN t400_bu_13_c1 USING b_oob.oob06
" WHERE oma01=?"
PREPARE t400_bu_13_p1 FROM g_sql
DECLARE t400_bu_13_c1 CURSOR FOR t400_bu_13_p1
OPEN t400_bu_13_c1 USING b_oob.oob06
沒有留言:
張貼留言