Skip to Content
avatar image
Former Member

Parameters validation in selection screen

HI Frnds,

    Can anyone please help me on, how to completely validate parameters (optional) and parameters (mandatory).

eg 1:

Parameters : p_matnr type matnr(optional).

parameters : p_mtart type mtartoptional.

validation:??

eg 2:

Parameters : p_matnr type matnr obligatory.

parameters : p_mtart type mtart.

validation:????

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

9 Answers

  • avatar image
    Former Member
    Oct 23, 2013 at 09:22 AM

    Use AT SELECTION SCREEN* EVENTS in your program for validation..

    e.g.

    PARAMETER : p_vbeln TYPE vbak-vbeln.

    AT SELECTION-SCREEN ON p_vbeln.

      IF NOT p_vbeln IS INITIAL.

        SELECT single vbeln FROM vbak into lv_vbeln WHERE vbeln EQ p_vbeln.

          IF sy-subrc NE 0.

            MESSAGE 'No sales doc exists', type 'E'.

          ENDIF.

        ENDIF.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 23, 2013 at 09:23 AM

    Hi Bala Krishna,

       We have to define paramters either optional or obligatory:

     

    1.  If it is optional, then no need to specify

        Parameters : P_matnr type mara-matnr.

    2. If it is mandatory, then we have to specify using "OBLIGATORY".

       Parameters : P_matnr type mara-matnr OBLIGATORY.

    Then as usual you can do validation in At selection screen event.

    Regards

    Kusuma

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 23, 2013 at 11:48 AM

    hi Bala,

    If the field is mandatory, you directly need to check the value of that field in the database table for validation under AT SELECTION-SCREEN on <field>. If user skips this entry, system will pop a message for mandatory field.

    If the field is not mandatory, then first check if field is not initial and then proceed with similar validation for the entered value as done in case of mandatory field( Validation req only if user entry is made).

    I am still not clear with the term 'how to completely validate parameters (optional) and parameters (mandatory).' can you explain what do you expect when you say completely validate.

    Regards,

    DN.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 23, 2013 at 12:17 PM

    Hii Bala,

    U can validate the parameters at event called AT SELECTION SCREEN like below

    DATA v_matnr TYPE matnr.

    AT SELECTION-SCREEN.

      IF p_matnr IS INITIAL.

        set CURSOR FIELD 'P_MATNR'.

        MESSAGE 'Enter the material number' TYPE 'E'.

      ELSE.

        SELECT  SINGLE MATNR               ---->to check the existence of entered materail no

          FROM mara

          INTO v_matnr

          WHERE MATNR eq p_matnr.

          IF sy-subrc <> 0.

            MESSAGE 'Enter the valid material number' TYPE 'E'.

          ENDIF.

      ENDIF.



      IF p_mtart IS INITIAL.

        SET CURSOR FIELD 'P_MTART'.

        MESSAGE 'Enter the description' TYPE 'E'.

      ENDIF.

    If u want that after selecting the matnr the mtart field should be automatically filled with respect to material number then u can achieve it like below is the simple [rogram illustrating that.

    REPORT  zr05_test.


    PARAMETERS: p_matnr TYPE matnr, "OBLIGATORY value CHECK,

                p_mtart TYPE mtart.

    DATA: t_mara TYPE STANDARD TABLE OF mara,

          v_matnr TYPE matnr. 

    DATA: t_f4 TYPE STANDARD TABLE OF mara, ----->will hold the data displayed in dynamic search help window

          t_dd TYPE TABLE OF dselc,    ---->for dynamic value selection

          t_ft TYPE TABLE OF dfies,

          t_ret TYPE TABLE OF ddshretval,    ------>will hold the selected value in search help

          x_dd TYPE dselc,

          x_ft TYPE dfies.


    FIELD-SYMBOLS <fs> TYPE mara.

    AT SELECTION-SCREEN on VALUE-REQUEST FOR p_matnr.

      PERFORM dynamic_f4.    ----> To provide dynamic search help to matnr and mtart get automatically filled based on the matnr value

    AT SELECTION-SCREEN.  -------->Evenet to validate data

      IF p_matnr IS INITIAL.

        set CURSOR FIELD 'P_MATNR'.

        MESSAGE 'Enter the material number' TYPE 'E'.

      ELSE.

        SELECT  SINGLE MATNR

          FROM mara

          INTO v_matnr

          WHERE MATNR eq p_matnr.

          IF sy-subrc <> 0.

            MESSAGE 'Enter the valid material number' TYPE 'E'.

          ENDIF.

      ENDIF.

      IF p_mtart IS INITIAL.

        SET CURSOR FIELD 'P_MTART'.

        MESSAGE 'Enter the description' TYPE 'E'.

      ENDIF.

    START-OF-SELECTION.

      SELECT *

        FROM mara

        INTO TABLE t_mara

        UP TO 3 rows

        WHERE matnr eq p_matnr
        AND mtart eq p_mtart.

        IF sy-subrc eq 0.

               SORT t_mara by MATNR ASCENDING.

         ELSE.
              MESSAGE 'No Records Found for entered Value' TYPE 'I' DISPLAY LIKE 'E'.
        ENDIF.

        LOOP AT t_mara ASSIGNING <fs>.

          WRITE:/ <fs>-matnr,

                  <fs>-mtart,

                  <fs>-ersda,

                  <fs>-ernam.

        ENDLOOP.

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

    *&      Form  DYNAMIC_F4

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

    *       text

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

    *  -->  p1        text

    *  <--  p2        text

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

    FORM DYNAMIC_F4 .

      IF t_f4 IS INITIAL.

        SELECT *

          FROM Mara

          CLIENT SPECIFIED

          INTO TABLE t_f4

          UP TO 500 ROWS

          WHERE mandt eq sy-mandt.

      ENDIF.

      REFRESH t_dd.

      x_dd-fldname   = 'MTART'.

      x_dd-dyfldname = 'P_MTART'.

      APPEND x_dd TO t_dd.

      CLEAR x_dd.

      REFRESH t_ft.

      x_ft-tabname   = 'MARA'.

      x_ft-fieldname = 'MATNR'.

      APPEND x_ft TO t_ft.

      CLEAR x_ft.

      x_ft-tabname   = 'MARA'.

      x_ft-fieldname = 'MTART'.

      APPEND x_ft TO t_ft.

      CLEAR x_ft.

      IF NOT t_f4 IS INITIAL.

        CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

          EXPORTING

            retfield               = 'MATNR'

           DYNPPROG               = sy-repid

           DYNPNR                 = sy-dynnr

           DYNPROFIELD            = 'P_MATNR'

           WINDOW_TITLE           = 'Search Help Selection'

           VALUE_ORG              = 'S'

          tables

           value_tab              = t_f4

           FIELD_TAB              = t_ft

    *       RETURN_TAB             = t_ret

           DYNPFLD_MAPPING        = t_dd

         EXCEPTIONS

           PARAMETER_ERROR        = 1

           NO_VALUES_FOUND        = 2

           OTHERS                 = 3.

        IF sy-subrc <> 0.

    * Implement suitable error handling here

        ENDIF.

      ENDIF.

    ENDFORM.                    " DYNAMIC_F4

    This is the example of dynamic search help and dynamic field value filled based on other field value.

    regards

    Syed

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 23, 2013 at 09:28 AM

    What are you looking for, the only difference is that you should not code validation for an initial value of a non-obligatory field, else look Abap documentation for information on PARAMETERS and AT SELECTION-SCREEN ON.

    Regards,

    Raymond

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 23, 2013 at 12:46 PM

    Hi Bala Krishna,

    You can use "AT SELECTION-SCREEN" event for validations on Screen.

    Though once you use "Obligatory" statement, system will not execute untill you pass value in parameter.

    Example 1:

    Parameters : p_matnr type matnr(optional).

    Parameters : p_mtart type mtartoptional.

    AT SELECTION SCREEN.

    IF P_MATNR IS NOT INITIAL.

    ....<Validation Statements>....

    ENDIF.

    Example 2:

    Parameters : p_matnr type matnr obligatory.

    parameters : p_mtart type mtart.

    AT SELECTION SCREEN.

    IF P_MATNR IS NOT INITIAL.

    ....<Validation Statements>....

    ENDIF.

    Thanks & Regards,

    Tushar Trivedi.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Its possible to make an field look like an obligatory field but not more with the following coding:

      AT SELECTION-SCREEN OUTPUT.

      LOOP AT SCREEN.
           IF  screen-name = '[FIELDNAME]'.
             screen-required = '2'.  "<-recommend = 2   obligatory = 1   optional = 0
             MODIFY SCREEN.
           ENDIF.
         ENDLOOP.

  • avatar image
    Former Member
    Oct 25, 2013 at 07:19 AM

    Thank you Everyone. For all your valuable answers.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 25, 2013 at 07:33 AM

    Hi Krishna,

    Sample for reference

    1. TYPE-POOLS: vrm. 
    2.  
    3. DATA: tab_values TYPE vrm_values, 
    4.       rcd_values LIKE LINE OF tab_values, 
    5.       variant_id TYPE vrm_id, 
    6.       oneorzero TYPE c. 
    7.  
    8. LOAD-OF-PROGRAM. 
    9.   rcd_values-key = '0'. 
    10.   rcd_values-text   = '0'. 
    11.   APPEND rcd_values TO tab_values. 
    12.   rcd_values-key = '1'. 
    13.   rcd_values-text   = '1'. 
    14.   APPEND rcd_values TO tab_values. 
    15.  
    16.   PARAMETERS: dropdown TYPE n AS LISTBOX VISIBLE LENGTH 3 OBLIGATORY, 
    17.               checkbox AS CHECKBOX, 
    18.               checkaft TYPE c. 
    19.  
    20. AT SELECTION-SCREEN OUTPUT. 
    21.   variant_id = 'DROPDOWN'. 
    22.   CALL FUNCTION 'VRM_SET_VALUES' 
    23.     EXPORTING 
    24.       id     = variant_id 
    25.       values = tab_values 
    26.     EXCEPTIONS 
    27.       OTHERS = 0. 
    28.  
    29. AT SELECTION-SCREEN ON checkbox. 
    30.   IF checkbox IS INITIAL. 
    31.     oneorzero = '0'. 
    32.   ELSE. 
    33.     oneorzero = '1'. 
    34.   ENDIF. 
    35.  
    36. AT SELECTION-SCREEN ON checkaft. 
    37.   IF checkaft NE '0' AND checkaft NE '1'. 
    38.     MESSAGE 'Invalid value' TYPE 'E'. 
    39.   ENDIF. 

    Regards,

    Rajesh

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 25, 2013 at 07:52 AM

    Hi

    If you use obligatory the system itself will throw an error message if the field is left blank.

    Once you enter the value and after that you want to display the message you can write it under

    AT SELECTION SCREEN event so that it will dispay message at the that screen itself.

    AT SELECTION SCREEN.

    write the query.

    if sy-subrc ne 0.

    message 'type the message' type 'E' (for error) can use W for warning, S status message

    With regards

    Suneesh

    Add comment
    10|10000 characters needed characters exceeded