Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182550
Active Contributor

When you write a report you should as a matter of course validate the input that the user has provided to make sure that the request thay have made is at least sane.

This validation generally takes place in the "AT SELECTION-SCREEN ON parameter" event where if the value in the parameter is incorrect in some way and an error message is displayed the relevant field is highlighted and made ready for input again.  The processing of the report is stopped at that point.

One of the things to check for is that a parameter is populated and this can be done automatically using the 'OBLIGATORY' clause of the ‘PARAMETERS’ statement,  however,  when the selection screen is interactive,  this in itself can cause problems.

An interactive selection screen could for example have a series of radio buttons that diefine different aspects of the report,  and selecting a specific radio button means that a specific parameter should be used.  Rather than keep all these other fields visible I tend to put a user-command function on the radio button and then in the AT SELECTION-SCREEN OUTPUT event hide those fields that are not relevant to the current radio button state.  With the ‘OBLIGATORY’ parameter set on other fields this process is interrupted when a mandatory field is not populated leading to incorrect information or fields being displayed.

Also,  I am of the opinion that checks should not happen until the user has made all their entries and have clicked the ‘Online’ button.

Something like this:

At Selection-Screen On p_Matnr.
*
   Data: l_Count Type i.
*
   If sy-UComm = c_Ok_Online.
      If p_Matnr Is Initial.
         Message E018.
      Else.
         Select Count(*)
           Into l_Count
           From Mara
          Where Matnr = p_Matnr And
                LvOrm = Space.
         If sy-Subrc <> 0.
            Message E007 With p_Matnr.
         EndIf.
      EndIf.
   EndIf.

This checks to see if the material number is populated and that it is valid.  If not an error message is issued.

This type of code though has a little ‘Gotcha’.  I don’t know about you,  but If I have to correct an erroneous field,  I make a new entry and then rather than clicking the ‘Online’ button again I hit the ‘Enter’ key.  This then re-validates the fields and processes the report….but hitting the ‘Enter’ key sets sy-ucomm to initial and the validation code is not run.  This means that if I entered an invalid material number again it would not be picked up – as would any other field with an invalid entry.

Now you say “But users would always click the online button” in which case the code would always work,  but I would say “Well – there might be others like myself who do otherwise”.

The fix is simple – keep a copy of the previous function code and if the current code is initial use that instead:

At Selection-Screen On p_Matnr.
*
   Data: l_Count Type i,
         l_UComm Type UiFunc.
*
   If sy-Ucomm Is Not Initial.
      l_UComm = sy-UComm.
   Else.
      l_UComm = g_UComm.
   EndIf.
   If l_UComm = c_Ok_Online.
      If p_Matnr Is Initial.

         g_UComm = sy-UComm.
         Message E018.
      Else.
         Select Count(*)
           Into l_Count
           From Mara
          Where Matnr = p_Matnr And
                LvOrm = Space.
         If sy-Subrc <> 0.
            g_UComm = sy-UComm.

            Message E007 With p_Matnr.
         EndIf.
      EndIf.
   EndIf.

Set the value of g_UComm prior to issuing an error message.

10 Comments