02-27-2015 5:40 PM
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?
02-27-2015 7:15 PM
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.
02-28-2015 8:39 AM
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).
02-28-2015 12:16 PM
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