Skip to Content
author's profile photo Former Member
Former Member

Optional Field Validation

Hi,

In my MPP screen, I have 5 fields out of which only 2 are required/mandatory. But if the user enters data into the optional field (or fields), I need to include them also in my selection criteria.

Now, do I need to check if the data exists in the optional fields and write separate select statements for cases where the user has provided some input? Is there an alternative solution to achieve this rather than writing so many select statements?

Thanks,

Mohit

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 08, 2008 at 01:00 PM

    Hi Mohit,

    You can directly write a SELECT query containing the Optional Field, if you Enter value in that field the SELECT query will limit the Records based on that field also, otherwise when you don't specify a Value in this Optional Field it will be Ignored in the SELECT query.

    In other Words the System Automatically checks this Optional Field whether it has some value or not and Fetches the Data based on that.

    Best Regards,

    Sunil

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 08, 2008 at 01:01 PM

    Hi Mohit,

    There is no need for validating the mandatory/obligatory fields. The system automatically checks whether the field is empty or not and if it is empty it will give an error specifying that enter all mandatory fields.

    And for optional fields there is no need to check whether they are empty or not, becouse they are optional.

    Hope this helps you.

    Regards,

    Chandra Sekhar

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 08, 2008 at 01:02 PM

    Hi,

    If it is select option then no need to have seperate select. Just include this condition also in the select. If this field is blank then select will ignore this condition.

    If it is parameter then u have to have 2 selects.

    IF thatfield IS INITIAL.

    SELECT1.....With out that condition.

    ELSE.

    SELECT1 ... With that condition.

    ENDIF.

    Thanks,

    Vinod.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 08, 2008 at 01:02 PM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 08, 2008 at 01:02 PM

    Hi,

    I think you are using parameters and not select-options.

    Check if you can change the selection screen parameters to

    select-options: p_fld for tab-fld no intervals no extension. Then you can use single select by using 'IN' .

    Thanks,

    Keerthi.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 08, 2008 at 01:04 PM

    HI Mohit,

    YOu can have select-options declared for the optional fields instead of parameters.

    If you still want to make them look like parameters, you can declare them like this

    DATA spfli_wa TYPE spfli. 
    
    SELECT-OPTIONS s_carrid FOR spfli_wa-carrid NO-EXTENSION NO INTERVALS. 
    
    your select should be some thing like:
    
    select * from <table> into table <intenal table>
    where matnr in s_matnr.....

    Regards,

    Ravi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 08, 2008 at 01:05 PM

    If your five fields are parameters, you can't just leave them in your WHERE criteria as your Select will fail - say you are selecting from MARA where MATNR = null - you won't find anything will you?

    The best solution is to build a dynamic where statement like this:-

    &---------------------------------------------------------------------*
    *&      Form  build_dynamic_where_statement
    *&---------------------------------------------------------------------*
    *       This routine takes the key values passed into module
    *       ZPP_PO_READ_LAB_HOURS_TABLE and builds a dynamic where statement
    *       into a string field that can then be used for SELECT statements
    *----------------------------------------------------------------------*
    form build_dynamic_where_statement.
    
    *--- Ensure the last where statement is cleared
      clear: gv_where_statement.
    
    *--- Need to go through each variable and add to the where statement if it
    *--- has a value assigned
      if gv_werks is not initial.
        gv_where_statement = 'WERKS EQ GV_WERKS'.
      endif.
      if gv_resrce is not initial.
        if gv_where_statement is not initial.
          concatenate gv_where_statement
                      'AND RESRCE EQ GV_RESRCE'
                 into gv_where_statement
                 separated by space.
        else.
          gv_where_statement = 'RESRCE EQ GV_RESRCE'.
        endif.
      endif.
      if gv_begda is not initial.
        if gv_where_statement is not initial.
          concatenate gv_where_statement
                      'AND BEGDA EQ GV_BEGDA'
                 into gv_where_statement
                 separated by space.
        else.
          gv_where_statement = 'BEGDA EQ GV_BEGDA'.
        endif.
      endif.
      if gv_budat is not initial.
        if gv_where_statement is not initial.
          concatenate gv_where_statement
                      'AND BUDAT EQ GV_BUDAT'
                 into gv_where_statement
                 separated by space.
        else.
          gv_where_statement = 'BUDAT EQ GV_BUDAT'.
        endif.
      endif.
      if gv_schgrup is not initial.
        if gv_where_statement is not initial.
          concatenate gv_where_statement
                      'AND SCHGRUP EQ GV_SCHGRUP'
                 into gv_where_statement
                 separated by space.
        else.
          gv_where_statement = 'SCHGRUP EQ GV_SCHGRUP'.
        endif.
      endif.
      if gv_kaptprog is not initial.
        if gv_where_statement is not initial.
          concatenate gv_where_statement
                      'AND KAPTPROG EQ GV_KAPTPROG'
                 into gv_where_statement
                 separated by space.
        else.
          gv_where_statement = 'KAPTPROG EQ GV_KAPTPROG'.
        endif.
      endif.
    endform.                    " build_dynamic_where_statement

    And then write your select something like this:-

    select  *
              into  table t_lab_hours
              from  zpp_po_lab_hours
             where  (gv_where_statement).

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 08, 2008 at 01:06 PM

    HI,

    You can achieve this by LIKE key word.

    for ex: if you have the field1, field2 (where these fields are not ranges) on the screen. if these are filled you should select the data regarding this, if they are empty you should fetch the data without considering this, so you can do as below.

    if field1 is initial.

    field1 = '%'.

    endif.

    if field2 is initial.

    field2 = '%'.

    endif.

    the query should be as below.

    select f1 f2

    from table1

    into table itab1

    where f1 LIKE field1

    and f2 LIKE field2.

    This will solve your problem.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.