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: 

How to carry out entry validation in SM30 with events

alejandro_bindi
Active Contributor
0 Kudos

Hi people,

I'm creating a Z table with Maintenance view in SM30...i've modified the view so all fields are required as Rich H explained in some other post. But now i need to validate user input for a particular field against a standard table, and force to reenter if data is not valid. I've been looking up the available events...event 05 triggers when the line is new, but not when modifying. I've tried a couple of other events but don't serve my purpose. What i want is to validate data upon user's entered all the required fields (whether the line was preeexistant or not). If data is valid then go on, if not trigger a message and force correction prior continuing (disallowing saving).

Anyone knows how to do this?

Many thanks

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

Hi,

Add this table " against a standard table" (you mentioned) as a check table against the fields you want to validate. The system automatically get validated for that field.

No need to write anything in the event.

aRs

7 REPLIES 7

former_member194669
Active Contributor
0 Kudos

Hi,

Add this table " against a standard table" (you mentioned) as a check table against the fields you want to validate. The system automatically get validated for that field.

No need to write anything in the event.

aRs

0 Kudos

I get what you suggest, but unfortunately i've already done that, it's not enough.

Here's the situation: The table has this fields:

KSCHL (PK-FK T685)

LIFNR (PK-FK LFA1)

EBELN (FK EKKO)

EBELP (FK EKPO)

Besides the implicit foreign key validations (i.e. the PO item exists in EKPO), i need to validate that it's not deleted (LOEKZ = 'L') and that the PO vendor is the one entered (i must not enter any PO which vendor isn't the one in that line). Hope I make myself clear.

This code works but in event 05 (new lines). I need to find out an event for the modified lines as well:


FORM f_validate_po.

  CHECK NOT ( ztmmiv001rps-lifnr IS INITIAL OR
              ztmmiv001rps-ebeln IS INITIAL OR
              ztmmiv001rps-ebelp IS INITIAL ).

  SELECT COUNT(*)
  FROM ekko
  WHERE ebeln = ztmmiv001rps-ebeln AND
        lifnr = ztmmiv001rps-lifnr AND
        exists ( SELECT *
                 FROM ekpo
                 WHERE ebeln = ztmmiv001rps-ebeln AND
                       ebelp = ztmmiv001rps-ebelp AND
                       loekz <> 'L' ).
  IF sy-dbcnt = 0.
    MESSAGE e000.
  ENDIF.

ENDFORM.

uwe_schieferstein
Active Contributor
0 Kudos

Hello Alejandro

Why don't you use event <b>01 </b>(<i>Before Saving the Data in the Database</i>)? Depending on the value of field symbol <b><ACTION></b> you can decide which validations are necessary.

For more details please refer to:

<a href="http://help.sap.com/saphelp_nw04/helpdata/en/91/ca9f0ba9d111d1a5690000e82deaaa/content.htm">Event 01: Before Saving the Data in the Database</a>

Regards

Uwe

former_member194669
Active Contributor
0 Kudos

Hi,

Please check for 08 Event

or

Write a custom table control program.(If you don't have transalation)

aRs

Message was edited by:

aRs

0 Kudos

Tried both events you suggest, don't work as expected or i'm not handling them as I should.

In this pages there are all the events listed and their documentation (in case someone else needs):

http://help.sap.com/saphelp_nw04/helpdata/en/91/ca9f0ea9d111d1a5690000e82deaaa/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/66/33f52010dd11d6999300508b5d5211/frameset.htm

Thanks to you both.

Update: Solved using both events 21 and 01.

0 Kudos

Hi Alejandro,

I have exactly the same issue.

Can you please send me (I'd use it as an example, how is it working) your code for the events via email? (or copy here)

Thanks and regards,

Gyula

0 Kudos

Check this link, in there you have sample code to handle TOTAL and EXTRACT internal tables, which you must loop to handle entered data in event 01:

http://help.sap.com/saphelp_nw04/helpdata/en/91/ca9f0ba9d111d1a5690000e82deaaa/content.htm

Anyway, i'm pasting that same code but with a few corrections, formatting, and additional comments:

FORM abc.
  DATA: f_index LIKE sy-tabix. "Index to note the lines found

  LOOP AT total.
    IF <action> = k_action. "desired CONSTANT.
      READ TABLE extract WITH KEY <vim_xtotal_key>.
      IF sy-subrc EQ 0.
        f_index = sy-tabix.
      ELSE.
        CLEAR f_index.
      ENDIF.
      "(make desired changes to the line total)
      MODIFY total.
      CHECK f_index GT 0.
      extract = total.
      MODIFY extract INDEX f_index.
    ENDIF.
  ENDLOOP.

  sy-subrc = 0."In order to save table changes
ENDFORM.

Form abc must be linked to 01 event in table maintenance.

As for the 21 event, you can use the table workarea (same name as the table) for handling line data.