Application Development and Automation 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: 
Read only

select options

Former Member
0 Likes
3,086

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
Read only

Sandra_Rossi
Active Contributor
2,917

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

Read only

Sandra_Rossi
Active Contributor
2,917

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.

Read only

AnmolBhat
Participant
0 Likes
2,917

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

Former Member
0 Likes
2,917

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?

Read only

2,917

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
Read only

Former Member
0 Likes
2,917

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

Read only

0 Likes
2,917

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.
Read only

Former Member
0 Likes
2,917

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.

Read only

Sandra_Rossi
Active Contributor
2,917

cross Ts and dot Is:

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

FredericGirod
Active Contributor
2,917

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.

Read only

Former Member
0 Likes
2,917

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

Read only

Former Member
0 Likes
2,917

frdric.girod Thank you so much.