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: 

Modify SM30 field based on value change during field validation

0 Kudos
292

Hi all,

I have a table ZTBUDGET, during SM30 entries I need to validate a field like below,

Balance Budget = Available Budget - Used Amount

for above I created a subroutine and written the following code, but my custom table is not getting modified based on calculated values. How to modify the data base table?

Following is the code which I wrote,

TABLES: ZMT_PO_ALLOC.
TYPES: BEGIN OF TY_POALLOC,
USEDAMT TYPE ZMT_PO_ALLOC-USEDAMT,
END OF TY_POALLOC.
form validate_entry.
DATA: lt_budget TYPE STANDARD TABLE OF ztbudget,
ls_budget TYPE ztbudget,
lt_poalloc TYPE STANDARD TABLE OF ty_poalloc,
ls_poalloc type ty_poalloc.
LOOP AT total.

clear ls_budget.
if <vim_total_struc> is ASSIGNED.
MOVE-CORRESPONDING <vim_total_struc> to ls_budget.
endif.

if <action> NE 'D' and <action> is NOT INITIAL and <action> NE 'X'.
BREAK-POINT.
if ls_budget-BUDAMT LT ls_budget-BUDBAL.
MESSAGE 'Available budget amount should be greater then Balance budget amount' TYPE 'S' DISPLAY LIKE 'E'.
vim_abort_saving = 'X'.
exit.
ELSE.
select USEDAMT from zmt_po_alloc into table lt_poalloc
where GJAHR = ls_budget-GJAHR
AND WERKS = ls_budget-WERKS
AND EKGRP = ls_budget-EKGRP.
READ TABLE lt_poalloc into ls_poalloc index 1.
ls_budget-BUDBAL = ls_budget-BUDAMT - ls_poalloc-USEDAMT.
endif.
MODIFY ztbudget FROM ls_budget.
endif.

ENDLOOP.
ENDFORM.

3 REPLIES 3

VXLozano
Active Contributor
0 Kudos
232

What's the point of having a calculated field in a table, and to allow to write values on it? I'd go for a different approach: like to remove the calculated field from your table and create a view (a cds, probably) where you make all the calculations required.

Sandra_Rossi
Active Contributor
0 Kudos
232

Please edit your question (actions > edit), select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!

raymond_giuseppi
Active Contributor
0 Kudos
232

I wouldn't code this in the budget dialog, a sum value should be updated by the program that consumes the budget, better look for another solution.

There are also standard options in SAP to manage a purchasing budget.

Nevertheless, if this is a training exercise or a POC, which event did you use, to fill any fields you could use Event 01: Before Saving the Data in the Database or for hidden fields Event 21: Fill Hidden Fields