Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Select query

Former Member
0 Kudos

Hello!

I have the following code in my method and im trying to test with a table of 4 fields-ID,Name,Branch,Gender.


1.          IF sy-subrc = 4.

2.               SELECT * FROM (mv_tabname) INTO <fs> WHERE (lv_where_clause).

3.                 IF sy-subrc EQ 0.

4.                   INSERT <fs> INTO TABLE <fs1>.

5.                 ENDIF.

6.               ENDSELECT.

7.         ENDIF.


The above query retrieves me record in <fs1> only wen the lv_where_clause has just the ID field (ex ID = 1).

So wen the lv_where_clause is included along with any other field (ex ID = 1 and GENDER = ' MALE ' ) no records are fetched.

When I checked it in debugging , the cursor doesn't enter line3. What cud be the reason?

3 REPLIES 3

Former Member
0 Kudos

Hello,

the select query as You use it is equivalent to a loop at all selected entries. So as no entry is found the loop is not entered. What You probably want to write is

1.          IF sy-subrc = 4.

2.               SELECT * FROM (mv_tabname) INTO TABLE itab WHERE (lv_where_clause).

3.                 IF sy-subrc EQ 0.

                    LOOP AT itab ASSIGNING <fs>.

4.                   INSERT <fs> INTO TABLE <fs1>.

                    ENDLOOP.

5.                 ENDIF.

7.         ENDIF.

Here line 3 is entered in any case.

Former Member
0 Kudos

hi sunil,

you are using select loop statement which means if there is atleast one record then cursor will move next line of select statement else it will comes of the loop (end select).

rajkumarnarasimman
Active Contributor
0 Kudos

Hi sunil,

  If value is available in database, it will be fetched in select condition. Based on SUBRC Value, the third line will execute.

  Pass the same condition in SE11/SE16N. If record is shown, then check any exit is maintained for the gender field. Confirm whether Gender = 'M' or Gender = 'MALE'.

Regards

Rajkumar Narasimman