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

Disable required parameter based on the radio button selected

0 Likes
3,165

Hi Members,

I have a requirement when you select rb1, p3 and p4 should be required fields. But when you select rb2, p1 and p2 should not be required anymore and p1 and p2 should be the required fields.

Currently, when I select rb2, p3 and p4 are still required fields. I tried to change or add condition but it seems not working as expected. Thank you!


Please see below sample code:

PARAMETERS:

RB1 RADIOBUTTON GROUP GR1 USER-COMMAND TEST DEFAULT 'X',
RB2 RADIOBUTTON GROUP GR1,
P1 TYPE ZAME_LGC_PATH MODIF ID G1,
P2 TYPE DATUM MODIF ID G1,
P3 TYPE ZAME_PRC_DATE MODIF ID G1,
P4 TYPE ZAME_PRC_TIME MODIF ID G1.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

 IF SCREEN-GROUP1 = 'G1'.

  IF RB1 = 'X'.

   IF SCREEN-NAME = 'P3'.
    SCREEN-REQUIRED = 1.
   ENDIF.
   IF SCREEN-NAME = 'P4'.
    SCREEN-REQUIRED = 1.
  ENDIF.
  MODIFY SCREEN.

 ELSE.

  IF SCREEN-NAME = 'P3'.
   SCREEN-REQUIRED = 0.
  ENDIF.
  IF SCREEN-NAME = 'P4'.
   SCREEN-REQUIRED = 0.
  ENDIF.
  MODIFY SCREEN.

  IF SCREEN-NAME = 'P1'.
   SCREEN-REQUIRED = 1.
  ENDIF.
  IF SCREEN-NAME = 'P2'.
   SCREEN-REQUIRED = 1.
  ENDIF.
  MODIFY SCREEN.

  ENDIF.
 ENDIF.
ENDLOOP.
1 ACCEPTED SOLUTION
Read only

BaerbelWinkler
SAP Champion
SAP Champion
3,068

Hi Joy,

when I had to something like this, I put the parameters which needed to be treated differently, into two type groups. So instead of

RB1 RADIOBUTTON GROUP GR1 USER-COMMAND TEST DEFAULT 'X',
RB2 RADIOBUTTON GROUP GR1,
P1 TYPE ZAME_LGC_PATH MODIF ID G1,
P2 TYPE DATUM MODIF ID G1,
P3 TYPE ZAME_PRC_DATE MODIF ID G1,
P4 TYPE ZAME_PRC_TIME MODIF ID G1.<br>

I'd have

RB1 RADIOBUTTONGROUP GR1 USER-COMMANDTESTDEFAULT'X',
RB2 RADIOBUTTONGROUP GR1,
P1 TYPE ZAME_LGC_PATH MODIF ID G1,
P2 TYPE DATUM MODIF ID G1,
P3 TYPE ZAME_PRC_DATE MODIF ID G2,
P4 TYPE ZAME_PRC_TIME MODIF ID G2.

And the two groups can then be treated differently depended on which radiobutton was checked in AT SELECTION-SCREEN OUTPUT within the loop.

Hope this helps!

Cheers

Bärbel

Added sandra.rossi's comment/answer as suggested by vicen.lozano below:

Better not using REQUIRED, keep all the fields optional and test field values via ABAP code, it will be much more simple. You may also combine that with the special value REQUIRED = '2' (recommended, fields appear like being mandatory, but there's no actual check by the kernel).

Hi Members,

I have a requirement when you select rb1, p3 and p4 should be required fields. But when you select rb2, p1 and p2 should not be required anymore and p1 and p2 should be the required fields.

Currently, when I select rb2, p3 and p4 are still required fields. I tried to change or add condition but it seems not working as expected. Thank you!


Please see below sample code:

PARAMETERS:

RB1 RADIOBUTTON GROUP GR1 USER-COMMAND TEST DEFAULT 'X',
RB2 RADIOBUTTON GROUP GR1,
P1 TYPE ZAME_LGC_PATH MODIF ID G1,
P2 TYPE DATUM MODIF ID G1,
P3 TYPE ZAME_PRC_DATE MODIF ID G1,
P4 TYPE ZAME_PRC_TIME MODIF ID G1.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

 IF SCREEN-GROUP1 = 'G1'.

  IF RB1 = 'X'.

   IF SCREEN-NAME = 'P3'.
    SCREEN-REQUIRED = 1.
   ENDIF.
   IF SCREEN-NAME = 'P4'.
    SCREEN-REQUIRED = 1.
  ENDIF.
  MODIFY SCREEN.

 ELSE.

  IF SCREEN-NAME = 'P3'.
   SCREEN-REQUIRED = 0.
  ENDIF.
  IF SCREEN-NAME = 'P4'.
   SCREEN-REQUIRED = 0.
  ENDIF.
  MODIFY SCREEN.

  IF SCREEN-NAME = 'P1'.
   SCREEN-REQUIRED = 1.
  ENDIF.
  IF SCREEN-NAME = 'P2'.
   SCREEN-REQUIRED = 1.
  ENDIF.
  MODIFY SCREEN.

  ENDIF.
 ENDIF.
ENDLOOP.
13 REPLIES 13
Read only

Sandra_Rossi
Active Contributor
0 Likes
3,068

Please edit your question, select your code and press the little [CODE] button to format nicely the code. Thank you.

Read only

ArthurParisius
Contributor
0 Likes
3,068

Have you tried to debug your code to see what's actually happening?

Read only

3,068

I'm sorry my question is now updated. Thank you too.

Read only

0 Likes
3,068

Yes, it seems once the field is set to required, the ATSELECTION-SCREENOUTPUT. debug cant' be triggered. I also tried to place the code to ATSELECTION-SCREEN but it's still not working.

Read only

BaerbelWinkler
SAP Champion
SAP Champion
3,069

Hi Joy,

when I had to something like this, I put the parameters which needed to be treated differently, into two type groups. So instead of

RB1 RADIOBUTTON GROUP GR1 USER-COMMAND TEST DEFAULT 'X',
RB2 RADIOBUTTON GROUP GR1,
P1 TYPE ZAME_LGC_PATH MODIF ID G1,
P2 TYPE DATUM MODIF ID G1,
P3 TYPE ZAME_PRC_DATE MODIF ID G1,
P4 TYPE ZAME_PRC_TIME MODIF ID G1.<br>

I'd have

RB1 RADIOBUTTONGROUP GR1 USER-COMMANDTESTDEFAULT'X',
RB2 RADIOBUTTONGROUP GR1,
P1 TYPE ZAME_LGC_PATH MODIF ID G1,
P2 TYPE DATUM MODIF ID G1,
P3 TYPE ZAME_PRC_DATE MODIF ID G2,
P4 TYPE ZAME_PRC_TIME MODIF ID G2.

And the two groups can then be treated differently depended on which radiobutton was checked in AT SELECTION-SCREEN OUTPUT within the loop.

Hope this helps!

Cheers

Bärbel

Added sandra.rossi's comment/answer as suggested by vicen.lozano below:

Better not using REQUIRED, keep all the fields optional and test field values via ABAP code, it will be much more simple. You may also combine that with the special value REQUIRED = '2' (recommended, fields appear like being mandatory, but there's no actual check by the kernel).

Read only

0 Likes
3,068

Hello Barbel,

I still set it as MODIF ID G1 and set the SCREEN-REQUIRED = 2. It's now working as expected but I just add separate condition for the error message of the required fields. Thank you for your suggestion and will note on this 🙂

Read only

3,068

Bärbel's approach is the proper one, Joy. Your code works, but it is "dirty", and it works on controls' names. Groups exists to differentiate groups (sigh) of controls with different behaviour, so if you want some of them to act one way and some others to act another way, then the proper approach is to put them in different groups and change the screen based on their group and not their names.

Read only

3,068

jaycee_o2 please, at least accept this answer as the correct way, although Sandra's solution worked. If someone comes here with a similar problem, they will have a proper answer.

Thanks in advance.

Read only

3,068

vicen.lozano I agree. Or he can post his own answer. Or I should have better posted my comment as an answer 😛 -- it's fixed now.

Read only

3,068

Hi Vicenc,

Yes, your're right sorry for that. Will follow this proper approach thank you guys 🙂

Read only

Sandra_Rossi
Active Contributor
3,068

Better not using REQUIRED, keep all the fields optional and test field values via ABAP code, it will be much more simple. You may also combine that with the special value REQUIRED = '2' (recommended, fields appear like being mandatory, but there's no actual check by the kernel).

Read only

3,068

8b889d0e8e6f4ed39f6c58e35664518f can you please add this reflexion to your answer to make it full? Would be nice.

Read only

3,068

Hi Sandra,

You're right, I changed the SCREEN-REQUIRED to 2 and it's working now and I just add condition for the error message of required fields. Thank you 🙂