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: 

Not able to create conditional required fields at Tcode CJ20N Proj Systems

Former Member
0 Kudos

Hello experts,

I have a requirement to create a few custom fields under custom enhancement tab in CJ20N transaction, and depending on a particular value for one of the fields, another set of fields need to be set to required. (If FIELD1 = 'Y', FIELD2 & FIELD3 should be set to required)

My approaches..

1. Assign a screen group to FIELD2 and FIELD3. If FIELD1 = 'Y' then LOOP AT SCREEN, and set screen-required = 1 for that specific screen group.

Problem with this approach is that, if I select FIELD1 = 'Y' (hit space or enter -> sy-ucomm = TOGGLE), the fields are successfully set to required. However, now if at this point I go and change value for FIELD1 = 'X' (hit space or enter), FIELD2 and FIELD3 still remain set to required, and keep requesting value.

2. Do not set any fields to required. Instead set it to an information message in PAI, informing user that this field requires a value when FIELD1 = 'Y' on TOGGLE and SAVE.

Problem with this approach is that even though during TOGGLE event user is provided with an informational message, if the user directly decides to SAVE (no change for TOGGLE event), in this case the same message is displayed, and the project screen itself is closed. I do not think it would be ideal for the user to see the entire project close on SAVE everytime they miss a conditionally required field.

I am just not sure at this point how to handle this at SAVE so that I can still have the same control as I would when TOGGLE event is triggered.

Experts please help if you have come across such a situation!!! Your insight would be greatly appreciated!

Edited by: akkinair on Dec 16, 2011 1:25 AM

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

In your PBO

- do nothing (easy)

In your PAI

- First use an explicit FIELD FIELD1 to insure value is copied from screen to program

- Then use a CHAIN/FIELD/ENCHAIN for the dependant fields, if one required field is initial, check OK_CODE (not sy-ucomm...) if its value is 'TOGGLE' issue a warning or status message, else raise an error message.

* PAI
PROCESS BEFORE OUTPUT.
  MODULE status_pbo.

PROCESS AFTER INPUT.
  FIELD field1.
  CHAIN.
    FIELD field2.
    FIELD field3.
    MODULE check_required_fields.
  ENDCHAIN.
* Include for PAI modules
MODULE check_required_fields INPUT.
  IF field1 EQ 'X'
  AND ( field2 IS INITIAL OR field3 IS INITIAL).
    CASE ok_code.
      WHEN 'TOGGLE'.
        MESSAGE 'Field mandatory' TYPE 'W'.
      WHEN OTHERS.
        MESSAGE 'Field mandatory' TYPE 'E'.
    ENDCASE.
  ENDIF.
ENDMODULE.                 " CHECK_REQUIRED_FIELDS  INPUT

Regards,

Raymond

3 REPLIES 3

nabheetscn
Active Contributor
0 Kudos

Please find below the response.

1. Assign a screen group to FIELD2 and FIELD3. If FIELD1 = 'Y' then LOOP AT SCREEN, and set screen-required = 1 for that specific screen group. 
Problem with this approach is that, if I select FIELD1 = 'Y' (hit space or enter -> sy-ucomm = TOGGLE), the fields are successfully set to required. However, now if at this point I go and change value for FIELD1 = 'X' (hit space or enter), FIELD2 and FIELD3 still remain set to required, and keep requesting value.

_*

--> When FIELD1 chnage used module with additon CHAIN-REQUEST and check its value if it is to be set to optional by using loop at screen and set screen-required =0.*_

2. Do not set any fields to required. Instead set it to an information message in PAI, informing user that this field requires a value when FIELD1 = 'Y' on TOGGLE and SAVE. 
Problem with this approach is that even though during TOGGLE event user is provided with an informational message, if the user directly decides to SAVE (no change for TOGGLE event), in this case the same message is displayed, and the project screen itself is closed. I do not think it would be ideal for the user to see the entire project close on SAVE everytime they miss a conditionally required field.

--> Can you please clarify it.

Thanks

Nabehet

raymond_giuseppi
Active Contributor
0 Kudos

In your PBO

- do nothing (easy)

In your PAI

- First use an explicit FIELD FIELD1 to insure value is copied from screen to program

- Then use a CHAIN/FIELD/ENCHAIN for the dependant fields, if one required field is initial, check OK_CODE (not sy-ucomm...) if its value is 'TOGGLE' issue a warning or status message, else raise an error message.

* PAI
PROCESS BEFORE OUTPUT.
  MODULE status_pbo.

PROCESS AFTER INPUT.
  FIELD field1.
  CHAIN.
    FIELD field2.
    FIELD field3.
    MODULE check_required_fields.
  ENDCHAIN.
* Include for PAI modules
MODULE check_required_fields INPUT.
  IF field1 EQ 'X'
  AND ( field2 IS INITIAL OR field3 IS INITIAL).
    CASE ok_code.
      WHEN 'TOGGLE'.
        MESSAGE 'Field mandatory' TYPE 'W'.
      WHEN OTHERS.
        MESSAGE 'Field mandatory' TYPE 'E'.
    ENDCASE.
  ENDIF.
ENDMODULE.                 " CHECK_REQUIRED_FIELDS  INPUT

Regards,

Raymond

Former Member
0 Kudos

Raymond, truly appreciate your help. It works! Thank you!

Btw, I am not able to set OK_CODE as screen-name for OK, as it appears grayed out. However, sy-ucomm works perfectly as oppose to OK_CODE in the CASE statement. Would there be any negative impact with this?

Edited by: akkinair on Dec 16, 2011 8:31 PM