How to do a combination of two fields in a selection screen

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
Ram Ramaswamy
Posts: 12
Joined: Sat Oct 13, 2007 6:32 pm

How to do a combination of two fields in a selection screen

Post by Ram Ramaswamy » Fri Aug 22, 2008 12:27 pm

I want the user to enter a combination of plant and storage location in a selection screen. Basically (for example),
Plant 1 Storageloc 1
Plant 1 Storageloc 2
Plant 2 Storageloc 1
Plant 3 Storageloc 4.

How do I do such a thing on the screen and then I can in the program do select * from mard where werks in swerks and lgort in slgort. The users keep on wanting to add new plants and storage location combinations and we do not want to modify the program everytime. We want it in a selection screen for the user to checkbox the new plant storage location combination in the future without having to modify the program.
The user needs to select a combination of plant and storage location from the screen. Once multiple combinations are selected, without hardcoding in the program, I need to loop through the mard table store the mard-labst into different quantity variables based on PC01 or PC03 or PIDD plants etc. Is there any way of looping through the table and based on user input, I can plug in the field into the different variables without hardcoding in the program. Now it is only PC01, PC03 or PIDD. LAter on,they may choose another new combination which we need to take care of without modifying the program. Right now the program is hardcoded as shown below: We want to remove the hardcoding and allow the user to select multiple combinations as shown above.

select single * from mard where matnr = detail-matnr
and werks = 'PC01'
and lgort = '0002'.
if sy-subrc eq 0.
save_whs1_qty = save_whs1_qty + mard-labst.
endif.

SELECT SINGLE * FROM MARD WHERE MATNR = DETAIL-MATNR AND
WERKS = 'PIDD' AND
LGORT = '0018'.
IF SY-SUBRC NE 0.
MARD-LABST = 0.
ENDIF.
SAVE_WHS3_QTY = MARD-LABST.

SELECT * FROM MARD WHERE MATNR = DETAIL-MATNR
and WERKS = 'PC03'
and LGORT in slgort.
IF SY-SUBRC NE 0.
MARD-LABST = 0.
ENDIF.
SAVE_WHS6_QTY = save_whs6_qty + mard-labst.
endselect.

grinman
Posts: 36
Joined: Tue Aug 05, 2008 10:01 pm

Re: How to do a combination of two fields in a selection screen

Post by grinman » Fri Aug 22, 2008 12:37 pm

Why not store the combinations in a table?

That way you can do a select * from combinations_Table.

and later do

select single * from mard
for all entries in combinations_table
where matnr = detail-matnr
and werks = combinations_table-werks
and lgort = combinations_table-lgort.

I don't think a report would be the best option, you would have to use a table control to keep the combinations right.

skarkada
Posts: 701
Joined: Mon Oct 21, 2002 1:12 pm
Location: Houston, TX, USA

Re: How to do a combination of two fields in a selection screen

Post by skarkada » Fri Aug 22, 2008 2:28 pm

You can not accomplish what you are trying to do using standard selection screen alone.

You have to provide an interactive screen (dialog program) so users can specify the parameters without getting confused.

Would users run this program in background? Then it becomes more complex. If not, you can provide a pushbutton in the selection screen and then launch a dialog box to receive parameter combinations.

Above comments are based on the assumptions that you will want your program to follow SAP's user interface guidelines.
Sudhi Karkada

wilhitern1
Posts: 135
Joined: Thu May 15, 2008 4:25 pm
Location: Butterball LLC., Goldsboro, NC, USA
Contact:

Re: How to do a combination of two fields in a selection screen

Post by wilhitern1 » Mon Aug 25, 2008 12:15 pm

I think that is is additionally important to point out that your code

Code: Select all

SELECT * FROM MARD WHERE MATNR = DETAIL-MATNR
and WERKS = 'PC03'
and LGORT in slgort.
IF SY-SUBRC NE 0.
MARD-LABST = 0.
ENDIF.
SAVE_WHS6_QTY = save_whs6_qty + mard-labst.
endselect.
Will probably not accomplish what it appears you are trying to accomplish.

Take for instance your:

Plant 1 Storageloc 1
Plant 1 Storageloc 2
Plant 2 Storageloc 1
Plant 3 Storageloc 4

Your plant 1 should only accept SLocs 1 & 2 but not 4.

however if you use

Code: Select all

LGORT in slgort
with plant 1 then if there is an SLoc 4 for plant 1 it will be returned also.

HTH,
Neal
Neal Wilhite (WilhiteRN1)Image

maen
Posts: 141
Joined: Wed Feb 21, 2007 7:01 am

Re: How to do a combination of two fields in a selection screen

Post by maen » Tue Sep 09, 2008 4:28 am

A very long time ago i had to do a similar thing.

My solution was to use select options (eg. SO_WERKS and SO_LGORT) and only allow single values to be inserted: only single values for WERKS and single values for LGORT (there are ways to accomplish that but i can't find an example for it).

Now, each rows in both select-options corresponds with eachother: SO_WERKS[1] belongs to SO_LGORT[1] and so on.

After pressing F8, i combined both select-options into 1 internal table with 2 fields (WERKS and LGORT); similar as one of the above posters suggested. Now you can do a select FOR ALL ENTRIES IN itab WHERE ....

Downside is: it's possible that in the number of entries in SO_WERKS and SO_LGORT do not correspond. You'll have to check that to make sure your selection won't fail.

Post Reply