文章目录
- ABAP 批次换算率和批次辅单位数量计算
- 第一种方式
- 批次换算率
- 获取辅单位
- 完整程序
- 运行结果
- 第二种方式
- 核心程序
- CONVERSION_EXIT_ATINN_INPUT:特征值转换
- 示例
ABAP 批次换算率和批次辅单位数量计算
如果一个物料有批次双单位,并且在报表里面展示批次辅单位的数量,则需要进行换算,下面是例子
第一种方式
批次换算率
CALL FUNCTION 'QC01_BATCH_VALUES_READ'EXPORTINGi_val_matnr = gs_total-matnri_val_werks = gs_total-werksi_val_charge = gs_total-chargi_language = sy-langui_date = sy-datum
* IMPORTING
* E_CLASS = E_CLASS
* E_CLASS_TYPE = E_CLASS_TYPETABLESt_val_tab = t_val_tabt_char_tab = t_char_tabt_att_tab = t_att_tabEXCEPTIONSno_class = 1internal_error = 2no_values = 3no_chars = 4OTHERS = 5.
获取辅单位
"-->辅单位SELECTa~matnr, "物料号"charg, "批次meinh "辅单位FROM @gt_total AS aLEFT JOIN marm AS b ON a~matnr = b~matnrINTO TABLE @DATA(gt_marm).SORT gt_marm BY matnr meinh.
完整程序
*&---------------------------------------------------------------------*
*& Report Z_BATCH_CONVERSION
*&---------------------------------------------------------------------*
*& TYPE:Report
*& Description:批次换算率和批次辅单位数量计算
*& Creator:Liuhongyu
*& Created On:2024年4月18日
*&---------------------------------------------------------------------*
* Change History
* ---------- ------------- ------------- -------------
* Version Date Change By Description
* ---------- ------------- ------------- -------------
* N 2024.4.18 Liuhongyu 创建
*&---------------------------------------------------------------------*
REPORT z_batch_conversion.*&-------------------变量定义------------------------------------------*
TYPES: BEGIN OF gty_alv,werks TYPE mchb-werks, "工厂matnr TYPE mchb-matnr, "物料编码maktx TYPE makt-maktx, "物料描述charg TYPE mchb-charg, "批次号clabs TYPE mchb-clabs, "批次数量meins TYPE mara-meins, "基本计量单位zfdwsh TYPE mchb-clabs, "批次辅单位数量meinh TYPE marm-meinh, "辅单位lgort TYPE mchb-lgort, "库存地点END OF gty_alv.DATA: gs_out TYPE gty_alv, "alv的工作区和内表gt_out TYPE TABLE OF gty_alv.DATA: gv_atflv TYPE p DECIMALS 8.
*&-------------------变量定义------------------------------------------**测试物料:EWM_RAW_01
*测试工厂:1710*&---------------------逻辑处理----------------------------------------*"-->获取数据SELECTa~werks, "工厂a~matnr, "物料号b~maktx, "物料描述a~charg, "批次号a~clabs, "批次数量c~meins, "基本计量单位a~lgort "库存地点FROM mchb AS aLEFT JOIN makt AS b ON a~matnr = b~matnrLEFT JOIN mara AS c ON a~matnr = c~matnrWHERE a~werks = '1710'AND a~matnr = 'EWM_RAW_01'AND b~spras = @sy-languINTO TABLE @DATA(gt_total).SORT gt_total BY werks matnr maktx charg clabs meins lgort."-->辅单位SELECTa~matnr, "物料号"charg, "批次meinh "辅单位FROM @gt_total AS aLEFT JOIN marm AS b ON a~matnr = b~matnrINTO TABLE @DATA(gt_marm).SORT gt_marm BY matnr meinh.LOOP AT gt_total INTO DATA(gs_total).READ TABLE gt_marm INTO DATA(gs_marm) WITH KEY matnr = gs_total-matnr BINARY SEARCH.IF sy-subrc = 0.MOVE-CORRESPONDING gs_total TO gs_out.
* DATA I_VAL_MATNR TYPE MARA-MATNR.
* DATA I_VAL_WERKS TYPE VBDPL-WERKS.
* DATA I_VAL_CHARGE TYPE VBDPL-CHARG.
* DATA I_LANGUAGE TYPE SY-LANGU.
* DATA I_DATE TYPE SY-DATUM.
* DATA E_CLASS TYPE KLAH-CLASS.
* DATA E_CLASS_TYPE TYPE KLAH-KLART.DATA t_val_tab TYPE STANDARD TABLE OF api_vali.DATA t_char_tab TYPE STANDARD TABLE OF api_char.DATA t_att_tab TYPE STANDARD TABLE OF api_ch_att.CALL FUNCTION 'QC01_BATCH_VALUES_READ'EXPORTINGi_val_matnr = gs_total-matnri_val_werks = gs_total-werksi_val_charge = gs_total-chargi_language = sy-langui_date = sy-datum
* IMPORTING
* E_CLASS = E_CLASS
* E_CLASS_TYPE = E_CLASS_TYPETABLESt_val_tab = t_val_tabt_char_tab = t_char_tabt_att_tab = t_att_tabEXCEPTIONSno_class = 1internal_error = 2no_values = 3no_chars = 4OTHERS = 5.IF sy-subrc = 0.LOOP AT t_val_tab INTO DATA(s_val_tab) WHERE atnam = 'Z_SW_DW_BA'.gv_atflv = s_val_tab-atflv.ENDLOOP.CLEAR s_val_tab.CLEAR:t_val_tab,t_char_tab,t_att_tab.IF gs_marm-meinh <> 'EA'.gs_out-zfdwsh = gv_atflv / gs_out-clabs.ELSE.gs_out-zfdwsh = gv_atflv * gs_out-clabs.ENDIF.ENDIF.gs_out-meinh = gs_marm-meinh.APPEND gs_out TO gt_out.CLEAR gs_out.ENDIF.ENDLOOP.cl_demo_output=>display( gt_out ).*&---------------------逻辑处理----------------------------------------*
运行结果
第二种方式
核心程序
"--> 辅单位SELECT a~matnr,a~meinh,a~atinn " 查询支数单位FROM marm AS aINNER JOIN @lt_data AS c ON a~matnr = c~matnrWHERE atinn <> ''INTO TABLE @DATA(lt_marm).SORT lt_marm BY matnr."--> 批次转换率SELECT a~matnr,a~werks,a~charg,inob~cuobj,inob~objek,ausp~atinn,ausp~atflv,ausp~ataweFROM inobJOIN ausp ON inob~cuobj = ausp~objekINNER JOIN @lt_data AS a ON substring( inob~objek , 1 , 18 ) = a~matnr AND substring( inob~objek , 41 , 10 ) = a~chargWHERE inob~klart = '023'AND inob~obtab = 'MCH1'AND ausp~atinn IN ( @lv_atinn_01,@lv_atinn_06,@lv_atinn_02 )INTO CORRESPONDING FIELDS OF TABLE @lt_charg."-->计算辅单位数量"辅单位READ TABLE lt_marm INTO DATA(ls_marm) WITH KEY matnr = ls_data-matnr BINARY SEARCH.IF sy-subrc EQ 0.gs_out-meinh = ls_marm-meinh.CLEAR lv_zenmng."--> 获取批次转换率,转换重量或支数READ TABLE lt_charg INTO ls_charg WITH KEY matnr = ls_data-matnr charg = ls_data-charg BINARY SEARCH.IF sy-subrc = 0.CLEAR ls_charg-atflv_c.CALL FUNCTION 'QSS0_FLTP_TO_CHAR_CONVERSION'EXPORTINGi_number_of_digits = 8i_fltp_value = ls_charg-atflvIMPORTINGe_char_field = ls_charg-atflv_c.CONDENSE ls_charg-atflv_c NO-GAPS.lv_zenmng = ls_charg-atflv_c.IF lv_zenmng = 0.lv_zenmng = 1.ENDIF.IF ls_marm-meinh <> 'KG'.gs_out-zqc_f = gs_out-zqc / lv_zenmng.gs_out-zqm_f = gs_out-zqm / lv_zenmng.gs_out-zrk_f = gs_out-zrk / lv_zenmng.gs_out-zck_f = gs_out-zck / lv_zenmng.ELSE.gs_out-zqc_f = gs_out-zqc * lv_zenmng.gs_out-zqm_f = gs_out-zqm * lv_zenmng.gs_out-zrk_f = gs_out-zrk * lv_zenmng.gs_out-zck_f = gs_out-zck * lv_zenmng.ENDIF.ENDIF.ENDIF.
CONVERSION_EXIT_ATINN_INPUT:特征值转换
因为在直接使用ZMM015这个特性值会报错
点击执行之后:
然而这个是N类型的,我们的筛选条件是C类型的,数据类型是不匹配的。
这个是经过转换的
所以我们使用CONVERSION_EXIT_ATINN_INPUT
进行转换即可
示例
*&------------------------Variables------------------------------------*DATA: lv_atinn_01 LIKE ausp-atinn.
*&--------------------------Logic--------------------------------------*"-->转换特征值CALL FUNCTION 'CONVERSION_EXIT_ATINN_INPUT'EXPORTINGinput = 'ZMM015'IMPORTINGoutput = lv_atinn_01.