07-22-2020 12:27 PM
Hi, I am just studying ABAP. I'm creating a program that uses select-options and date as input and extracts data by comparing with DB table . I don't know what to do when the get data. So please help me and provide sample code.
REPORT ZEXERCISE.
DATA: WA_DATE TYPE ZDATE-DATBI.
SELECT-OPTIONS DATE FOR WA_DATE NO INTERVALS.
*WA_DATE = ?? (what can i do)
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = WA_DATE
IMPORTING
date_internal = WA_DATE.
WRITE :/5 'No',20 'Valid Date'.
SKIP.
tables : ZDATE.
SELECT * FROM ZDATE.
IF ZDATE-DATBI < WA_DATE.
WRITE:/5 ZDATE-NO,20 ZDSTE-DATBI.
ENDIF.
ENDSELECT.
07-22-2020 12:44 PM
Please use the CODE button to format your code so that it's shown in a more user-friendly format (colorized).
07-22-2020 12:47 PM
Is that what you want to do
SELECT * FROM ZDATE INTO TABLE @DATA(lines_zdate) WHERE datbi IN date.
NB: TABLES is mostly obsolete, SELECT ... ENDSELECT is to avoid as far as possible.
07-22-2020 3:16 PM
Hi,
You need to learn with some latest ABAP documents. Please search for ABAP 740 and you get current syntax for ABAP.
Regarding your requirement, it can be written in few lines like below
DATA: WA_DATE TYPE ZDATE-DATBI.
SELECT-OPTIONS DATE FOR WA_DATE NO INTERVALS.
select * from zdate into table @data(lt_date) where DATBI in s_date.
"print
cl_abap_demo_services=>list_table( table = lt_date ).
07-30-2020 3:33 AM
anmolamb Thank you for advice. As your advice, the entered date has been output.
How do I do coding if I would like to list dates before the entered date?
07-30-2020 7:51 AM
In that case, you have to pass the LT operator to the select option.
you can do that in the initialization event, so the user also see that on the selection screen or if you want to do this silently then just do that before the select query
"in the initialization,
INITIALIZATION.
s_date[] = value #( ( sign = 'I' option = 'LT' ) ).
"or just before select query
loop at s_date assigning field-symbol(<ls_date>).
<ls_date>-option = 'LT'.
endloop.
"select query save as before
07-30-2020 8:31 AM
anmolamb I see. It was able to list previous dates. Thank you so much. I have to learn more.
07-30-2020 9:12 AM
You may edit your answer to correct a syntax error:
Before correction:
select * from zdate into table @data(lt_date) where DATBI in s_date.
After correction:
select * from zdate into table @data(lt_date) where DATBI in @date.
07-27-2020 12:36 PM
sandra.rossi Thank you for the sample code. I tried as your advice, but error was occurred.How to solve it.?
Error :
When escaped, all host variable must be escaped using @ The variable
DATE is not escaped in the same way as the preceding host variables.
07-27-2020 12:37 PM
cross Ts and dot Is:
SELECT * FROM ZDATE INTO TABLE @DATA(lines_zdate) WHERE datbi IN @date.
07-27-2020 12:45 PM
If I could add something.
Do not try to modify SELECT-OPTIONS, this is the perfect object to play with SELECT statement. It will accept a lot of possibility (Include, Exclude, Between, Greater than, ...). You just have to use IN operator in the WHERE clause.
07-30-2020 8:33 AM
07-30-2020 8:34 AM