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: 

Loop at parameters from selection-screen.

former_member246634
Active Participant
0 Kudos

Hi guys,

In my report I have three blocks on selection screen, each block has three parameters and one select-option and I am trying to make dynamic SELECT statement with it. I was wondering if I could do something like this:


DATA:

          line(200) type c,

          list like table of line(200).

LOOP AT parameters_from_sel_screen.

     IF parameter_n is not initial.

          CONCATENATE 'field_n =' parameter_n INTO line SEPARATED BY space.

          APPEND line to list.

          CLEAR line.

     ENDIF.

ENDLOOP.

SELECT * FROM table

WHERE (list).

Thank you in advance for your help.

1 ACCEPTED SOLUTION

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

I do not see the reasons for not using SELECT-OPTIONS.

You can use NO-EXTENSION and NO INTERVALS and it looks like PARAMETERS .

You can also use function SELECT_OPTIONS_RESTRICT for further customizing .

Do not waste your time on complex code use the KISS principle http://en.wikipedia.org/wiki/KISS_principle

Regards.

12 REPLIES 12

Former Member
0 Kudos

Hi Bartlomiej,

So basically you want to have dynamic selection condition with only the fields that are filled in the selection screen ? and ignore the fields that are not filled in Selection screen.

Regards,

Arulmani

0 Kudos

That's right.

I am also a little bit worried about adding "AND" in correct places (for example: I can't add 'AND' before every parameter because if first parameter won't be filled I will get something like this:

SELECT * FROM table INTO i_table

WHERE AND field_2 = parameter_2.)

I just want to avoid using "SELECT-OPTIONS" everywhere, cause in my opinion it doesn't look good for many fields like LIFNR and so on, where you want to insert only one value.

0 Kudos

Hi ,

each  time  only one block will active or multiple block may active?

Former Member
0 Kudos

Hi,

Please check the below link. Probably you can just add a extra IF condition before the 'Append statement' to use only the fields that are filled.

Dynamic where clause - ABAP Development - SCN Wiki

Regards,
Arulmani

PeterJonker
Active Contributor
0 Kudos

I think this is already standard behavior of parameters and select ioptions in the selection screen. If you don't fill them then all values will be selected.

So is there a specific reason why you want to do this ?

0 Kudos

I thought that if I use such SELECT statement:

SELECT * FROM zeic_rep_3way INTO CORRESPONDING FIELDS OF TABLE lt_zeic_rep_3way

     WHERE docno = p_docno

     AND bukrs = p_bukrs

     AND zeic_status = p_status

     AND zeic_symspr = p_symspr

     AND lifnr = p_lifnr

     AND ebeln = p_ebeln

     AND mblnr = p_mblnr

     AND budat IN p_budat

     AND bldat IN p_bldat

     AND zeic_data_da_ot IN p_daotfv.


and one of the fields (parameter) won't be filled the statement won't return any records. I was also curious how SELECT statement in SE16N transaction is built...

0 Kudos

If one of the parameters is not filled it will be ignored in the select as if it is not present in the where statement.

It is NOT like you said that in that case no records are returned. So that's why I was asking why you need this really ?

0 Kudos

I just wanted to try using dynamic select, no particular reason (I don't have to use it and now I know I won't).If you say that if one parameter is not filled on selection screen and is ommited in my select statement I'll give it a try.

Thanks for your answer, Peter.

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

I do not see the reasons for not using SELECT-OPTIONS.

You can use NO-EXTENSION and NO INTERVALS and it looks like PARAMETERS .

You can also use function SELECT_OPTIONS_RESTRICT for further customizing .

Do not waste your time on complex code use the KISS principle http://en.wikipedia.org/wiki/KISS_principle

Regards.

0 Kudos

I wrote simple code to fill one parameter when the other is entered:



SELECT * from dd07t INTO CORRESPONDING FIELDS OF TABLE lt_dd07t

     WHERE as4local = 'A'

     AND domvalue_l = p_skrsym          "you fill this parameter

     AND domname = 'ZEIC_SKRSYM'.

   loop at lt_dd07t INTO ls_dd07t.

     SELECT SINGLE domvalue_l from dd07t into p_symspr          "autofill on this parameter

       where domname = 'ZEIC_SYMSPR'

       and ddtext = ls_dd07t-ddtext.

   endloop.


It works fine when p_skrsym and p_symspr are PARAMETERS, but it doesn't work when they're SELECT-OPTIONS.


Regards.

0 Kudos

Hi,

Please check the online help for SELECT-OPTIONS .

A SELECT-OPTIONS is a table and your logic should take this into account .

Also use the "IN" in the sql statment:

DATA: s_skrsym TYPE RANGE OF domvalue_l .


  DATA: it_dd07t TYPE TABLE OF dd07t .

  SELECT * FROM dd07t INTO TABLE it_dd07t
  WHERE
    as4local EQ 'A' AND
    domvalue_l IN s_skrsym AND
    domname EQ 'MATNR'.


Regards.

0 Kudos

Hi,

Some code: see attached program.

Select airlines and press enter to get Connections

Regards.