执行CKM3,输入物料、工厂、年度,查询如下:
后台表及关联关系略。主要通过提取标准程式,加工后提取数据。
提取到内表数据样列:
可以看到已包含收/发/存/期初/期末/组件,标准件、实际、差异等,与CKM3界面数据是一致的。
提取到内表中的关键统计栏位说明:
1、内表数据中CATEG栏位
2、PTYP栏位
其他栏位对比数据就可以看出,不再累述了。
代码如下(当中的itabco估算号数据、t_list_disp获取的CKM3数据可自行处理)
TABLES:fcml4h_price_ui_s,ckmlpp,ckmlcr,mldoc.
DATA:
s_list TYPE fcml4h_list_s,
t_list TYPE STANDARD TABLE OF fcml4h_list_s,
gt_list TYPE STANDARD TABLE OF fcml4h_list_s,
t_list_disp TYPE STANDARD TABLE OF fcml4h_list_s,
t_hist_disp TYPE STANDARD TABLE OF fcml4h_doc_hist_s.
DATA: lt_data TYPE fcml4h_common_ccs_t.
CONSTANTS:
y_vgart_abrechnung_einst LIKE mlhd-vgart VALUE 'ST',
y_vgart_abrechnung_mehrst LIKE mlhd-vgart VALUE 'MS',
y_vgart_input_material LIKE mlhd-vgart VALUE 'MI',
y_vgart_input_wip_mat LIKE mlhd-vgart VALUE 'WI',
y_vgart_output_material LIKE mlhd-vgart VALUE 'MO',
y_vgart_anfangsbestand LIKE mlhd-vgart VALUE 'MB',
y_vgart_input_curtp_ms LIKE mlhd-vgart VALUE 'MC',
y_vgart_input_curtp_wip LIKE mlhd-vgart VALUE 'WC',
y_vgart_abschluss LIKE mlhd-vgart VALUE 'CL',
y_vgart_fortschreibung LIKE mlhd-vgart VALUE 'UP',
y_vgart_preisaenderung LIKE mlhd-vgart VALUE 'PC',
y_vgart_preisaenderung_oc LIKE mlhd-vgart VALUE 'OC', "Oil
y_vgart_beentlasten LIKE mlhd-vgart VALUE 'DC',
y_vgart_reparatur LIKE mlhd-vgart VALUE 'RE',
y_vgart_leistung_abschluss LIKE mlhd-vgart VALUE 'AL',
y_vgart_leistung LIKE mlhd-vgart VALUE 'AT',
y_vgart_input_leistung LIKE mlhd-vgart VALUE 'AC',
y_vgart_input_wip_leist LIKE mlhd-vgart VALUE 'WL',
y_vgart_wip LIKE mlhd-vgart VALUE 'WP',
y_vgart_objwip LIKE mlhd-vgart VALUE 'WQ',
y_vgart_wip_mat_sum LIKE mlhd-vgart VALUE 'W1',
y_vgart_wip_mat_proc LIKE mlhd-vgart VALUE 'W2',
y_vgart_wip_act_sum LIKE mlhd-vgart VALUE 'W3',
y_vgart_wip_act_proc LIKE mlhd-vgart VALUE 'W4',
y_vgart_vnb LIKE mlhd-vgart VALUE 'RC',
y_vgart_vnb_orig_konto LIKE mlhd-vgart VALUE 'RO',
y_vgart_vnb_sammel_konto LIKE mlhd-vgart VALUE 'RS',
y_vgart_manchang LIKE mlhd-vgart VALUE 'MA',
y_vgart_input_activity_in TYPE char2 VALUE 'AI',
y_vgart_adjustment LIKE mlhd-vgart VALUE 'AD',
y_vgart_ccs_repair LIKE mlhd-vgart VALUE 'FL',
y_vgart_initialization LIKE mlhd-vgart VALUE 'IN',
y_categ_anfangsbestand TYPE ckml_categ VALUE 'AB',
y_categ_preisaenderungen TYPE ckml_categ VALUE 'PC',
y_categ_zugaenge TYPE ckml_categ VALUE 'ZU',
y_categ_sonst_zugaenge TYPE ckml_categ VALUE 'VP',
y_categ_nicht_verteilt TYPE ckml_categ VALUE 'NV',
y_categ_kumuliert TYPE ckml_categ VALUE 'KB',
y_categ_verbraeuche TYPE ckml_categ VALUE 'VN',
y_categ_endbestand TYPE ckml_categ VALUE 'EB'.
*eject
TYPES:
BEGIN OF ckmv0_matobj_str,
kalnr LIKE ckmlhd-kalnr, "Kalnr des Material-Objekts
obtyp LIKE ckmlmv001-otyp, "Objekttyp
bwkey LIKE ckmlhd-bwkey, "Bewertungskreis
matnr LIKE ckmlhd-matnr, "Materialnummer
bwtar LIKE ckmlhd-bwtar, "Bewertungsart
wperi LIKE ckmlpp-poper, "WIP-Periode
wjahr LIKE ckmlpp-bdatj, "WIP-Gesch?ftsjahr
wuntper LIKE ckmlpp-untper, "WIP-Wertgerüsttyp
kzbws LIKE ckmlhd-kzbws, "KZ bew. Einzelbestand
xobew LIKE ckmlhd-xobew, "KZ Lohnbearb: Subcontr.(JPN)
sobkz LIKE ckmlhd-sobkz, "Sonderbestands-KZ
vbeln LIKE ckmlhd-vbeln, "Kundenauftragsnummer
posnr LIKE ckmlhd-posnr, "Kundenauftragsposition
pspnr LIKE ckmlhd-pspnr, "PSP-Element
lifnr LIKE obew-lifnr, "Kontonummer des Lieferanten
flg_lock LIKE boole-boole, "Kz: Objekt ist gesperrt
END OF ckmv0_matobj_str,
ckmv0_matobj_tbl TYPE ckmv0_matobj_str OCCURS 0,
ckmv0_laobj_str TYPE ckmv0_matobj_str,
ckmv0_laobj_tbl TYPE ckmv0_matobj_str OCCURS 0,
* List matobject lists by company code
BEGIN OF ckmv0_matobj_bukrs_str,
bukrs TYPE bukrs,
t_matobj TYPE ckmv0_matobj_tbl,
END OF ckmv0_matobj_bukrs_str,
ckmv0_matobj_bukrs_tbl TYPE STANDARD TABLE OF ckmv0_matobj_bukrs_str,
* Protokoll-Schnittstelle ( MGV-Lauf <-> Applikation )
* TODO: Include-Strukutur im DDIC hinterlegen "KXXXXXX
BEGIN OF ckmv0_mgv_runcontrol.
* fmodus LIKE ckmli_mgv_strg-fmodus,
* component LIKE ckmli_mgv_strg-component,
* laufid LIKE ckmli_mgv_strg-laufid,
* kalst LIKE ckmli_mgv_strg-kalst,
* cyclenr LIKE ckmli_mgv_strg-cyclenr,
* status LIKE ckmli_mgv_strg-status,
* flg_test LIKE ckmli_mgv_strg-flg_test,
* flg_nachb LIKE ckmli_mgv_strg-flg_nachb,
* flg_error_mat LIKE ckmli_mgv_strg-flg_error_mat,
INCLUDE STRUCTURE ckml_s_mgv_strg_intern. TYPES:
END OF ckmv0_mgv_runcontrol,
* Tabellentyp über ckmlmv011f
ckmv0_ty_t_ckmlmv011f LIKE ckmlmv011f OCCURS 0,
* Rangestabellen zum Lesen des Schichtungsbuffers
ckmv0_yt_keart TYPE RANGE OF keart,
ckmv0_yt_prtyp TYPE RANGE OF ck_prtyp,
ckmv0_yt_kkzst TYPE RANGE OF ck_stufe,
ckmv0_yt_patnr TYPE RANGE OF nkprtn,
ckmv0_yt_dipa TYPE RANGE OF ck_dipa,
ckmv0_yt_curtp TYPE RANGE OF curtp,
ckmv0_yt_categ TYPE RANGE OF ckml_categ,
ckmv0_yt_bvalt TYPE RANGE OF ckml_alprocnr,
ckmv0_yt_mlcct TYPE RANGE OF ck_slml,
ckmv0_yt_ptyp TYPE RANGE OF ck_ptyp_bvalt.
* Period data for KE27: the same as GT_ML_PERIOD_DATA CL_FML_JOIN_CKMLPP_CKMLCR
TYPES: ckmv0_tt_gt_ml_period_data TYPE cl_fml_join_ckmlpp_cr_buffer=>tt_gt_ml_period_data.
TYPES: ckmv0_ts_gs_ml_period_data TYPE cl_fml_join_ckmlpp_cr_buffer=>ts_gs_ml_period_dat
DATA: BEGIN OF typ_table OCCURS 0 ,
kalnr TYPE ckmlhd-kalnr,
curtp TYPE ckmlcr-curtp,
mlast TYPE ckmlhd-mlast,
bwkey TYPE ckmlhd-bwkey,
waers LIKE matdoc-waers,
peinh LIKE ckmlcr-peinh,
matnr LIKE mara-matnr,
END OF itabco.
DATA: lt_itabcolist LIKE LINE OF itabco.
itabco内表数据,按年度区间可从CKMLHD,CKMLCR获取。
LOOP AT itabco ASSIGNING FIELD-SYMBOL(<lt_itabco>).
CLEAR lt_itabcolist.
lt_itabcolist-kalnr = <lt_itabco>-kalnr.
lt_itabcolist-curtp = <lt_itabco>-curtp.
lt_itabcolist-matnr = <lt_itabco>-matnr.
lt_itabcolist-werks = <lt_itabco>- bwkey.
lt_itabcolist-peinh = <lt_itabco>-peinh.
lt_itabcolist-waers = <lt_itabco>-waers.
REFRESH: t_list_disp, t_list.
CLEAR :lt_data,lt_data[],t_list_disp,t_list_disp[],t_list,t_list[].
*************S-主要代码**************************************************
PERFORM get_ckm3n_data CHANGING lt_data.
PERFORM complete_data_text USING lt_data.
*************E-主要代码******************************************
LOOP AT t_list_disp ASSIGNING FIELD-SYMBOL(<ls_list>).
"此段代码内处理获取的数据,t_list_disp
ENDLOOP.
ENDLOOP.
FORM get_ckm3n_data CHANGING ct_list TYPE fcml4h_common_ccs_t.
DATA: lt_all_sum TYPE fcml4h_common_ccs_t,
ls_all_sum LIKE LINE OF lt_all_sum.
DATA: lt_kalnr_pmat TYPE TABLE OF ckmv0_matobj_str,
lt_kalnr_acti TYPE TABLE OF ckmv0_matobj_str,
ls_kalnr_pmat TYPE ckmv0_matobj_str,
ls_kalnr_acti TYPE ckmv0_matobj_str,
ls_kalnr_process TYPE ckml_s_mgv_kalnr,
lt_kalnr_process TYPE ckml_t_mgv_kalnr.
DATA: lt_jahper TYPE RANGE OF mldoc-jahrper.
DATA: ls_jahper LIKE LINE OF lt_jahper.
DATA: cs_list LIKE LINE OF ct_list.
DATA: ls_elm TYPE fcml4h_ccs_element_s.
DATA: lv_mlcct TYPE ml4h_mlcct.
DATA: ls_parent TYPE fcml4h_list_s.
DATA: ls_value TYPE fcml4h_mldoc_value_s.
DATA: lt_common_kb TYPE SORTED TABLE OF fcml4h_common_ccs_s WITH NON-UNIQUE DEFAULT KEY,
lt_common_eb TYPE SORTED TABLE OF fcml4h_common_ccs_s WITH NON-UNIQUE DEFAULT KEY,
lt_common_nc TYPE SORTED TABLE OF fcml4h_common_ccs_s WITH NON-UNIQUE DEFAULT KEY.
DATA:
t_tckh3 TYPE STANDARD TABLE OF tckh3
WITH NON-UNIQUE KEY elehk elemt,
t_tckh1 TYPE STANDARD TABLE OF tckh1
WITH NON-UNIQUE KEY spras elehk elemt,
ref_tab TYPE SORTED TABLE OF ref_tab_line
WITH UNIQUE KEY kalnr poper bdatj elehk appl runtyp.
DATA: ref_tab_line LIKE LINE OF ref_tab.
DATA: gr_select TYPE REF TO cl_ml_data_select.
FIELD-SYMBOLS: <ls_list> LIKE LINE OF lt_all_sum.
REFRESH ct_list.
CLEAR:lt_all_sum[] ,
ls_all_sum ,
lt_kalnr_pmat ,
lt_kalnr_acti ,
ls_kalnr_pmat ,
ls_kalnr_acti ,
ls_kalnr_process,
lt_kalnr_process,
lt_jahper[] ,
ls_jahper ,
cs_list ,
ls_elm ,
lv_mlcct ,
ls_parent ,
ls_value ,
lt_common_kb ,
lt_common_eb ,
lt_common_nc ,
ls_matnr ,
t_tckh3[] ,
t_tckh1[] ,
ref_tab[] ,
ref_tab_line ,
gr_select .
*会计期间拼接
CONCATENATE p_bdatj p_poper INTO ls_jahper-high.
ls_jahper-low = ls_jahper-high.
ls_jahper-sign = 'I'.
ls_jahper-option ='EQ'.
APPEND ls_jahper TO lt_jahper.
CLEAR:t_tckh1,t_tckh3.
*结构扩展
CALL FUNCTION 'CK_F_TCKH4_HIERARCHY_READING'
EXPORTING
p_elehk = '02'
* f_tckh8_standard = lf_tckh8_standard
TABLES
t_tckh1 = t_tckh1
t_tckh3 = t_tckh3. "gt_ccs_tckh3.
*成本数据获取
"LOOP AT wt_matnr INTO ls_matnr.
CLEAR: ref_tab_line,gr_select,lv_mlcct.
READ TABLE ref_tab INTO ref_tab_line
WITH KEY kalnr = lt_itabcolist-kalnr
poper = p_poper
bdatj = p_bdatj
elehk = '02'.
IF sy-subrc <> 0.
CREATE OBJECT gr_select
EXPORTING
iv_kalnr = lt_itabcolist-kalnr
iv_runref = 'ACT'
iv_rldnr = '0L'
it_jahrper = lt_jahper
it_tckh3 = t_tckh3
iv_elesmhk = '02'.
ref_tab_line-kalnr = lt_itabcolist-kalnr.
ref_tab_line-poper = p_poper.
ref_tab_line-bdatj = p_bdatj.
* ref_tab_line-appl = ckmlrunperiod-appl.
* ref_tab_line-runtyp = ckmlrunperiod-run_type.
ref_tab_line-elehk = '02'.
IF gr_select IS BOUND.
ref_tab_line-ml_ref = gr_select.
INSERT ref_tab_line INTO TABLE ref_tab.
ENDIF.
ELSE.
gr_select = ref_tab_line-ml_ref.
ENDIF.
*---------------------------------
* Select sum data from DB
*---------------------------------
IF gr_select IS BOUND.
CALL METHOD gr_select->get_sum_init
EXPORTING
iv_curtp = lt_itabcolist-curtp
iv_bwkey = lt_itabcolist-werks
iv_keart = 'H'
iv_mlcct = lv_mlcct
iv_varfix = ''
iv_kkzst = ''
iv_svrel = '' " flag on UI Space: select relevant and MARKUP CCS; X means all CCS. If one ELM has both rel and non-rel CCS, it is added together!!
iv_wip = gv_show_wip
IMPORTING
et_sum = lt_all_sum
EXCEPTIONS
material_not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'W' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
RETURN.
ENDIF.
ENDIF.
IF lt_itabcolist-matnr IS NOT INITIAL.
PERFORM determ_kdm_st USING ls_parent
CHANGING lt_all_sum.
ENDIF.
LOOP AT lt_all_sum ASSIGNING <ls_list> WHERE categ = 'NC'.
MOVE-CORRESPONDING <ls_list> TO ls_elm.
MOVE-CORRESPONDING <ls_list> TO ls_value.
CLEAR ls_value-meins.
IF ls_value IS INITIAL AND ls_elm IS INITIAL.
DELETE TABLE lt_all_sum FROM <ls_list>.
ENDIF.
ENDLOOP.
APPEND LINES OF lt_all_sum TO ct_list.
CLEAR lt_all_sum.
ENDFORM.
FORM determ_kdm_st USING ls_parent TYPE fcml4h_list_s
CHANGING ct_sum TYPE fcml4h_common_ccs_t.
FIELD-SYMBOLS: <ls_sum> LIKE LINE OF ct_sum.
DATA: ls_elm TYPE fcml4h_ccs_element_s.
DATA: lv_exist_kdm_st TYPE abap_bool,
lv_exist_kdm TYPE abap_bool.
DATA: lt_list TYPE STANDARD TABLE OF fcml4h_common_ccs_s.
DATA: BEGIN OF ls_name_elm,
text(3) TYPE c VALUE 'ELM',
number(3) TYPE n VALUE 0,
END OF ls_name_elm.
FIELD-SYMBOLS <value> TYPE any.
DATA: ls_sum LIKE LINE OF ct_sum.
DATA:
lt_kdm TYPE ty_t_fcml4h,
ls_kdm LIKE LINE OF lt_kdm,
ls_value TYPE fcml4h_mldoc_value_s,
ls_kdm_ccs LIKE ls_kdm,
lt_kdm_ccs TYPE ty_t_fcml4h.
LOOP AT ct_sum INTO ls_sum.
CLEAR: ls_sum-xkdm_nact.
COLLECT ls_sum INTO lt_list.
ENDLOOP.
ct_sum = lt_list.
ENDFORM. " form determ_kdm_st
FORM complete_data_text USING it_list TYPE fcml4h_common_ccs_t.
DATA: lt_kalnr_pmat TYPE TABLE OF ckmv0_matobj_str,
lt_kalnr_acti TYPE TABLE OF ckmv0_matobj_str,
ls_kalnr_pmat TYPE ckmv0_matobj_str,
ls_kalnr_acti TYPE ckmv0_matobj_str,
ls_kalnr_process TYPE ckml_s_mgv_kalnr,
lt_kalnr_process TYPE ckml_t_mgv_kalnr.
DATA: lt_jahper TYPE RANGE OF mldoc-jahrper.
DATA: ls_jahper LIKE LINE OF lt_jahper,
ls_ckmlpp TYPE ckmlpp,
ls_ckmlcr TYPE ckmlcr.
DATA: lv_jahper TYPE mldoc-jahrper.
DATA: ls_list TYPE fcml4h_common_ccs_s.
DATA: ls_text TYPE fcml4h_text_s,
lt_text TYPE fcml4h_text_t.
DATA: ls_alproc TYPE ckml_s_alproc_texts,
ls_bvalt TYPE ckml_s_text_read.
DATA: ls_ckmllacr TYPE ckmllacr,
ls_ckmllacr_act TYPE ckmllacr,
lv_peinh LIKE ckmlcr-peinh.
FIELD-SYMBOLS <ls_list> TYPE fcml4h_list_s.
*-----------------------------------------------------------------------------------
* Reverse sign for vn lines and calculate price
*----------------------------------------------------------------------------------
LOOP AT it_list INTO ls_list.
CLEAR s_list.
MOVE-CORRESPONDING ls_list TO s_list.
ASSIGN s_list TO <ls_list>.
IF <ls_list>-categ = y_categ_verbraeuche. " for EB lines, it has beeen done in select
PERFORM change_sign CHANGING <ls_list>.
ENDIF.
<ls_list>-total = <ls_list>-stval + <ls_list>-prd + <ls_list>-kdm .
IF NOT <ls_list>-quant IS INITIAL.
TRY.
<ls_list>-price = <ls_list>-total / <ls_list>-quant * lt_itabcolist-peinh."lv_peinh.
CATCH cx_sy_arithmetic_overflow.
ENDTRY.
ELSEIF <ls_list>-categ <> 'EB'.
CLEAR <ls_list>-price.
ELSEIF <ls_list>-categ = 'EB'.
<ls_list>-price = fcml4h_price_ui_s-pvprs.
ENDIF.
APPEND s_list TO t_list.
IF gv_show_wip IS NOT INITIAL OR
gv_show_wip IS INITIAL AND s_list-posart <> 'WR' AND s_list-posart <> 'WI'.
APPEND s_list TO t_list_disp.
ENDIF.
ENDLOOP.
SORT t_list.
DELETE ADJACENT DUPLICATES FROM t_list.
SORT t_list_disp.
DELETE ADJACENT DUPLICATES FROM t_list_disp.
IF gr_select IS BOUND. " set to buffer
gr_select->set_list( t_list ).
ENDIF.
ENDFORM. "complete_data_text
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form CHANGE_SIGN
*&---------------------------------------------------------------------*
*& text Change sign for PRD/KDM/CCS/KDM_ST
*&---------------------------------------------------------------------*
* <--CS_LIST text
*&---------------------------------------------------------------------*
FORM change_sign CHANGING cs_list TYPE fcml4h_list_s.
DATA: BEGIN OF ls_name_elm,
text(3) TYPE c VALUE 'ELM',
number(3) TYPE n VALUE 0,
END OF ls_name_elm.
FIELD-SYMBOLS <value> TYPE any.
CASE cs_list-categ.
WHEN y_categ_endbestand OR y_categ_anfangsbestand.
*--------------------------------------------------------------
* Change sign for price change
*--------------------------------------------------------------
IF cs_list-categ = y_categ_endbestand.
cs_list-prd = -1 * cs_list-prd.
cs_list-kdm = -1 * cs_list-kdm.
cs_list-kdm_st = -1 * cs_list-kdm_st.
cs_list-markup = -1 * cs_list-markup.
ENDIF.
WHEN y_categ_verbraeuche.
*-------------------------------------------------------------------------------
*Change sign for VN: all value field as of QUANT/PRD/KDM/ELM001/KST001
*-------------------------------------------------------------------------------
cs_list-prd = -1 * cs_list-prd.
cs_list-kdm = -1 * cs_list-kdm.
cs_list-kdm_st = -1 * cs_list-kdm_st.
cs_list-quant = -1 * cs_list-quant .
cs_list-stval = -1 * cs_list-stval.
cs_list-altval = -1 * cs_list-altval.
cs_list-markup = -1 * cs_list-markup.
WHEN OTHERS.
ENDCASE.
*--------------------------------------------------------------
* Change sign for ELM001
*--------------------------------------------------------------
ls_name_elm-text = 'ELM'.
DO.
ls_name_elm-number = sy-index.
ASSIGN COMPONENT ls_name_elm OF STRUCTURE cs_list TO <value>.
IF sy-subrc = 0 AND <value> IS NOT INITIAL.
<value> = -1 * <value>.
ELSEIF sy-subrc <> 0.
EXIT.
ELSE.
CONTINUE.
ENDIF.
ENDDO.
ENDFORM.