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

One select using dynamic statements....

Former Member
0 Likes
1,331

Hello ,

I am using for all entries. I want to combine all in one because currently I have to write two select statements based on condition for internal table not empty.

IF IT_WIID[] IS NOT INITIAL.
SELECT * FROM zcust into CORRESPONDING FIELDS OF TABLE i_t01_dup
         FOR ALL ENTRIES IN IT__WIID
         WHERE WI_ID = IT_WIID-WI_D
         AND RECNO IN TRECNO.

ESLE.
SELECT * FROM zcust into CORRESPONDING FIELDS OF TABLE i_t01_dup
         WHERE RECNO IN TRECNO.
ENDIF.

Regards,

Jainam.

Edited by: Jainam Shah on Mar 5, 2010 8:31 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,281

Hi,

there is no possibility to write dynamic select here. As I understand you simply want to make your code more beautiful. But if we imagine that there is a possibility to write such a dynamic statement that will work for both situations, in any way you will need an IF statement for defining two different dynamic "where" statements.

On the other hand, if you want to avoid IF at all, you need to write definite SELECT which will work for both situations. And if you can do it, why do you need it to be dynamic?

Leave it so as you wrote it

Good luck!

13 REPLIES 13
Read only

Former Member
0 Likes
1,281

Simply what I want to know is can I make "FOR ALL ENTRIES' clause dynamic ?

Read only

0 Likes
1,281

Your code


IF IT_WIID[] IS NOT INITIAL.
SELECT * FROM zcust into CORRESPONDING FIELDS OF TABLE i_t01_dup
         FOR ALL ENTRIES IN IT__WIID
         WHERE WI_ID = IT_WIID-WI_D
         AND RECNO IN TRECNO.
 
ESLE.
SELECT * FROM zcust into CORRESPONDING FIELDS OF TABLE i_t01_dup
         WHERE RECNO IN TRECNO.
ENDIF.

I do not see why you should use the 2nd select. The 2nd select is automatically in the 1st select in case

the table it_wiid is initial ( ie. all records in table zcust into will be selected and will be evaludated only on condition recno in trecno only)

Regards

Dean Q

Read only

0 Likes
1,281

What you guys said above is not correct. It selects all data if I don't check internal table. For example, If on the selection-screen I just put one record, it will select omly that record on output. But if I do the way you guys are telling, it will select eveything.

Regards,

Jianam.

Read only

0 Likes
1,281

If the table i_t01_dup contains 1 record , data selected is on that i_t01_dup record and subject to condition reno in t_recno . If the table i_t01_dup is empty then all recors will be selected and evaluated only on condition reno in t_recno. Now the question is * WHERE THE INFO IN TABLE i_t01_dup coming from?????*

The code logic you wrote can be resumed in 1 single select.

Regards

Dean Q

Edited by: Dean Q on Mar 5, 2010 10:06 PM

Read only

Former Member
0 Likes
1,281

That is the beauty of FOR ALL ENTRIES option. You don't need the IF block. If the internal table is empty, the SQL will automatically become:


SELECT * FROM zcust into CORRESPONDING FIELDS OF TABLE i_t01_dup
         WHERE RECNO IN TRECNO.

Just use:


SELECT * FROM zcust into CORRESPONDING FIELDS OF TABLE i_t01_dup
         FOR ALL ENTRIES IN IT_WIID
         WHERE WI_ID = IT_WIID-WI_ID
         AND RECNO IN TRECNO.

Read only

Former Member
0 Likes
1,281

From the documentation for FOR ALL ENTRIES:

>If the internal table itab is empty, the whole WHERE statement is ignored and all lines in the database are put in the resulting set.

So you are correct. and I'm not aware of any way (other than a dynamic program) that you can do this.

the easiest way is to keep the two SELECTs.

Rob

Read only

0 Likes
1,281

Rob,

If the internal table is empty, he should get all the data that satifies the second WHERE clause in the SELECT statement. What is the need for the second statement?

If I am really missing something obvious, then I blame it on Friday afternoon.

Read only

0 Likes
1,281

Well I wouldn't say it's obvious, but it is documented

I tried it before posting and got ther same results as the OP. (I seem to recall getting bitten by the same situation some time ago. If you search, you may find it.)

Rob

Read only

0 Likes
1,281

OK, I wrote a test program myself which proves my theory. I can't believe I am resorting to a p***ing contest instead of going home for the weekend.

First count SE16 records on DD02L by specifying 'A' for AS4LOCAL field and note down the count.

Then, try this program:


REPORT y_sk_test .

PARAMETERS: p_itabfl TYPE c AS CHECKBOX DEFAULT 'X',
            p_as4lcl TYPE dd02l-tabclass DEFAULT 'A'.

DATA: t_dd02l TYPE STANDARD TABLE OF dd02l INITIAL SIZE 0 WITH HEADER LINE,
      t_itab  TYPE STANDARD TABLE OF dd02l INITIAL SIZE 0 WITH HEADER LINE.

IF p_itabfl = 'X'.
  t_itab-tabname = 'T000'.
  APPEND t_itab.
ENDIF.

SELECT *
INTO   TABLE t_dd02l
FROM   dd02l
FOR ALL ENTRIES IN t_itab
WHERE  tabname = t_itab-tabname
  AND  as4local = p_as4lcl.

DESCRIBE TABLE t_dd02l LINES sy-tfill.

WRITE: / 'Number of rows selected:', sy-tfill.

If you uncheck the checkbox, the count matches the SE16 count and I didn't have to use the IF ELSE block.

Read only

0 Likes
1,281

Sorry - I lost track of this and didn't see your response.

I never thought of this as a "p***ing contest ", but a search for the truth.

Anyway, I ran your program and found that it proved my case, not yours (unless we misunderstand each other):

Total number of records in DD02L: 317,530 from SE16.

Records in SE16 with as4local = 'A': 315,921 from SE16

Output from the program: with the checkbox unchecked.

Number of rows selected: 317,530

Rob

Read only

0 Likes
1,281

1) I don't know what I counted on Friday and why I thought my theory was proved.

2) Good lesson for me - I thought I knew how FAEI worked. Having always used IF NOT ITAB[] IS INITIAL condition, I never came across this.

Thanks!

Read only

0 Likes
1,281

Hi,

Thanks rob and sudhi , i learned a new lesson of for all entries in from this post.this thread is really a value add.

thanks

tanmaya

Read only

Former Member
0 Likes
1,282

Hi,

there is no possibility to write dynamic select here. As I understand you simply want to make your code more beautiful. But if we imagine that there is a possibility to write such a dynamic statement that will work for both situations, in any way you will need an IF statement for defining two different dynamic "where" statements.

On the other hand, if you want to avoid IF at all, you need to write definite SELECT which will work for both situations. And if you can do it, why do you need it to be dynamic?

Leave it so as you wrote it

Good luck!