3

I'm trying to check if a field is leaved initial or not in sm30 with a table that I've made. I've gone to table maintenance generator, then Environment->Modifications->Events and made an entrance named check_class with type 01 (before saving the data in the database) with the following code:

FORM CHECK_CLASS.

IF z10ficlassfica-z_class IS INITIAL.
  MESSAGE text-001 TYPE 'E'.
ENDIF.

ENDFORM.

It works all fine except that when z10ficlassfica is initial it doesn't stay in the maintenance of the table and goes to the sm30 first screen. How can I make it stay on the maintenance screen of sm30? Hope I've made myself clear. Thank you.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Eva Dias
  • 1,709
  • 9
  • 36
  • 67
  • if you use messagetype 'E', the current context is aborted. Try another message type more appropriate for your case, for instance 'S' or 'I'. See here for the different message types and their effect on the running program: http://help.sap.com/saphelp_470/helpdata/en/9f/dbaae335c111d1829f0000e829fbfe/content.htm – Dirk Trilsbeek Oct 16 '12 at 09:08
  • Yes, but I don't want it to save the entry with having that field filled. S is for success so it's not very appropriated. I it's for information, don't know if it's the right one either. But I'll try it. Thanks. – Eva Dias Oct 16 '12 at 09:14
  • 1
    Please edit the original question instead adding another one. I've answered the question there already: Do not use an event, but modify the generated screen. Events are unsuitable here because you have to raise the MESSAGE within the screen LOOP statement. – vwegert Oct 16 '12 at 09:26
  • possible duplicate of [Automatic filling of NAME\_1 when entered a valid KUNNR - SM30](http://stackoverflow.com/questions/12898732/automatic-filling-of-name-1-when-entered-a-valid-kunnr-sm30) – vwegert Oct 16 '12 at 09:26
  • if you just want to make the field mandatory, you can modify the maintenance screen and change the field to be required. In the table maint. generator, go to Environment->Modifications->Maintenance Screens, select the details screen, go to the element list and check the "Input" column. I'm not sure if the transaction will still perform your check_class, so maybe you will receive a standard message if the field is initial. – Dirk Trilsbeek Oct 16 '12 at 09:28
  • @Dirk, this is a bad idea because then the field will be displayed as a mandatory field even in lines that are totally empty (when adding new entries, for example). – vwegert Oct 16 '12 at 09:29
  • yes, but that only makes sense in the context of the original question with an additional requirement (only mandatory if another field is filled), which wasn't part of this question. I only just saw your reference to the other question. – Dirk Trilsbeek Oct 16 '12 at 09:35

2 Answers2

3

please see this link :

  • You can use events, and should use them, dont go modify generated screens, that is why SAP provided events.
  • You just need 2 things to stop saving and stay on screen
    • MESSAGE 'Currency must be USD or IDR' TYPE 'S' DISPLAY LIKE 'E'.
    • vim_abort_saving = 'X'.
  • Read that link, there is a lot of information you need in there.
  • As a good practice, use the key of the record that went wrong in the error message, so the user can find the record back when entering thousands of new records
tomdemuyt
  • 4,572
  • 2
  • 31
  • 60
  • Thank you, that works too and it's even more elegante than the one that I achieved. – Eva Dias Oct 16 '12 at 14:14
  • From my point of view, that's an inferior approach: You lose the option to highlight the fields that contain the invalid values. Imagine a table with thousands of lines - you'd have to search for the invalid entries for yourself. That's a bad way to fly. – vwegert Oct 18 '12 at 09:04
  • @vwegert, this only applies to new entries, there are not thousands of lines when you click 'Add new entries' in SM30, all existing entries are hidden. – tomdemuyt Oct 18 '12 at 12:11
  • @tomdemuyt, so it's not allowed to enter the value FOO when adding an entry, but you can add an entry with the new value BAR and then change it to the forbidden value FOO? That makes even less sense to me. – vwegert Oct 18 '12 at 13:55
2

Please edit your original question instead adding another one. I've answered the question there already: Do not use an event, but modify the generated screen. Events are unsuitable here because you have to raise the MESSAGE within the screen LOOP statement.

Community
  • 1
  • 1
vwegert
  • 18,371
  • 3
  • 37
  • 55