APPENDIX
METHOD if_ujq_sqe_post_process~post_process.
CONSTANTS:
c_wages_salaries(20) TYPE c VALUE 'CE0004020',
c_total_personnel(20) TYPE c VALUE 'CE0004000',
c_new_account(20) TYPE c VALUE 'RYANNEWACCT'.
DATA:
l_total_salary(11) TYPE p DECIMALS 7,
l_total_personnel(11) TYPE p DECIMALS 7,
lr_data TYPE REF TO data,
lr_new_data TYPE REF TO data,
lrt_new_data TYPE REF TO data,
l_count TYPE c,
l_temp TYPE string,
BEGIN OF ls_flds,
name1 TYPE string,
valu1 TYPE string,
name2 TYPE string,
valu2 TYPE string,
name3 TYPE string,
valu3 TYPE string,
name4 TYPE string,
valu4 TYPE string,
name5 TYPE string,
valu5 TYPE string,
name6 TYPE string,
valu6 TYPE string,
END OF ls_flds.
FIELD-SYMBOLS:
<ls_data> TYPE ANY,
<ls_ref_rec> TYPE ANY,
<lt_new_data> TYPE ANY TABLE,
<ls_new_data> TYPE ANY,
<l_account> TYPE ANY,
<l_new_acct> TYPE ANY,
<l_category> TYPE ANY,
<l_entity> TYPE ANY,
<l_activity> TYPE ANY,
<l_datasource> TYPE ANY,
<l_currency> TYPE ANY,
<l_time> TYPE ANY,
<l_measure> TYPE ANY,
<l_ref_meas> TYPE ANY,
<l_new_meas> TYPE ANY,
<l_fieldname> TYPE ANY,
<l_fieldvalu> TYPE ANY.
* The goal of this BAdI is to create a new calculated account value that
* shows Wages & Salaries as a percent of Total Personnel Costs.
LOOP AT ct_array ASSIGNING <ls_data>.
ASSIGN COMPONENT 'P_ACCT' OF STRUCTURE <ls_data> TO <l_account>.
IF sy-subrc > 0.
EXIT. "Only going through this logic if account is being displayed
ENDIF.
IF <l_account> = c_wages_salaries.
CLEAR: l_total_salary, l_count, ls_flds, l_total_personnel.
ASSIGN COMPONENT 'SIGNEDDATA' OF STRUCTURE <ls_data> TO <l_measure>.
IF sy-subrc > 0.
EXIT. "Only going through this logic if signeddata is available
ENDIF.
l_total_salary = <l_measure>.
l_count = 0.
********************************* CATEGORY *********************************
ASSIGN COMPONENT 'CATEGORY' OF STRUCTURE <ls_data> TO <l_category>.
IF sy-subrc = 0.
l_count = l_count + 1.
* Set LS_FLDS-NAME(x)
CONCATENATE 'LS_FLDS-NAME' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldname>.
IF sy-subrc = 0.
<l_fieldname> = `CATEGORY`.
ENDIF.
* Set LS_FLDS-VALU(x)
CONCATENATE 'LS_FLDS-VALU' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldvalu> .
IF sy-subrc = 0.
<l_fieldvalu> = <l_category>.
ENDIF.
ENDIF.
********************************* ENTITY *********************************
ASSIGN COMPONENT 'ENTITY' OF STRUCTURE <ls_data> TO <l_entity>.
IF sy-subrc = 0.
l_count = l_count + 1.
* Set LS_FLDS-NAME(x)
CONCATENATE 'LS_FLDS-NAME' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldname>.
IF sy-subrc = 0.
<l_fieldname> = `ENTITY`.
ENDIF.
* Set LS_FLDS-VALU(x)
CONCATENATE 'LS_FLDS-VALU' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldvalu> .
IF sy-subrc = 0.
<l_fieldvalu> = <l_entity>.
ENDIF.
ENDIF.
********************************* ACTIVITY *********************************
ASSIGN COMPONENT 'P_ACTIVITY' OF STRUCTURE <ls_data> TO <l_activity>.
IF sy-subrc = 0.
l_count = l_count + 1.
* Set LS_FLDS-NAME(x)
CONCATENATE 'LS_FLDS-NAME' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldname>.
IF sy-subrc = 0.
<l_fieldname> = `P_ACTIVITY`.
ENDIF.
* Set LS_FLDS-VALU(x)
CONCATENATE 'LS_FLDS-VALU' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldvalu> .
IF sy-subrc = 0.
<l_fieldvalu> = <l_activity>.
ENDIF.
ENDIF.
********************************* DATASRC *********************************
ASSIGN COMPONENT 'P_DATASRC' OF STRUCTURE <ls_data> TO <l_datasource>.
IF sy-subrc = 0.
l_count = l_count + 1.
* Set LS_FLDS-NAME(x)
CONCATENATE 'LS_FLDS-NAME' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldname>.
IF sy-subrc = 0.
<l_fieldname> = `P_DATASRC`.
ENDIF.
* Set LS_FLDS-VALU(x)
CONCATENATE 'LS_FLDS-VALU' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldvalu> .
IF sy-subrc = 0.
<l_fieldvalu> = <l_datasource>.
ENDIF.
ENDIF.
******************************* RPTCURRENCY *********************************
ASSIGN COMPONENT 'RPTCURRENCY' OF STRUCTURE <ls_data> TO <l_currency>.
IF sy-subrc = 0.
l_count = l_count + 1.
* Set LS_FLDS-NAME(x)
CONCATENATE 'LS_FLDS-NAME' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldname>.
IF sy-subrc = 0.
<l_fieldname> = `RPTCURRENCY`.
ENDIF.
* Set LS_FLDS-VALU(x)
CONCATENATE 'LS_FLDS-VALU' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldvalu> .
IF sy-subrc = 0.
<l_fieldvalu> = <l_currency>.
ENDIF.
ENDIF.
********************************* TIME *********************************
ASSIGN COMPONENT 'TIME' OF STRUCTURE <ls_data> TO <l_time>.
IF sy-subrc = 0.
l_count = l_count + 1.
* Set LS_FLDS-NAME(x)
CONCATENATE 'LS_FLDS-NAME' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldname>.
IF sy-subrc = 0.
<l_fieldname> = `TIME`.
ENDIF.
* Set LS_FLDS-VALU(x)
CONCATENATE 'LS_FLDS-VALU' l_count INTO l_temp.
ASSIGN (l_temp) TO <l_fieldvalu> .
IF sy-subrc = 0.
<l_fieldvalu> = <l_time>.
ENDIF.
ENDIF.
* Any time i found the Wages & Salaries account, I need to find the
* corresponding record with the total personnel costs...
* Unfortunately, ABAP does not support specifying the WITH KEY clause in a
* READ TABLE statement dynamically, nor can the WHERE clause by dynamic in a
* LOOP AT - i.e. the statement I want, which isn't supported yet, would be:
* READ TABLE ct_array ASSIGNING <ls_ref_rec> WITH KEY (l_where_clause).
* Since I dont know which fields are on the slicer or in the array, I have t
* build these READ TABLE statements manually, and just fall into the correct
* one. I know Account will always be there (already checked), and the
* max number of entries are the total number of dimensions in my Application
CASE l_count.
WHEN '0'.
READ TABLE ct_array ASSIGNING <ls_ref_rec> WITH KEY
('P_ACCT') = c_total_personnel.
WHEN '1'.
READ TABLE ct_array ASSIGNING <ls_ref_rec> WITH KEY
('P_ACCT') = c_total_personnel
(ls_flds-name1) = ls_flds-valu1.
WHEN '2'.
READ TABLE ct_array ASSIGNING <ls_ref_rec> WITH KEY
('P_ACCT') = c_total_personnel
(ls_flds-name1) = ls_flds-valu1
(ls_flds-name2) = ls_flds-valu2.
WHEN '3'.
READ TABLE ct_array ASSIGNING <ls_ref_rec> WITH KEY
('P_ACCT') = c_total_personnel
(ls_flds-name1) = ls_flds-valu1
(ls_flds-name2) = ls_flds-valu2
(ls_flds-name3) = ls_flds-valu3.
WHEN '4'.
READ TABLE ct_array ASSIGNING <ls_ref_rec> WITH KEY
('P_ACCT') = c_total_personnel
(ls_flds-name1) = ls_flds-valu1
(ls_flds-name2) = ls_flds-valu2
(ls_flds-name3) = ls_flds-valu3
(ls_flds-name4) = ls_flds-valu4.
WHEN '5'.
READ TABLE ct_array ASSIGNING <ls_ref_rec> WITH KEY
('P_ACCT') = c_total_personnel
(ls_flds-name1) = ls_flds-valu1
(ls_flds-name2) = ls_flds-valu2
(ls_flds-name3) = ls_flds-valu3
(ls_flds-name4) = ls_flds-valu4
(ls_flds-name5) = ls_flds-valu5.
WHEN '6'.
READ TABLE ct_array ASSIGNING <ls_ref_rec> WITH KEY
('P_ACCT') = c_total_personnel
(ls_flds-name1) = ls_flds-valu1
(ls_flds-name2) = ls_flds-valu2
(ls_flds-name3) = ls_flds-valu3
(ls_flds-name4) = ls_flds-valu4
(ls_flds-name5) = ls_flds-valu5
(ls_flds-name6) = ls_flds-valu6.
ENDCASE.
IF sy-subrc = 0.
ASSIGN COMPONENT 'SIGNEDDATA'
OF STRUCTURE <ls_ref_rec> TO <l_ref_meas>.
l_total_personnel = <l_ref_meas>.
* Now I can calculate the percentage value, and insert my record into a
* temporary table
IF l_total_personnel > 0.
CREATE DATA lr_new_data LIKE LINE OF ct_array.
ASSIGN lr_new_data->* TO <ls_new_data>.
IF <lt_new_data> IS NOT ASSIGNED.
CREATE DATA lrt_new_data LIKE TABLE OF <ls_new_data>.
ASSIGN lrt_new_data->* TO <lt_new_data>.
ENDIF.
<ls_new_data> = <ls_data>.
ASSIGN COMPONENT 'P_ACCT'
OF STRUCTURE <ls_new_data> TO <l_new_acct>.
ASSIGN COMPONENT 'SIGNEDDATA'
OF STRUCTURE <ls_new_data> TO <l_new_meas>.
<l_new_acct> = c_new_account.
<l_new_meas> = ( l_total_salary / l_total_personnel ) * 100.
COLLECT <ls_new_data> INTO <lt_new_data>.
ELSE.
*Can't find it - just skip this account and dont display any new records
CONTINUE.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
* Now finally insert our new records into ct_array
IF <lt_new_data> IS ASSIGNED.
INSERT LINES OF <lt_new_data> INTO TABLE ct_array.
ENDIF.
ENDMETHOD.