你能帮我解决一下ABAP代码(我为BW做了一些简单的逻辑)。
当数据附加到表时,它会计算第一行,但会将结果写入第二行,第二行,第二行等。而在第一行,我的结果为零。
它能是什么?请帮助我,也许我在代码中遗失了一些东西。
我的代码:
FIELD-SYMBOLS: <ls_data> TYPE any,
<lv_plant> TYPE /BI0/OIPLANT.
TYPES: begin of ty_kpi_result,
plant type /BI0/OIPLANT,
mat_num_01(18) type n,
mat_num_02(18) type n,
END OF ty_kpi_result.
DATA: lt_result TYPE TABLE OF ty_kpi_result,
ls_result like LINE OF lt_result,
lv_count type i,
lv_plant_1 type /BI0/OIPLANT.
sort ct_data ASCENDING.
LOOP AT ct_data ASSIGNING <ls_data>.
ASSIGN COMPONENT 'PLANT' OF STRUCTURE <ls_data> to <lv_plant>.
* lv_count = lv_count + 1.
ls_result-plant = <lv_plant>.
IF lv_plant_1 = <lv_plant>.
lv_count = lv_count + 1.
ls_result-mat_num_01 = lv_count.
ELSE.
lv_count = 0.
lv_count = lv_count + 1.
APPEND ls_result to lt_result.
ENDIF.
lv_plant_1 = <lv_plant>.
ls_result-mat_num_01 = lv_count.
ENDLOOP.
答案 0 :(得分:2)
在SAP论坛上找到解决方案:
FIELD-SYMBOLS: <ls_data> TYPE any,
<lv_plant> TYPE /bi0/oiplant.
TYPES: BEGIN OF ty_kpi_result,
plant TYPE /bi0/oiplant,
mat_num_01 TYPE i,
mat_num_02 TYPE i,
END OF ty_kpi_result.
DATA: lt_result TYPE sorted TABLE OF ty_kpi_result with UNIQUE KEY plant,
ls_result LIKE LINE OF lt_result,
lv_count TYPE i,
lv_plant_1 TYPE /bi0/oiplant.
SORT ct_data BY ('PLANT').
CLEAR ls_result.
LOOP AT ct_data ASSIGNING <ls_data>.
ASSIGN COMPONENT 'PLANT' OF STRUCTURE <ls_data> TO <lv_plant>.
IF <lv_plant> EQ ls_result-plant.
ADD 1 TO ls_result-mat_num_01.
ELSE.
IF ls_result-plant IS NOT INITIAL. " first record
APPEND ls_result TO lt_result.
ENDIF.
CLEAR ls_result.
ls_result-plant = <lv_plant>.
ls_result-mat_num_01 = 1.
ENDIF.
AT LAST. " last record
APPEND ls_result TO lt_result.
ENDAT.
ENDLOOP.
ENDMETHOD.