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 validate data when press enter or save in maintenance view

Former Member
0 Kudos

Hi all,

     How to add some validation logic into maintenance view when user inputs some data in table control then press enter or click save ?

     I need to throw up an error message when data in one column duplicates, but I do not know where to add  custom code into the auto-generated code by table maintenance generator.

     I tried the event 01 and 05, in them I throw a message , however I do not see it, am I use it in the incorrect way?

     Thank you very much.

Best regards,

Xu Chris

12 REPLIES 12

venkateswaran_k
Active Contributor
0 Kudos

Hi

In the screen layout - flow logic tab,

You will see a auto generated code as

LOOP at <your internal table>

CHAIN

  ......

   FIELD ........

   FIELD .............

  .....

ENDCHAIN

ENDLOOP

at end of the FIELD statement  -- Add a statement as MODULE <your_validation_function_name>.

Example:

 
    CHAIN.

      FIELD ZLCHDR-BONDID MODULE CHECK_ATTRIBUTES_BOND.
      FIELD ZLCHDR-PROJID MODULE CHECK_ATTRIBUTES_PROJ.

In the main program

MODULE <your_validation_function_name>

    ****wRITE HERE YOUR LOGIC TO VALIDATE

 

ENDMODULE

Regards,

Venkat

former_member193464
Contributor
0 Kudos

01 should work for while pressing save...
try putting a break point and see whether the form triggers .... when you press save.

kamesh_g
Contributor
0 Kudos

Hi

In PAI of the screen .use the field in CHAIN and ENDCHAIN and add module to that field .

PAI

CHAIN

FIELD <filed1> module <module name >.

ENDCHAIN

Add module code . So when press enter or save code inmodule will trigger automatially

Thanks

Former Member
0 Kudos

Hi Chris,

I have implemented a similar kind of requirement by using the event 01 only.

Create a form routine for the event 01 and inside it write your logic and display an error message.

MESSAGE 'Duplicate Data' TYPE 'E'.

Regards,

Sanjeev Kotwal.

Former Member
0 Kudos

Hi,

Go to the Functional Pool where in you have saved the Table maintenance generator.

Search for the screen number of your corresponding view.

In the PAI event, inside the CHAIN END CHAIN event create a MODULE with ON CHAIN event and write the validations there.

Hope this helps

VijayaKrishnaG
Active Contributor
0 Kudos

Hi Chris,

I have tried some validation in event 05 (New entry) and it is working fine too. Here is some sample code I have tried.

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

***INCLUDE LZTEST1F01 .

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

FORM NEW_ENTRY.

  DATA : LT_TAB TYPE STANDARD TABLE OF YTEST_EMP,

         LS_TAB TYPE YTEST_EMP.

    SELECT * FROM YTEST_EMP INTO TABLE LT_TAB.

    IF SY-SUBRC EQ 0.

        LOOP AT LT_TAB INTO LS_TAB.

           IF LS_TAB-EMPNAME EQ 'VIJAY'.

             MESSAGE E000(ZMESSAGES) WITH 'RECORD ALREADY FOUND'.

           ENDIF.

         ENDLOOP.

     ENDIF.

ENDFORM.

After all activating your Include activate your function group too.

Hope this helps.

0 Kudos

HI Vijay ,

in your code where you are checking the duplicate entries ? , am i missing anything?

Hi Chris ,

i think events 01,05 should work in you case ,i think something wrong with the codee , so better to paste ur code here to check...

Prabhu

0 Kudos

Hi Prabhu,

I have not checked for duplicate entries, I just tested whether the validation is possible or not and throwing an error message at event 5 or 1. And if the duplicates is the case, in my code after "SELECT" statement read the Itab with the current entered key like,

SELECT * FROM YTEST_EMP INTO TABLE LT_TAB.        "Here we get entries maintained so far.

READ TABLE LT_TAB WITH KEY <field_to_compare> = <key>.

IF SY-SUBRC NE 0.

    MESSAGE E.

  ENDIF.

Note :: YTEST_EMP is the table on which we are maintaining view.

As you said, event 01 and 05 should workout actually.

--Vijay

0 Kudos

Hi Vijay , in those events internal tables TOTAL & EXTRACT will hold the latest data.so any validations on the data then you need to consider these table only bcos data havent saved.

HI Chris ,

do u wanna put validations on non-key fields  ?

regards

Prabhu

0 Kudos

Hi Prabhu,

I think Mr.Chris wants to validate the current entry with all the data available in the table not only with the latest data that hold in TOTAL or EXTRACT tables. If we use the SELECT statement as I mentioned above we can get the data including data saved in the current session too.

Hi Chris,

As Mr.Prabhu mentioned, better to paste your code here.

--Vijay

0 Kudos

Hi Vijay ,

no need of any addditional selections , internal table TOTAL & EXTRACT will hold the required data i.e old and new. if you have any doubts then check in your table events code.

Prabhu

0 Kudos

Hi Prabhu,

Sorry, I didn't get this first. And even I don't know this. Thanks for the info.

-- Vijay