cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate Value for field in Resul_package

0 Kudos

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.

Accepted Solutions (0)

Answers (1)

Answers (1)

MKreitlein
Active Contributor

Hello Michel,

if I understand your coding correctly, you can work with one Loop only, as well.

I would use the following coding. Give it a try.

TYPE: gs_Stundensatz LIKE LINE OF lt_Stundensatz.

LOOP AT Result_package ASSIGNING <result_fields>.

    CLEAR gs_Stundensatz
    READ TABLE lt_Stundensatz WITH KEY 
         /BIC/mihrolle = <fs_line>-/bic/mihrolle 
         /BIC/mihprkun = <fs_line>-/bic/mihprkun
         INTO gs_Stundensatz.

    IF sy-subrc = 0.
        <result_fields>-/bic/mihumsatz = <result_fields>-/bic/mihprstu * gs_Stundensatz-/bic/mihstusa.
    ENDIF.
ENDLOOP.

Best regards, Martin

ranganath_korata
Contributor
0 Kudos

This looks good. A small suggestion for performance improvement would be to add SORT and BINARY SEARCH on the IT

Thanks,

Ranganath