Skip to Content
0
Jul 24, 2023 at 05:10 PM

Calculate Value for field in Resul_package

100 Views

Hello,

My task is to calculate the value for revenue, like revenue = hourrate * hour.

i get the hour from my Result_package and the hourrate from my active database table that i read into my program.

This is my code so far. The problem with this code is, that the field <fs_line>-/bic/mihstsas has always the value of the last iteration of the second loop. for example the last loop has the role 'Senior' and therfore the hourrate 100€. the programm will then correctly calculate the value for revenue in my result_package. the problem is that when the first loop gets to a record where the Role is 'Junior' the programm will still have the hourrate of 100, wich is wrong. How can i write the code so that the programm will get the correct Hourrate for the corresponding role.

result package

Customer, Role, Hour

lt_Stundensatz

Customer, Roler, Hour rate

calculate revenue (Hour * Hourrate) when Customer and Role are equal

 DATA : lt_Stundensatz TYPE TABLE of /BIC/AMIHDSATZ7,
       ls_Stundensatz LIKE LINE OF lt_Stundensatz.

FIELD-SYMBOLS : <fs_line> type /BIC/AMIHDSATZ7.

SELECT *
FROM /BIC/AMIHDSATZ7 INTO TABLE lt_Stundensatz.


LOOP AT Result_package ASSIGNING <result_fields>.
    LOOP AT lt_Stundensatz ASSIGNING <fs_line>.
READ TABLE lt_Stundensatz into <fs_line> WITH KEY /BIC/mihrolle = <fs_line>-/bic/mihrolle /BIC/mihprkun = <fs_line>-/bic/mihprkun.
ENDLOOP.
if sy-subrc = 0.
<result_fields>-/bic/mihumsatz = <result_fields>-/bic/mihprstu * <fs_line>-/bic/mihstusa.
ENDIF.
ENDLOOP.