<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Field validation in table maintenance generator before saving in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117330#M1973978</link>
    <description>&lt;P&gt;Your code looks good, You could play with message type Error to change the sy-subrc or directly impact the variable SPAN   vim_abort_saving&lt;/P&gt;&lt;P&gt;(vim_abord_saving = abap_true )&lt;/P&gt;</description>
    <pubDate>Fri, 08 Nov 2019 10:10:28 GMT</pubDate>
    <dc:creator>FredericGirod</dc:creator>
    <dc:date>2019-11-08T10:10:28Z</dc:date>
    <item>
      <title>Field validation in table maintenance generator before saving</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117329#M1973977</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;im rather new to ABAP and want to implement the following:&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Within the maintenance View in which one can enter data, I want to have a check if the sum() consisting to a specific Company code is =&amp;gt; 1.00 (100 percent).&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; The table Looks as follows: &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Company; CodeValue&lt;BR /&gt;01;0.3&lt;BR /&gt;01;0.4&lt;BR /&gt;01;0.3&lt;BR /&gt;02;0.2&lt;BR /&gt;02;0.2&lt;BR /&gt;02;0.2&lt;BR /&gt;02;0.2&lt;BR /&gt;02;0,199&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;The user should only be able to fill up values consisting to one Company code up to 1.00. For example, if one now tries to enter a row with Company Code 2; 0.3 -&amp;gt; it should not be savable and and error should Show that the value can only be up to one.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I was thinking about adding a before_save check to the maintenance view, something like this:&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;FORM form_03_CHECK_VALUES.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;DATA: l_value TYPE value.&lt;BR /&gt; SELECT sum(value)&lt;BR /&gt;FROM table&lt;BR /&gt;INTO l_value&lt;BR /&gt;group by Company Code&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; IF l_value &amp;gt; 1.&lt;BR /&gt; MESSAGE 'ERROR' TYPE 'E' DISPLAY LIKE 'S'.&lt;BR /&gt; ENDIF.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;ENDFORM.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;But since I am rather new to ABAP, I guess I misunderstand some concept here. Can anyone help me here please?&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Highly appreciated,&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 09:55:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117329#M1973977</guid>
      <dc:creator>former_member685807</dc:creator>
      <dc:date>2019-11-08T09:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Field validation in table maintenance generator before saving</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117330#M1973978</link>
      <description>&lt;P&gt;Your code looks good, You could play with message type Error to change the sy-subrc or directly impact the variable SPAN   vim_abort_saving&lt;/P&gt;&lt;P&gt;(vim_abord_saving = abap_true )&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 10:10:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117330#M1973978</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2019-11-08T10:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Field validation in table maintenance generator before saving</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117331#M1973979</link>
      <description>&lt;P&gt;Hello &lt;A href="https://answers.sap.com/users/405062/frheep.html"&gt;Franziskus Heep&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;Am doubtful on the event that you have selected, Check if it is working fine if not try with event 05 as well and let us know the success case.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 12:50:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117331#M1973979</guid>
      <dc:creator>former_member1716</dc:creator>
      <dc:date>2019-11-08T12:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Field validation in table maintenance generator before saving</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117332#M1973980</link>
      <description>&lt;P&gt;Hi Franziskus,&lt;/P&gt;&lt;P&gt;Several ways to do this. I just briefly describe one, assuming you go with 'classic' ABAP since you mention a FORM.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;* Assume your internal table of incoming data is something like:
TYPES: BEGIN OF tys_val_buk,
         bukrs TYPE bukrs,
         val   TYPE p DECIMALS 2,
       END OF tys_val_buk,
       tyt_val_buk TYPE STANDARD TABLE OF tys_val_buk.
&lt;BR /&gt;* You may define a result set:
TYPES: tyt_res_buk TYPE SORTED TABLE OF bukrs
         WITH KEY bukrs.

DATA: lt_val_buk TYPE tyt_val_buk,
      lt_res_buk TYPE tyt_res_buk.

* You may call your FORM like this:
PERFORM check_buk_val USING lt_val_buk
                   CHANGING lt_res_buk.
* Do whatever you want to evaluate the results list of BUKRS / FLAG combo.

* Your FORM may look like this:
FORM check_buk USING it_val_buk TYPE tyt_val_buk
            CHANGING ct_res_buk TYPE tyt_res_buk. 
  DATA lt_val TYPE tyt_val_buk.
  DATA lf_val TYPE p DECIMALS 2.
  FIELD-SYMBOLS: &amp;lt;val&amp;gt; TYPE tys_val_buk.

* Make sure all Company Codes are together
  lt_val = it_val_buk.
  SORT lt_val BY bukrs.

* Evaluate&lt;BR /&gt;  LOOP AT lt_val ASSINGING &amp;lt;val&amp;gt;.
* Group change. Remember results for all Companies with sum val &amp;gt;=1.
    AT NEW bukrs.
      IF lf_val &amp;gt;= 1.&lt;BR /&gt;        INSERT &amp;lt;val&amp;gt;-bukrs INTO ct_res_buk.&lt;BR /&gt;      ENDIF.&lt;BR /&gt;      CLEAR lf_val.
    ENDAT.

* Accumulate the values
    lf_val = lf_val + &amp;lt;val&amp;gt;-val.
  ENDLOOP.
ENDFORM.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Of course this can be solved much more elegantly using ABAP OO, but we are not there yet &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;... Also, I don't guarantee buglessness... &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Also, for future reference, and to better familiarize yourself with the ABAP concepts, check the ABAP help, e.g.:&lt;/P&gt;&lt;P&gt; &lt;A href="https://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm"&gt;https://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Hope that gets you started,&lt;BR /&gt;Mike&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 15:13:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117332#M1973980</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-11-08T15:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Field validation in table maintenance generator before saving</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117333#M1973981</link>
      <description>&lt;P&gt;You can implement the event 01 (before save), but the data is not saved in the database yet, it's in the internal table &lt;STRONG&gt;TOTAL&lt;/STRONG&gt;. It has a special format that you must first transfer to an internal table with usable format, as shown below. I use the same names (LT_VAL_BUK) as proposed by Mike.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FORM z_before_saving.
 field-symbols &amp;lt;ls_val_buk&amp;gt; type name_of_your_table.
 data lt_val_buk type name_of_your_table.

 LOOP AT total.
   assign total to &amp;lt;ls_val_buk&amp;gt; casting.
   append &amp;lt;ls_val_buk&amp;gt; to lt_val_buk.
 ENDLOOP.

 " your algorithm to find error - do as Mike said or algo you want

 IF error = abap_true.
   MESSAGE 'ERROR' TYPE 'S' DISPLAY LIKE 'E'.
   VIM_ABORT_SAVING = 'X'. " do not leave in case of error
 ENDIF.

 sy-subrc = 0. " save is done only if sy-subrc = 0
ENDFORM.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Nov 2019 18:49:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/field-validation-in-table-maintenance-generator-before-saving/m-p/12117333#M1973981</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-11-08T18:49:30Z</dc:date>
    </item>
  </channel>
</rss>

