1 *&---------------------------------------------------------------------* 2 *& 包括 ZCM_ZMARC_DMSNEW_F01 3 *&---------------------------------------------------------------------* 4 5 FORM SUB_SETDMS USING P_WERKS TYPE MARC-WERKS. 6 7 ***常量*** 8 CONSTANTS: C_VTWEG LIKE S983-VTWEG VALUE ‘30‘, "*分销渠道** 9 C_FACTOR TYPE P LENGTH 2 DECIMALS 2 VALUE ‘0.3‘,"*FACTOR值** 10 C_MAX_DATA_RANGE TYPE I VALUE 10. "DMS最大计算日期范围. 11 12 DATA: L_WA_ZMARCFACTOR TYPE ZMARCFACTOR. 13 DATA: L_DATE TYPE DATS, 14 L_DMS TYPE P LENGTH 12 DECIMALS 2. 15 DATA: L_OBJECTCLAS LIKE CDHDR-OBJECTCLAS, 16 L_LASTDATE TYPE DATS, "*存放DMS最后更新日期** 17 L_FACTOR_C(4) TYPE C, 18 L_ERROR(1) TYPE C, 19 L_CNT TYPE I. 20 21 L_DATE = SY-DATUM - 1."做前一天的. 22 23 PERFORM SUB_ADDLOG USING TEXT-013 ‘S‘. "*添加日志信息.** 24 25 ***从ZMARCLOG表中取出最后更新日期*** 26 CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘ 27 EXPORTING 28 INPUT = ‘ZDMS‘ 29 IMPORTING 30 OUTPUT = L_OBJECTCLAS. 31 32 SELECT SINGLE * INTO CORRESPONDING FIELDS OF G_WA_ZMARCLOG 33 FROM ZMARCDMSLOG 34 WHERE ZTYPE = ‘6‘ 35 AND WERKS = P_WERKS. 36 37 IF SY-SUBRC <> 0. 38 G_WA_ZMARCLOG-OBJECTCLAS = L_OBJECTCLAS. 39 G_WA_ZMARCLOG-ZTYPE = ‘6‘. 40 G_WA_ZMARCLOG-WERKS = P_WERKS. 41 G_WA_ZMARCLOG-ZFLAG = SPACE. "初始值为空。 42 ENDIF. 43 44 ***从日志中查看今天是否已做过,做过,退出*** 45 CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_OUTPUT‘ 46 EXPORTING 47 INPUT = G_WA_ZMARCLOG-CHANGENR 48 IMPORTING 49 OUTPUT = G_WA_ZMARCLOG-CHANGENR. 50 51 SHIFT G_WA_ZMARCLOG-CHANGENR LEFT DELETING LEADING ‘0‘. 52 L_LASTDATE = G_WA_ZMARCLOG-CHANGENR+0(8). 53 ***判断日期有效性!!!!*** 54 CALL FUNCTION ‘DATE_CHECK_PLAUSIBILITY‘ 55 EXPORTING 56 DATE = L_LASTDATE 57 EXCEPTIONS 58 PLAUSIBILITY_CHECK_FAILED = 1 59 OTHERS = 2. 60 61 ***L_CNT = L_DATE - L_LASTDATE. 62 IF SY-SUBRC <> 0. 63 CONCATENATE TEXT-026 L_LASTDATE INTO G_WA_ZXSYSLOG-ZDESC. "*生成日志信息.** 64 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 65 PERFORM SUB_ADDLOG USING TEXT-024 ‘E‘. "*添加日志信息.** 66 RETURN. 67 ENDIF. 68 69 ***判断DMS是否已计算过.*** 判断日期和是否执行成功。by sunxm add. 70 IF L_LASTDATE >= L_DATE AND G_WA_ZMARCLOG-ZFLAG = ‘X‘. 71 CONCATENATE TEXT-023 L_LASTDATE ‘-‘ P_WERKS INTO G_WA_ZXSYSLOG-ZDESC. 72 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘W‘. "*添加日志信息.** 73 PERFORM SUB_ADDLOG USING TEXT-024 ‘E‘. "*添加日志信息.** 74 RETURN. 75 ENDIF. 76 77 ***取出factor数据*** 78 SELECT SINGLE FACTOR INTO CORRESPONDING FIELDS OF L_WA_ZMARCFACTOR 79 FROM ZMARCFACTOR. 80 81 ***如未取出factor值.停止计算*** 82 IF SY-SUBRC <> 0. 83 CONCATENATE ‘未找到FACTOR的值.‘ TEXT-024 INTO G_WA_ZXSYSLOG-ZDESC. 84 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 85 RETURN. 86 ENDIF. 87 88 ****如果中间有N天未算,要补算.*** 89 WHILE L_LASTDATE < L_DATE. 90 L_LASTDATE = L_LASTDATE + 1. 91 ***生成临时数据*** 92 PERFORM SUB_SET_DMSTD USING L_LASTDATE P_WERKS 93 CHANGING L_ERROR. 94 95 IF L_ERROR <> ‘‘. 96 EXIT. 97 ENDIF. 98 ***计算DMS*** 99 PERFORM SUB_SET_DMSCALC USING L_WA_ZMARCFACTOR-FACTOR P_WERKS 100 CHANGING L_ERROR. 101 102 IF L_ERROR <> ‘‘. 103 EXIT. 104 ENDIF. 105 ***写入ZMARC*** 106 PERFORM SUB_SET_DMSSYNC USING L_LASTDATE L_WA_ZMARCFACTOR-FACTOR P_WERKS 107 CHANGING L_ERROR. 108 109 IF L_ERROR <> ‘‘. 110 EXIT. 111 ENDIF. 112 113 ENDWHILE. 114 115 IF L_ERROR = ‘‘. 116 CONCATENATE TEXT-029 L_FACTOR_C INTO G_WA_ZXSYSLOG-ZDESC. 117 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘S‘. "*添加日志信息.** 118 ELSE. 119 CONCATENATE TEXT-030 L_FACTOR_C INTO G_WA_ZXSYSLOG-ZDESC. 120 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 121 ENDIF. 122 123 124 ENDFORM. "sub_setdms 125 126 127 128 ********************************功能注释******************************** 129 **功能名称: SUB_ADDLOG 130 **功能说明: 添加系统日志内容。 131 ** xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 132 ** 参数 参数类型 说明 133 ** ------- ------------- ---------------------------------- 134 ** xxxxx xxxxxxxx xxxxxxxxxxxxxxxxxxxxxx 135 ** xxxxx xxxxxxxx xxxxxxxxxxxxxxxxxxxxxx 136 ************************************************************************ 137 138 FORM SUB_ADDLOG USING P_MSG TYPE C P_ETYPE TYPE C. 139 G_WA_ZXSYSLOG-ZDESC = P_MSG. "*生成日志信息.** 140 G_WA_ZXSYSLOG-ZETYPE = P_ETYPE. 141 G_WA_ZXSYSLOG-ZNO = G_WA_ZXSYSLOG-ZNO + 1. 142 APPEND G_WA_ZXSYSLOG TO G_ITAB_ZXSYSLOG. 143 ENDFORM. "SUB_ADDLOG 144 145 ********************************功能注释******************************** 146 **功能名称: SUB_SAVELOG 147 **功能说明: 保存系统日志。 148 ** xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 149 ** 参数 参数类型 说明 150 ** ------- ------------- ---------------------------------- 151 ** xxxxx xxxxxxxx xxxxxxxxxxxxxxxxxxxxxx 152 ** xxxxx xxxxxxxx xxxxxxxxxxxxxxxxxxxxxx 153 ************************************************************************ 154 155 FORM SUB_SAVELOG . 156 CALL FUNCTION ‘ZFUN_CREATE_LOG‘ 157 EXPORTING 158 P_OBJECT = ‘ZCM‘ "*对象名.** 159 P_SUBOBJECT = ‘ZMARC‘ "*子对象名.** 160 TABLES 161 P_ITAB_LOG = G_ITAB_ZXSYSLOG. "*日志内容内表.** 162 163 ENDFORM. " SUB_SAVELOG 164 165 166 167 168 ********************************功能注释******************************** 169 **功能名称: SUB_SET_DMSTD 170 **功能说明: 生成DMS临时数据. 171 ** 参数 参数类型 说明 172 ** ------- ------------- ---------------------------------- 173 ** P_DATE DATS 计算DMS的日期 174 ** P_RETURN C 返回值.空:成功.X:出错. 175 ************************************************************************ 176 FORM SUB_SET_DMSTD USING P_DATE TYPE DATS 177 P_WERKS TYPE MARC-WERKS 178 CHANGING P_RETURN TYPE C. 179 180 DATA: L_DATERANGE TYPE DATS, 181 L_WA_ZMARCDMS LIKE ZMARCDMS. 182 PERFORM SUB_ADDLOG USING TEXT-018 ‘S‘. "*添加日志信息.** 183 184 FREE P_RETURN. 185 L_DATERANGE = P_DATE - 6."7天内.包括当天,所以少减一天. 186 187 ***查询ZMARCDMS中是否有数据*** 188 SELECT SINGLE * INTO CORRESPONDING FIELDS OF L_WA_ZMARCDMS 189 FROM ZMARCDMS 190 WHERE WERKS = P_WERKS. 191 IF SY-SUBRC <> 4. 192 DELETE FROM ZMARCDMS WHERE WERKS = P_WERKS. 193 IF SY-SUBRC = 0. 194 CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘. 195 ELSE. 196 P_RETURN = ‘X‘. 197 CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 198 CONCATENATE TEXT-020 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 199 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 200 RETURN. 201 ENDIF. 202 ENDIF. 203 204 ***1.STORE*** 205 ***1.1 生成7天有销售的数据-门店*** 206 *** BY SUNXM 加地点条件 207 FREE EXC_REF. 208 TRY. 209 EXEC SQL. 210 INSERT INTO ZMARCDMS(MANDT,MATNR,WERKS) 211 (SELECT DISTINCT A.MANDT,A.MATNR,A.WERKS 212 FROM S983 A,T001W B 213 WHERE A.MANDT=B.MANDT AND A.WERKS=B.WERKS 214 AND B.WERKS = :P_WERKS 215 AND A.MANDT = :SY-MANDT AND B.VLFKZ = :C_VLFKZ_ST 216 AND A.SPTAG >= :L_DATERANGE AND A.SPTAG <= :P_DATE 217 AND A.VTWEG <> :C_VTWEG 218 AND A.VKBUR = ‘ ‘) 219 ENDEXEC. 220 **获取错误.*** 221 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 222 ERROR_TEXT = EXC_REF->GET_TEXT( ). 223 ENDTRY. 224 225 IF EXC_REF IS INITIAL. 226 CALL FUNCTION ‘DB_COMMIT‘. 227 ELSE. 228 P_RETURN = ‘X‘. 229 * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 230 CONCATENATE TEXT-020 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 231 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 232 RETURN. 233 ENDIF. 234 235 IF P_DMSN IS NOT INITIAL. 236 **新算法. 237 ***1.1B 按促销单,生成促销售据-门店 和 DC*** 238 DATA: BEGIN OF LT_PROMOTION OCCURS 0, 239 AKTNR LIKE WAKP-AKTNR, 240 MATNR LIKE WAKP-ARTNR, 241 KUNNR LIKE WALE-KUNNR, 242 WERKS LIKE T001W-WERKS, 243 AKART LIKE WAKH-AKART, 244 EKKPS LIKE WAKP-EKKPS,"*采购价格条件** 245 VKKPS LIKE WAKP-VKKPS,"*维护销售价格条件的状态** 246 * EKKON LIKE WAKP-EKKON,"*创建采购价格条件记录** 247 * VKKON LIKE WAKP-VKKON,"*创建销售价格条件记录** 248 EKGEN LIKE WALE-EKGEN,"*采购价格生成状态 249 END OF LT_PROMOTION. 250 251 DATA: LT_PRO_DMS LIKE ZMARCDMS OCCURS 0 WITH HEADER LINE, 252 LT_PRO_DMS_DC LIKE ZMARCDMS OCCURS 0 WITH HEADER LINE. 253 254 *** 转换地点用。 255 DATA: LW_KUNNR LIKE WALE-KUNNR. 256 257 FIELD-SYMBOLS: <LFS_PRO> LIKE LINE OF LT_PROMOTION. 258 259 TYPES: BEGIN OF LX_T001W, 260 WERKS LIKE T001W-WERKS, 261 VLFKZ LIKE T001W-VLFKZ, 262 END OF LX_T001W. 263 264 DATA LT_T001W TYPE LX_T001W OCCURS 0. 265 "取 DC 编号 266 SELECT WERKS 267 INTO CORRESPONDING FIELDS OF TABLE LT_T001W 268 FROM T001W 269 WHERE VLFKZ = C_VLFKZ_DC 270 AND WERKS = P_WERKS. " by sunxm 加地点条件。 271 SORT LT_T001W BY WERKS. 272 273 CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘ 274 EXPORTING 275 INPUT = P_WERKS 276 IMPORTING 277 OUTPUT = LW_KUNNR. 278 279 SELECT WAKP~AKTNR WAKP~ARTNR AS MATNR 280 WALE~KUNNR WAKH~AKART WAKP~EKKPS WAKP~VKKPS WALE~EKGEN 281 FROM WAKH 282 INNER JOIN WAKP ON WAKH~AKTNR = WAKP~AKTNR 283 INNER JOIN WALE ON WAKP~ARTNR = WALE~ARTNR AND WAKP~AKTNR = WALE~AKTNR 284 INTO CORRESPONDING FIELDS OF TABLE LT_PROMOTION 285 WHERE WAKH~VKDAB <= P_DATE 286 AND WAKH~VKDBI >= P_DATE 287 AND WALE~KUNNR = LW_KUNNR " by sunxm 加地点条件。!!! 时间要改为wakh判断。 288 * AND wale~vkdab <= p_date 289 * AND wale~vkdbi >= p_date 290 AND WAKH~AKART IN (‘ZS01‘,‘ZP02‘,‘ZP03‘). 291 292 LOOP AT LT_PROMOTION ASSIGNING <LFS_PRO> . 293 CASE <LFS_PRO>-AKART. 294 WHEN ‘ZS01‘."销售促销 295 CHECK <LFS_PRO>-VKKPS = ‘B‘. 296 WHEN ‘ZP03‘."进价促销 297 CHECK <LFS_PRO>-EKKPS = ‘B‘. 298 CHECK <LFS_PRO>-EKGEN = ‘B‘. 299 WHEN ‘ZP02‘."进售价联动促销 300 CHECK <LFS_PRO>-VKKPS = ‘B‘. 301 CHECK <LFS_PRO>-EKKPS = ‘B‘. 302 CHECK <LFS_PRO>-EKGEN = ‘B‘. 303 ENDCASE. 304 305 CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_OUTPUT‘ 306 EXPORTING 307 INPUT = <LFS_PRO>-KUNNR 308 IMPORTING 309 OUTPUT = <LFS_PRO>-WERKS. 310 311 LT_PRO_DMS-MATNR = <LFS_PRO>-MATNR. 312 LT_PRO_DMS-WERKS = <LFS_PRO>-WERKS. 313 LT_PRO_DMS-AKTNR = <LFS_PRO>-AKTNR. 314 READ TABLE LT_T001W WITH KEY 315 WERKS = <LFS_PRO>-WERKS BINARY SEARCH TRANSPORTING NO FIELDS. 316 IF SY-SUBRC = 0. 317 "DC 促销信息。 318 APPEND LT_PRO_DMS TO LT_PRO_DMS_DC. 319 ELSE. 320 "门店促销信息。 321 APPEND LT_PRO_DMS. 322 ENDIF. 323 324 ENDLOOP. 325 IF LINES( LT_PRO_DMS ) > 0. 326 MODIFY ZMARCDMS FROM TABLE LT_PRO_DMS . 327 IF SY-SUBRC = 0. 328 COMMIT WORK. 329 ELSE. 330 ROLLBACK WORK. 331 P_RETURN = ‘X‘. 332 * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 333 CONCATENATE TEXT-020 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 334 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 335 RETURN. 336 ENDIF. 337 338 FREE LT_PRO_DMS. 339 ENDIF. 340 341 ENDIF. 342 343 344 345 ****begin added by zhangwei 增加解决map为零商品的dms计算逻辑。 2012-11-20 346 ****首先计算出所有的门店销售记录。此步骤并不排除sto数量。排除条件 and A.UMSGEO <> 0 347 FREE EXC_REF. 348 TRY. 349 EXEC SQL. 350 UPDATE ZMARCDMS C SET (C.AKTNR,C.UMSMNG)=( 351 SELECT MAX(A.AKTNR) AKTNR,SUM(A.UMSMNG) UMSMNG 352 FROM S983 A,T001W B 353 WHERE C.MANDT=A.MANDT AND C.MATNR=A.MATNR 354 AND C.WERKS=A.WERKS 355 AND A.MANDT=B.MANDT AND A.WERKS=B.WERKS 356 AND A.MANDT = :SY-MANDT AND B.VLFKZ = :C_VLFKZ_ST 357 AND B.WERKS = :P_WERKS 358 AND A.SPTAG = :P_DATE 359 AND A.VTWEG <> :C_VTWEG 360 AND A.VKBUR = ‘ ‘ 361 AND A.UMSMNG <> 0 362 363 GROUP BY A.MANDT,A.MATNR,A.WERKS 364 ) 365 WHERE EXISTS 366 (SELECT 1 367 FROM S983 A,T001W B 368 WHERE C.MANDT=A.MANDT AND C.MATNR=A.MATNR 369 AND C.WERKS=A.WERKS 370 AND A.MANDT=B.MANDT AND A.WERKS=B.WERKS 371 AND A.MANDT = :SY-MANDT AND B.VLFKZ = :C_VLFKZ_ST 372 AND B.WERKS = :P_WERKS 373 AND A.SPTAG = :P_DATE 374 AND A.VTWEG <> :C_VTWEG 375 AND A.VKBUR = ‘ ‘ 376 AND A.UMSMNG <> 0 377 378 GROUP BY A.MANDT,A.MATNR,A.WERKS 379 ) 380 381 ENDEXEC. 382 **获取错误.*** 383 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 384 ERROR_TEXT = EXC_REF->GET_TEXT( ). 385 ENDTRY. 386 387 IF EXC_REF IS INITIAL. 388 CALL FUNCTION ‘DB_COMMIT‘. 389 ELSE. 390 P_RETURN = ‘X‘. 391 * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 392 CONCATENATE TEXT-020 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 393 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 394 RETURN. 395 ENDIF. 396 397 ****begin added by zhangwei 增加解决map为零商品的dms计算逻辑。 2012-11-20 398 ****首先计算出所有的门店销售记录。此步骤并不排除sto数量。 399 400 401 402 403 ***1.2 生成当日销售数据-门店*** 404 *** by sunxm 加地点条件。 405 *** by sunxm add DMS取数据逻辑修改 RELK900040 20120530. 406 *** sum(a.umsmng) 替换为. sum(umsmng-kzwi2/(umsgeo/umsmng)) 407 FREE EXC_REF. 408 TRY. 409 EXEC SQL. 410 UPDATE ZMARCDMS C SET (C.AKTNR,C.UMSMNG)=( 411 SELECT MAX(A.AKTNR) AKTNR,SUM(A.UMSMNG-A.KZWI2/(A.UMSGEO/A.UMSMNG)) UMSMNG 412 FROM S983 A,T001W B 413 WHERE C.MANDT=A.MANDT AND C.MATNR=A.MATNR 414 AND C.WERKS=A.WERKS 415 AND A.MANDT=B.MANDT AND A.WERKS=B.WERKS 416 AND A.MANDT = :SY-MANDT AND B.VLFKZ = :C_VLFKZ_ST 417 AND B.WERKS = :P_WERKS 418 AND A.SPTAG = :P_DATE 419 AND A.VTWEG <> :C_VTWEG 420 AND A.VKBUR = ‘ ‘ 421 AND A.UMSMNG <> 0 422 and A.UMSGEO <> 0 423 GROUP BY A.MANDT,A.MATNR,A.WERKS 424 ) 425 WHERE EXISTS 426 (SELECT 1 427 FROM S983 A,T001W B 428 WHERE C.MANDT=A.MANDT AND C.MATNR=A.MATNR 429 AND C.WERKS=A.WERKS 430 AND A.MANDT=B.MANDT AND A.WERKS=B.WERKS 431 AND A.MANDT = :SY-MANDT AND B.VLFKZ = :C_VLFKZ_ST 432 AND B.WERKS = :P_WERKS 433 AND A.SPTAG = :P_DATE 434 AND A.VTWEG <> :C_VTWEG 435 AND A.VKBUR = ‘ ‘ 436 AND A.UMSMNG <> 0 437 and A.UMSGEO <> 0 438 GROUP BY A.MANDT,A.MATNR,A.WERKS 439 ) 440 441 ENDEXEC. 442 **获取错误.*** 443 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 444 ERROR_TEXT = EXC_REF->GET_TEXT( ). 445 ENDTRY. 446 447 IF EXC_REF IS INITIAL. 448 CALL FUNCTION ‘DB_COMMIT‘. 449 ELSE. 450 P_RETURN = ‘X‘. 451 * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 452 CONCATENATE TEXT-020 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 453 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 454 RETURN. 455 ENDIF. 456 457 458 459 460 ***2.DC*** "ABGMNG ,KMAMNG 461 ***2.1 生成7天有商品转移的数据-DC 462 ***2.2 用S984 替换 S083 信息结构. by sunxm 2011-5-13. 463 *** BY SUNXM 加地点条件。 464 FREE EXC_REF. 465 TRY. 466 EXEC SQL. 467 INSERT INTO ZMARCDMS(MANDT,MATNR,WERKS) 468 (SELECT DISTINCT A.MANDT,A.MATNR,A.WERKS 469 FROM S984 A,T001W B 470 WHERE A.MANDT = B.MANDT AND A.WERKS = B.WERKS 471 AND A.MANDT = :SY-MANDT AND B.VLFKZ = :C_VLFKZ_DC 472 AND B.WERKS = :P_WERKS 473 AND A.SPTAG >= :L_DATERANGE AND A.SPTAG <= :P_DATE 474 AND ( A.KMAMNG <> 0 OR A.UMSMNG <> 0 )) 475 ENDEXEC. 476 **获取错误.*** 477 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 478 ERROR_TEXT = EXC_REF->GET_TEXT( ). 479 ENDTRY. 480 481 IF EXC_REF IS INITIAL. 482 CALL FUNCTION ‘DB_COMMIT‘. 483 ELSE. 484 P_RETURN = ‘X‘. 485 * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 486 CONCATENATE TEXT-020 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 487 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 488 RETURN. 489 ENDIF. 490 491 IF P_DMSN IS NOT INITIAL. 492 **新算法. 493 ***1.1B 按促销单,生成促销售据-DC*** 494 IF LINES( LT_PRO_DMS_DC ) > 0. 495 MODIFY ZMARCDMS FROM TABLE LT_PRO_DMS_DC . 496 IF SY-SUBRC = 0. 497 COMMIT WORK. 498 ELSE. 499 ROLLBACK WORK. 500 P_RETURN = ‘X‘. 501 * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 502 CONCATENATE TEXT-020 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 503 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 504 RETURN. 505 ENDIF. 506 507 FREE LT_PRO_DMS_DC. 508 ENDIF. 509 ENDIF. 510 511 ***2.2 生成当日商品转移数据-DC*** 512 *** BY SUNXM 加地点条件. 513 FREE EXC_REF. 514 TRY. 515 EXEC SQL. 516 517 UPDATE ZMARCDMS C SET (C.UMSMNG)=( 518 SELECT SUM(A.KMAMNG + A.UMSMNG) UMSMNG 519 * SELECT SUM(A.ABGMNG) UMSMNG 520 FROM S984 A,T001W B 521 WHERE C.MANDT=A.MANDT AND C.MATNR=A.MATNR 522 AND C.WERKS=A.WERKS 523 AND A.MANDT=B.MANDT AND A.WERKS=B.WERKS 524 AND A.MANDT = :SY-MANDT AND B.VLFKZ = :C_VLFKZ_DC 525 AND B.WERKS = :P_WERKS 526 AND A.SPTAG = :P_DATE 527 AND ( A.KMAMNG <> 0 OR A.UMSMNG <> 0 ) 528 * AND A.SPTAG = :P_DATE AND A.ABGMNG <> 0 529 GROUP BY A.MANDT,A.MATNR,A.WERKS 530 ) 531 WHERE EXISTS 532 (SELECT 1 533 FROM S984 A,T001W B 534 WHERE C.MANDT=A.MANDT AND C.MATNR=A.MATNR 535 AND C.WERKS=A.WERKS 536 AND A.MANDT=B.MANDT AND A.WERKS=B.WERKS 537 AND A.MANDT = :SY-MANDT AND B.VLFKZ = :C_VLFKZ_DC 538 AND B.WERKS = :P_WERKS 539 AND A.SPTAG = :P_DATE 540 AND ( A.KMAMNG <> 0 OR A.UMSMNG <> 0 ) 541 * AND A.SPTAG = :P_DATE AND A.ABGMNG <> 0 542 GROUP BY A.MANDT,A.MATNR,A.WERKS 543 ) 544 ENDEXEC. 545 **获取错误.*** 546 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 547 ERROR_TEXT = EXC_REF->GET_TEXT( ). 548 ENDTRY. 549 550 IF EXC_REF IS INITIAL. 551 CALL FUNCTION ‘DB_COMMIT‘. 552 ELSE. 553 P_RETURN = ‘X‘. 554 * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 555 CONCATENATE TEXT-020 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 556 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 557 RETURN. 558 ENDIF. 559 560 ***3.加入DMS*** 561 *** by sunxm 加地点条件. 562 FREE EXC_REF. 563 IF P_DMSN IS INITIAL. 564 TRY. 565 EXEC SQL. 566 UPDATE (SELECT A.ZDMS,B.ZDMS AS NEWZDMS 567 FROM ZMARCDMS A,ZMARC B 568 WHERE A.MANDT=B.MANDT AND A.MATNR=B.MATNR 569 AND A.WERKS=B.WERKS AND A.MANDT = :SY-MANDT 570 AND A.WERKS = :P_WERKS 571 ) 572 SET ZDMS=NEWZDMS 573 ENDEXEC. 574 **获取错误.*** 575 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 576 ERROR_TEXT = EXC_REF->GET_TEXT( ). 577 ENDTRY. 578 ELSE. 579 "新DMS算法 580 TRY. 581 EXEC SQL. 582 UPDATE (SELECT A.ZDMS_N,A.ZDMS_P 583 ,B.ZDMS_N AS NEWZDMS_N,B.ZDMS_P AS NEWZDMS_P 584 FROM ZMARCDMS A,ZMARC B 585 WHERE A.MANDT=B.MANDT AND A.MATNR=B.MATNR 586 AND A.WERKS=B.WERKS AND A.MANDT = :SY-MANDT 587 AND A.WERKS = :P_WERKS 588 ) 589 SET ZDMS_N=NEWZDMS_N 590 ,ZDMS_P=NEWZDMS_P 591 ENDEXEC. 592 **获取错误.*** 593 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 594 ERROR_TEXT = EXC_REF->GET_TEXT( ). 595 ENDTRY. 596 ENDIF. 597 598 IF EXC_REF IS INITIAL. 599 CALL FUNCTION ‘DB_COMMIT‘. 600 ELSE. 601 P_RETURN = ‘X‘. 602 * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 603 CONCATENATE TEXT-020 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 604 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 605 RETURN. 606 ENDIF. 607 608 PERFORM SUB_ADDLOG USING TEXT-019 ‘S‘. "*添加日志信息.** 609 610 ENDFORM. "sub_set_dmstd 611 612 613 614 ********************************功能注释******************************** 615 **功能名称: SUB_SET_DMSCALC 616 **功能说明: 计算DMS BY SUNXM 加地点条件。 617 ** 参数 参数类型 说明 618 ** ------- ------------- ---------------------------------- 619 ** P_FATCOR ZMARCFACTOR-FACTOR 计算DMS的FACTOR 系数 620 ** P_RETURN C 返回值.空:成功.X:出错. 621 ************************************************************************ 622 FORM SUB_SET_DMSCALC USING P_FACTOR LIKE ZMARCFACTOR-FACTOR 623 P_WERKS LIKE MARC-WERKS 624 CHANGING P_RETURN TYPE C. 625 626 DATA: L_SUBFACTOR LIKE ZMARCFACTOR-FACTOR. 627 628 L_SUBFACTOR = 1 - P_FACTOR. 629 630 FREE P_RETURN. 631 FREE EXC_REF. 632 IF P_DMSN IS INITIAL. 633 TRY. 634 635 ***1.计算 正常销售 并且 原DMS >0 的数据*** 636 ***在正常销售时dms = 当日销售数量 * factor + (1 - factor) * dms*** 637 EXEC SQL. 638 UPDATE ZMARCDMS SET ZDMS = ROUND(UMSMNG * :P_FACTOR + ZDMS * :L_SUBFACTOR,2) 639 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND AKTNR = ‘ ‘ AND ZDMS > 0 640 ENDEXEC. 641 642 ***2.计算 促销销售 并且 原DMS >0 的数据*** 643 ***促销销售时dms = 当日销售数量 * (1-factor) + factor * dms*** 644 EXEC SQL. 645 UPDATE ZMARCDMS SET ZDMS = ROUND(UMSMNG * :L_SUBFACTOR + ZDMS * :P_FACTOR,2) 646 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND AKTNR <> ‘ ‘ AND ZDMS > 0 647 ENDEXEC. 648 ***3.计算 原DMS = 0 的数据;*** 649 ***因为UMSMNG与ZDMS位数不一致,先将UMSMNG更新,避免溢出*** 650 EXEC SQL. 651 UPDATE ZMARCDMS SET UMSMNG = 99999 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS = 0 AND UMSMNG > 99999 652 ENDEXEC. 653 654 EXEC SQL. 655 UPDATE ZMARCDMS SET UMSMNG = 0.05 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS = 0 AND UMSMNG < 0.05 656 ENDEXEC. 657 658 EXEC SQL. 659 UPDATE ZMARCDMS SET ZDMS = ROUND(UMSMNG,2) WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS = 0 660 ENDEXEC. 661 **4. DMS >99999 -> =99999 *** 662 EXEC SQL. 663 UPDATE ZMARCDMS SET ZDMS = 99999 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS > 99999 664 ENDEXEC. 665 **5. DMS <0.05 -> =0.05 *** 666 EXEC SQL. 667 UPDATE ZMARCDMS SET ZDMS = 0.05 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS < 0.05 668 ENDEXEC. 669 **获取错误.*** 670 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 671 ERROR_TEXT = EXC_REF->GET_TEXT( ). 672 ENDTRY. 673 ELSE. 674 "新DMS算法 675 TRY. 676 677 ***1.计算 正常销售 并且 原DMS <>0 的数据*** 678 ***在正常销售时dms = 当日销售数量 * factor + (1 - factor) * dms*** 679 EXEC SQL. 680 UPDATE ZMARCDMS SET ZDMS = ROUND(UMSMNG * :P_FACTOR + ZDMS_N * :L_SUBFACTOR,2) 681 ,ZDMS_N = ROUND(UMSMNG * :P_FACTOR + ZDMS_N * :L_SUBFACTOR,2) 682 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND AKTNR = ‘ ‘ AND ZDMS_N <> 0 683 ENDEXEC. 684 COMMIT WORK. 685 ***2.计算 促销销售 并且 原DMS <>0 的数据*** 686 ***促销销售时dms = 当日销售数量 * (1-factor) + factor * dms*** 687 EXEC SQL. 688 UPDATE ZMARCDMS SET ZDMS = ROUND(UMSMNG * :L_SUBFACTOR + ZDMS_P * :P_FACTOR,2) 689 ,ZDMS_P = ROUND(UMSMNG * :L_SUBFACTOR + ZDMS_P * :P_FACTOR,2) 690 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND AKTNR <> ‘ ‘ AND ZDMS_P <> 0 691 ENDEXEC. 692 COMMIT WORK. 693 ***3.计算 原DMS = 0 的数据;*** 694 ***因为UMSMNG与ZDMS位数不一致,先将UMSMNG更新,避免溢出*** 695 EXEC SQL. 696 UPDATE ZMARCDMS SET UMSMNG = 99999 697 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND UMSMNG > 99999 AND (ZDMS_N = 0 OR ZDMS_P = 0) 698 ENDEXEC. 699 COMMIT WORK. 700 EXEC SQL. 701 UPDATE ZMARCDMS SET UMSMNG = 0.05 702 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND UMSMNG < 0.05 AND (ZDMS_N = 0 OR ZDMS_P = 0) 703 ENDEXEC. 704 COMMIT WORK. 705 EXEC SQL. 706 UPDATE ZMARCDMS SET ZDMS = ROUND(UMSMNG,2) 707 ,ZDMS_N = ROUND(UMSMNG,2) 708 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS_N = 0 AND AKTNR = ‘ ‘ 709 ENDEXEC. 710 COMMIT WORK. 711 EXEC SQL. 712 UPDATE ZMARCDMS SET ZDMS = ROUND(UMSMNG,2) 713 ,ZDMS_P = ROUND(UMSMNG,2) 714 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS_P = 0 AND AKTNR <> ‘ ‘ 715 ENDEXEC. 716 COMMIT WORK. 717 **4. DMS >99999 -> =99999 *** 718 EXEC SQL. 719 UPDATE ZMARCDMS SET ZDMS = 99999 720 ,ZDMS_N = 99999 721 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS_N > 99999 722 ENDEXEC. 723 COMMIT WORK. 724 EXEC SQL. 725 UPDATE ZMARCDMS SET ZDMS = 99999 726 ,ZDMS_P = 99999 727 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS_P > 99999 728 ENDEXEC. 729 COMMIT WORK. 730 **5. DMS <0.05 -> =0.05 *** 731 EXEC SQL. 732 UPDATE ZMARCDMS SET ZDMS = 0.05 733 ,ZDMS_N = 0.05 734 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS_N < 0.05 AND ZDMS_N <> 0 735 ENDEXEC. 736 COMMIT WORK. 737 EXEC SQL. 738 UPDATE ZMARCDMS SET ZDMS = 0.05 739 ,ZDMS_P = 0.05 740 WHERE MANDT = :SY-MANDT AND WERKS = :P_WERKS AND ZDMS_P < 0.05 AND ZDMS_P <> 0 741 ENDEXEC. 742 COMMIT WORK. 743 **获取错误.*** 744 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 745 ERROR_TEXT = EXC_REF->GET_TEXT( ). 746 ENDTRY. 747 ENDIF. 748 749 IF EXC_REF IS INITIAL. 750 CALL FUNCTION ‘DB_COMMIT‘. 751 PERFORM SUB_ADDLOG USING TEXT-029 ‘S‘. "*添加日志信息.** 752 ELSE. 753 P_RETURN = ‘X‘. 754 * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 755 CONCATENATE TEXT-030 ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 756 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 757 RETURN. 758 ENDIF. 759 760 761 762 ENDFORM. "sub_set_dmscalc 763 764 765 766 ********************************功能注释******************************** 767 **功能名称: SUB_SET_DMSSYNC 768 **功能说明: DMS数据写入ZMARC,并保存增量日志. 769 ** 参数 参数类型 说明 770 ** ------- ------------- ---------------------------------- 771 ** P_DATE DATS 计算DMS的日期 772 ** P_RETURN C 返回值.空:成功.X:出错. 773 ************************************************************************ 774 FORM SUB_SET_DMSSYNC USING P_DATE TYPE DATS 775 P_FACTOR LIKE ZMARCFACTOR-FACTOR 776 P_WERKS LIKE MARC-WERKS 777 CHANGING P_RETURN TYPE C. 778 DATA: L_SUBFACTOR LIKE ZMARCFACTOR-FACTOR. 779 780 L_SUBFACTOR = 1 - P_FACTOR. 781 FREE P_RETURN. 782 FREE EXC_REF. 783 784 DATA: MY_SEED LIKE QF00-RAN_INT VALUE 1, 785 MY_VALUE LIKE QF00-RAN_INT VALUE 0, 786 MY_SEND TYPE P LENGTH 10 DECIMALS 2. 787 788 CALL FUNCTION ‘QF05_RANDOM_INTEGER‘ 789 EXPORTING 790 RAN_INT_MAX = 2 791 RAN_INT_MIN = 1 792 IMPORTING 793 RAN_INT = MY_SEED. "种子 794 795 DO 5 TIMES. 796 797 CALL FUNCTION ‘QF05_RANDOM_INTEGER‘ 798 EXPORTING 799 RAN_INT_MAX = 2000 800 RAN_INT_MIN = 500 801 IMPORTING 802 RAN_INT = MY_VALUE. 803 804 IF P_DMSN IS INITIAL. 805 TRY. 806 EXEC SQL. 807 UPDATE (SELECT A.ZDMS,B.ZDMS AS NEWZDMS 808 ,A.UDATE,to_char(sysdate,‘yyyymmdd‘) AS NEWUDATE 809 FROM ZMARC A,ZMARCDMS B 810 WHERE A.MANDT=B.MANDT AND A.MATNR=B.MATNR 811 AND A.WERKS=B.WERKS AND A.MANDT = :SY-MANDT 812 AND B.WERKS = :P_WERKS 813 ) 814 SET ZDMS = NEWZDMS 815 ,UDATE = NEWUDATE 816 817 ENDEXEC. 818 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 819 ERROR_TEXT = EXC_REF->GET_TEXT( ). 820 ENDTRY. 821 ELSE. 822 TRY. 823 EXEC SQL. 824 UPDATE (SELECT A.ZDMS,A.ZDMS_N,A.ZDMS_P 825 ,B.ZDMS AS NEWZDMS,B.ZDMS_N AS NEWZDMS_N,B.ZDMS_P AS NEWZDMS_P 826 ,A.UDATE,to_char(sysdate,‘yyyymmdd‘) AS NEWUDATE 827 FROM ZMARC A,ZMARCDMS B 828 WHERE A.MANDT=B.MANDT AND A.MATNR=B.MATNR 829 AND A.WERKS=B.WERKS AND A.MANDT = :SY-MANDT 830 AND B.WERKS = :P_WERKS 831 ) 832 SET ZDMS = NEWZDMS 833 ,ZDMS_N=NEWZDMS_N 834 ,ZDMS_P=NEWZDMS_P 835 ,UDATE = NEWUDATE 836 837 ENDEXEC. 838 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 839 ERROR_TEXT = EXC_REF->GET_TEXT( ). 840 ENDTRY. 841 *** beg by sunxm 20120530 更改没有更新的数据。乘以系数值 842 TRY . 843 EXEC SQL. 844 UPDATE ZMARC SET ZDMS_N = ROUND(ZDMS_N * :L_SUBFACTOR,2), 845 ZDMS = ROUND(ZDMS * :L_SUBFACTOR,2) 846 WHERE not exists ( 847 SELECT * FROM ZMARCDMS 848 WHERE ZMARC.MATNR = ZMARCDMS.MATNR AND ZMARC.WERKS = ZMARCDMS.WERKS ) 849 AND ZMARC.WERKS = :P_WERKS 850 AND ZMARC.ZDMS_N <> 0 851 ENDEXEC. 852 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 853 ERROR_TEXT = EXC_REF->GET_TEXT( ). 854 ENDTRY. 855 856 ENDIF. 857 858 *****处理ZDMS_N < 0.05。 859 TRY . 860 EXEC SQL. 861 UPDATE ZMARC SET ZDMS_N = 0.05, 862 ZDMS = 0.05 863 WHERE not exists ( 864 SELECT * FROM ZMARCDMS 865 WHERE ZMARC.MATNR = ZMARCDMS.MATNR AND ZMARC.WERKS = ZMARCDMS.WERKS ) 866 AND ZMARC.WERKS = :P_WERKS 867 AND ZMARC.ZDMS_N < 0.05 868 AND ZMARC.ZDMS_N <> 0 869 ENDEXEC. 870 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF. 871 ERROR_TEXT = EXC_REF->GET_TEXT( ). 872 ENDTRY. 873 874 875 *** ***begin added by zhangwei : 从marc表中获取商品状态数据覆盖zmarc中商品状态、2013-07-15 876 877 878 * UPDATE ZMARC SET ZMARC.PERSTATUS = MARC.MMSTA, 879 * STATUSDATE = to_char(sysdate,‘yyyymmdd‘) 880 * WHERE exists ( 881 * SELECT MMSTA 882 * FROM MARC 883 * WHERE ZMARC.MANDT=MARC.MANDT AND ZMARC.MATNR=MARC.MATNR 884 * AND ZMARC.WERKS=MARC.WERKS ) 885 * AND ZMARC.MANDT = :SY-MANDT 886 * AND ZMARC.PERSTATUS <> 0 887 * AND ZMARC.WERKS = :P_WERKS 888 * IF P_ZT = ‘X‘. 889 * TRY . 890 * EXEC SQL. 891 * 892 * UPDATE (SELECT A.PERSTATUS,A.STATUSDATE,B.MMSTA, 893 * to_char(sysdate,‘yyyymmdd‘) AS NEWUDATE 894 * FROM ZMARC A,MARC B 895 * WHERE A.MANDT=B.MANDT AND A.MATNR=B.MATNR 896 * AND A.WERKS=B.WERKS AND A.MANDT = :SY-MANDT 897 * AND A.WERKS = :P_WERKS 898 * ) 899 * SET PERSTATUS = MMSTA, 900 * STATUSDATE = NEWUDATE 901 * 902 * ENDEXEC. 903 * CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF." AND A.PERSTATUS <> B.MMSTA 904 * ERROR_TEXT = EXC_REF->GET_TEXT( ). 905 * ENDTRY. 906 * ENDIF. 907 908 ***end added by zhangwei : 从marc表中获取商品状态数据覆盖zmarc中商品状态、2013-07-15 909 *** end by sunxm 20120530 更改没有更新的数据。 910 911 912 913 IF EXC_REF IS INITIAL. 914 *** 保存增量文档最后更新日期*** 915 G_WA_ZMARCLOG-CHANGENR = P_DATE. 916 * g_wa_zmarclog-werks = p_werks. " 添加地点。 917 G_WA_ZMARCLOG-ZFLAG = ‘X‘. " 更新成功。 by sunxm. 918 MODIFY ZMARCDMSLOG FROM G_WA_ZMARCLOG. 919 IF SY-SUBRC = 0. 920 CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘. 921 CONCATENATE TEXT-005 P_DATE ‘-‘ P_WERKS INTO G_WA_ZXSYSLOG-ZDESC. 922 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘S‘. "*添加日志信息.** 923 ELSE. 924 P_RETURN = ‘X‘. 925 CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 926 CONCATENATE TEXT-025 P_DATE INTO G_WA_ZXSYSLOG-ZDESC. 927 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 928 ENDIF. 929 *** 如果成功,退出循环。 930 EXIT. 931 ELSE. 932 P_RETURN = ‘X‘. 933 CALL FUNCTION ‘DB_ROLLBACK‘. 934 * g_wa_zmarclog-changenr = p_date. 935 * g_wa_zmarclog-werks = p_werks. " 添加地点。 936 G_WA_ZMARCLOG-ZFLAG = SPACE. " 更新失败。 by sunxm. 937 MODIFY ZMARCDMSLOG FROM G_WA_ZMARCLOG. 938 IF SY-SUBRC = 0. 939 CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘. 940 CONCATENATE TEXT-005 P_DATE ‘-‘ P_WERKS INTO G_WA_ZXSYSLOG-ZDESC. 941 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘S‘. "*添加日志信息.** 942 ELSE. 943 P_RETURN = ‘X‘. 944 CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. 945 CONCATENATE TEXT-025 P_DATE INTO G_WA_ZXSYSLOG-ZDESC. 946 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 947 ENDIF. 948 CONCATENATE TEXT-016 P_DATE ‘-‘ P_WERKS ERROR_TEXT INTO G_WA_ZXSYSLOG-ZDESC. 949 PERFORM SUB_ADDLOG USING G_WA_ZXSYSLOG-ZDESC ‘E‘. "*添加日志信息.** 950 *** 如果有异常,得到随机数,等待。 951 MY_SEND = MY_VALUE / 1000. 952 WAIT UP TO MY_SEND SECONDS. 953 *** 释放异常变量。 954 FREE EXC_REF. 955 ENDIF. 956 ENDDO. 957 958 ENDFORM. "sub_set_dmssync 959 960 961 *&---------------------------------------------------------------------* 962 *& Form sub_loopupdate 963 *&---------------------------------------------------------------------* 964 * text 循环处理P_DMS ZMARC数据。 965 *----------------------------------------------------------------------* 966 FORM SUB_LOOP_P_DMS USING P_WERKS LIKE MARC-WERKS. 967 * DATA : my_value LIKE qf00-ran_int VALUE 1, 968 * my_send TYPE p LENGTH 10 DECIMALS 2. 969 * 970 * FREE exc_ref. 971 * CLEAR my_send. 972 **** add random number beg. 973 * 974 * CALL FUNCTION ‘QF05_RANDOM_INTEGER‘ 975 * EXPORTING 976 * ran_int_max = 2000 977 * ran_int_min = 500 978 * IMPORTING 979 * ran_int = my_value. 980 **** 得到随机数。 981 * my_send = my_value / 1000. 982 * WAIT UP TO my_send SECONDS. 983 * TRY. 984 * EXEC SQL. 985 * UPDATE (SELECT A.ZDMS,B.ZDMS AS NEWZDMS 986 * ,A.UDATE,to_char(sysdate,‘yyyymmdd‘) AS NEWUDATE 987 * FROM ZMARC A,ZMARCDMS B 988 * WHERE A.MANDT=B.MANDT AND A.MATNR=B.MATNR 989 * AND A.WERKS=B.WERKS AND A.MANDT = :SY-MANDT 990 * AND B.WERKS = :P_WERKS 991 * ) 992 * SET ZDMS = NEWZDMS 993 * ,UDATE = NEWUDATE 994 * 995 * ENDEXEC. 996 * CATCH cx_sy_native_sql_error INTO exc_ref. 997 * error_text = exc_ref->get_text( ). 998 * ENDTRY. 999 *** add random number end. 1000 1001 ENDFORM. "sub_loopupdate 1002 1003 *&---------------------------------------------------------------------* 1004 *& Form sub_loop_p_dmsn 1005 *&---------------------------------------------------------------------* 1006 * text 循环处理P_DMSN ZMARC数据。 1007 *----------------------------------------------------------------------* 1008 FORM SUB_LOOP_P_DMSN USING P_WERKS LIKE MARC-WERKS. 1009 * DATA : my_seed LIKE qf00-ran_int, 1010 * my_value LIKE qf00-ran_int VALUE 0, 1011 * my_send TYPE p LENGTH 10 DECIMALS 2. 1012 * 1013 * FREE exc_ref. 1014 * CLEAR my_send. 1015 **** add random number beg. 1016 * CALL FUNCTION ‘QF05_RANDOM_INTEGER‘ 1017 * EXPORTING 1018 * ran_int_max = 2 1019 * ran_int_min = 1 1020 * IMPORTING 1021 * ran_int = my_seed. "种子 1022 * 1023 * CALL FUNCTION ‘QF05_RANDOM_INTEGER‘ 1024 * EXPORTING 1025 * ran_int_max = 2000 1026 * ran_int_min = 500 1027 * IMPORTING 1028 * ran_int = my_value. 1029 **** 得到随机数。 1030 * my_send = my_value / 1000. 1031 * WAIT UP TO my_send SECONDS. 1032 * TRY. 1033 * EXEC SQL. 1034 * UPDATE (SELECT A.ZDMS,A.ZDMS_N,A.ZDMS_P 1035 * ,B.ZDMS AS NEWZDMS,B.ZDMS_N AS NEWZDMS_N,B.ZDMS_P AS NEWZDMS_P 1036 * ,A.UDATE,to_char(sysdate,‘yyyymmdd‘) AS NEWUDATE 1037 * FROM ZMARC A,ZMARCDMS B 1038 * WHERE A.MANDT=B.MANDT AND A.MATNR=B.MATNR 1039 * AND A.WERKS=B.WERKS AND A.MANDT = :SY-MANDT 1040 * AND B.WERKS = :P_WERKS 1041 * ) 1042 * SET ZDMS = NEWZDMS 1043 * ,ZDMS_N=NEWZDMS_N 1044 * ,ZDMS_P=NEWZDMS_P 1045 * ,UDATE = NEWUDATE 1046 * 1047 * ENDEXEC. 1048 * CATCH cx_sy_native_sql_error INTO exc_ref. 1049 * error_text = exc_ref->get_text( ). 1050 * ENDTRY. 1051 1052 ENDFORM. "sub_loop_p_dmsn 1053 *&---------------------------------------------------------------------* 1054 *& Form SUB_UPDMMSTA 1055 *&---------------------------------------------------------------------* 1056 * text 1057 *----------------------------------------------------------------------* 1058 * --> p1 text 1059 * <-- p2 text 1060 *----------------------------------------------------------------------* 1061 FORM SUB_UPDMMSTA . 1062 DATA:P_WERKS LIKE MARC-WERKS. 1063 IF P_ZT = ‘X‘. 1064 LOOP AT S_WERKS. 1065 P_WERKS = S_WERKS-LOW. 1066 TRY . 1067 EXEC SQL. 1068 1069 UPDATE (SELECT A.PERSTATUS,A.STATUSDATE,B.MMSTA, 1070 to_char(sysdate,‘yyyymmdd‘) AS NEWUDATE 1071 FROM ZMARC A,MARC B 1072 WHERE A.MANDT=B.MANDT AND A.MATNR=B.MATNR 1073 AND A.WERKS=B.WERKS AND nvl(A.PERSTATUS,0) <> B.MMSTA AND A.MANDT = :SY-MANDT 1074 AND A.WERKS = :P_WERKS 1075 ) 1076 SET PERSTATUS = MMSTA, 1077 STATUSDATE = NEWUDATE 1078 1079 ENDEXEC. 1080 CATCH CX_SY_NATIVE_SQL_ERROR INTO EXC_REF." AND A.PERSTATUS <> B.MMSTA 1081 ERROR_TEXT = EXC_REF->GET_TEXT( ). 1082 ENDTRY. 1083 ENDLOOP. 1084 ENDIF. 1085 " 1086 IF EXC_REF IS INITIAL. 1087 CALL FUNCTION ‘DB_COMMIT‘. 1088 ELSE. 1089 CALL FUNCTION ‘DB_ROLLBACK‘. 1090 ENDIF. 1091 ENDFORM. " SUB_UPDMMSTA