11-25-2004 11:25 AM
Hi,
I want to delete internal data based on user input so I wrote the following code and it is working fine if I hard-code s_zage-low and s_zage-high but without that hardcode if you user inputs it's not working. How to make it work?
Advance thanks.
-
SELECT-OPTIONS: s_zage FOR zsubdci-znldays.
MOVE: 'NB' TO s_zage-option,
'I' TO s_zage-sign,
'10' TO s_zage-low,
'20' TO s_zage-high.
APPEND s_zage.
DELETE itab_data WHERE
zage IN s_zage.
Regards,
V Balaji.
11-25-2004 12:03 PM
Hello Balaji,
It is not totally clear why you face a problem here. But I can think of one thing that you might have missed out.
In the statement DELETE ITAB_DATA WHERE ZAGE IN S_ZAGE, if the select-options internal table is empty, that is to say if the user does not enter anything in this field on the selection-screen, then all the contents of the internal table will get deleted.
Is this the problem you are facing? If yes, then you can do some processing and adopt either of these two approaches as suits your case:
1. Force the user to amke some input on these select-options, by making them mandatory. For example, you can use something like:
tables vbak.
select-options s_vbeln for vbak-vbeln obligatory.
2. You need not make the select-options field mandatory, but you can give warning message on the selection screen when the user hits EXECUTE (F8) on the screen. For example:
AT SELECTION-SCREEN.
IF S_VBELN IS INITIAL.
MESSAGE W001(XYZ) WITH 'All the records will be deleted, are you sure you want to continue?'.
ENDIF.
If these are not the actual descriptions of your problem, please state the exact nature of the issue that you are facing.
Regards,
Anand Mandalika.
11-25-2004 12:03 PM
Hello Balaji,
It is not totally clear why you face a problem here. But I can think of one thing that you might have missed out.
In the statement DELETE ITAB_DATA WHERE ZAGE IN S_ZAGE, if the select-options internal table is empty, that is to say if the user does not enter anything in this field on the selection-screen, then all the contents of the internal table will get deleted.
Is this the problem you are facing? If yes, then you can do some processing and adopt either of these two approaches as suits your case:
1. Force the user to amke some input on these select-options, by making them mandatory. For example, you can use something like:
tables vbak.
select-options s_vbeln for vbak-vbeln obligatory.
2. You need not make the select-options field mandatory, but you can give warning message on the selection screen when the user hits EXECUTE (F8) on the screen. For example:
AT SELECTION-SCREEN.
IF S_VBELN IS INITIAL.
MESSAGE W001(XYZ) WITH 'All the records will be deleted, are you sure you want to continue?'.
ENDIF.
If these are not the actual descriptions of your problem, please state the exact nature of the issue that you are facing.
Regards,
Anand Mandalika.
11-25-2004 1:36 PM
I will make it clearer.
In my program, I am populating an internal table and then I am calculating age by subtracting two date fields and storing that field (zage) also in the internal table.
So now internal table contains all the data. I want to delete the extra data which is not falling in user selection (i.e. S_ZAGE)
So if the user enter age as 10 to 20 means I want to delete all the records which are not falling in that range. So I am using DELETE command and "NB".
But below code is not working... (user input 10 and 20)
MOVE: 'NB' TO s_zage-option.
'I' TO s_zage-sign.
APPEND s_zage.
But if I hard-code... like below... then it's working as I expect....
MOVE: 'NB' TO s_zage-option.
'I' TO s_zage-sign.
'10' TO s_zage-low,
'20' TO s_zage-high.
APPEND s_zage.
Regards,
Balaji Viswanath.
11-25-2004 1:54 PM
If you want to exclude the user selection from your DELETE, maybe you must change the selection, and not add another selection...
Try changing only the sign, from "I" to "E", and it will work, and don't use APPEND, use MODIFY.
11-25-2004 2:16 PM
If I use modify I am getting "TABLE_ILLEGAL_STATEMENT" dump.
Regards,
Balaji Viswanath
11-25-2004 2:20 PM
Hi Balaji,
I now understand the issue. when you hard code the values, the select-options table contains only one row, which is
OPTION : NB ; SIGN : I ; LOW : 10 ; HIGH : 20.
This row is actually quite fine. So the delete works as expected.
In the other case, the select-options internal table contains two rows:
OPTION : NB ; SIGN : I ; LOW : ; HIGH : .(thru append statement)
OPTION : BT ; SIGN : I ; LOW : 10 ; HIGH : 20.( thru the user-input on the selection screen)
So to accomplish your requirement, you would have to code something like this:
at selection-screen.
s_zage-option = 'NB'.
modify s_zage index 1.
Now you can go ahead with your DELETE operation on the internal table.
Hope this will solve your probelm.
Regards,
Anand Mandalika
11-25-2004 2:29 PM
Hi Poornanand Mandalika,
Excatly what you told is correct. You solved my problem. Thanks.
Regards,
Balaji Viswanath.
11-25-2004 12:03 PM
That code must work... it deletes all data who is not between 10 and 20...
If you used SELECT-OPTIONS without the MOVE and APPEND sentences, it must work too, I believe... Just be sure your selection is well done (maybe your user is selecting data BETWEEN 10 and 20 and not NOT BETWEEN them...
Try to debug it and catch the values of s_zage...
Best luck,
Vic
11-25-2004 12:06 PM
Hi,
plz dbug , if SO s_zage is the same
1) with your default values
and
2) with user values
perhaps option (NB in 1) differs,
Grx Andreas