SY-SUBRC 的含义
使用SELECT語句選擇查詢:?
SY-SUBRC = 0: 至少有一行數據,當ENDSELECT語句執行完,SY-DBCNT中保存著記錄的個數。?
SY-SUBRC = 4: 沒有數據。?
SY-SUBRC = 8: 只有使用“SELECT SINGLE FOR UPDATE”時才會有,?
????????????? 表示: WHERE條件指定的記錄不止一行,結果是沒有記錄被選中。?
??
使用INSERT語句,向表中插入一行,必須注意INSERT的順序與表中字段的順序一致:?
SY-SUBRC = 0: 插入成功,SY-DBCNT包含了插入的行數,0或1。?
SY-SUBRC = 4: 由于有相同的KEY存在,所以插入失敗。?
??
使用LOOP語句來遍歷一個內表:?
SY-SUBRC = 0: 循環至少被執行一次。?
SY-SUBRC = 4: 循環沒有被執行,可能是沒有數據,也可能是沒有符合條件的記錄。?
??
使用DELETE語句來刪除一條記錄:?
SY-SUBRC = 0: 找到一行并刪除之,如果該表有不唯一主鍵,也就是有多條重復的記錄,則只刪除第一條記錄。?
SY-SUBRC = 4: 沒有找到符合條件的記錄,也沒有刪除。?
??
使用UPDATE語句來更新一條記錄:?
SY-SUBRC = 0: 找到記錄并更新,(如果有多條記錄呢?)?
SY-SUBRC = 4: 沒有找到符合條件的記錄,也沒有更新。?
?
+++++++++++++++++++++++ 實例RFC ++++++++++++++++++++++++++++++++++++++++++++++?
*建立臨時表ZTEST1,字段為:?
* ZUSERID CHAR 20?
* ZPASSWD CHAR 20?
*-------------------------------------------------?
FUNCTION ZRFC_01.?
*"----------------------------------------------------------------------?
*"*"Local Interface:?
*"? IMPORTING?
*"???? VALUE(ACTION) TYPE? /1SAP1/CL_ACH0001? 傳入參數ACTION,表示CREATE、EDIT、DELETE記錄?
*"???? VALUE(WHEREUSERID) TYPE? /GC1/DTE_MSG_TXT 傳入參數WHEREUSERID,按照USERID來查找關鍵字?
*"? EXPORTING?
*"???? VALUE(RETURN) TYPE? /AIN/ACT_PUB_PARAMNAME 傳出參數RETURN,返回是否成功,空串表示成功,非空串表示未成功?
*"???? VALUE(ERRNUM) TYPE? /AIN/ACTIVITY_COUNTER 傳出參數ERRNUM,返回錯誤代碼?
*"? TABLES?
*"????? ZTEMPTABLE STRUCTURE? ZTEST1??? 傳入、傳出表,以表為參數?
*"----------------------------------------------------------------------?
??
? TABLES:ZTEST1.?
??
? DATA:?
? WA_ZTEMPTABLE LIKE ZTEMPTABLE,?
? TRANSACTION_ID LIKE ARFCTID,?
? V_VAILD(1) TYPE C.?
??
? V_VAILD = 'X'.?
??
* OPEN A DATA TRANSACTION?
? CALL FUNCTION 'TRANSACTION_BEGIN'?
??? IMPORTING?
????? TRANSACTION_ID = TRANSACTION_ID.?
?
? CASE ACTION .?
? *按照關鍵字ZUSERID查詢?
???? WHEN 'QUERY'.?
????? SELECT * FROM ZTEST1 INTO TABLE ZTEMPTABLE where ZUSERID = WHEREUSERID.?
??????? IF SY-SUBRC = 0.?
??????? ELSE.?
????????? V_VAILD = ''.?
????????? ERRNUM = SY-SUBRC.?
??????? ENDIF.?
???????
? *選擇所有的記錄?
??? WHEN 'SELECTALL'.?
????? SELECT * FROM ZTEST1 INTO TABLE ZTEMPTABLE.?
??????? IF SY-SUBRC = 0.?
??????? ELSE.?
????????? V_VAILD = ''.?
????????? ERRNUM = SY-SUBRC.?
??????? ENDIF.?
???????
*插入記錄?
??? WHEN 'CREATE'.?
??
????? LOOP AT ZTEMPTABLE INTO WA_ZTEMPTABLE.?
??????? INSERT ZTEST1 FROM WA_ZTEMPTABLE.?
??????? IF SY-SUBRC = 0.?
??????? ELSE.?
????????? V_VAILD = ''.?
????????? ERRNUM = SY-SUBRC.?
??????? ENDIF.?
????? ENDLOOP.?
??
*修改記錄?
??? WHEN 'EDIT'.?
??
????? LOOP AT ZTEMPTABLE INTO WA_ZTEMPTABLE.?
??????? UPDATE ZTEST1 FROM WA_ZTEMPTABLE.?
??????? IF SY-SUBRC = 0.?
??????? ELSE.?
????????? V_VAILD = ''.?
????????? ERRNUM = SY-SUBRC.?
??????? ENDIF.?
????? ENDLOOP.?
??
*刪除記錄?
??? WHEN 'DELETE'.?
??
????? LOOP AT ZTEMPTABLE INTO WA_ZTEMPTABLE.?
??????? DELETE ZTEST1 FROM WA_ZTEMPTABLE.?
??????? IF SY-SUBRC = 0.?
??????? ELSE.?
????????? V_VAILD = ''.?
????????? ERRNUM = SY-SUBRC.?
??????? ENDIF.?
????? ENDLOOP.?
??
??? WHEN OTHERS.?
??
? ENDCASE.?
??
? *如果V_VALID為X,則表示成功,否則表示失敗,并返回RETURN錯誤代碼?
? IF V_VAILD = 'X'.?
??? CALL FUNCTION 'TRANSACTION_END'?
????? EXPORTING?
??????? TRANSACTION_ID = TRANSACTION_ID.?
??? RETURN = ''.?
? ELSE.?
??? CALL FUNCTION 'TRANSACTION_ABORT'?
????? EXPORTING?
??????? TRANSACTION_ID = TRANSACTION_ID.?
??? RETURN = 'THE CURRENT ACTION IS FAILURE!'.?
?
? ENDIF.?
?
ENDFUNCTION.
總結
以上是生活随笔為你收集整理的SY-SUBRC 的含义的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sap中Excel的模版上传和下载
- 下一篇: OOALV 中DATA_CHANGED_