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 MARA ordered by select-options?

Former Member
0 Likes
4,050

Hi,

it try to get the data from mara ordered by the select-option, is this possible.

Normally i use:


TABLES: MARA.
*
SELECT-OPTIONS:   S_MATNR FOR MARA-MATNR.
*
select * from mara where matnr in s_matnr.
  write: / mara-matnr.
endselect.

Is there any FM, BAPI or any parameter for "ORDER BY" which i get use?

Thanks.

Regards, dieter

Hi,

it try to get the data from mara ordered by the select-option, is this possible.

Normally i use:


TABLES: MARA.
*
SELECT-OPTIONS:   S_MATNR FOR MARA-MATNR.
*
select * from mara where matnr in s_matnr.
  write: / mara-matnr.
endselect.

Is there any FM, BAPI or any parameter for "ORDER BY" which i get use?

Thanks.

Regards, dieter

14 REPLIES 14
Read only

Former Member
0 Likes
2,507

hi

change the select query like this:

select * from mara where matnr in s_matnr ORDER BY matnr.

If you are not using order by clause in select query by default it takes sorted values from table.

Regards,

Priyanka

Read only

Former Member
0 Likes
2,507

Deiter,

your question is not very clear. what do you mean by order by select option?

Read only

0 Likes
2,507

Hi,

thanks for your answer.

What i mean is this:

In selection screen i insert this value: 3, 2, 4, 1.

the output is 1, 2, 3, 4, but i will get this: 3, 2, 4, 1 like my selection.

Is this possible?

Regards, Dieter

Read only

0 Likes
2,507

Not possible through select query - Read SAP help. Try to do it in the coding if required.

Read only

0 Likes
2,507

Hi ,

Use ascending /descing in query.

select * from mara where matnr in s_matnr ORDER BY matnr descending

OR

select * from mara where matnr in s_matnr ORDER BY matnr asceneding

As per requirement.

regards,

Praphull

Edited by: T Praphull on Dec 6, 2011 10:27 AM

Read only

0 Likes
2,507

hi

you can use asc or desc :-

select <field > from mara order by <field> asc/desc.

by default it is asc thats why u were gertting 1 2 3 4 like that.

hope this helps ..

regards ,

somesh

Read only

0 Likes
2,507

Hi

Not possible..

Use in your coding section ..

thanks

Read only

Former Member
0 Likes
2,507

It would be pretty difficult to do even with coding.

What do you do if the user has entered patterns, or exclusions or NEs?

Rob

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,507

Just for the fun

TABLES: mara.
* data def
DATA: t1_mara TYPE TABLE OF mara WITH HEADER LINE,
      t2_mara TYPE TABLE OF mara WITH HEADER LINE,
      s2_matnr TYPE RANGE OF mara-matnr.
* selection screen
SELECT-OPTIONS so_matnr FOR mara-matnr.

START-OF-SELECTION.
* load wholde data in temp itab
  SELECT * INTO TABLE t1_mara FROM mara
    WHERE matnr IN so_matnr
    ORDER BY matnr.
* now final itab
  REFRESH t2_mara.
* for every Include select option, process its own records
  LOOP AT so_matnr WHERE sign = 'I'.
    REFRESH s2_matnr.
    APPEND so_matnr TO s2_matnr.
    LOOP AT t1_mara WHERE matnr IN s2_matnr.
      APPEND t1_mara TO t2_mara.
      DELETE t1_mara.
    ENDLOOP.
  ENDLOOP.
* If there is no "I" records,
  IF t1_mara[] IS NOT INITIAL.
    APPEND LINES OF t1_mara TO t2_mara.
  ENDIF.
* free memory
  REFRESH t1_mara. " FREE
* Proof of concept
  LOOP AT t2_mara.
    WRITE: / t2_mara-matnr.
  ENDLOOP.

Regards,

Raymond

Read only

0 Likes
2,507

And what do you do if there are overlapping ranges:

1-10

5-20

Rob

Read only

0 Likes
2,507

First selection will win, if you accept duplicates, just remove the "DELETE t1_mara."

(only for 5-20 then 1-10, else no problem)

Regards,

Raymond

Read only

0 Likes
2,507

No, I mean that the requirements are contradictory. Do the entries 5-10 come after 1-4 because they are in the first select-options or after 1-10 because they are in the second.

Rob

Read only

0 Likes
2,507

- If you keep the delete, they come after 1-4 cause they are in the first range and will only appear once

- If you remove the delete they will come twice

The request should be completed for "duplicated selections", are they to be displayed once or as many times they were selected.

But honestly, no user ever dared to make such a request (am I too harsh?)

Regards,

Raymond

Read only

0 Likes
2,507

But honestly, no user ever dared to make such a request (am I too harsh?)

No, but the first thing a developer has to do after receiving new specs is to question them and make sure that the user understands exactly what they are asking for.

Only start coding after this is done.

Rob