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

Former Member
0 Likes
1,408

Hi all,

How is it possible to make a select-option 'obligatory' based on some 'if-else' logic in simple ABAP code?

regards,

vishy

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,383

Hi Vishwanath,

use this statement.

select-options : s_matnr for mara-matnr obligatory.

U can use <b>Ranges</b> to make them obligatory on some if..else condition

Read help on <b>'Ranges'.</b>

Reward points if helpful.

Regards,

Hemant

14 REPLIES 14
Read only

Former Member
0 Likes
1,383

Hi

Why to write code straight away you can make it as Obligatory

select-options:s_bukrs for t001-bukrs no intervals no-extension

obligatory.

Reward points if useful

Regards

Anji

Read only

Former Member
0 Likes
1,383

You can make the entry for the field obligatory by writing obligatory itself in the select-option like this...

select-options: s_matnr type matnr obligatory.

there is no need for if endif logic..

Regards,

jayant

Read only

Former Member
0 Likes
1,383

Hi Vishy,

Its better give like this.

SELECT-OPTIONS : s_budat FOR bkpf-budat obligatory,

s_dbacct FOR bseg-hkont obligatory,

s_cracct FOR bseg-hkont obligatory,

s_amt FOR bseg-dmbtr.

Reward for useful answers.

Read only

Former Member
0 Likes
1,383

Hi Vishwanath ,

If you want to make a select option obligatory based on a condition then you can do it in the event AT SELECTION SCREEN , in the event if your condition is true then check if an entry is there in the select option , if it is not there then raise an error message.

Regards

Arun

Read only

Former Member
0 Likes
1,383

Hi vishy,

we can restrict the users using Messages.

Consider this Example,

IF FIELD1 IS INITIAL AND FIELD2 IS INITIAL.

MESSAGE 'PLEASE ENTER YOUR NAME AND DOB AND PRESS ENTER' TYPE 'I'.

ENDIF.

Thanks.

Reward If Helpful.

Read only

Former Member
0 Likes
1,384

Hi Vishwanath,

use this statement.

select-options : s_matnr for mara-matnr obligatory.

U can use <b>Ranges</b> to make them obligatory on some if..else condition

Read help on <b>'Ranges'.</b>

Reward points if helpful.

Regards,

Hemant

Read only

Former Member
0 Likes
1,383

Hi vishwanath

Try this sample code

*****************
*selection-screen
******************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 25(23) text-002.
*SELECT-OPTIONS: s_lifnr FOR ekko-lifnr.
PARAMETERS:p_lifnr LIKE ekko-lifnr obligatory.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 25(20) text-006.
*PARAMETERS:p_ebeln LIKE ekko-ebeln obligatory.
SELECT-OPTIONS:s_ebeln FOR ekko-ebeln OBLIGATORY.
SELECTION-SCREEN END OF LINE.

*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 25(23) text-003.
*PARAMETERS:p_ekorg LIKE ekko-ekorg.
*SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 25(20) text-004.
*PARAMETERS:p_werks LIKE ekpo-werks obligatory.
*SELECT-OPTIONS: S_werks FOR ekpo-werks obligatory.
SELECTION-SCREEN END OF LINE.


*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 25(23) text-005.
*SELECT-OPTIONS:s_bedat FOR ekko-bedat.
*SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.
  PERFORM get_data.
  PERFORM field_catalog.
  PERFORM display_data.

END-OF-SELECTION.

Rewards if helpfull

Regards,

Pavan

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,383

Hi,

Try this and reward points if it helps.

tables mara.

select-options s_matnr for mara-matnr obligatory.

initialization.

loop at screen.

if screen-name = 'S_MATNR-HIGH'.

screen-required = '1'.

modify screen.

endif.

endloop.

Read only

Former Member
0 Likes
1,383

Thanks all for the overwhelming response, but the requirement is like:

there is a check box and a select-option in the same selection screen. Whenever the check box is checked, the select-option should be made obligatory. How can this be achieved? I hope this is more clear.

Regards,

Vishy.

Read only

0 Likes
1,383

Hi Vishwanath ,

Here is a sample code for your requirement.

Tables : mard.

parameters : p_test as checkbox USER-COMMAND test  .
select-options : s_matnr for mard-matnr.
data : v_flag type c..


at selection-screen output.
clear v_flag.

 loop at screen.
  if screen-name = 'S_MATNR-LOW'.
 if p_test is initial.
    screen-REQUIRED = '0'.
 else.
    screen-REQUIRED = '1'.
 endif.
    MODIFY SCREEN.
  ENDIF.
 endloop.

But this has one shortcomming , once you make the select option obligatory by checking the check box , and then you uncheck the check box , the select option remains obligatory .

So a better solution would be as i said in my previous post , check if the check box is checked in the event AT SELECTION SCREEN and if if is checked then check is values have been entred in the select option.

Feel free to revert back in case of further queries.

Regards

Arun

Read only

0 Likes
1,383

Hi,

Another way is to do that with validations.

tables mara.

parameters c1 as checkbox .

select-options s_matnr for mara-matnr .

at selection-screen output.

if c1 = 'X' and s_matnr[] is initial.

message s000 with 'Enter values in s_matnr' .

leave list-processing.

endif.

write 'Correct'.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,383

Hi,

Try this.After you pressed enter,you can see the fields are made obligatory.

tables mara.

parameters c1 as checkbox .

select-options s_matnr for mara-matnr .

at selection-screen output.

if c1 = 'X'.

loop at screen.

if ( screen-name = 'S_MATNR-HIGH' or screen-name = 'S_MATNR-LOW' ) .

screen-required = '1'.

modify screen.

endif.

endloop.

endif.

Read only

Former Member
0 Likes
1,383

hi,

selection-screen : begin of block blk1 with frame title text-001.

select-option : s_werks for marc-werks obligatory,

s_matnr for mara-matnr obligatory.

selection-screen : end of block blk1.

reward with points if helpful

Read only

Former Member
0 Likes
1,383

u can use keywords like no-intervals and no extension for select options to make as a parameter.

ex: s_matnr like mara-matnr no-intervals no extensions.

then s_matnr acts as a simple parameter.