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: 

Data validation

Former Member
0 Kudos

Hi Experts,

How to validate data on database tables?

9 REPLIES 9

former_member195383
Active Contributor
0 Kudos

HI...

Do u mean to say..u want to validate data wen u r updating the database table...if so then just before updating the data from ur program to the database table...just use the validation u want to put...

Hope this is wat ur requirement is...

Former Member
0 Kudos

hi,

do this way on to your suitable table ...Assuming that you are looking for validating the selection screen data


at selection-screen.
if not p_matnr is initial.
  select single * from mara where matnr = p_matnr.
endif.

Former Member
0 Kudos

Hi,

Can you please elaborate?

Regards

R Adarsh

Former Member
0 Kudos

hii

you can validate data different ways.like if its blank or if its invalid data in database table.for database table you can write a query like below & validate data.

* Validate Plant
  SELECT werks
    INTO w_werks
    FROM t001w
    UP TO 1 ROWS
    WHERE werks IN s_werks.
  ENDSELECT.

  CHECK sy-subrc NE 0.

  SET CURSOR FIELD 'S_WERKS'.
  MESSAGE e220(zmsg).                  " Invalid Plant

reward if useful

thx

twinkal

Former Member
0 Kudos

Hi Siva... check this...

PARAMETER:
    P_CARRID.

AT SELECTION-SCREEN ON p_carrid.
  perform validate_carrid.


form validate_carrid.
  select carrid
            connid
     from spfli
    up to 1 rows
   where carrid eq p_carrid.

if sy-subrc NE 0.
  message 'Record not found' TYPE 'E'.
endif.
 
 
endform.

Former Member
0 Kudos

hi.. u can execute the above stated example..

Reward points if useful..

Regards,

Narin Nandivada

Former Member
0 Kudos

hi siva

at selection-screen on p_matnr.
if p_matnr is not initial.
   select single matnr
       into lw_matnr
       from mara
     where matnr eq p_matnr.

if sy-subrc <> 0.
    message e272(61).
endif.

endselect.

Former Member
0 Kudos

Hi,

If u need to validate data while entering new entries in the database table then you can maintain an event and restrict and validate the entries by writing the code in the event.

Event is maintained in table maintainence generator.

In detail,

Go to table maintainence generator.create one table maintainence generator for the table.

Go to environment tab and go for modifications in which you can find the events in the dropdown.

Click on that and create one event with code as 05.

Write the code in that event.

For example to write the code for restricting the user to enter all the fields as mandatory.

IF ( ( ztable-field1 IS INITIAL ) OR

( ztable-field1 IS INITIAL ) OR

(ztable-field1 IS INITIAL ) ).

MESSAGE e000(yco_message) WITH text-000.

ENDIF.

save the table maintaince generator.

create a tcode and give the screen as sm30 and skip teh first screen to maintain the values through sm30.

Reward me the points if the info is useful.

Former Member
0 Kudos

Select data from database table into internal table while giving the condition with which you want to validate it.

then check sy-subrc whether it is 0 or not.

if is 0 then data is valid otherwise it is invalid.

E.g

select * from vbrp into corresponding fields of table it_vbrp

where vbrp-vbeln = it_vbrp-vbeln.

if sy-subrc EQ 0.

write: "Data Valid.".

endif.

hope this will work fine for you.

Thanks& Regards,

Rajesh Kumar.