2021 Aug 18 2:00 PM
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.
2021 Aug 18 4:19 PM
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.
2021 Aug 18 2:39 PM
Please edit your question, select your code and press the little [CODE] button to format nicely the code. Thank you.
2021 Aug 18 2:49 PM
Have you tried to debug your code to see what's actually happening?
2021 Aug 18 3:34 PM
2021 Aug 18 3:40 PM
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.
2021 Aug 18 4:19 PM
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).
2021 Aug 19 2:14 AM
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 🙂
2021 Aug 19 7:19 AM
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.
2021 Aug 19 7:21 AM
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.
2021 Aug 19 7:53 AM
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.
2021 Aug 19 8:53 AM
Hi Vicenc,
Yes, your're right sorry for that. Will follow this proper approach thank you guys 🙂
2021 Aug 18 8:01 PM
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).
2021 Aug 19 9:12 AM
8b889d0e8e6f4ed39f6c58e35664518f can you please add this reflexion to your answer to make it full? Would be nice.
2021 Aug 19 2:16 AM
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 🙂