1. 在这公司做项目不要相信任何文档。也不要相信任何所谓资深顾问。唯一可以相信的是代码。
2. 一定搞清楚使用人是谁,他是如何跟你核对数据的。
3. 使用不熟悉的标准数据源,还不如自己创建一个数据源。
4. VIEW中避免不必要的表,否则会增加C_T_DATA的行数.
5. IDOC的跨包问题,尚无解决方法,最好的方法是保证VIEW尽可能简洁不含不必要的行;其次的方法保证两次包中的数据一致,上传DSO中可以覆盖掉。
6. 增强数据源的时候,使用内表的时候,一定要使用CLEAR将表清空后再次使用。
**&---------------------------------------------------------------------*
**& Subroutine pool
**&
**&---------------------------------------------------------------------*
**& lipeng 2014-5-10 增强数据源
**&
**&---------------------------------------------------------------------*
*
PROGRAM ZBI_ZFICO15.
TYPE-POOLS: sbiwa.
TABLES:AUFK,
AFPO.
TYPES:
I_ZOXED10223 TYPE ZOXED10223 OCCURS 0.
*
TYPES : BEGIN OF TY_S_AFKO,
AUFNR TYPE AFKO-AUFNR,
RSNUM TYPE AFKO-RSNUM,
AUFPL TYPE AFKO-AUFPL,
END OF TY_S_AFKO,
TY_T_AFKO TYPE TABLE OF TY_S_AFKO.
DATA: LS_AFKO TYPE TY_S_AFKO,
LT_AFKO TYPE TY_T_AFKO,
LT_AFKO1 TYPE TY_T_AFKO.
*
TYPES : BEGIN OF TY_S_J_3AFSRESB,
RSNUM TYPE AFKO-RSNUM,
J_3AKORDX TYPE J_3AFSRESB-J_3AKORDX,
J_3APGNR TYPE J_3AFSRESB-J_3APGNR,
END OF TY_S_J_3AFSRESB,
TY_T_J_3AFSRESB TYPE TABLE OF TY_S_J_3AFSRESB.
DATA: LS_J_3AFSRESB TYPE TY_S_J_3AFSRESB,
LT_J_3AFSRESB TYPE TY_T_J_3AFSRESB.
*
TYPES : BEGIN OF TY_S_MBEW,
BWKEY TYPE MBEW-BWKEY,
MATNR TYPE MBEW-MATNR,
BWTAR TYPE MBEW-BWTAR,
BKLAS TYPE MBEW-BKLAS,
END OF TY_S_MBEW,
TY_T_MBEW TYPE TABLE OF TY_S_MBEW.
DATA: LS_MBEW TYPE TY_S_MBEW,
LT_MBEW TYPE TY_T_MBEW.
*
*
TYPES : BEGIN OF TY_S_JEST,
OBJNR TYPE JEST-OBJNR,
INACT TYPE JEST-INACT,
STAT TYPE JEST-STAT,
END OF TY_S_JEST,
TY_T_JEST TYPE TABLE OF TY_S_JEST.
DATA: LS_JEST TYPE TY_S_JEST,
LT_JEST TYPE TY_T_JEST.
*
*
TYPES : BEGIN OF TY_S_TJ02T,
ISTAT TYPE TJ02T-ISTAT,
TXT04 TYPE TJ02T-TXT04,
TXT30 TYPE TJ02T-TXT30,
END OF TY_S_TJ02T,
TY_T_TJ02T TYPE TABLE OF TY_S_TJ02T.
DATA: LS_TJ02T TYPE TY_S_TJ02T,
LT_TJ02T TYPE TY_T_TJ02T.
*
**
TYPES : BEGIN OF TY_S_COSP,
LEDNR TYPE COSP-LEDNR,
OBJNR TYPE COSP-OBJNR,
GJAHR TYPE COSP-GJAHR,
WRTTP TYPE COSP-WRTTP,
VERSN TYPE COSP-VERSN,
KSTAR TYPE COSP-KSTAR,
HRKFT TYPE COSP-HRKFT,
VRGNG TYPE COSP-VRGNG,
VBUND TYPE COSP-VBUND,
PARGB TYPE COSP-PARGB,
BEKNZ TYPE COSP-BEKNZ,
TWAER TYPE COSP-TWAER,
PERBL TYPE COSP-PERBL,
WKG001 TYPE COSP-WKG001,
WKG002 TYPE COSP-WKG001,
WKG003 TYPE COSP-WKG001,
WKG004 TYPE COSP-WKG001,
WKG005 TYPE COSP-WKG001,
WKG006 TYPE COSP-WKG001,
WKG007 TYPE COSP-WKG001,
WKG008 TYPE COSP-WKG001,
WKG009 TYPE COSP-WKG001,
WKG010 TYPE COSP-WKG001,
WKG011 TYPE COSP-WKG001,
WKG012 TYPE COSP-WKG001,
WKGSUM TYPE COSP-WKG001,
"I TYPE I,
END OF TY_S_COSP,
TY_T_COSP TYPE TABLE OF TY_S_COSP.
DATA: LS_COSP TYPE TY_S_COSP,
LT_COSP1 TYPE TY_T_COSP,
LT_COSP3 TYPE TY_T_COSP,
LT_COSP4 TYPE TY_T_COSP.
TYPES : BEGIN OF TY_S_COSS,
LEDNR TYPE COSS-LEDNR,
OBJNR TYPE COSS-OBJNR,
GJAHR TYPE COSS-GJAHR,
WRTTP TYPE COSS-WRTTP,
VERSN TYPE COSS-VERSN,
KSTAR TYPE COSS-KSTAR,
HRKFT TYPE COSS-HRKFT,
VRGNG TYPE COSS-VRGNG,
PAROB TYPE COSS-PAROB,
USPOB TYPE COSS-USPOB,
BEKNZ TYPE COSS-BEKNZ,
TWAER TYPE COSS-TWAER,
PERBL TYPE COSS-PERBL,
WKG001 TYPE COSS-WKG001,
WKG002 TYPE COSS-WKG001,
WKG003 TYPE COSS-WKG001,
WKG004 TYPE COSS-WKG001,
WKG005 TYPE COSS-WKG001,
WKG006 TYPE COSS-WKG001,
WKG007 TYPE COSS-WKG001,
WKG008 TYPE COSS-WKG001,
WKG009 TYPE COSS-WKG001,
WKG010 TYPE COSS-WKG001,
WKG011 TYPE COSS-WKG001,
WKG012 TYPE COSS-WKG001,
WKGSUM TYPE COSS-WKG001,
I TYPE I,
END OF TY_S_COSS,
TY_T_COSS TYPE TABLE OF TY_S_COSS.
DATA: LS_COSS TYPE TY_S_COSS,
LT_COSS1 TYPE TY_T_COSS,
LT_COSS4 TYPE TY_T_COSS.
*
******以下标准料的逻辑, 待定:
*
*
TYPES : BEGIN OF TY_S_RESB,
RSNUM TYPE RESB-RSNUM,
RSPOS TYPE RESB-RSPOS,
RSART TYPE RESB-RSART,
PLNFL TYPE RESB-PLNFL,
MATNR2 TYPE RESB-MATNR,
VORNR TYPE RESB-VORNR,
AUFNR TYPE RESB-AUFNR,
GPREIS TYPE RESB-GPREIS,
BDMNG TYPE RESB-BDMNG,
WKG011 TYPE COSS-WKG011,
END OF TY_S_RESB,
TY_T_RESB TYPE TABLE OF TY_S_RESB.
DATA: LS_RESB TYPE TY_S_RESB,
LT_RESB TYPE TY_T_RESB,
LT_RESB1 TYPE TY_T_RESB.
*
*
*
******COEP的相关定义
** COEP
TYPES : BEGIN OF TY_S_COEP,
KOKRS TYPE COEP-KOKRS,
BELNR TYPE COEP-BELNR,
BUZEI TYPE COEP-BUZEI,
OBJNR TYPE COEP-OBJNR,
WRTTP TYPE COEP-WRTTP,
KSTAR TYPE COEP-KSTAR,
MATNR TYPE COEP-MATNR,
WKGBTR TYPE COEP-WKGBTR,
AUFNR TYPE AUFK-AUFNR,
END OF TY_S_COEP,
TY_T_COEP TYPE TABLE OF TY_S_COEP.
DATA: LS_COEP TYPE TY_S_COEP,
LT_COEP1 TYPE TY_T_COEP,
LT_COEP2 TYPE TY_T_COEP,
LT_COEP TYPE TY_T_COEP.
**
*&---------------------------------------------------------------------*
Form CALL_USER_EXIT tables i_t_select type sbiwa_t_select
i_t_fields type sbiwa_t_fields
c_t_data structure ZOXED10223
c_t_messages type balmi_tab.
DATA: LS_RESULT LIKE ZOXED10223,
LT_RESULT like ZOXED10223 Occurs 0.
DATA: LS_RESULT1 LIKE ZOXED10223,
LS_RESULT2 LIKE ZOXED10223,
LT_RESULT1 LIKE ZOXED10223 OCCURS 0.
DATA: I_RECORD TYPE I.
I_RECORD = 0 .
*
FIELD-SYMBOLS : <L_RESULT> TYPE ZOXED10223,
<L_RESULT1> TYPE ZOXED10223.
*
BREAK-POINT.
LT_RESULT[] = C_T_DATA[].
SORT LT_RESULT BY AUFNR.
DELETE ADJACENT DUPLICATES FROM LT_RESULT COMPARING AUFNR.
IF NOT LT_RESULT[] IS INITIAL.
CLEAR LT_AFKO.
SELECT
AUFNR
RSNUM
AUFPL
INTO TABLE LT_AFKO
FROM AFKO
FOR ALL ENTRIES IN LT_RESULT
WHERE AUFNR = LT_RESULT-AUFNR.
SORT LT_AFKO BY AUFNR.
CLEAR LT_AFKO1.
SELECT
AUFNR
RSNUM
INTO TABLE LT_AFKO1
FROM AFKO
FOR ALL ENTRIES IN LT_RESULT
WHERE AUFNR = LT_RESULT-AUFNR.
SORT LT_AFKO BY AUFNR.
DELETE ADJACENT DUPLICATES FROM LT_AFKO1 COMPARING AUFNR RSNUM.
*
CLEAR LT_J_3AFSRESB.
SELECT
RSNUM
J_3AKORDX
J_3APGNR
INTO TABLE LT_J_3AFSRESB
FROM J_3AFSRESB
FOR ALL ENTRIES IN LT_RESULT
WHERE RSNUM = LT_RESULT-RSNUM
AND RSPOS = '1' .
SORT LT_J_3AFSRESB BY RSNUM.
*
CLEAR LT_MBEW.
SELECT
BWKEY
MATNR
BWTAR
BKLAS
INTO TABLE LT_MBEW
FROM MBEW
FOR ALL ENTRIES IN LT_RESULT
WHERE BWKEY = LT_RESULT-WERKS
AND MATNR = LT_RESULT-PLNBEZ.
SORT LT_MBEW BY BWKEY MATNR BKLAS.
*
CLEAR LT_JEST.
SELECT
OBJNR
INACT
STAT
INTO TABLE LT_JEST
FROM JEST
FOR ALL ENTRIES IN LT_RESULT
WHERE OBJNR = LT_RESULT-OBJNR
AND ( STAT = 'I0012' OR STAT = 'I0045' )
AND INACT EQ SPACE.
SORT LT_JEST BY OBJNR STAT.
CLEAR LT_TJ02T.
SELECT ISTAT
TXT04
TXT30
INTO TABLE LT_TJ02T
FROM TJ02T
FOR ALL ENTRIES IN LT_JEST
WHERE ISTAT = LT_JEST-STAT
AND SPRAS = '1'.
SORT LT_TJ02T BY ISTAT TXT04.
*
*
CLEAR LT_COEP.
CLEAR LT_COEP1.
CLEAR LT_COEP2.
SELECT KOKRS
BELNR
BUZEI
OBJNR
WRTTP
KSTAR
MATNR
WKGBTR
INTO TABLE LT_COEP1
FROM COEP
FOR ALL ENTRIES IN LT_RESULT
WHERE OBJNR = LT_RESULT-OBJNR
AND WRTTP EQ '04'."未去除物料。
LT_COEP2[] = LT_COEP1[].
LOOP AT LT_COEP1 INTO LS_COEP WHERE KSTAR = '5001010000'.
READ TABLE LT_RESULT INTO LS_RESULT WITH KEY OBJNR = LS_COEP-OBJNR.
IF SY-SUBRC = 0.
LS_COEP-AUFNR = LS_RESULT-AUFNR.
ENDIF.
APPEND LS_COEP TO LT_COEP. "COEP1加上订单号
CLEAR LS_RESULT.
ENDLOOP.
CLEAR LT_COEP1.
LT_COEP1[] = LT_COEP[].
CLEAR LT_COEP.
SORT LT_COEP1 BY AUFNR MATNR.
DELETE ADJACENT DUPLICATES FROM LT_COEP1 COMPARING AUFNR MATNR. " LT_COEP1订单带物料
LOOP AT LT_COEP2 INTO LS_COEP WHERE KSTAR NE '5001080000'.
CLEAR LS_COEP-KOKRS.
CLEAR LS_COEP-BELNR.
CLEAR LS_COEP-BUZEI.
CLEAR LS_COEP-MATNR.
COLLECT LS_COEP INTO LT_COEP.
ENDLOOP. "去除物料的
SORT LT_COEP BY OBJNR KSTAR. "LT_COEP 为成本要素的合计
************************以下为标准料的取值,“2016-10-21 待定
CLEAR LT_RESB.
CLEAR LT_RESB1.
CLEAR LS_RESB.
SELECT
RSNUM
RSPOS
RSART
PLNFL
MATNR
VORNR
AUFNR
GPREIS
BDMNG
INTO TABLE LT_RESB
FROM RESB
FOR ALL ENTRIES IN LT_AFKO1
WHERE RSNUM = LT_AFKO1-RSNUM .
CLEAR LS_COEP.
LOOP AT LT_COEP1 INTO LS_COEP.
LOOP AT LT_RESB INTO LS_RESB WHERE AUFNR = LS_COEP-AUFNR AND MATNR2 = LS_COEP-MATNR.
LS_RESB-WKG011 = LS_RESB-GPREIS * LS_RESB-BDMNG.
CLEAR LS_RESB-RSPOS.
CLEAR LS_RESB-RSART.
CLEAR LS_RESB-MATNR2.
CLEAR LS_RESB-GPREIS.
CLEAR LS_RESB-BDMNG.
COLLECT LS_RESB INTO LT_RESB1.
ENDLOOP.
ENDLOOP.
CLEAR LT_RESB.
LT_RESB[] = LT_RESB1[].
SORT LT_RESB BY AUFNR. " lT_RESB 为 COEP1中物料的标准值
*
*
*
CLEAR LT_COSP1.
SELECT
LEDNR OBJNR GJAHR WRTTP VERSN KSTAR HRKFT VRGNG VBUND
PARGB BEKNZ TWAER PERBL
WKG001 WKG002 WKG003 WKG004 WKG005 WKG006
WKG007 WKG008 WKG009 WKG010 WKG011 WKG012
INTO TABLE LT_COSP1
FROM COSP
FOR ALL ENTRIES IN LT_RESULT
WHERE OBJNR = LT_RESULT-OBJNR
AND WRTTP = '01'. "标准
CLEAR LT_COSP4.
LOOP AT LT_COSP1 INTO LS_COSP.
CLEAR: LS_COSP-LEDNR,
LS_COSP-GJAHR, LS_COSP-WRTTP, LS_COSP-VERSN, LS_COSP-HRKFT, LS_COSP-VRGNG, LS_COSP-VBUND,
LS_COSP-PARGB, LS_COSP-BEKNZ, LS_COSP-TWAER, LS_COSP-PERBL.
COLLECT LS_COSP INTO LT_COSP4.
ENDLOOP.
LT_COSP1[] = LT_COSP4[].
CLEAR: LT_COSP4. CLEAR: LS_COSP.
SORT LT_COSP1 BY OBJNR KSTAR.
*
CLEAR LT_COSS1.
SELECT
LEDNR OBJNR GJAHR WRTTP VERSN KSTAR HRKFT VRGNG PAROB
USPOB BEKNZ TWAER PERBL
WKG001 WKG002 WKG003 WKG004 WKG005 WKG006
WKG007 WKG008 WKG009 WKG010 WKG011 WKG012
INTO TABLE LT_COSS1
FROM COSS
FOR ALL ENTRIES IN LT_RESULT
WHERE OBJNR = LT_RESULT-OBJNR
AND WRTTP = '01'. "标准
CLEAR LT_COSS4.
LOOP AT LT_COSS1 INTO LS_COSS.
CLEAR: LS_COSS-LEDNR,
LS_COSS-LEDNR,LS_COSS-GJAHR ,LS_COSS-WRTTP ,LS_COSS-VERSN ,LS_COSS-HRKFT ,LS_COSS-VRGNG ,LS_COSS-PAROB
,LS_COSS-USPOB ,LS_COSS-BEKNZ ,LS_COSS-TWAER ,LS_COSS-PERBL.
COLLECT LS_COSS INTO LT_COSS4.
ENDLOOP.
LT_COSS1[] = LT_COSS4[].
CLEAR LT_COSS4. CLEAR LS_COSS.
SORT LT_COSS1 BY OBJNR KSTAR.
*
*
*
*
ENDIF.
***---------------------------------------------------------------
LOOP AT LT_RESULT into LS_RESULT.
READ TABLE LT_J_3AFSRESB INTO LS_J_3AFSRESB WITH KEY RSNUM = LS_RESULT-RSNUM BINARY SEARCH.
IF SY-SUBRC = 0.
LS_RESULT-J_3AKORDX = LS_J_3AFSRESB-J_3AKORDX." 网格值
LS_RESULT-J_3APGNR = LS_J_3AFSRESB-J_3APGNR.
ENDIF.
*
READ TABLE LT_MBEW INTO LS_MBEW WITH KEY BWKEY = LS_RESULT-WERKS MATNR = LS_RESULT-PLNBEZ BINARY SEARCH.
IF SY-SUBRC = 0.
LS_RESULT-BKLAS = LS_MBEW-BKLAS." 评估类
ENDIF.
*
READ TABLE LT_JEST INTO LS_JEST WITH KEY OBJNR = LS_RESULT-OBJNR BINARY SEARCH.
IF SY-SUBRC = 0.
LS_RESULT-STAT = LS_JEST-STAT." 对象状态
ENDIF.
*
READ TABLE LT_TJ02T INTO LS_TJ02T WITH KEY ISTAT = LS_RESULT-STAT BINARY SEARCH.
IF SY-SUBRC = 0.
LS_RESULT-TXT04 = LS_TJ02T-TXT04.
"LS_RESULT-TXT30 = LS_TJ02T-TXT30.
ENDIF." 订单状态
MODIFY LT_RESULT FROM LS_RESULT.
ENDLOOP.
DELETE LT_RESULT WHERE TXT04 EQ ''.
****************************************************************以上补上所有非数量字段
******************以下为实际值
LOOP AT LT_COEP INTO LS_COEP.
LOOP AT LT_RESULT INTO LS_RESULT WHERE OBJNR = LS_COEP-OBJNR.
LS_RESULT-KSTAR = LS_COEP-KSTAR.
IF LS_RESULT-WEMNG = 0.
LS_RESULT-WKG01 = 0.
ELSE.
LS_RESULT-WKG01 = LS_COEP-WKGBTR / LS_RESULT-WEMNG.
ENDIF.
APPEND LS_RESULT TO LT_RESULT1.
ENDLOOP .
ENDLOOP.
CLEAR LT_RESULT.
LT_RESULT[] = LT_RESULT1[].
***********************************以下为标准值。
LOOP AT LT_RESULT INTO LS_RESULT.
IF LS_RESULT-KSTAR = '5001010000'.
READ TABLE LT_RESB INTO LS_RESB WITH KEY RSNUM = LS_RESULT-RSNUM.
IF SY-SUBRC = 0 AND LS_RESULT-WEMNG <> 0.
LS_RESULT-WKG11 = LS_RESB-WKG011 / LS_RESULT-WEMNG.
ELSE.
LS_RESULT-WKG11 = 0.
ENDIF. "
CLEAR LS_RESB.
ELSEIF ( LS_RESULT-KSTAR GE '0000800100' AND LS_RESULT-KSTAR LE '0000800600' ).
READ TABLE LT_COSS1 INTO LS_COSS WITH KEY OBJNR = LS_RESULT-OBJNR KSTAR = LS_RESULT-KSTAR BINARY SEARCH.
IF SY-SUBRC = 0 AND LS_RESULT-WEMNG <> 0.
LS_COSS-WKGSUM = LS_COSS-WKG001 + LS_COSS-WKG002 + LS_COSS-WKG003 + LS_COSS-WKG004 + LS_COSS-WKG005 + LS_COSS-WKG006
+ LS_COSS-WKG007 + LS_COSS-WKG008 + LS_COSS-WKG009 + LS_COSS-WKG010 + LS_COSS-WKG011 + LS_COSS-WKG012.
LS_RESULT-WKG11 = LS_COSS-WKGSUM / LS_RESULT-WEMNG.
ENDIF."标准工/费
CLEAR LS_COSS.
ELSEIF ( LS_RESULT-KSTAR GE '5001090001' AND LS_RESULT-KSTAR LE '5001099999' ).
READ TABLE LT_COSP1 INTO LS_COSP WITH KEY OBJNR = LS_RESULT-OBJNR KSTAR = LS_RESULT-KSTAR BINARY SEARCH.
IF SY-SUBRC = 0 AND LS_RESULT-WEMNG <> 0.
LS_COSP-WKGSUM = LS_COSP-WKG001 + LS_COSP-WKG002 + LS_COSP-WKG003 + LS_COSP-WKG004 + LS_COSP-WKG005 + LS_COSP-WKG006
+ LS_COSP-WKG007 + LS_COSP-WKG008 + LS_COSP-WKG009 + LS_COSP-WKG010 + LS_COSP-WKG011 + LS_COSP-WKG012.
LS_RESULT-WKG01 = LS_COSP-WKGSUM / LS_RESULT-WEMNG.
ENDIF."标准/委外
CLEAR LS_COSP.
ENDIF.
MODIFY LT_RESULT FROM LS_RESULT.
ENDLOOP.
CLEAR c_t_data. REFRESH c_t_data.
c_t_data[] = LT_RESULT[].
CLEAR LS_RESULT. REFRESH LT_RESULT.
*
ENDFORM. "CALL_USER_EXIT