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: 

2 Listbox dependent and other fields are mandatory in modulepool

0 Kudos

I have created a screen in which there are 2 list box and some input/output fields.

Listbox 2 value will come from listbox 1 value selection and other fields are mandatory.

I am able to populate the values in listbox 2 by triggering Function code in Listbox 1 value selection. But if I am making other remaining fields as mandatory then Listbox2 values are not coming and Automatic field check getting triggered.

If I am making input/output fields as mandatory then I am not able populate values in Listbox2 and if I am populating values in Listbox2 using event of Listbox1 then I have make other remaining fields as non mandatory.

I want both listbox values and other fields as mandatory.

problem.png

1 ACCEPTED SOLUTION

0 Kudos

Thanks everyone,

I solved it by
Chain ..... Endchain and check the code at the time of saving.

This If condition of sy-ucomm works for me.

chain.
field:  ZTBPROJECT-ZPROJ_NAME,
        ZTBPROJECT-ZENG_NAME,
        ZTBPROJECT-ZGROUP_NAME,
        ZTBPROJECT-ZPROJ_NAME,
        ZTBPROJECT-PROJ_DESCRIPTION,     
        ZTBPROJECT-PROJ_STATUS.
 module check_filled.
endchain.


MODULE CHECK_FILLED INPUT.
  IF SY-UCOMM = 'FC_OK'.
    PERFORM CHECK_FIELDS.
  ENDIF.
ENDMODULE.


13 REPLIES 13

Sandra_Rossi
Active Contributor
0 Kudos

Dynpros have some limits. You reached one. You must find a compromise. All mandatory fields must be entered before function codes can be processed, so you must wait before defining the values of the second listbox. Or you can make your own mandatory checks in full ABAP and keep the dynpro fields optional.

0 Kudos

While checking at ABAP level I need to make sure that they are filled otherwise data should not be saved, I am populating error but it is greying out all the fields as I am not doing the same in
Chain ....... Endchain.

I just need to make sure that all the fields are filled.

0 Kudos

It's probably because you did not trigger the error from a module inside the PAI (statement MODULE) [inserted] or you didn't use CHAIN/ENDCHAIN (<!--removed:It's not related to CHAIN/ENDCHAIN-->, nor with the mandatory fields, nor with my answer. So, as I said, keep the dynpro fields optional, and check their values via the ABAP code.

0 Kudos

I tried to validate at the time of saving in PAI but if I am giving error then fields are greying out and if I am not giving error then data get saved.

Please suggest how can I check at ABAP level, where can I code for that (fields are filled) validation.

Thanks.

satyapriyanka_vana
Active Participant
0 Kudos

Hi,

Any user defined function code will be taken as an input and hence it will trigger PAI. And it will check the mandatory fields. The better thing you can do is make the mandatory fields as 'recomended' i.e. screen-required = 2. So the mandatory mark will be shown for the field. At the final execution check for those fields to be filled.

Regards,

Priyanka.

0 Kudos

At the final execution I am populating error but it is greying out all the fields without error message it will save the data.

0 Kudos

May I know why CHAIN..END CHAIN is not used?

0 Kudos

If I am using Chain... Endchain, then it is giving same problem i.e. Listbox values's are not getting populated.

Currently I am choosing one of them, either populating values in listbox or make fields mandatory. But I want both Please suggest how can I check whether fields are filled or not at ABAP level.

0 Kudos

But if you use chain endchain, once after you enter the mandatory field, it will auto fill the list box 2. When an error or warning is triggered, you cannot get the field values which are processed after PAI.

I know this is not an effective idea, but sharing my thought on this!

If you want to do both at same time, i.e. informing user as the field is mandatory and auto filling the listbox, you make the message as information message, but show it as an error to the user. So that he can fill all the remaining fields. But make sure it's filled before your final execution(here it's F_SAVE)


PROCESS BEFORE OUTPUT.

  MODULE status_0500.

PROCESS AFTER INPUT.

 FIELD v_rdtype MODULE auto_fill_fd ON REQUEST.

  CHAIN.

    FIELD v_vbukr.

    FIELD v_proj.

    MODULE validate.

  ENDCHAIN.

  MODULE user_command_0500.

  MODULE exit AT EXIT-COMMAND.
MODULE status_0500 OUTPUT.

  SET PF-STATUS 'ZSTAT'.

*  SET TITLEBAR 'xxx'.

  LOOP AT SCREEN.

    IF screen-name = 'V_VBUKR'.

      screen-required = '2'.

      MODIFY SCREEN.

    ENDIF.

  ENDLOOP.

  IF v_flag = 'X'.

    SET CURSOR FIELD 'V_VBUKR'.

  ENDIF.

ENDMODULE.                 " STATUS_0500  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  USER_COMMAND_0500  INPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE user_command_0500 INPUT.

  IF sy-ucomm = 'F_SAVE'.

    IF v_vbukr IS INITIAL.

      MESSAGE 'ENTER C.CODE' TYPE 'E'.

    ELSE.

      MESSAGE 'SAVED' TYPE 'S'.

    ENDIF.

  ENDIF.

ENDMODULE.                 " USER_COMMAND_0500  INPUT

*&---------------------------------------------------------------------*

*&      Module  AUTO_FILL_FD  INPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE auto_fill_fd INPUT.

  ok_code = sy-ucomm.

  IF ok_code = 'F_CODE'.

    IF NOT v_rdtype IS INITIAL.

      CASE v_rdtype.

        WHEN 'C'.

          v_fdtype = 'SFCPCI'.

        WHEN 'D'.

          v_fdtype = 'SFCPDE'.

        WHEN 'M'.

          v_fdtype = 'SFCPTA'.

      ENDCASE.

    ENDIF.

  ENDIF.

ENDMODULE.                 " AUTO_FILL_FD  INPUT

*&---------------------------------------------------------------------*

*&      Module  VALIDATE  INPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE validate INPUT.

  CLEAR v_flag.

  IF v_vbukr IS INITIAL.

    v_flag = 'X'.

    MESSAGE 'ENTER C.CODE' TYPE 'I' DISPLAY LIKE 'E'.

  ENDIF.

ENDMODULE.              

Regards,

Priyanka.

former_member182550
Active Contributor

Hi,

When you have an interactive screen in the same way that you have then the use of mandatory fields interrupts the flow of the users work because whenever you get a PAI you get the various error messages. Because of this, I never use mandatory fields any more but rather do all the checking myself. This can be made considerably easier by defining a macro just to check whether a field is initial or not which you then put in your PAI processing and ONLY check when the user goes online (ie sy-ucomm = ONLI) or has pressed another button specific to your program that will result in the program processing.

Because of this I have developed a set of macros that are used specifically for screens which handle things like the placement of objects ( check boxes to the right or left), status icons on screens, description fields that automatically update so on and so forth. You will find that you will keep having to code stuff that is similar over and over again in screen handling so why not start building yourself a library of useful macros for report screens.

For example,

Begin_Of_Nested_SubScreen 3000 1.
      Begin_Of_Block TRA.
            Parameter_With_Listbox: 1 20 Text-TW1 Wash  Tw_File_Type    TRA WASH.
            Standard_Par:           1 20 Text-TW2 StDat Tw_Start_Date   TRA BU_DATE_CHAR,
                                    1 20 Text-TW3 StZet Tw_Start_Time   TRA SRM_F4_UZEIT,
                                    1 20 Text-TW4 FiDat Tw_Finish_Date  TRA BU_DATE_CHAR,
                                    1 20 Text-TW5 FiZet Tw_Finish_Time  TRA SRM_F4_UZEIT.
            Parameter_With_Listbox: 1 20 Text-TW6 PType Tw_Program_Type TRA PTYPE.
            Input_Line:             RF1 Tw_Rdr RfId_Reader d_Tw_Rdr     TRA,
                                    Tw7 TagId  Tw_Rfid_Tag d_TagId      TRA.
            Begin_Of_Line.
                  Selection-Screen Comment 1(20) Text-Tw8 For Field p_Temp Modif Id TRA.
                  Parameters: p_Temp Type Tw_Wash_Temp                     Modif Id TRA.
                  Selection-Screen Comment 30(20) Text-Tw9 For Field p_UoM Modif Id TRA.
                  Parameters: p_UoM  Type Tw_Wash_UoM                      Matchcode Object OUMT
                                                                           Modif Id TRA.
            End_Of_Line.
            Input_Line:             TWA ErCde Tw_Error_Code d_ErCde        TRA.
            Begin_Of_Block TIA.
                  Select-Options s_Inact For g_Inactive Modif Id TRA.
            End_Of_Block TIA.
      End_Of_Block TRA.
End_Of_SubScreen 3000.

This defines a subscreen on a report parameter screen with blocks, standard parameters with description fields for the values, list boxes etc etc.

At Selection-Screen On p_IntNme.
   If_Online.
      If p_IntNme Is Initial.
         Message E053.
      EndIf.
   EndIf.

The code above shows the validation of one of the parameters. And this is what i am talking about - only do your checks when the user is about to go online (If you are wondering about the phrase 'Go Online' and why that particular ok code is ONLI then go back to SAP's roots on the IBM Mainframes....)

The macro IF_ONLINE is as follows:

Define If_OnLine.
          If SSCRFields-UComm = 'ONLI'
             or SSCRFields-UComm = 'PRIN'
                Or SSCRFields-UComm = 'SJOB'.
End-Of-Definition.
<br>

So this only carries out any validation when the user is requesting the report and not when they are filling in the screen and moving from field to field.

As an example of one of the input screen macros would be:

Define Parameter_With_ListBox.
       Begin_Of_Line.
             Selection-Screen Comment &1(&2) &3 For Field p_&4 Modif Id &6.
             Parameters p_&4 Type &5                           As ListBox Visible Length 30
                                                               User-Command &7
                                                               Modif Id &6.
             Selection-Screen Comment 70(30) d_&4 For Field p_&4 Modif Id &6.
       End_Of_Line.
End-Of-Definition.

0 Kudos

Thanks for your reply,

How can I use this event (at selection screen on field) in modulepool, In modulepool we have liimitation of 4 events PBO, PAI, POV, POH.

Please suggest how can I validate whether fields are empty or filled in PAI without greying out the fields after error. I tried to validate at the time of saving but was greying out the fields.

Thanks.

In a module pool you have the FIELDS command which causes a field transport. This applies to a single field and if you look at the ABAP Help (place cursor on a command and press F1) you will see all of this. So in your PAI for a single field you would use something like:

Field gs_Display-Reason
      Module Check_Skip_Reason_0100.
Module Exit_Command_0100 At Exit-Command.
Module User_Command_0100.

This transports field Reason and then for that field if an error is displayed that field will be coloured yellow and ready for input whilst all other fields would be grey.

The other Modules are called if teh user command is flagged as an exit command, or is called regardless.

If you have a series of fields that you require to be all available for input you would use a CHAIN statement:

Chain.
      Fields: gs_Display-Reason,
              gs_Display-F1,
              gs_Display-F2.
      Module Check_Skip_Reason_0100.
EndChain.
Module Exit_Command_0100 At Exit-Command.
Module User_Command_0100.
<br>

This would then make the fields listed between Chain and EndChain available for input if an error is displayed.

However, you can also only call these things under specific circumstances using an extention to the Module statement. Again, these are described in the documentation:

Module Check_Skip_reason_0100 On Input 
                              On Request 
                              On *-Input 
                              On Chain-Input
                              On Chain-Request

The main difference is that On Input calls the module when there is input in the field and On-Request calls the module when there is changed input in the field. Obviously CHAIN- is used inside a chain block.

These modules that are mentioned are defined in a module pool.

Although you can have other statements inside a module, SAP strongly recommends that only a perform statement is used:

*&---------------------------------------------------------------------*
*&      Module  CHECK_SKIP_REASON_0100  INPUT
*&---------------------------------------------------------------------*
*       text    If the OK code is the skip button then this field must
*               be populated.
*----------------------------------------------------------------------*
Module CHECK_SKIP_REASON_0100 Input.
       Perform Check_Skip_Reason Using gs_Display-Ok_Code
                                       gs_Display-Reason.
EndModule.

Also Note that I am passing the global fields as parameters to the routine rather than accessing them directly in the routine.

In the routine you would then check the OK code, and if it is one of the online codes mentioned above you would then test for initial (if the field is mandatory) and then any other errors with the field otherwise, issuing the relevant E type error message.

0 Kudos

Thanks everyone,

I solved it by
Chain ..... Endchain and check the code at the time of saving.

This If condition of sy-ucomm works for me.

chain.
field:  ZTBPROJECT-ZPROJ_NAME,
        ZTBPROJECT-ZENG_NAME,
        ZTBPROJECT-ZGROUP_NAME,
        ZTBPROJECT-ZPROJ_NAME,
        ZTBPROJECT-PROJ_DESCRIPTION,     
        ZTBPROJECT-PROJ_STATUS.
 module check_filled.
endchain.


MODULE CHECK_FILLED INPUT.
  IF SY-UCOMM = 'FC_OK'.
    PERFORM CHECK_FIELDS.
  ENDIF.
ENDMODULE.