采购合同的条件价格取值逻辑(如ME35K/ME3M显示报表的多个日期范围的条件价格)
1、根据采购订单合同和行项目和类型(合同是M)在A016表中取值条件号,
2、根据A016的条件号在KONP中取得价格
ME35K、ME3M的增强点在子程序LMEREPI02下的 METHOD if_reader_mm~read_table. 里面
代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
METHOD if_reader_mm~read_table. "823673 DATA: l_ref_ekko TYPE REF TO data, l_ref_ekkn TYPE REF TO data, lt_ekpo TYPE lty_t_sorted_ekpo, lt_outtab_acc TYPE lty_t_outtab_accounting, lt_outtab_schedlines TYPE lty_t_outtab_schedlines, ls_ekko TYPE ekko, ls_ekpo TYPE ekpo, ls_ekko_add TYPE lty_s_ekko_add, ls_outtab_purchdoc TYPE merep_outtab_purchdoc, ls_outtab_downpay TYPE merep_outtab_downpay, "EhP4 lt_outtab_scrap TYPE lty_t_outtab_scrap, "EhP4 ls_outtab_purchdoc_rel TYPE merep_outtab_purchdoc_rel. FIELD-SYMBOLS: <ekko> TYPE lty_t_sorted_ekko, <ekkn> TYPE lty_t_sorted_ekkn, <outtab> TYPE STANDARD TABLE. CALL METHOD super->if_reader_mm~read_table EXPORTING im_name = im_name IMPORTING ex_structname = ex_structname ex_fieldcatalog = ex_fieldcatalog ex_table_ref = ex_table_ref EXCEPTIONS OTHERS = 1. IF NOT sy-subrc IS INITIAL. RAISE not_found. ENDIF. * assign output table ASSIGN ex_table_ref->* TO <outtab>. * get table objects my_any_ekko = my_table_manager->lookup( 'EKKO' ). CHECK my_any_ekko IS BOUND. my_any_ekpo = my_table_manager->lookup( 'EKPO' ). CHECK my_any_ekpo IS BOUND. my_any_eket = my_table_manager->lookup( 'EKET' ). CHECK my_any_eket IS BOUND. my_any_ekkn = my_table_manager->lookup( 'EKKN' ). CHECK my_any_ekkn IS BOUND. my_any_lfa1 = my_table_manager->lookup( 'LFA1' ). CHECK my_any_lfa1 IS BOUND. my_any_authority = my_table_manager->lookup( 'MEREP_AUTHORITY' ). CHECK my_any_authority IS BOUND. my_any_ekbes = my_table_manager->lookup( 'EKBES' ). CHECK my_any_ekbes IS BOUND. * sub-contracting component consumption my_any_ekbe_sc = my_table_manager->lookup( 'EKBE_SC' ). "Comp. Consumption CHECK my_any_ekbe_sc IS BOUND. * down payments my_any_downpay = my_table_manager->lookup( 'DOWNPAY' ). CHECK my_any_downpay IS BOUND. * get header info l_ref_ekko = my_any_ekko->get_table( ). ASSIGN l_ref_ekko->* TO <ekko>. * get accounting info l_ref_ekkn = my_any_ekkn->get_table( ). ASSIGN l_ref_ekkn->* TO <ekkn>. IF my_struct_name EQ 'MEREP_OUTTAB_ACCOUNTING'. "823027 * usually we did not read the accounting info up to now so we have * to do this here: IF <ekkn> IS INITIAL. <ekkn> = me->prefetch_accounting( my_any_ekpo ). ENDIF. ENDIF. "823027 LOOP AT <ekko> INTO ls_ekko. * determine field 'super' ls_ekko_add-superfield = build_superfield( ls_ekko ). * get released value for release docu IF ls_ekko-bstyp EQ cl_mmpur_constants=>bstyp_k. "bstyp-kont. ls_ekko_add-ktwtr = fetch_ekab_tot_ktwtr( ls_ekko ). ENDIF. * get item info CLEAR lt_ekpo[]. my_any_ekpo->read_lines( EXPORTING im_key = ls_ekko-ebeln IMPORTING ex_table = lt_ekpo ). LOOP AT lt_ekpo INTO ls_ekpo. CASE my_struct_name. WHEN 'MEREP_OUTTAB_PURCHDOC'. * basic list ls_outtab_purchdoc = build_base_list( im_ekko = ls_ekko im_ekpo = ls_ekpo im_ekko_add = ls_ekko_add ). APPEND ls_outtab_purchdoc TO <outtab>. WHEN 'MEREP_OUTTAB_PURCHDOC_REL'. * release ls_outtab_purchdoc = build_base_list( im_ekko = ls_ekko im_ekpo = ls_ekpo im_ekko_add = ls_ekko_add ). CLEAR ls_outtab_purchdoc_rel. MOVE-CORRESPONDING ls_outtab_purchdoc TO ls_outtab_purchdoc_rel. APPEND ls_outtab_purchdoc_rel TO <outtab>. WHEN 'MEREP_OUTTAB_SCHEDLINES'. * schedule lines build_schedlines_list( EXPORTING im_ekko = ls_ekko im_ekpo = ls_ekpo im_ekko_add = ls_ekko_add IMPORTING ex_outtab_shedl = lt_outtab_schedlines ). APPEND LINES OF lt_outtab_schedlines TO <outtab>. WHEN 'MEREP_OUTTAB_ACCOUNTING'. * accounting data build_acc_list( EXPORTING im_ekko = ls_ekko im_ekpo = ls_ekpo im_ekko_add = ls_ekko_add im_t_ekkn = <ekkn> "886087 IMPORTING ex_outtab_acc = lt_outtab_acc ). APPEND LINES OF lt_outtab_acc TO <outtab>. WHEN 'MEREP_OUTTAB_DOWNPAY'. BREAK-POINT ID mmpur_downpay. * down payment (extended view on basic list) ls_outtab_downpay = build_downpay_list( im_ekko = ls_ekko im_ekpo = ls_ekpo im_ekko_add = ls_ekko_add ). APPEND ls_outtab_downpay TO <outtab>. WHEN 'MEREP_OUTTAB_COMPCONSUMP'. * component consumption IF cl_ops_switch_check=>mm_om1_sfws_sc( ) EQ cl_mmpur_constants=>yes. ls_outtab_purchdoc = build_base_list( im_ekko = ls_ekko im_ekpo = ls_ekpo im_ekko_add = ls_ekko_add ). INSERT ls_outtab_purchdoc INTO TABLE <outtab>. "#EC * ENDIF. WHEN 'MEREP_OUTTAB_SCRAP'. "EhP 4 * build scrap overview IF cl_ops_switch_check=>mm_om1_sfws_sc( ) EQ cl_mmpur_constants=>yes. CLEAR lt_outtab_scrap. build_scrap_list( EXPORTING is_ekko = ls_ekko is_ekpo = ls_ekpo is_ekko_add = ls_ekko_add IMPORTING et_outtab = lt_outtab_scrap ). INSERT LINES OF lt_outtab_scrap INTO TABLE <outtab>. "#EC * ENDIF. ENDCASE. ENDLOOP. " at lt_ekpo ENDLOOP. " at <ekko> * long procurement number TRY. /sappspro/cl_numbers=>lookup_many( CHANGING ct_table = <outtab> ). CATCH /sappspro/cx_number_wrong_strc. "#EC NO_HANDLER EXIT. ENDTRY. * call BAdIs (customer- and industry-specific) for modifying the output table CALL FUNCTION 'MEPOBADI_CHANGE_OUTTAB' EXPORTING im_struct_name = my_struct_name im_id = me->if_datablade_mm~class_id im_handle = my_handle im_loggroup = my_log_group CHANGING ch_outtab = <outtab>. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1)\PR:SAPLMEREP\TY:LCL_DATABLADE_PURCHDOC\IN:IF_READER_MM\ME:READ_TABLE\SE:END\EI A *$*$-Start: (1)---------------------------------------------------------------------------------$*$* ENHANCEMENT 3 ZEXPORT_CHARG. "active version * * *增加展示合同所有区间条件价格 at 20150901 by hp_gongzg DATA: lt_outtab_purchdoc TYPE STANDARD TABLE OF merep_outtab_purchdoc. DATA:LT_KONP TYPE STANDARD TABLE OF KONP, LW_KONP TYPE KONP, LT_A016 TYPE STANDARD TABLE OF A016, LW_A016 TYPE A016, lv_tabix TYPE sy-tabix. * FIELD-SYMBOLS:<fs_outtab_purchdoc_rel> TYPE merep_outtab_purchdoc_rel. DATA:lt_outtab_purchdoc_rel TYPE STANDARD TABLE OF merep_outtab_purchdoc_rel. DATA:lw_outtab_purchdoc_rel TYPE merep_outtab_purchdoc_rel. IF my_struct_name = 'MEREP_OUTTAB_PURCHDOC' or my_struct_name = 'MEREP_OUTTAB_PURCHDOC_REL' . "++ 2017-2-27 LOOP AT <outtab> INTO ls_outtab_purchdoc . CHECK ls_outtab_purchdoc-BSTYP = 'K'. * CHECK ls_outtab_purchdoc-LOEKZ = ''. lv_tabix = sy-tabix. refresh: LT_A016,LT_KONP. SELECT * INTO TABLE LT_A016 FROM A016 WHERE A016~KAPPL = 'M' AND A016~EVRTN = ls_outtab_purchdoc-ebeln AND A016~EVRTP = ls_outtab_purchdoc-ebelp. IF SY-SUBRC = 0 and LT_A016[] is NOT INITIAL. SELECT * INTO TABLE LT_KONP FROM KONP FOR ALL ENTRIES IN LT_A016 WHERE KONP~KNUMH = LT_A016-KNUMH AND LOEVM_KO = ''. LOOP at LT_A016 INTO LW_A016. CLEAR:ls_outtab_purchdoc-DATBI01, ls_outtab_purchdoc-DATAB01, ls_outtab_purchdoc-ZKBETR01, ls_outtab_purchdoc-ZKBETR02, ls_outtab_purchdoc-ZKBETR03, ls_outtab_purchdoc-ZKBETR04, ls_outtab_purchdoc-ZKBETR05, ls_outtab_purchdoc-NETPR. ls_outtab_purchdoc-DATBI01 = LW_A016-DATBI. ls_outtab_purchdoc-DATAB01 = LW_A016-DATAB. LOOP AT LT_KONP INTO LW_KONP WHERE KNUMH = LW_A016-KNUMH. ls_outtab_purchdoc-NETPR = ls_outtab_purchdoc-NETPR + LW_KONP-KBETR. CASE LW_KONP-KSCHL. WHEN 'ZLGP' OR 'PB00'. ls_outtab_purchdoc-ZKBETR01 = LW_KONP-KBETR. WHEN 'ZMP2'. ls_outtab_purchdoc-ZKBETR02 = LW_KONP-KBETR. WHEN 'ZTP2'. ls_outtab_purchdoc-ZKBETR03 = LW_KONP-KBETR. WHEN 'ZPK2'. ls_outtab_purchdoc-ZKBETR04 = LW_KONP-KBETR. WHEN 'ZTS2'. ls_outtab_purchdoc-ZKBETR05 = LW_KONP-KBETR. WHEN OTHERS. ENDCASE. ENDLOOP. APPEND ls_outtab_purchdoc to lt_outtab_purchdoc. ENDLOOP. ENDIF. delete <outtab> INDEX lv_tabix. ENDLOOP. SORT lt_outtab_purchdoc by EBELN EBELP DATBI01. APPEND LINES OF lt_outtab_purchdoc TO <outtab>. * REFRESH GT_OUTTAB_PURCHDOC_TMP. * APPEND LINES OF lt_outtab_purchdoc TO GT_OUTTAB_PURCHDOC_TMP. * ELSEIF my_struct_name = 'MEREP_OUTTAB_PURCHDOC_REL'. ** 合同审批的时候,处理 * LOOP AT <outtab> INTO lw_outtab_purchdoc_rel. * CHECK lw_outtab_purchdoc_rel-BSTYP = 'K'. ** CHECK ls_outtab_purchdoc-LOEKZ = ''. * lv_tabix = sy-tabix. * REFRESH: LT_A016,LT_KONP. * ** IF ls_outtab_purchdoc-LOEKZ <> ''. ** delete <outtab> INDEX lv_tabix. ** CONTINUE. ** ENDIF. * * SELECT * INTO TABLE LT_A016 FROM A016 * WHERE A016~KAPPL = 'M' * AND A016~EVRTN = lw_outtab_purchdoc_rel-ebeln * AND A016~EVRTP = lw_outtab_purchdoc_rel-ebelp * AND A016~DATBI >= SY-DATUM * AND A016~DATAB <= SY-DATUM."显示当前期间条件价格 * * IF SY-SUBRC = 0 and LT_A016[] is NOT INITIAL. * SELECT * INTO TABLE LT_KONP FROM KONP * FOR ALL ENTRIES IN LT_A016 * WHERE KONP~KNUMH = LT_A016-KNUMH * AND LOEVM_KO = ''. ** CLEAR <fs_outtab_purchdoc_rel>-NETPR. * LOOP at LT_A016 INTO LW_A016. * CLEAR:lw_outtab_purchdoc_rel-DATBI01, * lw_outtab_purchdoc_rel-DATAB01, * lw_outtab_purchdoc_rel-ZKBETR01, * lw_outtab_purchdoc_rel-ZKBETR02, * lw_outtab_purchdoc_rel-ZKBETR03, * lw_outtab_purchdoc_rel-ZKBETR04, * lw_outtab_purchdoc_rel-ZKBETR05, * lw_outtab_purchdoc_rel-NETPR. * lw_outtab_purchdoc_rel-DATBI01 = LW_A016-DATBI. * lw_outtab_purchdoc_rel-DATAB01 = LW_A016-DATAB. * LOOP AT LT_KONP INTO LW_KONP WHERE KNUMH = LW_A016-KNUMH. * lw_outtab_purchdoc_rel-NETPR = lw_outtab_purchdoc_rel-NETPR * + LW_KONP-KBETR. * CASE LW_KONP-KSCHL. * WHEN 'ZLGP' OR 'PB00'. * lw_outtab_purchdoc_rel-ZKBETR01 = LW_KONP-KBETR. * WHEN 'ZMP2'. * lw_outtab_purchdoc_rel-ZKBETR02 = LW_KONP-KBETR. * WHEN 'ZTP2'. * lw_outtab_purchdoc_rel-ZKBETR03 = LW_KONP-KBETR. * WHEN 'ZPK2'. * lw_outtab_purchdoc_rel-ZKBETR04 = LW_KONP-KBETR. * WHEN 'ZTS2'. * lw_outtab_purchdoc_rel-ZKBETR05 = LW_KONP-KBETR. * WHEN OTHERS. * ENDCASE. * * ENDLOOP. * APPEND lw_outtab_purchdoc_rel to lT_outtab_purchdoc_rel. * * ENDLOOP. * ELSE. * CLEAR lw_outtab_purchdoc_rel-NETPR. * ENDIF. ** delete <outtab> INDEX lv_tabix. * ENDLOOP. * <outtab> = lt_outtab_purchdoc_rel. ENDIF. *增加展示合同所有区间条件价格 at 20150901 by hp_gongzg ENDENHANCEMENT. *$*$-End: (1)---------------------------------------------------------------------------------$*$* ENDMETHOD. "if_reader_mm~read_table