TOC Measurements with SAP Part 2

TOC Measurements with SAP Part 2

Let´s continue with the second measurement OE (Operating Expenses):

OE (Operating Expenses):

The definition says that OE = all the money in the system that is spent in turning the investments into throughput. Again, there are plenty of procedures to get to these numbers. I chose the following approach with G/L accounts. (See Transaction FS10N).

     There are two selection options for accounts in my report. The first one is for accounts for investment(I) and the second one for operating expenses(OE). The reason is these accounts are needed for both measurements. The function module(FM) BAPI_GL_ACC_GETLIST delivers all accounts in the company which are then reduced to our selected accounts.

The next step is the loop sequence on the table with accounts and each account is evaluated with FM BAPI_GL_ACC_GETPERIODBALANCES. Values are added to columns with OE or I depending on the selection above. See my methods:

METHOD get_balances. 
DATA:
 lt_helper LIKE lcl_measure=>lt_main.
 lt_helper = lcl_measure=>lt_main. 
SORT lt_helper STABLE BY werks lfgja. 
DELETE ADJACENT DUPLICATES FROM lt_helper COMPARING werks lfgja. 
LOOP AT lt_helper ASSIGNING FIELD-SYMBOL(<helper>) 
WHERE werks = ls_account-comp_code. 
CALL FUNCTION 'BAPI_GL_GETGLACCPERIODBALANCES' 
EXPORTING 
companycode = ls_account-comp_code 
glacct = ls_account-gl_account 
fiscalyear = <helper>-lfgja 
currencytype = '10' 
* IMPORTING 
* balance_carried_forward = balance_carried_forward 
* return = return 
TABLES
 account_balances = lt_balances . 
LOOP AT lcl_measure=>lt_main ASSIGNING FIELD-SYMBOL(<main>) 
WHERE werks = ls_account-comp_code 
AND lfgja = <helper>-lfgja. 
TRY.
 ASSIGN lt_balances[ fisc_year = <helper>-lfgja fis_period = <main>-lfmon ]
 TO FIELD-SYMBOL(<line>).
 IF sy-subrc = 0. 
MOVE-CORRESPONDING ls_account TO ls_account_line. 
MOVE-CORRESPONDING <main> TO ls_account_line. 
ls_account_line-oe = <line>-per_sales.
 ls_account_line-i = <line>-balance. 
ls_account_line-short_text =
 lt_accounts[ comp_code = ls_account-comp_code gl_account = ls_account-gl_account ]-short_text. 
ls_account_line-long_text = lt_accounts[ comp_code = ls_account-comp_code gl_account = ls_account-gl_account ]-long_text. 
APPEND ls_account_line TO lt_accounts_lines.
 IF <line>-gl_account IN sl_knoe. 
<main>-oe = <main>-oe + <line>-per_sales. 
ENDIF. 
IF <line>-gl_account
 IN sl_knti. <main>-i = <main>-i + <line>-balance. 
ENDIF.
 ENDIF. 
CATCH cx_sy_itab_line_not_found. 
ENDTRY. 
CLEAR: ls_account_line.
 ENDLOOP. 
CLEAR: lt_balances. 
ENDLOOP. 
ENDMETHOD.

This section is about OE but we gain in this approach as a side effect also a part of Investment at the same time and therefore let´s move on Investment(I).

I (Investment):

The definition is that I = all the money the system invests in purchasing items the system intends to sell. In a simple way, it has two parts: Inventory (all materials) and Assets (machines, buildings etc.). Now, after having T and OE in place, we can use previous methods for building value for I. We have already got assets as a side effect by evaluation of OE. Now we have to add inventory in TOC sense and that means for unfinished goods and finished goods only their TVC part (without adding the value of direct labour). For raw materials, its price and quantity for the time period are stored in table MBEWH. In the same table are stored time period, quantity and price for unfinished and finished goods. That price must be replaced through TVC for one piece multiplied by quantity. TVC comes from the same method as in the case for T. See the complete coding:

*&---------------------------------------------------------------------* 
*& Report ZTOCMASURE 
*& 
*&---------------------------------------------------------------------* 
*& 
*& 
*&---------------------------------------------------------------------* 
REPORT ztocmasure. 
DATA: 
wa_matnr TYPE matnr, 
wa_spmonth TYPE spmon, 
wa_werks TYPE werks-werks, 
wa_konto TYPE saknr, 
wa_nomatnr TYPE matnr,
 wa_dismm TYPE dismm. 
SELECT-OPTIONS: 
sl_matnr FOR wa_matnr, 
sl_month FOR wa_spmonth OBLIGATORY, 
sl_werk FOR wa_werks, 
sl_nomat FOR wa_nomatnr. 
SELECTION-SCREEN ULINE.
 PARAMETERS: 
p_trhpt RADIOBUTTON GROUP 1. 
PARAMETERS: p_sum_t AS CHECKBOX. 
SELECTION-SCREEN ULINE. 
PARAMETERS:p_invtr RADIOBUTTON GROUP 1. 
PARAMETERS: p_sum_i AS CHECKBOX. 
SELECT-OPTIONS: sl_knti FOR wa_konto. "select konto for inventory 
SELECTION-SCREEN ULINE.
PARAMETERS: p_oe RADIOBUTTON GROUP 1. 
PARAMETERS: p_sum_oe AS CHECKBOX. 
SELECT-OPTIONS: sl_knoe FOR wa_konto. "select konto for oe
 SELECTION-SCREEN ULINE. 
PARAMETERS: p_all RADIOBUTTON GROUP 1. 
PARAMETERS: p_allsm AS CHECKBOX, "all werks together 
p_no_i AS CHECKBOX. " without investment 
SELECTION-SCREEN ULINE. 
SELECTION-SCREEN ULINE. 
SELECT-OPTIONS:sl_dismm FOR wa_dismm. 
CLASS lcl_main DEFINITION CREATE PRIVATE. 
PUBLIC SECTION. 
CLASS-METHODS create 
RETURNING VALUE(r_result) TYPE REF TO lcl_main. 
METHODS run. 
PROTECTED SECTION. 
PRIVATE SECTION. 
DATA: lo_list TYPE REF TO cl_salv_table. 
DATA: lo_alv_events TYPE REF TO cl_salv_events_table. 
DATA: lo_funct TYPE REF TO cl_salv_functions_list. 
DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table. 
** declaration for Layout Settings 
DATA : 
lo_layout TYPE REF TO cl_salv_layout, 
ls_layout_key TYPE salv_s_layout_key. 
METHODS display CHANGING ch_itab TYPE ANY TABLE. 
ENDCLASS. 
CLASS lcl_measure DEFINITION CREATE PRIVATE.
 PUBLIC SECTION. TYPES: BEGIN OF t_main. 
TYPES: spmon TYPE spmon, 
lfgja TYPE lfgja,
 lfmon TYPE lfmon, 
werks TYPE werks-werks,
 t TYPE curr23_2,
 i TYPE curr23_2, 
oe TYPE curr23_2. 
TYPES END OF t_main . 
CLASS-METHODS class_constructor. 
CLASS-METHODS create 
RETURNING VALUE(r_result) TYPE REF TO lcl_measure. 
METHODS run. 
CLASS-DATA lt_main TYPE STANDARD TABLE OF t_main . 
PROTECTED SECTION. 
PRIVATE SECTION. 
METHODS make_sum_plants.. 
ENDCLASS. 
CLASS lcl_stock DEFINITION CREATE PRIVATE. 
PUBLIC SECTION. 
TYPES: BEGIN OF t_stock. 
INCLUDE TYPE zcds_mbewh1. 
TYPES: spmon TYPE spmon. 
TYPES: i TYPE curr23_2. 
TYPES END OF t_stock . 
CLASS-DATA: lt_stock TYPE STANDARD TABLE OF t_stock .
 DATA ls_stock TYPE t_stock. 
CLASS-METHODS create 
IMPORTING is_stock TYPE t_stock
 RETURNING VALUE(r_result) TYPE REF TO lcl_stock. 
CLASS-METHODS class_constructor. 
CLASS-METHODS get_stock. 
METHODS constructor 
IMPORTING is_stock TYPE t_stock. 
PROTECTED SECTION. 
PRIVATE SECTION. 
CLASS-DATA: 
lo_stock TYPE REF TO lcl_stock,
 lt_mbew TYPE HASHED TABLE OF zcds_mbew1 WITH UNIQUE KEY werks matnr, lt_mbewh TYPE HASHED TABLE OF zcds_mbewh1 
WITH UNIQUE KEY lfgja lfmon werks matnr. 
METHODS get_line. 
METHODS get_tvc. 
ENDCLASS. 
CLASS lcl_calc DEFINITION CREATE PRIVATE. 
PUBLIC SECTION. 
CLASS-METHODS class_constructor.
CLASS-METHODS get_mek
 IMPORTING is_main TYPE lcl_measure=>t_main i_matnr TYPE matnr
 RETURNING VALUE(r_mek) TYPE zcds_calc_tvc-tvc. 
PROTECTED SECTION. 
PRIVATE SECTION. 
CLASS-DATA lt_calc TYPE HASHED TABLE OF zcds_calc_tvc 
WITH UNIQUE KEY werks kalnr matnr kadky. 
ENDCLASS.
 CLASS lcl_throuput DEFINITION CREATE PRIVATE.
 PUBLIC SECTION. 
CLASS-DATA lt_thrpt TYPE TABLE OF zcds_throuput . 
CLASS-METHODS create 
IMPORTING i_thrpt TYPE zcds_throuput 
RETURNING VALUE(r_result) TYPE REF TO lcl_throuput. 
CLASS-METHODS: get_throughput. 
METHODS constructor 
IMPORTING i_thrpt TYPE zcds_throuput. 
PROTECTED SECTION. 
PRIVATE SECTION. 
CLASS-DATA: lo_thrpt TYPE REF TO lcl_throuput,
 ls_thrpt TYPE zcds_throuput. 
METHODS calc_position. 
ENDCLASS. 
CLASS lcl_account DEFINITION CREATE PRIVATE.
 PUBLIC SECTION. 
TYPES: BEGIN OF t_account. 
INCLUDE TYPE bapi3006_1. 
TYPES: spmon TYPE spmon. 
TYPES: i TYPE curr23_2. 
TYPES: oe TYPE curr23_2.
 TYPES END OF t_account .
 CLASS-DATA:lt_accounts_lines TYPE TABLE OF t_account. 
CLASS-METHODS class_constructor. 
CLASS-METHODS create 
IMPORTING is_account TYPE bapi3006_1 
RETURNING VALUE(r_result) TYPE REF TO lcl_account. 
CLASS-METHODS get_oe. 
METHODS constructor 
IMPORTING is_account TYPE bapi3006_1. 
PROTECTED SECTION. 
PRIVATE SECTION. 
CLASS-DATA lt_accounts TYPE STANDARD TABLE OF bapi3006_1.
 CLASS-DATA lo_account TYPE REF TO lcl_account. 
DATA ls_account TYPE bapi3006_1. 
DATA lt_balances TYPE STANDARD TABLE OF bapi1028_4. 
DATA ls_account_line TYPE t_account. 
METHODS: 
get_balances. **pozn BAPI_GL_ACC_GETLIST
 **BAPI_GL_GETGLACCPERIODBALANCES 
ENDCLASS. 
CLASS lcl_account IMPLEMENTATION. 
METHOD class_constructor. 
DATA: sl_all_accounts LIKE TABLE OF sl_knoe. 
DATA: lt_helper TYPE STANDARD TABLE OF lcl_measure=>t_main, 
account_list TYPE STANDARD TABLE OF bapi3006_1. 
sl_all_accounts[] = sl_knoe[]. 
APPEND LINES OF sl_knti TO sl_all_accounts.
 lt_helper = lcl_measure=>lt_main. 
SORT lt_helper STABLE BY werks. 
DELETE ADJACENT DUPLICATES FROM lt_helper COMPARING werks. 
LOOP AT lt_helper ASSIGNING FIELD-SYMBOL(<helper>). 
CALL FUNCTION 'BAPI_GL_ACC_GETLIST' 
EXPORTING 
companycode = <helper>-werks 
* LANGUAGE = LANGUAGE 
* LANGUAGE_ISO = LANGUAGE_ISO 
* IMPORTING 
* RETURN = RETURN 
TABLES account_list = account_list.
 APPEND LINES OF account_list TO lt_accounts.
 LOOP AT lt_accounts ASSIGNING FIELD-SYMBOL(<accont>). 
IF <accont>-gl_account NOT IN sl_all_accounts. 
DELETE lt_accounts WHERE comp_code = <accont>-comp_code 
AND gl_account = <accont>-gl_account.
 ENDIF. 
ENDLOOP. 
ENDLOOP. 
ENDMETHOD. 
METHOD constructor. 
ls_account = is_account. 
ENDMETHOD. 
METHOD create. 
r_result = NEW #( is_account ).
 ENDMETHOD.
 METHOD get_balances. 
DATA: 
lt_helper LIKE lcl_measure=>lt_main. 
lt_helper = lcl_measure=>lt_main. 
SORT lt_helper STABLE BY werks lfgja. 
DELETE ADJACENT DUPLICATES FROM lt_helper COMPARING werks lfgja. 
LOOP AT lt_helper ASSIGNING FIELD-SYMBOL(<helper>) 
WHERE werks = ls_account-comp_code. 
CALL FUNCTION 'BAPI_GL_GETGLACCPERIODBALANCES' 
EXPORTING 
companycode = ls_account-comp_code 
glacct = ls_account-gl_account 
fiscalyear = <helper>-lfgja currencytype = '10' 
* IMPORTING 
* balance_carried_forward = balance_carried_forward 
* return = return
 TABLES 
account_balances = lt_balances . 
LOOP AT lcl_measure=>lt_main ASSIGNING FIELD-SYMBOL(<main>) 
WHERE werks = ls_account-comp_code 
AND lfgja = <helper>-lfgja.
 TRY. 
ASSIGN lt_balances[ fisc_year = <helper>-lfgja fis_period = <main>-lfmon ] 
TO FIELD-SYMBOL(<line>).
 IF sy-subrc = 0. 
MOVE-CORRESPONDING ls_account TO ls_account_line. 
MOVE-CORRESPONDING <main> TO ls_account_line. 
ls_account_line-oe = <line>-per_sales. 
ls_account_line-i = <line>-balance.
 ls_account_line-short_text = lt_accounts[ comp_code = ls_account-comp_code gl_account = ls_account-gl_account ]-short_text.
 ls_account_line-long_text = lt_accounts[ comp_code = ls_account-comp_code gl_account = ls_account-gl_account ]-long_text. 
APPEND ls_account_line TO lt_accounts_lines.
 IF <line>-gl_account IN sl_knoe. 
<main>-oe = <main>-oe + <line>-per_sales.
 ENDIF.
 IF <line>-gl_account IN sl_knti. 
<main>-i = <main>-i + <line>-balance. 
ENDIF. 
ENDIF. 
CATCH cx_sy_itab_line_not_found.
 ENDTRY. 
CLEAR: ls_account_line. 
ENDLOOP. 
CLEAR: lt_balances. 
ENDLOOP.
 ENDMETHOD. 
METHOD get_oe. 
LOOP AT lt_accounts ASSIGNING FIELD-SYMBOL(<account>). 
lo_account = lcl_account=>create( <account> ). 
lo_account->get_balances( ). 
ENDLOOP. 
ENDMETHOD. 
ENDCLASS. 
CLASS lcl_throuput IMPLEMENTATION. 
METHOD constructor. 
ls_thrpt = i_thrpt. 
ENDMETHOD. 
METHOD create.
 r_result = NEW #( i_thrpt ). 
ENDMETHOD. 
METHOD get_throughput. 
SELECT * FROM zcds_throuput INTO TABLE lt_thrpt WHERE matnr IN sl_matnr 
AND spmon IN sl_month 
AND vkorg IN sl_werk 
AND matnr NOT IN sl_nomat. 
LOOP AT lt_thrpt ASSIGNING FIELD-SYMBOL(<thrpt>). 
lo_thrpt = lcl_throuput=>create( <thrpt> ). 
lo_thrpt->calc_position( ).
 <thrpt>-throughput = lo_thrpt->ls_thrpt-throughput.
 ENDLOOP. 
ENDMETHOD. 
METHOD calc_position. 
CLEAR: ls_thrpt-throughput. 
ASSIGN lcl_measure=>lt_main[ werks = ls_thrpt-vkorg spmon = ls_thrpt-spmon ] TO FIELD-SYMBOL(<line>).
 ls_thrpt-throughput = ls_thrpt-umsatz - ( ls_thrpt-unit * lcl_calc=>get_mek( i_matnr = ls_thrpt-matnr is_main = <line> ) ). 
<line>-t = <line>-t + ls_thrpt-throughput.
 ENDMETHOD.
 ENDCLASS. 
CLASS lcl_calc IMPLEMENTATION. 
METHOD class_constructor. 
SELECT * FROM zcds_calc_tvc INTO TABLE @lt_calc 
WHERE matnr IN @sl_matnr 
AND werks IN @sl_werk 
AND matnr NOT IN @sl_nomat.
 ENDMETHOD. 
METHOD get_mek. 
DATA(lv_year) = is_main-lfgja. 
DATA(lv_month) = is_main-lfmon.
 DO 100 TIMES. 
TRY. r_mek = lt_calc[ matnr = i_matnr werks = is_main-werks rok = lv_year mesic = lv_month ]-tvc / lt_calc[ matnr = i_matnr werks = is_main-werks rok = lv_year mesic = lv_month ]-losgr. 
EXIT. 
CATCH cx_sy_itab_line_not_found. 
lv_month = lv_month - 1. 
IF lv_month = 0.
 lv_month = 12.
 lv_year = lv_year - 1. 
ENDIF. 
IF lv_year < 199.
 EXIT. 
ENDIF. 
ENDTRY. 
ENDDO. 
ENDMETHOD. 
ENDCLASS. 
CLASS lcl_stock IMPLEMENTATION. 
METHOD class_constructor. 
SELECT * FROM zcds_mbew1 INTO TABLE @lt_mbew 
WHERE matnr IN @sl_matnr 
AND matnr NOT IN @sl_nomat 
AND werks IN @sl_werk 
AND dismm IN @sl_dismm. 
SELECT * FROM zcds_mbewh1 INTO TABLE @lt_mbewh FOR ALL ENTRIES IN @lt_mbew 
WHERE matnr = @lt_mbew-matnr. 
ENDMETHOD. 
METHOD constructor.
 ls_stock = is_stock. 
ENDMETHOD. 
METHOD create.
 r_result = NEW #( is_stock ).
 ENDMETHOD. 
METHOD get_stock. 
DATA: lls_stock TYPE t_stock, 
lt_helper LIKE lt_mbew.
 lt_helper = lt_mbew. 
SORT lt_helper STABLE BY matnr. 
DELETE ADJACENT DUPLICATES FROM lt_helper COMPARING matnr.
 LOOP AT lt_helper ASSIGNING FIELD-SYMBOL(<mbew>). 
LOOP AT lcl_measure=>lt_main ASSIGNING FIELD-SYMBOL(<main>). 
lls_stock-matnr = <mbew>-matnr. 
MOVE-CORRESPONDING <main> TO lls_stock. 
CLEAR: lls_stock-i. 
lo_stock = lcl_stock=>create( lls_stock ).
 lo_stock->get_line( ).
 IF lo_stock->ls_stock-lbkum > 0 
AND lo_stock->ls_stock-i = 0. 
lo_stock->get_tvc( ). 
ENDIF.
IF lo_stock->ls_stock-lbkum > 0. 
<main>-i = <main>-i + lo_stock->ls_stock-i.
 INSERT lo_stock->ls_stock INTO TABLE lt_stock. 
ENDIF. 
CLEAR: lls_stock, lo_stock. 
ENDLOOP. 
ENDLOOP. 
ENDMETHOD. 
METHOD get_line. 
DATA:
 lv_flag TYPE char1,
 lv_lfmon TYPE mbewh-lfmon, 
lv_year TYPE mbewh-lfgja,
 e_gjahr TYPE bkpf-gjahr, 
e_monat TYPE bkpf-monat. 
CALL FUNCTION 'FI_PERIOD_DETERMINE' 
EXPORTING 
i_budat = sy-datum
 i_bukrs = ls_stock-werks 
IMPORTING 
e_gjahr = e_gjahr 
e_monat = e_monat 
* E_POPER = E_POPER 
* EXCEPTIONS 
* FISCAL_YEAR = 1 
* PERIOD = 2 
* PERIOD_VERSION = 3 
* POSTING_PERIOD = 4 
* SPECIAL_PERIOD = 5 
* VERSION = 6 
* POSTING_DATE = 7 . 
lv_lfmon = ls_stock-lfmon.
 lv_year = ls_stock-lfgja. 
DO. 
TRY.
 lv_flag = 'X'. 
ls_stock-lbkum = lt_mbewh[ matnr = ls_stock-matnr lfgja = lv_year lfmon = lv_lfmon werks = ls_stock-werks ]-lbkum. 
IF ls_stock-lbkum > 0 
AND lt_mbewh[ matnr = ls_stock-matnr lfgja = lv_year lfmon = lv_lfmon werks = ls_stock-werks ]-vprsv = 'V'.
 ls_stock-i = lt_mbewh[ matnr = ls_stock-matnr lfgja = lv_year lfmon = lv_lfmon werks = ls_stock-werks ]-salk3.
 ENDIF. 
CATCH cx_sy_itab_line_not_found .
 IF lv_lfmon < 12.
 lv_lfmon = lv_lfmon + 1. ELSE. 
lv_year = lv_year + 1. 
lv_lfmon = 1. 
ENDIF.
 IF lv_year = e_gjahr 
AND lv_lfmon = e_monat. 
TRY.
 ls_stock-lbkum = lt_mbew[ matnr = ls_stock-matnr werks = ls_stock-werks mbrue = 'X' ]-lbkum. 
IF ls_stock-lbkum > 0 
AND lt_mbew[ matnr = ls_stock-matnr werks = ls_stock-werks mbrue = 'X' ]-vprsv = 'V'. ls_stock-i = lt_mbew[ matnr = ls_stock-matnr werks = ls_stock-werks mbrue = 'X' ]-salk3. 
ENDIF.
 EXIT. 
CATCH cx_sy_itab_line_not_found . 
EXIT.
 ENDTRY. 
ENDIF. 
CLEAR: lv_flag.
 ENDTRY.
 IF lv_flag IS NOT INITIAL.
 EXIT. 
ENDIF. 
ENDDO. 
ENDMETHOD. 
METHOD get_tvc. 
CLEAR: ls_stock-i. 
ASSIGN lcl_measure=>lt_main[ werks = ls_stock-werks spmon = ls_stock-spmon ] TO FIELD-SYMBOL(<line>). 
ls_stock-i = ( ls_stock-lbkum * lcl_calc=>get_mek( i_matnr = ls_stock-matnr is_main = <line> ) ). 
ENDMETHOD.
 ENDCLASS. 
CLASS lcl_measure IMPLEMENTATION. 
METHOD class_constructor. 
DATA: lt_help TYPE STANDARD TABLE OF zcds_s660_v, 
i_budat TYPE bkpf-budat. 
SELECT * FROM zcds_s660_v INTO TABLE @lt_help WHERE spmon IN @sl_month AND werks IN @sl_werk.
 SORT lt_help STABLE BY spmon werks. 
DELETE ADJACENT DUPLICATES FROM lt_help COMPARING spmon werks. 
MOVE-CORRESPONDING lt_help TO lt_main. 
CLEAR lt_help. 
LOOP AT lt_main ASSIGNING FIELD-SYMBOL(<main>).
 i_budat = <main>-spmon && '01'. 
CALL FUNCTION 'FI_PERIOD_DETERMINE' 
EXPORTING
i_budat = i_budat
 i_bukrs = <main>-werks
 IMPORTING 
e_gjahr = <main>-lfgja 
e_monat = <main>-lfmon . 
ENDLOOP. 
ENDMETHOD. 
METHOD create. 
CREATE OBJECT r_result. 
ENDMETHOD. 
METHOD run. 
IF p_trhpt IS NOT INITIAL.
 lcl_throuput=>get_throughput( ). 
ELSEIF p_invtr IS NOT INITIAL.
 lcl_stock=>get_stock( ). 
ELSEIF p_oe IS NOT INITIAL.
 lcl_account=>get_oe( ). 
ELSEIF p_all IS NOT INITIAL.
 lcl_throuput=>get_throughput( ).
 IF p_no_i = ' '.
 lcl_stock=>get_stock( ). 
ENDIF. 
lcl_account=>get_oe( ).
 IF p_allsm = 'X'. 
make_sum_plants( ). 
ENDIF. 
ENDIF. 
ENDMETHOD. 
METHOD make_sum_plants.
 DATA: lt_helper LIKE lt_main.
lt_helper = lt_main. 
SORT lt_helper BY spmon.
DELETE ADJACENT DUPLICATES FROM lt_helper COMPARING spmon. 
LOOP AT lt_helper ASSIGNING FIELD-SYMBOL(<help>). 
CLEAR:<help>-t,<help>-i, <help>-oe. 
ENDLOOP.
 LOOP AT lt_helper ASSIGNING FIELD-SYMBOL(<helper>). 
LOOP AT lt_main ASSIGNING FIELD-SYMBOL(<main>) 
WHERE spmon = <helper>-spmon. 
CLEAR:<helper>-werks.
 <helper>-t = <helper>-t + <main>-t. 
<helper>-i = <helper>-i + <main>-i. 
<helper>-oe = <helper>-oe + <main>-oe. 
ENDLOOP. 
ENDLOOP.
 CLEAR: lt_main. lt_main = lt_helper. 
CLEAR: lt_helper. 
ENDMETHOD.
 ENDCLASS. 
CLASS lcl_main IMPLEMENTATION. 
METHOD create. 
CREATE OBJECT r_result. 
ENDMETHOD.
 METHOD run. 
lcl_measure=>create( )->run( ).
 IF p_trhpt IS NOT INITIAL. 
IF p_sum_t IS INITIAL. 
display( CHANGING ch_itab = lcl_throuput=>lt_thrpt ).
 ELSE. 
display( CHANGING ch_itab = lcl_measure=>lt_main ). 
ENDIF. 
ELSEIF p_invtr IS NOT INITIAL. 
IF p_sum_i IS INITIAL. 
display( CHANGING ch_itab = lcl_stock=>lt_stock ). 
ELSE. display( CHANGING ch_itab = lcl_measure=>lt_main ). 
ENDIF. 
ELSEIF p_oe IS NOT INITIAL.
 IF p_sum_oe IS INITIAL. display( CHANGING ch_itab = lcl_account=>lt_accounts_lines ). ELSE. 
display( CHANGING ch_itab = lcl_measure=>lt_main ).
 ENDIF. 
ELSEIF p_all IS NOT INITIAL. 
display( CHANGING ch_itab = lcl_measure=>lt_main ). 
ENDIF. 
ENDMETHOD. 
METHOD display. 
TRY. CALL METHOD cl_salv_table=>factory 
* EXPORTING 
* LIST_DISPLAY = IF_SALV_C_BOOL_SAP=>FALSE 
* r_container = g_ordlst_container 
* CONTAINER_NAME = lv_prenos 
IMPORTIN r_salv_table = lo_list
 CHANGING t_table = ch_itab. 
CATCH cx_salv_msg INTO DATA(lc_msg) . 
DATA(lv_string) = lc_msg->get_text( ).
 MESSAGE lv_string TYPE 'I'.
 ENDTRY.
 lo_funct = lo_list->get_functions( ). 
lo_funct->set_all( abap_true ).
 lo_alv_events = lo_list->get_event( ). 
lo_cols_tab = lo_list->get_columns( ).
 lo_list->display( ). 
ENDMETHOD.
 ENDCLASS. 
START-OF-SELECTION. 
lcl_main=>create( )->run( ).

Conclusion:

Having all three parts(T, I, OE) in one table, we can assess NP(NetProfi) and ROI(Return on Investments), or Productivity and Turns as shown at the beginning of this miniseries. It was the goal of our project, an easy way to evaluate the overall performance of a company according to TOC.

  I would appreciate any feedback especially if you use SAP in a combination with the Theory of constraint.