`
evangxli
  • 浏览: 231668 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

SELECT SINGLE 和 SELECT ENDSELECT的区别!

阅读更多
今天碰到一个小问题,当我验证SELECT执行是否成功时,使用select endselect就可以,而用select single就不可以。
AT SELECTION-SCREEN.
*  DO 1 TIMES.

    SELECT SINGLE NAME1
      FROM T001W
      INTO PLT_NAME
      WHERE T001W~WERKS = S_PLT.
    IF SY-SUBRC = 4.
      MESSAGE E027(ZPPMRP) WITH S_PLT.
    ENDIF.
*  ENDDO.
*ENDSELECT.



S_PLT是屏幕screen的字段
SELECTION-SCREEN BEGIN OF BLOCK BLOCK1 .
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS : P_PLT AS CHECKBOX DEFAULT 'X'.              "P_PLANT
SELECTION-SCREEN COMMENT (19) TEXT-C01.
SELECT-OPTIONS : S_PLT FOR T001W-WERKS OBLIGATORY NO-EXTENSION NO INTERVALS.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BLOCK1.



起因,条件,使用SELECT SINGLE,当判断条件为SY-SUBRC = 4时,条件成立,执行不成功,会一直执行if条件中的代码,即MESSAGE E027(ZPPMRP) WITH S_PLT.
而使用select endselect时候,当判断条件为SY-SUBRC <> 0时,则执行成功,即此时的SY-SUBRC = 0。

备注:按照下面的解释,当
SELECT sets SY-SUBRC to 0 if at least one line was read, otherwise to 4, or possibly 8 in SELECT SINGLE FOR UPDATE.
即,当SY-SUBRC = 0时,至少有一行数据;
其他情况为SY-SUBRC = 4;
另外当SY-SUBRC =8时,只有在SELECT SINGLE FOR UPDATE的时候,这个我也解释不好。



Haha, I had this information so thought of sharing with you all.

Values of SY-SUBRC on different ABAP statements

'sy-subrc' is a return code, set by the following ABAP statements.
As a rule, if SY-SUBRC = 0, the statement was executed successfully.
ASSIGN sets SY-SUBRC to 0 if the field symbol assignment was possible, otherwise to 4. 
AUTHORITY-CHECK sets SY-SUBRC to 0 if the user has the required authorization, otherwise to 4, 8, 12, 16, 24, 28, 32, or 36 depending on the cause of the authorization failure. 
CALL DIALOG with USING sets SY-SUBRC to 0 if the processing is successful, otherwise to a value other than 0. 
CALL FUNCTION sets SY-SUBRC in accordance with the defined exception handling. 
CALL METHOD sets SY-SUBRC in accordance with the defined exception handling. 
CALL SELECTION-SCREEN sets SY-SUBRC to 0 if the user chooses Enter or Execute, and 4 if the user chooses Cancel. 
CALL TRANSACTION with USING sets SY-SUBRC to 0 if the processing is successful, otherwise to a value other than 0. 
CATCH SYSTEM-EXCEPTIONS sets SY-SUBRC after the ENDCATCH statement if a system exception occurs. The value is set in the program. 
COMMIT WORK sets SY-SUBRC to 0. COMMIT WORK AND WAIT sets SY-SUBRC to 0 if the update is successful, otherwise to a value other than 0. 
COMMUNICATION INIT DESTINATION ... RETURNCODE sets SY-SUBRC as specified. 
CONCATENATE sets SY-SUBRC to 0 if the result fits into the target variable, otherwise to 4. 
CREATE OBJECT sets SY-SUBRC if the exceptions of the instance constructor are handled in the program. 
CREATE OBJECT in OLE2 sets SY-SUBRC to 0 if an external object could be created, otherwise to 1, 2, or 3, depending on the cause. 
DELETE sets SY-SUBRC to 0 if the operation is successful, otherwise to 4 or another value other than 0, depending on the cause. 
DEMAND ... MESSAGES INTO sets SY-SUBRC to 0 if the message table is empty, otherwise to a value other than 0. 
DESCRIBE LIST sets SY-SUBRC to 0 if the line or list exists, otherwise to 4 or 8. 
EXEC SQL - ENDEXEC sets SY-SUBRC to 0 in nearly all cases. It does, however, set SYSUBRC to 4 if no entry is read in a FETCH statement. 
FETCH sets SY-SUBRC to 0 if at least one line was read, otherwise to 4. 
GENERATE SUBROUTINE POOL sets SY-SUBRC to 0 if the generation was successful, otherwise to 8. 
GET CURSOR sets SY-SUBRC to 0 if the cursor is correctly positioned, otherwise to 4. 
GET PARAMETER sets SY-SUBRC to 0 if a corresponding value exists in SAP memory, otherwise to 4. 
IMPORT sets SY-SUBRC to 0 if the import is successful, otherwise to 4. 
INSERT sets SY-SUBRC to 0 if the operation is successful, otherwise to 4. 
LOAD REPORT sets SY-SUBRC to 0 if the operation is successful, otherwise to 4 or 8 depending on the cause of the error. 
LOOP sets SY-SUBRC to 0 if there is at least one pass through the extract. Otherwise, it is set to a value other than 0. 
LOOP AT sets SY-SUBRC to 0 if there is at least one loop pass through the internal table, otherwise to 4. 
MODIFY sets SY-SUBRC to 0 if the operation is successful, otherwise to 4. 
MODIFY LINE sets SY-SUBRC to 0 if a line in the list was changed, otherwise it sets it to a value other than 0. 
MODIFY sets SY-SUBRC to 0 if the operation is successful, otherwise to 4. 
OLE2 Automation, executed successfully, otherwise 1, 2, 3, or 4, depending on the cause of the error. 
OPEN DATASET sets SY-SUBRC to 0 if the file could be opened, otherwise to 8. 
Open SQL statements set SY-SUBRC to 0 if the operation is successful, otherwise to a value other than 0. 
OVERLAY sets SY-SUBRC to 0 if at least one character is overlaid, otherwise to 4. 
READ DATASET sets SY-SUBRC to 0 if the read operation was successful, otherwise to 4 or 8, depending on the cause of the error. 
READ LINE sets SY-SUBRC to 0 if a list line exists, otherwise to a value other than 0. 
READ TABLE sets SY-SUBRC to 0 if table lines are found, otherwise to 2, 4, or 8, depending on the context and cause of the error. 
REPLACE sets SY-SUBRC to 0 if the search string was replaced, otherwise to a value other than 0. 
SCROLL sets SY-SUBRC to 0 if the scrolling within the list was successful, otherwise to 4 or 8, depending on the cause. 
SEARCH sets SY-SUBRC to 0 if the search string was found, otherwise to 4. 
SELECT sets SY-SUBRC to 0 if at least one line was read, otherwise to 4, or possibly 8 in SELECT SINGLE FOR UPDATE. 
SET COUNTRY sets SY-SUBRC if the country code exists in table T005X, otherwise to 4. 
SET BIT sets SY-SUBRC to 0 if the bit could be set, otherwise to a value other than 0. 
SET TITLEBAR sets SY-SUBRC to 0 if the title exists, otherwise to 4. 
SHIFT ... UP TO sets SY-SUBRC to 0 if the position could be found within the string, otherwise to 4. 
SPLIT sets SY-SUBRC to 0 if the sizes of the target fields are adequate, otherwise to 4. 
UPDATE sets SY-SUBRC to 0 if the operation is successful, otherwise to 4. 
WRITE ... TO sets SY-SUBRC to 0 if the assignment is successful, otherwise to 4. 
0
0
分享到:
评论

相关推荐

    ABAP程序的数据查询语句SELECT.doc

    1. 循环选择:使用SELECT / ENDSELECT语句块逐行读取数据,例如: SELECT [DISTINCT] &lt;result&gt;...&lt;statement block&gt; ENDSELECT. 2. 选择至内表:一次性将所有匹配的记录加载到内表,如: SELECT ... INTO|...

    ABAP SQL使用技巧

    - **7.3 SELECT-ENDSELECT 循环 VS 数组选择**:循环处理内部表时,使用 **SELECT-ENDSELECT** 结合循环结构可以简化代码。 ```abap SELECT * FROM T006 INTO X006_WA. LOOP AT X006 INTO X006_WA. ENDLOOP. ``...

    abap SQL优化

    Endselect. ``` - **优化后**: ```abap Select * from zflight where airln = 'LF' and fligh = '222'. Endselect. ``` 2. **最大值计算**:避免使用循环来寻找最大值,直接利用SQL的聚合函数。 - **原始...

    vb图书管理系统~net

    End Select End Sub Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single) End Sub Private Sub txtBookId_GotFocus() txtBookId.BackColor = vbBlue txtBookId.ForeColor = vbYellow End ...

    ABAP 函数&接口 RFC实例

    SY-SUBRC = 0: 至少有一行数据,当ENDSELECT语句执行完,SY-DBCNT中保存着记录的个数。 SY-SUBRC = 4: 没有数据。 SY-SUBRC = 8: 只有使用“SELECT SINGLE FOR UPDATE”时才会有,  表示: WHERE条件指定的记录不止...

    水波 水纹 DDL代码

    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim LClickCount As Long ' Randomize If Button = 1 Then WaveDropStone X, Y, 2, 256 Else LClickCount = Rnd...

    MYSQL语句大全

    SELECT COUNT(singles) FROM team_stats WHERE singles &gt; 0; -- 计算singles大于0的记录数 ``` ##### SUM - **功能**: 返回指定列的总和。 - **语法**: ```sql SELECT SUM(column_name) FROM table_name [WHERE...

    ABAP数据库操作

    Endselect. 9. 选择至内表 ABAP 也可以选择数据至内表,基本语法为: Select * from spfli into table ta_spfli. 10. 指定查询条件 ABAP 提供了多种指定查询条件的方式,包括: * 比较运算符:= &lt; &gt; &lt;&gt; &lt;= &gt;= ...

    C#语法及存储过程.docx

    --set和select的区别 大部分情况用set就可以,set不能将返回多个值获取到,相对严禁 select可以将获取返回的多个结果的最后一条,相对灵活 --事务 begin transaction //开启一个事务 declare @sum int = 0 //...

    经典SQL语句大全

    select type,sum(case vender when 'A' then pcs else 0 end),sum(case vender when 'C' then pcs else 0 end),sum(case vender when 'B' then pcs else 0 end) FROM tablename group by type 显示结果: type ...

    数据库操作语句大全(sql)

    select type,sum(case vender when 'A' then pcs else 0 end),sum(case vender when 'C' then pcs else 0 end),sum(case vender when 'B' then pcs else 0 end) FROM tablename group by type 显示结果: type ...

    SQL测试题.doc

    更新`test`表中的`issingle`字段,`UPDATE a SET Issingle = CASE c.tag WHEN '1' THEN 1 ELSE 0 END FROM test a INNER JOIN (SELECT person, isnull((SELECT TOP 1 person FROM test a WHERE a.friend=b.person), ...

    AC-学号-姓名- 题号28501

    single_button = tk.Button(root, text="Single Select", command=on_single_select) single_button.pack() multi_button = tk.Button(root, text="Multi Select", command=on_multi_select) multi_button.pack() ...

    【SQL Server 数据库】常用语句文档 免费下载!!

    - **格式**: `ALTER DATABASE 数据库名 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;` - **然后执行**: ```sql ALTER DATABASE 数据库名 SET OFFLINE WITH ROLLBACK IMMEDIATE; ``` #### 13. 附加数据库 - **格式...

    Visual Basic程序设计教程:第四章 Visual Basic的基本控制结构.ppt

    VB提供了两种选择结构:If-Then-Else-End If语句和Select-Case-End Select语句。 **2.1 If-Then-Else-End If 语句** 这是双分支结构,当条件满足时执行一组语句,否则执行另一组语句。格式如下: ```vb If &lt;条件&gt;...

    Abap效率.docx

    尽量减少子查询和嵌套SELECT...ENDSELECT的使用,因为它们会增加执行次数。在索引字段上避免使用NOT, 等不等操作符,而是使用&gt;或&lt;。避免前导百分号的LIKE操作,因为它无法利用索引。对于OR连接的索引字段,考虑使用...

    用VB编写的学生学籍管理

    Private Sub Grid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then PopupMenu student End If End Sub Private Sub Grid1_RowColChange(ByVal Row As Long, ByVal ...

    react-native-single-select:React Native的可定制且易于使用的单选库

    黑暗主题轻主题安装添加依赖项: npm i @freakycoder/react-native-single-selectnpx pod-install // After Install the ` react-native-spinkit `对等依赖您需要安装此依赖项" react-native-spinkit " : " ^1.5.1 ...

    Excel与VBA编程中的常用代码

    在Excel与VBA编程中,掌握常用的代码片段能够极大地提高工作效率和编程的便捷性。首先,我们来看一下如何声明变量。在VBA中,声明变量的语法与...记得在实际编程时根据需要添加`Sub`和`End Sub`来封装成完整的子程序。

Global site tag (gtag.js) - Google Analytics