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-Endselect

Former Member
0 Likes
1,245

Hi experts,

I want to change the following code. Using select-endselect is not allowed, how can I change the code? I also have to avoid of using select *.

SELECT * FROM /PTGWFI/M_PRKMTR

WHERE BELNR = RBKP-BELNR

AND GJAHR = RBKP-GJAHR

ORDER BY COUNTER DESCENDING.

LV_PARKRSN = /PTGWFI/M_PRKMTR-PARKRSN.

LV_BELNR = /PTGWFI/M_PRKMTR-BELNR.

EXIT.

ENDSELECT.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
1,211

>

> Hi experts,

>

> I want to change the following code. Using select-endselect is not allowed, how can I change the code? I also have to avoid of using select *.

>

> SELECT * FROM /PTGWFI/M_PRKMTR

> WHERE BELNR = RBKP-BELNR

> AND GJAHR = RBKP-GJAHR

> ORDER BY COUNTER DESCENDING.

> LV_PARKRSN = /PTGWFI/M_PRKMTR-PARKRSN.

> LV_BELNR = /PTGWFI/M_PRKMTR-BELNR.

> EXIT.

> ENDSELECT.

Here's another alternative:

DATA: lv_counter TYPE /PTGWFI/M_PRKMTR-counter.

SELECT MAX( counter ) INTO lv_counter FROM /ptgwfi/m_prkmtr
    WHERE belnr EQ rbkp-belnr
      AND gjahr EQ rbkp-gjahr.

SELECT parkrsn belnr INTO (lv_parkrsn, lv_belnr) FROM /ptgwfi/m_prkmtr
    WHERE belnr EQ rbkp-belnr
      AND gjahr EQ rbkp-gjahr
      AND counter EQ lv_counter.

It would be interesting to compare the performance of the various alternatives, as matched against the original. SELECT... ENDSELECT should generally not be used, but there are times when it is the most appropriate construct.

matt

11 REPLIES 11
Read only

Former Member
0 Likes
1,211

Hi,

Take one internal table which contain this 2 fields,

Like in the following way.

Data: Begin of itab occurs 1,

LV_PARKRSN type /PTGWFI/M_PRKMTR-PARKRSN,

LV_BELNR type /PTGWFI/M_PRKMTR-BELNR,

end of itab.

SELECT * FROM /PTGWFI/M_PRKMTR into corresponding fields of table itab

WHERE BELNR = RBKP-BELNR

AND GJAHR = RBKP-GJAHR

ORDER BY COUNTER DESCENDING.

Read only

0 Likes
1,211

I'm not allowed to use select *, and instead of using 'into corresponding' I'm only allowed to use simple 'into'

Read only

Former Member
0 Likes
1,211

Hi

Declare an internal table and fill that table with a select query.

(Select * from Table into Corresponding fields of Table ITab).

You can sort the itab by

Sort Itab by COUNTER DESCENDING. and then execute the loop

Now make a loop at Itab (Internal Table) into wa_Itab (Work Area)

Loop at Itab into wa_Itab.

Do all the processing over here that you previously did in Select - EndSelect.

EndLoop.

Hope this works out

Regards

Read only

Former Member
0 Likes
1,211

Hi,

try the below code.

Data: Begin of itab occurs 1,

LV_PARKRSN type /PTGWFI/M_PRKMTR-PARKRSN,

LV_BELNR type /PTGWFI/M_PRKMTR-BELNR,

counter type /PTGWFI/M_PRKMTR-counter,

end of itab.

Select parkrsn

belnr

counter

from /PTGWFI/M_PRKMTR

into table itab

where BELNR = RBKP-BELNR and

GJAHR = RBKP-GJAHR

order by counter descending.

if sy-subrc = 0.

if LV_PARKRSN = /PTGWFI/M_PRKMTR-PARKRSN and

LV_BELNR = /PTGWFI/M_PRKMTR-BELNR.

EXIT.

endif.

endif.

Read only

Former Member
0 Likes
1,211

hi,

i am not understand /PTGWFI/M

but try this............................

SELECT * FROM /PTGWFI/M_PRKMTR into corresponding fields of itab

WHERE BELNR = RBKP-BELNR

AND GJAHR = RBKP-GJAHR

ORDER BY COUNTER DESCENDING

LV_PARKRSN = /PTGWFI/M_PRKMTR-PARKRSN.

LV_BELNR = /PTGWFI/M_PRKMTR-BELNR.

end select.

if helpful give reward points

pankaj

Read only

matt
Active Contributor
0 Likes
1,211

>

> hi,

> i am not understand /PTGWFI/M

Just for information, /PTGWFI/ is a namespace. It serves to seperate different applications from each other.

Read only

0 Likes
1,211

/PTGWFI/M_PRKMTR is a transparent table in SAP it is for LIX Parked Process Monitor.

Read only

matt
Active Contributor
0 Likes
1,211

Yes, and you use the whole thing as the table name, but technically, the /PTGWFI/ is the namespace - the table is M_PRKMTR. This allows us to, for example, have a table M_PRKMTR that is part of BI - it would be called /BIC/M_PRKMTR.

matt

Read only

Former Member
0 Likes
1,211

write like this...

data: wa_/PTGWFI/M_PRKMTR type /PTGWFI/M_PRKMTR .

SELECT * FROM /PTGWFI/M_PRKMTR

into wa_/PTGWFI/M_PRKMTR

WHERE BELNR = RBKP-BELNR

AND GJAHR = RBKP-GJAHR

ORDER BY COUNTER DESCENDING.

LV_PARKRSN = /PTGWFI/M_PRKMTR-PARKRSN.

LV_BELNR = /PTGWFI/M_PRKMTR-BELNR.

EXIT.

ENDSELECT.

regards,

venkat.

Read only

matt
Active Contributor
0 Likes
1,212

>

> Hi experts,

>

> I want to change the following code. Using select-endselect is not allowed, how can I change the code? I also have to avoid of using select *.

>

> SELECT * FROM /PTGWFI/M_PRKMTR

> WHERE BELNR = RBKP-BELNR

> AND GJAHR = RBKP-GJAHR

> ORDER BY COUNTER DESCENDING.

> LV_PARKRSN = /PTGWFI/M_PRKMTR-PARKRSN.

> LV_BELNR = /PTGWFI/M_PRKMTR-BELNR.

> EXIT.

> ENDSELECT.

Here's another alternative:

DATA: lv_counter TYPE /PTGWFI/M_PRKMTR-counter.

SELECT MAX( counter ) INTO lv_counter FROM /ptgwfi/m_prkmtr
    WHERE belnr EQ rbkp-belnr
      AND gjahr EQ rbkp-gjahr.

SELECT parkrsn belnr INTO (lv_parkrsn, lv_belnr) FROM /ptgwfi/m_prkmtr
    WHERE belnr EQ rbkp-belnr
      AND gjahr EQ rbkp-gjahr
      AND counter EQ lv_counter.

It would be interesting to compare the performance of the various alternatives, as matched against the original. SELECT... ENDSELECT should generally not be used, but there are times when it is the most appropriate construct.

matt

Read only

Former Member
0 Likes
1,211

Thanks for the answer, respect!