Application Development and Automation 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: 
Read only

ABAP programming: Data validation

Former Member
0 Likes
7,119

Hi everybody,

I wanted to know how to display error messages if a user enters invalid data at the selection screen in a particular select-options field. Also the selection screen should be redisplayed after the message.

thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,634

Hi sorry, for not specifying properly

but the problem is that data entered by the user on the screen for the high and low value of the select-option field at the selection screen sould be present in the master table if this is not the case an error message should be displayed asking the user to enter appropriate entry and the selection screen should be redisplayed. There is no problem as far as validating the value entered in parameter is concerned.

13 REPLIES 13
Read only

Former Member
0 Likes
2,634

Hi,

Do the validations in AT SELECTION-SCREEN ON <field> event.

Regards

Abhijeet

Read only

0 Likes
2,634

Hi you use as.

AT SELECTION-SCREEN ON <fieldname>.

if <fieldname> GE 1000.

message e001(zsgclass).

endif.

Read only

Former Member
0 Likes
2,634

Use the at selection-screen event to perform the validations and it will stay on the selection screen.

To issue the error message use the "message" statement such as

message e600(fr) with 'Error'.

Read only

Former Member
0 Likes
2,634

HI,

write the code in the

AT Selection-screen on <field>.

<write the Error message there with validation code>

Regards

Sumit Agarwal

Read only

0 Likes
2,634

AT Selection-screen on <selfield>.

***example for mara table.

select single matnr from mara into check_field

where matnr = <selfield>-low.

if sy-subrc NE 0.

message e001(zsgcls).

endif.

Edited by: swati gupta on Sep 25, 2008 2:07 PM

Edited by: swati gupta on Sep 25, 2008 2:07 PM

Read only

Former Member
0 Likes
2,634

Hi Prem,

Welcome to SDN

try it like this:



At selection-screen on field s_data.

  select field 
    from itab  " the table with which u want to validate d data
     into w_data
  where field in s_data.
if sy-subrc NE 0.
  message 'enter a valid data' type 'E'.
endif.

With luck,

Pritam.

Read only

Former Member
0 Likes
2,634

hi,

AT SELECTION-SCREEN ON <fieldname>.

if <fieldname> NE 1000.

message i000(zfi) display like 'E' .

leave list-processing.

endif.

Rgds.,

subash

Read only

Former Member
0 Likes
2,634

Hi,

Check this sample code


REPORT z_sdn.

DATA:
  BEGIN OF fs_flight,
    carrid TYPE sflight-carrid,
  END OF fs_flight.



PARAMETERS:
  p_carrid TYPE sflight-carrid.


AT SELECTION-SCREEN ON p_carrid.

  SELECT carrid
   FROM sflight
   INTO fs_flight
  UP TO 1 ROWS
  WHERE carrid = p_carrid.
  ENDSELECT.


    IF fs_flight IS INITIAL.
      MESSAGE 'ENTER A VALID VALUE' TYPE 'E'.
    ENDIF.

START-OF-SELECTION.


  WRITE: / p_carrid.

Regards

Abhijeet

Read only

Former Member
0 Likes
2,634

Hi,

Understand my select query where i am validating my password.

If Username and password are wrong then it will trigger a message saying password does not matches.

WHEN 'LOGIN'.

SELECT SINGLE EMPLOGIN

FROM ZPASS INTO L_EMP WHERE EMPLOGIN = ZPASS-EMPLOGIN AND PASSWORD = ZFIR_PASS-PASSWORD.

IF SY-SUBRC <> 0.

MESSAGE I000. "give the error msg in SE91

call screen 900. "it will hold in the same screen

ENDIF.

Cheers!!

Read only

Former Member
0 Likes
2,635

Hi sorry, for not specifying properly

but the problem is that data entered by the user on the screen for the high and low value of the select-option field at the selection screen sould be present in the master table if this is not the case an error message should be displayed asking the user to enter appropriate entry and the selection screen should be redisplayed. There is no problem as far as validating the value entered in parameter is concerned.

Read only

0 Likes
2,634

Hi ,

try this way...

AT SELECTION-SCREEN .

SELECT MATNR FROM MARA INTO V_MATNR UPTO 1 ROW WHERE MATNR IN S_MATNR.

IF sy-subrc <> 0 .

MESSAGE WHAT EVER U WANT.

ENDIF.

Read only

0 Likes
2,634

Hi,

Check this code


REPORT z_sdn.
TABLES:
  vbak.

DATA:
  w_vbeln TYPE vbak-vbeln.

SELECT-OPTIONS:
  s_vbeln  FOR vbak-vbeln.             " Sales Document

*----------------------------------------------------------------------*
*                 AT SELECTION-SCREEN ON s_vbeln EVENT
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON s_vbeln.

* Subroutine to validate the sales document entered by user.
  PERFORM f0000_validate_sales_doc.

START-OF-SELECTION.
  WRITE: / 'TEST'.
*&---------------------------------------------------------------------*
*&      Form  f0000_validate_sales_doc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM f0000_validate_sales_doc .

  IF s_vbeln[] IS NOT INITIAL.
* Select query to fetch sales document
    SELECT vbeln                       " Sales Document
      FROM vbak
      INTO w_vbeln
     UP TO 1 ROWS
     WHERE vbeln IN s_vbeln.

    ENDSELECT.                         " SELECT vbeln
    IF sy-subrc NE 0.
      MESSAGE 'The entries you have specified do not exist in master table' TYPE 'E'.
    ENDIF.                             " IF sy-subrc NE 0.
    CLEAR w_vbeln.
  ENDIF.                               " IF s_vbeln IS NOT INITIAL

Regards

Abhijeet

Read only

former_member203501
Active Contributor
0 Likes
2,634

at selection screen on s_data .

select field

from table

into v_field

where field in s_field .

if sy-subrc ne 0 .

message e000 with 'enter a vaild message'.

endif.

endselect .

this will validate all the messages from low to high