Application Development 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: 

Problem with mandatory fields

former_member622551
Participant
0 Kudos

Hello,

i have 3 radio buttons, and 2 select-options. In first term, the 2 select-options are mandatory, but i need that when the radio buttons change, the first select-option set up to not mandatory.

I have some code but when i change the radio button, SAP gives me an error and tell me to fill all mandatory fields.

Any suggestion?

Thank you!!!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

I suggest you not to mark the fields as mandatory. Each time you change the radio button a error message is issued since Mandatory field check is performed automatically by the system. Instead you can check the fields in AT SELECTION-SCREEN event and issue an error message if they are initial (only when the user clicks on execute button, by checking sy-ucomm).

I had a similar requirement, Please check the following code snippets.


* Selection screen elements.............................................
SELECTION-SCREEN BEGIN OF BLOCK rbg WITH FRAME TITLE tit.

PARAMETERS:
  r_vendor RADIOBUTTON GROUP rad USER-COMMAND vendor,
  r_ship   RADIOBUTTON GROUP rad DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK rbg.

SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE tit1.

SELECT-OPTIONS:
  s_matnr FOR lips-matnr NO INTERVALS,
  s_vsbed FOR likp-vsbed MODIF ID so1 NO INTERVALS,
  s_wadat FOR likp-wadat_ist NO-EXTENSION.

SELECTION-SCREEN END OF BLOCK blk.

The following are the selection screen Events.


*----------------------------------------------------------------------*
*                  AT SELECTION-SCREEN OUTPUT EVENT                    *
*----------------------------------------------------------------------*

AT SELECTION-SCREEN OUTPUT.

* To set the selection screen attributes.
  PERFORM set_screen_attributes.

*----------------------------------------------------------------------*
*                      AT SELECTION-SCREEN EVENT                       *
*----------------------------------------------------------------------*

AT SELECTION-SCREEN.

  MOVE sy-ucomm TO sscrfields-ucomm.
  CHECK sscrfields-ucomm EQ 'ONLI'.

* To validate the selection screen fields.
  PERFORM validate_sel_screen_fields.

In the following code, I am writing the logic for hiding or displaying select-options based on the radio-button selected.


*----------------------------------------------------------------------*
*  FORM SET_SCREEN_ATTRIBUTES                                          *
*----------------------------------------------------------------------*
*  Subroutine for setting the selection screen display attributes      *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM set_screen_attributes .

  IF r_vendor EQ c_flag_x.
    w_check_group = c_flag_x.
  ENDIF.                               " IF R_VENDOR EQ C_FLAG_X

  IF w_check_group EQ c_flag_x.
    CLEAR w_check_group.
    LOOP AT SCREEN.
      IF screen-group1 = 'SO1'.
        screen-active = '0'.
        screen-invisible = '1'.
        MODIFY SCREEN.
      ENDIF.                           " IF SCREEN-GROUP1 = 'SO1'
    ENDLOOP.                           " LOOP AT SCREEN
  ELSE.
    LOOP AT SCREEN.
      IF screen-group1 = 'SO1'.
        screen-active = '1'.
        screen-invisible = '0'.
        MODIFY SCREEN.
      ENDIF.                           " IF SCREEN-GROUP1 = 'SO1'
    ENDLOOP.                           " LOOP AT SCREEN
  ENDIF.                               " IF W_CHECK_GROUP EQ C_FLAG_X

ENDFORM.                               " SET_SCREEN_ATTRIBUTES

Instead of marking select-options as mandatory (which are infact mandatory), i am issuing an error message if they are left blank and executed.


*----------------------------------------------------------------------*
*  FORM VALIDATE_SEL_SCREEN_FIELDS                                     *
*----------------------------------------------------------------------*
*  Subroutine for validating selection screen fields                   *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM validate_sel_screen_fields .

  IF s_wadat IS INITIAL.
    MESSAGE e888(sabapdocu)
       WITH text-dat.
  ELSEIF s_matnr IS INITIAL.
    MESSAGE e888(sabapdocu)
       WITH text-mti.
  ENDIF.                               " IF S_WADAT IS INITIAL

ENDFORM.                               " VALIDATE_SEL_SCREEN_FIELDS

6 REPLIES 6

piyush_mathur
Active Participant
0 Kudos

Hi...

Whenever you dont want to fill the Select Option on Radio Button Change...Screen-Input for that field.

Thanks

Former Member
0 Kudos

Hi ,

Initailly donot include the obligatory keyword . Instead you can use this code.

at selection-screen output.

<Your Condition>

Loop at screen .

if screen-name = 'S_MAR' " name of the selection-option.

screen-required = '1'.

modify screen.

endif.

endloop.

Former Member
0 Kudos

Hi,

I suggest you not to mark the fields as mandatory. Each time you change the radio button a error message is issued since Mandatory field check is performed automatically by the system. Instead you can check the fields in AT SELECTION-SCREEN event and issue an error message if they are initial (only when the user clicks on execute button, by checking sy-ucomm).

I had a similar requirement, Please check the following code snippets.


* Selection screen elements.............................................
SELECTION-SCREEN BEGIN OF BLOCK rbg WITH FRAME TITLE tit.

PARAMETERS:
  r_vendor RADIOBUTTON GROUP rad USER-COMMAND vendor,
  r_ship   RADIOBUTTON GROUP rad DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK rbg.

SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE tit1.

SELECT-OPTIONS:
  s_matnr FOR lips-matnr NO INTERVALS,
  s_vsbed FOR likp-vsbed MODIF ID so1 NO INTERVALS,
  s_wadat FOR likp-wadat_ist NO-EXTENSION.

SELECTION-SCREEN END OF BLOCK blk.

The following are the selection screen Events.


*----------------------------------------------------------------------*
*                  AT SELECTION-SCREEN OUTPUT EVENT                    *
*----------------------------------------------------------------------*

AT SELECTION-SCREEN OUTPUT.

* To set the selection screen attributes.
  PERFORM set_screen_attributes.

*----------------------------------------------------------------------*
*                      AT SELECTION-SCREEN EVENT                       *
*----------------------------------------------------------------------*

AT SELECTION-SCREEN.

  MOVE sy-ucomm TO sscrfields-ucomm.
  CHECK sscrfields-ucomm EQ 'ONLI'.

* To validate the selection screen fields.
  PERFORM validate_sel_screen_fields.

In the following code, I am writing the logic for hiding or displaying select-options based on the radio-button selected.


*----------------------------------------------------------------------*
*  FORM SET_SCREEN_ATTRIBUTES                                          *
*----------------------------------------------------------------------*
*  Subroutine for setting the selection screen display attributes      *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM set_screen_attributes .

  IF r_vendor EQ c_flag_x.
    w_check_group = c_flag_x.
  ENDIF.                               " IF R_VENDOR EQ C_FLAG_X

  IF w_check_group EQ c_flag_x.
    CLEAR w_check_group.
    LOOP AT SCREEN.
      IF screen-group1 = 'SO1'.
        screen-active = '0'.
        screen-invisible = '1'.
        MODIFY SCREEN.
      ENDIF.                           " IF SCREEN-GROUP1 = 'SO1'
    ENDLOOP.                           " LOOP AT SCREEN
  ELSE.
    LOOP AT SCREEN.
      IF screen-group1 = 'SO1'.
        screen-active = '1'.
        screen-invisible = '0'.
        MODIFY SCREEN.
      ENDIF.                           " IF SCREEN-GROUP1 = 'SO1'
    ENDLOOP.                           " LOOP AT SCREEN
  ENDIF.                               " IF W_CHECK_GROUP EQ C_FLAG_X

ENDFORM.                               " SET_SCREEN_ATTRIBUTES

Instead of marking select-options as mandatory (which are infact mandatory), i am issuing an error message if they are left blank and executed.


*----------------------------------------------------------------------*
*  FORM VALIDATE_SEL_SCREEN_FIELDS                                     *
*----------------------------------------------------------------------*
*  Subroutine for validating selection screen fields                   *
*----------------------------------------------------------------------*
*  There are no interface parameters to be passed to this subroutine.  *
*----------------------------------------------------------------------*
FORM validate_sel_screen_fields .

  IF s_wadat IS INITIAL.
    MESSAGE e888(sabapdocu)
       WITH text-dat.
  ELSEIF s_matnr IS INITIAL.
    MESSAGE e888(sabapdocu)
       WITH text-mti.
  ENDIF.                               " IF S_WADAT IS INITIAL

ENDFORM.                               " VALIDATE_SEL_SCREEN_FIELDS

Former Member
0 Kudos

Hi Try like this..



if radio_b1 eq 'X'.
  if p_filed1 is initial.
    message e(xxx).
  endif.
 if p_filed2 is initial.
   message e(xxx).
 endif.
else if radio_b2 eq 'X'.
" check what ever fields u want to keep as mandatory.
endif.

continue with u r logic...

Regards,

Sunil Kumar M........

Former Member
0 Kudos

Hi,

try this code.


At selection-screen output.
if w_flag eq 'x'.
loop at screen.
if screen-name eq 'xyz'.
 screen-input = 0.
modify screen.
endloop.
endif.
clear w_flag.

at selection-screen.
if rad_1 ne 'x'.
w_flag = 'x'.
endif.
  if w_flag ne 'x'.
 if s_xyz is initial.
  ur eror message.
endif.
endif.

.

hope it will help you.

regards

Manjari.

former_member188685
Active Contributor
0 Kudos

Instead of that you can do this..

Based on the radio button check the values and Raise the error message.

REPORT  ztest_radio.

TABLES: sflight.

SELECT-OPTIONS: carrid FOR sflight-carrid,
                             fldate FOR sflight-fldate.
PARAMETERS: rcar RADIOBUTTON GROUP g1 DEFAULT 'X' USER-COMMAND aaa,
            rdat RADIOBUTTON GROUP g1.

AT SELECTION-SCREEN.
  IF sy-ucomm = 'ONLI'.
    IF rcar = 'X' AND
     carrid-low IS INITIAL.
      MESSAGE 'enter carrid ' TYPE 'E'.
    ENDIF.
    IF rdat = 'X' AND
     fldate-low IS INITIAL.
      MESSAGE 'enter Fldate' TYPE 'E'.
    ENDIF.
  ENDIF.

Regards

Vijay Babu Dudla