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 multiple entries in table maintenance

Former Member
0 Kudos

Hi,

i have a table maintenance wherein i need to validate multiple entries before saving to db. for ex. when user hits new entries button he will enter 5 records and then he will hit save button. i kept break point in event 05 and found that table TOTAL, EXTRACT, <VIM_TOTAL_STRUC>, <VIM_EXTRACT_STRUC> all have only last record. how could i make all 5 records visible in event 05 so that i can make any validations?

please advise.

Rgds

1 ACCEPTED SOLUTION

sivaganesh_krishnan
Contributor
0 Kudos

HI sudhanshu,

Try the validation in event 01 - Before saving the data in the database

inside it you must code in such a way that you need to move the values of standard structure to your custom structure . see the following code .

LOOP AT total.

     CLEAR x_seat.                 "Copying Values to an Internal Table

     IF <vim_total_struc> IS ASSIGNED.

       MOVE-CORRESPONDING <vim_total_struc> TO x_seat.

       APPEND x_seat TO t_seat.

     ENDIF.

                                "Checking Currency Field Is Empty or Not

     IF <action> NE 'D' AND <action> IS NOT INITIAL AND <action> NE 'X'.

       IF x_seat-currency IS INITIAL.

         vim_abort_saving = 'X'.                                                   " showing error and abort saving

         MESSAGE S029(zo3_msg_class) DISPLAY LIKE 'E'

                                     WITH x_seat-seat_type.

         EXIT.

       ENDIF.

     ENDIF.

   ENDLOOP.


you can also loop the internal table and process it..


Here I have check if the previous value and current value are same or not.. If so i have show an error . You can try like this.


"Checking the Currency Field For a Stadium.

   LOOP AT t_seat INTO x_seat.

     IF v_code <> x_seat-std_code. "To Find New Stadium Code

       v_curr  = x_seat-currency.

       v_code = x_seat-std_code.

     ENDIF.

     IF x_seat-currency <> v_curr.

       vim_abort_saving = 'X'.

       MESSAGE S030(zo3_msg_class) DISPLAY LIKE 'E' WITH v_curr.

       EXIT.

     ENDIF.

   ENDLOOP.


15 REPLIES 15

JJosh
Active Participant
0 Kudos

Hi,

Create a subroutine for the event.

form e_validate.

  DATA wa_lines TYPE <TABLE NAME>.

  LOOP AT total.
  clear wa_lines.
  

    IF <vim_total_struc> is ASSIGNED.
      MOVE-CORRESPONDING <vim_total_struc> to wa_lines.
    ENDIF.

   IF <action> IS NOT INITIAL AND ADD CHECKS HERE .
 

  IF wa_lines-<FIELD 1> NE '<VALUE>'.
     MESSAGE 'XX' TYPE 'S' DISPLAY LIKE 'E'.
     vim_abort_saving = 'X'.
     exit.

   elseif wa_lines-<FIELD 2> NE '<VALUE>'

    MESSAGE 'XX' TYPE 'S' DISPLAY LIKE 'E'.

    vim_abort_saving = 'X'.

    exit.

  endif.
  endif.
  ENDLOOP.
ENDFORM.

Regards,

Josh

Former Member
0 Kudos

thanks for your time !

but total always has entries already saved in DB and <VIM...> always has last record (in my case 5th record). how would i compare.

nabheetscn
Active Contributor
0 Kudos

Sudhanshu

In 01 event you can compare total and extract

Nabheet

JJosh
Active Participant
0 Kudos

The code needs to be added in EVENT01 and not in 05.

Former Member
0 Kudos

that looks correct. EXTRACT has existing entries and TOTAL has existing plus 5 new entries.

nabheetscn
Active Contributor
0 Kudos

Hi Sudhanshu

You will have to use event 01. In event 05 entry will come in a loop one entry each time. The values entered will be available in ZTMP1 where ZTMP1 is your table name.

Nabheet

0 Kudos

thanks for your time !

where in 01 i can see those 5 records. could you pls let me know.

Rgds

0 Kudos

hello All,

extremely sorry for wrong information. im doing it in 01 only. but my question remain same..i can see all the entries existed in DB in TOTAL but where can i see those 5 records?

@ Jacob, Siva: is there any standard internal table (like total or extract) wherein i can see all those 5 records OR do you mean program will check each of those 5 records one by one and will compare with all existing data in total?

my scenario is that i have some distributed amount in those 5 new entries and before saving all those entries i need to check whether sum of amount field is 100 or not.

does it make any sense? please let mek now.

Rgds

0 Kudos

Those 5 new records will be in EXTRACT


0 Kudos

Hi sudhanshu,

see the below code , the other way is to copy the values to other internal table and process it for validation. I have written the code below  , please go through that.

Regards,

sivaganesh

0 Kudos

hello All,

looks im close to resolving this. could you please check if this is the correct approach:

i) count no. of records in total and extract by using describe.

ii) if the difference between number of lines in these two are greater than 0 (say n) read first n lines of total.

iii) select all from db table and compare these n lines with db entries

would it be good approach? please advise

rgds

0 Kudos

that is actually better. could you please let me know what is 'D' & 'X' for <action>? i guess i would need to work around this also.

Rgds

0 Kudos

<action> variable, which also automatically assigned during loop, that show the action performed for that entries.

List of value for action

N = New entry

U = Updated entry

D = Deleted entry

X = Deleted new entry

blank = No change on entry

sivaganesh_krishnan
Contributor
0 Kudos

HI sudhanshu,

Try the validation in event 01 - Before saving the data in the database

inside it you must code in such a way that you need to move the values of standard structure to your custom structure . see the following code .

LOOP AT total.

     CLEAR x_seat.                 "Copying Values to an Internal Table

     IF <vim_total_struc> IS ASSIGNED.

       MOVE-CORRESPONDING <vim_total_struc> TO x_seat.

       APPEND x_seat TO t_seat.

     ENDIF.

                                "Checking Currency Field Is Empty or Not

     IF <action> NE 'D' AND <action> IS NOT INITIAL AND <action> NE 'X'.

       IF x_seat-currency IS INITIAL.

         vim_abort_saving = 'X'.                                                   " showing error and abort saving

         MESSAGE S029(zo3_msg_class) DISPLAY LIKE 'E'

                                     WITH x_seat-seat_type.

         EXIT.

       ENDIF.

     ENDIF.

   ENDLOOP.


you can also loop the internal table and process it..


Here I have check if the previous value and current value are same or not.. If so i have show an error . You can try like this.


"Checking the Currency Field For a Stadium.

   LOOP AT t_seat INTO x_seat.

     IF v_code <> x_seat-std_code. "To Find New Stadium Code

       v_curr  = x_seat-currency.

       v_code = x_seat-std_code.

     ENDIF.

     IF x_seat-currency <> v_curr.

       vim_abort_saving = 'X'.

       MESSAGE S030(zo3_msg_class) DISPLAY LIKE 'E' WITH v_curr.

       EXIT.

     ENDIF.

   ENDLOOP.


Former Member
0 Kudos

This message was moderated.