Вопрос более не актуален.
Как правильно вызывать функциональный модуль. API_COSTACTPLN_POSTPRIMCOST, чтобы загрузить данные в CO.
Создал c ABAP2XLSX приложение, которое загружает с екселя данные в Z-таблицу. Теперь нужно все загрузить в CO.
Кому интересно код ниже.
BAPI вызавается два раза: длай текущего года с плавающим плановым месяцем и для следующего года.
Соответственно задействована внутренняя таблица
pervalue (Planned values per period)
вместо
totvalue (Plan values per year Plan values per year and distribution key),
WBS_ELEMENТ не нужен.
Конечно корректнее будет добавить в код вызов CALL FUNCTION 'BAPI_COSTACTPLN_CHECKPRIMCOST'.
Есть ссылка:
https://sapboard.ru/forum/viewtopic.php?f=6&t=76380Сделал такую вот форму:
Code:
form update_plandaten .
data : lt_messtab type table of bdcmsgcoll,
ls_messtab type bdcmsgcoll.
data: ls_headerinfo like bapiplnhdr,
lt_indexstruc type table of bapiacpstru with header line,
ls_indexstruc like line of lt_indexstruc,
lt_coobject type table of bapipcpobj with header line,
ls_coobject like line of lt_coobject,
lt_totvalue type table of bapipcptot with header line,
lt_pervalue type table of bapipcpval with header line,
ls_pervalue like line of lt_pervalue,
lt_return type table of bapiret2 with header line,
ls_return like line of lt_return.
data : lv_object type obj_indx,
lv_value type val_indx,
lv_waers type waers,
lv_coarea type kokrs,
lv_kstar_alt type kstar,
lv_index type int4,
lv_jahr type gjahr,
lv_istmonat type monat,
lv_cnt type i.
data:
lt_bapi_return type standard table of bapiret2,
wa_bapi_return like line of lt_bapi_return.
data:
lt_zplanproct_imp type table of zplanproct,
ls_zplanproct_imp like line of lt_zplanproct_imp.
field-symbols: <fs_zplanprocsi> like line of gt_zplanproct_imp.
if gt_zplanproct_imp[] is not initial.
clear : lv_object, lv_value, ls_headerinfo.
refresh : lt_indexstruc, lt_coobject.
select single ta~kokrs into lv_coarea
from cskb as ka
inner join tka02 as ta on ta~kokrs = ka~kokrs
where ta~bukrs = p_bukrs.
select single waers from t001 into lv_waers where bukrs = p_bukrs and spras = 'D'.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = gv_version
importing
output = gv_version.
clear lv_kstar_alt.
refresh: lt_indexstruc,lt_indexstruc,lt_coobject,lt_pervalue.
unassign <fs_zplanprocsi>.
refresh lt_zplanproct_imp.
loop at gt_zplanproct_imp assigning <fs_zplanprocsi>.
clear <fs_zplanprocsi>-zzcokat.
clear <fs_zplanprocsi>-zzlifnr.
collect <fs_zplanprocsi> into lt_zplanproct_imp.
endloop.
sort lt_zplanproct_imp by gjahr kostl hkont monat.
lv_cnt = 1.
lv_index = 1.
do 2 times.
if lv_cnt = 1.
lv_jahr = gv_istjahr.
lv_istmonat = gv_istmonat.
else.
lv_jahr = gv_nextjahr.
lv_istmonat = '01'.
endif.
ls_headerinfo-co_area = lv_coarea.
ls_headerinfo-period_to = '012'.
ls_headerinfo-version = gv_version.
ls_headerinfo-plan_currtype = 'C'.
ls_headerinfo-fisc_year = lv_jahr.
ls_headerinfo-period_from = lv_istmonat.
clear lv_kstar_alt.
lv_index = 0.
clear ls_pervalue.
loop at lt_zplanproct_imp into ls_zplanproct_imp where gjahr = lv_jahr.
if lv_kstar_alt <> ls_zplanproct_imp-hkont.
if ls_pervalue is not initial.
append ls_pervalue to lt_pervalue.
endif.
lv_kstar_alt = ls_zplanproct_imp-hkont.
lv_index = lv_index + 1.
clear ls_indexstruc.
ls_indexstruc-object_index = lv_index.
ls_indexstruc-value_index = lv_index.
append ls_indexstruc to lt_indexstruc.
clear ls_coobject.
ls_coobject-object_index = lv_index.
ls_coobject-costcenter = p_kostl.
append ls_coobject to lt_coobject.
clear ls_pervalue.
ls_pervalue-value_index = lv_index.
ls_pervalue-cost_elem = ls_zplanproct_imp-hkont.
endif.
case ls_zplanproct_imp-monat.
when 01.
if lv_istmonat = '01'. ls_pervalue-fix_val_per01 = ls_zplanproct_imp-dmbtr. endif.
when 02.
if lv_istmonat <= '02'. ls_pervalue-fix_val_per02 = ls_zplanproct_imp-dmbtr. endif.
when 03.
if lv_istmonat <= '03'. ls_pervalue-fix_val_per03 = ls_zplanproct_imp-dmbtr. endif.
when 04.
if lv_istmonat <= '04'. ls_pervalue-fix_val_per04 = ls_zplanproct_imp-dmbtr. endif.
when 05.
if lv_istmonat <= '05'. ls_pervalue-fix_val_per05 = ls_zplanproct_imp-dmbtr. endif.
when 06.
if lv_istmonat <= '06'. ls_pervalue-fix_val_per06 = ls_zplanproct_imp-dmbtr. endif.
when 07.
if lv_istmonat <= '07'. ls_pervalue-fix_val_per07 = ls_zplanproct_imp-dmbtr. endif.
when 08.
if lv_istmonat <= '08'. ls_pervalue-fix_val_per08 = ls_zplanproct_imp-dmbtr. endif.
when 09.
if lv_istmonat <= '09'. ls_pervalue-fix_val_per09 = ls_zplanproct_imp-dmbtr. endif.
when 10.
if lv_istmonat <= '10'. ls_pervalue-fix_val_per10 = ls_zplanproct_imp-dmbtr. endif.
when 11.
if lv_istmonat <= '11'. ls_pervalue-fix_val_per11 = ls_zplanproct_imp-dmbtr. endif.
when 12.
if gv_istmonat <= '12'. ls_pervalue-fix_val_per12 = ls_zplanproct_imp-dmbtr. endif.
endcase.
endloop.
append ls_pervalue to lt_pervalue.
call function 'BAPI_COSTACTPLN_POSTPRIMCOST'
exporting
headerinfo = ls_headerinfo
tables
indexstructure = lt_indexstruc[]
coobject = lt_coobject[]
pervalue = lt_pervalue[]
return = lt_return.
refresh: lt_indexstruc,lt_indexstruc,lt_coobject,lt_pervalue.
clear: lv_object, lv_value.
describe table lt_return lines gv_lines.
if lines( lt_return ) > 0 .
loop at lt_return into gs_bapi_log.
append gs_bapi_log to gt_bapi_log.
endloop.
exit.
endif.
lv_cnt = lv_cnt + 1.
enddo.
endif.
if lt_return[] is initial.
call function 'BAPI_TRANSACTION_COMMIT'.
else.
call function 'BAPI_TRANSACTION_ROLLBACK'.
loop at lt_return into gs_bapi_log.
append gs_bapi_log to gt_bapi_log.
endloop.
sort gt_bapi_log.
delete adjacent duplicates from gt_bapi_log.
endif.
free: lt_indexstruc,lt_coobject,lt_pervalue,lt_return,lt_zplanproct_imp.
endform. " UPDATE_PLANDATEN