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: 

Check Table data in Maintenance View event

Former Member
0 Kudos

Dear all, i created a maintenance view for a customer table and a must carry out a validation over the whole table when any record is created, modified or deleted.

The table has a column with percentages and after save a modification I have to verify that the values in this columns make 1 (100%).

For this, I created a routine in the event 01 (Before Saving the Data in the Database ) of the maintenance view, but I can find the way to read all the records of the table.

I tried with the tables TOTAL and EXTRACT, but these have '#####' as values in the percentages column.

If someone need further information please let me know.

I´d be grateful if someone lead me to a solution.

Thanks in advance.

Mariano.

3 REPLIES 3

uwe_schieferstein
Active Contributor
0 Kudos

Hello Mariano

I cannot tell you why the percentage values are displayed in this strange way (perhaps wrong typing of used variables).

However, below you see a sample routine for event 01 which loops over all displayed entries (have you thought about the possibility that the user displays the view entries with a selection criteria!? In this case not all DB entries are displayed in the view).


*&---------------------------------------------------------------------*
*&      Form  CHECK_BEFORE_SAVE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  Event 01: Before Saving the Data in the Database
*  <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/91/ca9f0ba9d111d1a5690000e82deaaa/content.htm" TARGET="test_blank">http://help.sap.com/saphelp_nw2004s/helpdata/en/91/ca9f0ba9d111d1a5690000e82deaaa/content.htm</a>
*----------------------------------------------------------------------*
FORM check_before_save .
* define local data
  DATA: ld_idx     TYPE i. " Index to note the lines found

  data: ld_percent_total  type i.

  " <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/91/ca9fb9a9d111d1a5690000e82deaaa/content.htm" TARGET="test_blank">http://help.sap.com/saphelp_nw2004s/helpdata/en/91/ca9fb9a9d111d1a5690000e82deaaa/content.htm</a>
  TYPES: BEGIN OF ty_s_total.
  INCLUDE TYPE zus_sdn_v_t001w.
**    include type <text table name>.
  INCLUDE TYPE vimtbflags.
  TYPES: END OF ty_s_total.
  DATA: ls_total   TYPE ty_s_total,
        ls_extract TYPE ty_s_total.


  BREAK-POINT.
  LOOP AT total INTO ls_total.
    IF ( <action> = geloescht ).
      CONTINUE.
    ENDIF.

    READ TABLE extract INTO ls_extract WITH KEY <vim_xtotal_key>.
    IF ( syst-subrc = 0 ).
      ld_idx = syst-tabix.
    ELSE.
      CONTINUE.
    ENDIF.

    " Make desired changes to the line total, e.g.:
*    ADD ls_total-percent to ld_percent_total.
  ENDLOOP.

  IF ( ld_percent_total = 100 ).
    sy-subrc = 0. " Data can be saved to DB
  ELSE.
    sy-subrc = 4. " Data cannot be saved to DB
  ENDIF.

**  # GELOESCHT
**  # : flagged for deletion NEUER_EINTRAG
**  # : New entry AENDERN
**  # : changed entry UPDATE_GELOESCHT
**  # : entry first changed and then flagged for deletion NEUER_GELOESCHT
**  # : entry first newly created, not yet saved, and then flagged for deletion ORIGINAL
**  : the same as the database status


**Internal Table EXTRACT Work Area Field Symbols
**
**The following field symbols are filled for each maintenance dialog:
**
**    * <TABLE2>:
**    * internal table EXTRACT header line. <VIM_EXTRACT_KEY>: 
**    * unique key of the current entry in the internal table EXTRACT. It is either:
**    * view key fields, or
**    * the entity table key of a table or table with text table.
**
**The following field symbols are only filled if the maintenance dialog is based on a table with a text table, 
**and the tables are linked by the foreign key relationship TEXT.
**
**    * <EXTRACT_ENTI>: work area of internal table EXTRACT for the entity table fields, without the text table fields.
**    * <EXTRACT_TEXT>: work area of internal table EXTRACT for the fields of the text table read.

**  DATA: f_index LIKE sy-tabix. "Index to note the lines found
**  LOOP AT total.
**    IF <action> = desired CONSTANT.
**      READ TABLE extract WITH KEY <vim_xtotal_key>.
**      IF sy-subrc EQ 0.
**        f_index = sy-tabix.
**      ELSE.
**        CLEAR f_indx.
**      ENDIF.
**      (make desired changes to the line total)
**      modify total.
**      CHECK f_indx GT 0.
**      extract = total.
**      MODIFY extract INDEX f_indx.
**    ENDIF.
**  ENDLOOP.
**  sy-subrc = 0.

ENDFORM.                    " CHECK_BEFORE_SAVE

Regards

Uwe

former_member188685
Active Contributor
0 Kudos

is that column defined as a Qunatity or character ..? the problem is with the definition i feel. if it is qunatity and you are passing % to it, because of it may be you are getting that .

what datalement you are using.

Former Member
0 Kudos

Hi, firstly thx Uwe Schieferstein and Vijay Babu Dudla.

I'll try with the code proposed by Uwe Schieferstein.

The column is defined as dec 3,2 and is filled with values like 0.25 or 0.10 in the view.

Thanks for your help; i'll appreciate any kind of help.

Mariano.