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 options

0 Kudos

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.

12 REPLIES 12

Sandra_Rossi
Active Contributor

Please use the CODE button to format your code so that it's shown in a more user-friendly format (colorized).

Sandra_Rossi
Active Contributor

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.

anmolamb
Participant
0 Kudos

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 ).

0 Kudos

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?

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

0 Kudos

anmolamb I see. It was able to list previous dates. Thank you so much. I have to learn more.

0 Kudos

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.

0 Kudos

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.

Sandra_Rossi
Active Contributor

cross Ts and dot Is:

SELECT * FROM ZDATE INTO TABLE @DATA(lines_zdate) WHERE datbi IN @date.

FredericGirod
Active Contributor

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.

0 Kudos

sandra.rossi Thank you so much. It was solve the error.

0 Kudos

frdric.girod Thank you so much.