这里用到两次replace拼接物料和批次之间的空格
"批次特征值 SELECT a~matnr,a~charg,b~objek,c~atwrt,e~zcwms FROM @lt_data AS a INNER JOIN inob AS b ON b~klart = '023' AND b~obtab = 'MCH1' AND objek = replace( replace( concat( rpad( a~matnr, 40, '*' ), a~charg ), '*', ' + ' ), '+', ' ' ) INNER JOIN ausp AS c ON b~cuobj = CAST( c~objek AS NUMC ) AND c~klart = b~klart INNER JOIN cabn AS d ON c~atinn = d~atinn AND d~atnam IN ('ZBATCH_CSPC') INNER JOIN ksml AS f ON c~atinn = f~imerk INNER JOIN klah AS g ON f~clint = g~clint AND g~class = 'ZBATCH' LEFT JOIN zmmt031 AS e ON c~atwrt = e~zbin WHERE a~emlif IS INITIAL INTO TABLE @DATA(lt_ausp1). SORT lt_ausp1 BY matnr charg. * "物料特征值 * SELECT DISTINCT * a~matnr, * d~atnam, "类型 * c~atwrt, "特征值 * e~atwtb, "特征值描述 * g~class * FROM @lt_data AS a * INNER JOIN ausp AS c ON c~objek = a~matnr AND datub >= @sy-datum * INNER JOIN cabn AS d ON c~atinn = d~atinn * INNER JOIN cawnt AS e ON c~atinn = e~atinn AND lpad( c~atzhl,4,'0' ) = e~atzhl AND spras = '1' * INNER JOIN ksml AS f ON c~atinn = f~imerk * INNER JOIN klah AS g ON f~clint = g~clint * WHERE a~emlif IS INITIAL * INTO TABLE @DATA(lt_ausp2). * SORT lt_ausp2 BY matnr.
物料特征值因为上面是直接数据库里取数,但是金额字段显示为科学计数法,需要用BAPI转换成数量。也可以直接用下面BAPI取特征值
DATA: lv_objectkey TYPE bapi1003_key-object, lv_classnumnew TYPE bapi1003_key-classnum, lt_return TYPE STANDARD TABLE OF bapiret2, lt_allocvaluesnum TYPE STANDARD TABLE OF bapi1003_alloc_values_num, "数值型特性值 ls_allocvaluesnum TYPE bapi1003_alloc_values_num, lt_allocvalueschar TYPE STANDARD TABLE OF bapi1003_alloc_values_char, "字符型特性值 ls_allocvalueschar TYPE bapi1003_alloc_values_char, lt_allocvaluescurr TYPE STANDARD TABLE OF bapi1003_alloc_values_curr, "金额型特性值 ls_allocvaluescurr TYPE bapi1003_alloc_values_curr, lv_num_char TYPE qsollwertc. "特征值 IF ls_data-matkl(3) = 'A01'. lv_classnumnew = 'ZR01_ZZ'. "纸类 ELSEIF ( ls_data-matkl(3) = 'A02' OR ls_data-matkl(3) = 'A03' OR ls_data-matkl(3) = 'A04' ). lv_classnumnew = 'ZR01_FZZ'. "非纸类 ENDIF. lv_objectkey = ls_data-matnr. CLEAR lt_allocvalueschar. CALL FUNCTION 'BAPI_OBJCL_GETDETAIL' EXPORTING objectkey = lv_objectkey "物料编码 objecttable = 'MARA' classnum = lv_classnumnew "分类编号 classtype = '001' "分类的类型 TABLES allocvaluesnum = lt_allocvaluesnum "数值型特性值 allocvalueschar = lt_allocvalueschar "字符型特性值 allocvaluescurr = lt_allocvaluescurr "货币型特性值 return = lt_return. "返回值. LOOP AT lt_allocvalueschar INTO ls_allocvalueschar. CASE ls_allocvalueschar-charact. WHEN 'ZR01_002'. ms_out-zr01_002 = ls_allocvalueschar-value_neutral_long. ms_out-zr01_002t = ls_allocvalueschar-value_char_long.. WHEN OTHERS. ENDCASE. ENDLOOP. LOOP AT lt_allocvaluesnum INTO ls_allocvaluesnum. CASE ls_allocvaluesnum-charact. WHEN 'ZR01_009'. "长度 CLEAR:lv_num_char. CALL FUNCTION 'QSS0_FLTP_TO_CHAR_CONVERSION' "科学计数法转换成char EXPORTING i_number_of_digits = 0 i_fltp_value = ls_allocvaluesnum-value_from i_value_not_initial_flag = 'X' i_screen_fieldlength = 16 IMPORTING e_char_field = lv_num_char. CONDENSE lv_num_char NO-GAPS. ms_out-zr01_009 = lv_num_char. WHEN OTHERS. ENDCASE. ENDLOOP.
标签:特征值,JOIN,lt,取数,ABAP,ls,lv,TYPE,allocvalueschar From: https://www.cnblogs.com/yangliu11223/p/17851969.html