*********************************************************************** * Title : YHLMR009 * * Application : LM * * Subject : 交货清单查询 * * Requested by : Yang_Teng Fei (YH_LM) * * Execution : Online when required * * Ref no: : ERPS0115 * * Author : AD_CAIXIANG * * Req Date : 20120722 * *********************************************************************** * 交货清单查询程序 * *********************************************************************** * 设计主要逻辑与原理说明 * *********************************************************************** *1.取数:根据用户的输入单据编号、交货单类型、计划发货日期、实际发货日期* * 配入机构、商品编码等输入条件单一或者组合进行交货订单的查询。 * * 涉及到的表 LIKP T001W KNA1 LIPS MARA MAKT MBEW MEAN LIPSD ZMADQ * *2.输出: 进行alv输出交货清单信息 * *********************************************************************** * MODIFICATIONS (latest entry at the top) * * ------------------------------------------------------------------- * * REL DATE NAME (COMPANY) DESCRIPTION TASK-NO * * --- ---- ---- --------- ----------- ------- * * 01 20121206 LM 交货清单查询修改 by AD_CAIXIANG ECDK906448 * * 02 20121210 LM 交货清单查询修改 by AD_CAIXIANG ECDK906618 * * 03 20121210 LN 程序规范化 by AD_CAIXIANG ECDK906622 * * 04 20130111 LM 加直接显示明细按钮 BY AD_CAIXIANG ECDK907564 * * 05 20130126 LM 交货单类型增添 BY AD_CAIXIANG ECDK907564 * * 06 20130222 LM 价格取数修改 移动类型671,673 ECDK908753.* * 价格取数改为 EKPO-KZWI1/EKPO-MENGE * * 07 20130402 LM 程序优化 BY AD_CAIXIANG ECDK910228 * * 08 20130516 LM 移出库位作为查询条件出现问题的修改 * * BY AD_CAIXIANG ECDK911439 * * 09 20130603 LM 价格取数问题调整 BY AD_CAIXIANG ECDK912048 * * 10 20130703 LM 取税率优化 BY AD_CAIXIANG ECDK912680 * * 11 20130726 LM 取数部分优化, * * 当S_WBSTK 为空的时候,把VBUK的取数单独出来, * * 对于EKPO和EKBE进行分批取数 ECDK913630 * *********************************************************************** REPORT YHLMR009 NO STANDARD PAGE HEADING LINE-SIZE 132 LINE-COUNT 65(1) MESSAGE-ID YH_LM1. *---------------------------------------------------------------------- * PUB-INCLDUE *---------------------------------------------------------------------- INCLUDE <ICON>. *INCLUDE YHLM009_TOP. *---------------------------------------------------------------------- * TYPE-POOLS *---------------------------------------------------------------------- TYPE-POOLS: SLIS. *--------------------------------------------------------------------* * 宏的调用方式: *--------------------------------------------------------------------* *---------------------------------------------------------------------- * TABLES/Structure *---------------------------------------------------------------------- TABLES: LIKP, "SD凭证:交货抬头数据 LIPS, "SD凭证 :交货:项目数据 KNA1, "客户主文件的一般数据 MBEW, "商品评估 MEAN, "商品的条码 LIPSD,"交货项目的动态部分 VBUK, "销售凭证:抬头状态和管理数据 VBFA, "销售凭证流 ADRP, "个人(办公地址管理) EKPO. "采购凭证项目 TABLES: MARA, MARC, MAKT, T001W. *---------------------------------------------------------------------- * Internal table *---------------------------------------------------------------------- DATA: BEGIN OF GT_ITAB OCCURS 0, VBELN LIKE LIKP-VBELN, POSNR LIKE LIPS-POSNR, LFART LIKE LIKP-LFART, WERKS LIKE LIPS-WERKS, NAME1 LIKE T001W-NAME1,"配出机构名称 KUNNR LIKE LIKP-KUNNR, NAME2 LIKE KNA1-NAME1, YYCARNO LIKE LIKP-YYCARNO, TDDAT LIKE LIKP-TDDAT, BLDAT LIKE LIKP-BLDAT, ANZPK LIKE LIKP-ANZPK, RESLO LIKE EKPO-RESLO, LGOBE1 LIKE T001L-LGOBE,"移出 LGORT LIKE LIPS-LGORT, LGOBE2 LIKE T001L-LGOBE,"移入 MENGE TYPE EKPO-MENGE, "订货数量 LFIMG TYPE LIPS-LFIMG, "实发数量 SHFA TYPE P DECIMALS 1, "实发件数 VGBEL LIKE LIPS-VGBEL, VGPOS LIKE LIPS-VGPOS, VGTYP LIKE LIPS-VGTYP, MATNR LIKE LIPS-MATNR, EAN11 LIKE MEAN-EAN11, WADAT_IST LIKE LIKP-WADAT_IST, MAKTX LIKE MAKT-MAKTX, MEINS LIKE LIPS-MEINS, VRKME LIKE LIPS-VRKME, GROES LIKE MARA-GROES, YUMREZ1 LIKE YTMADQ-YUMREZ1, BRGEW TYPE LIPS-BRGEW, "毛重 NTGEW TYPE LIPS-NTGEW, "净重 JINZH TYPE LIPS-NTGEW, "皮重 KOSTK TYPE VBUK-KOSTK, "交货状态 ERNAM LIKE LIKP-ERNAM, VTEXT TYPE TVLKT-VTEXT, DINH TYPE P DECIMALS 1,"订货件数 WBSTK TYPE VBUK-WBSTK, "状态 NAME_TEXT LIKE ADRP-NAME_FIRST, LIFEX TYPE LIKP-LIFEX, LIFNR TYPE EORD-LIFNR, NAME3 TYPE LFA1-NAME1, JIAGE TYPE EKPO-KZWI5, JINE TYPE EKPO-KZWI5, KZWI5 TYPE EKPO-KZWI5, DMBTR TYPE MSEG-DMBTR, ERZET TYPE LIKP-ERZET, BWART LIKE LIPS-BWART, KBETR TYPE KBETR, *&->START ADD BY AD_CAIXIANG ON 20130514. YLBID1 LIKE YTLBDY-YLBID2, YDLNAM LIKE YTLBCJ-YLBNAME, *&-END ADD TIMMM(14) TYPE C, FLAG(1) TYPE C, END OF GT_ITAB. DATA: BEGIN OF GT_DATA OCCURS 0, VBELN LIKE LIKP-VBELN, LFART LIKE LIKP-LFART, VTEXT TYPE TVLKT-VTEXT, WERKS LIKE LIPS-WERKS, NAME1 LIKE T001W-NAME1, KUNNR LIKE LIKP-KUNNR, NAME2 LIKE KNA1-NAME1, RESLO LIKE EKPO-RESLO, "移出 LGOBE1 LIKE T001L-LGOBE, LGORT LIKE EKPO-LGORT, "移入 LGOBE2 LIKE T001L-LGOBE, YYCARNO LIKE LIKP-YYCARNO, TDDAT LIKE LIKP-TDDAT, BLDAT LIKE LIKP-BLDAT, WADAT_IST LIKE LIKP-WADAT_IST, MENGE TYPE EKPO-MENGE, "订货数量 LFIMG TYPE LIPS-LFIMG, "实发数量 JINZH TYPE LIPS-NTGEW, "皮重 ERNAM LIKE LIKP-ERNAM, NAME_TEXT LIKE ADRP-NAME_FIRST, KOSTK TYPE VBUK-KOSTK, "交货状态 WBSTK TYPE VBUK-WBSTK, "状态 LIFEX TYPE LIKP-LIFEX, *&START CHANGED BY AD_CAIXIANG ON 20121210 ECDK906622 * LIFNR TYPE EORD-LIFNR, * NAME3 TYPE LFA1-NAME1, *&END CHANGED BY AD_CAIXIANG ON 20121210. ERZET TYPE LIPS-ERZET, JINE TYPE EKPO-KZWI5, * LNN TYPE SY-TABIX, END OF GT_DATA. *---------------------------------------------------------------------- * Variants *---------------------------------------------------------------------- DATA: G_LEN TYPE I. DATA: WA LIKE GT_ITAB. DATA: G_LIN TYPE I. DATA: G_TABIX LIKE SY-TABIX. RANGES:R_LFART FOR LIKP-LFART. *---------------------------------------------------------------------* * Data parameters for alv report use *---------------------------------------------------------------------* DATA: G_PROGRAM TYPE SY-REPID, GS_LAYOUT TYPE SLIS_LAYOUT_ALV, GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, GS_FIELDCAT LIKE LINE OF GT_FIELDCAT, GT_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV, GS_FIELDCAT2 LIKE LINE OF GT_FIELDCAT, WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV, IT_EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE, GT_EVENT TYPE SLIS_T_EVENT, WA_EVENT TYPE SLIS_ALV_EVENT. DATA: GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER. DATA: GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'ALV_TOP_OF_PAGE'. DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID. *--------------------------------------------------------------------* * D宏的定义 *--------------------------------------------------------------------* DEFINE MAR_ADD_FIELDCAT. CLEAR WA_FIELDCAT. WA_FIELDCAT-FIELDNAME = &1. WA_FIELDCAT-SELTEXT_L = &2. WA_FIELDCAT-COL_POS = &3. WA_FIELDCAT-JUST = &4. WA_FIELDCAT-OUTPUTLEN = &5. WA_FIELDCAT-FIX_COLUMN = &6. WA_FIELDCAT-EDIT = &7. WA_FIELDCAT-NO_ZERO = &8. APPEND WA_FIELDCAT TO GT_FIELDCAT. END-OF-DEFINITION. *--------------------------------------------------------------------* * D宏的定义2 *--------------------------------------------------------------------* DEFINE MAR_ADD_FIELDCAT2. CLEAR WA_FIELDCAT. WA_FIELDCAT-FIELDNAME = &1. WA_FIELDCAT-SELTEXT_L = &2. WA_FIELDCAT-COL_POS = &3. WA_FIELDCAT-JUST = &4. WA_FIELDCAT-OUTPUTLEN = &5. WA_FIELDCAT-FIX_COLUMN = &6. WA_FIELDCAT-EDIT = &7. WA_FIELDCAT-NO_ZERO = &8. APPEND WA_FIELDCAT TO GT_FIELDCAT2. END-OF-DEFINITION. *====================================================================== * SELECTION-SCREEN *====================================================================== SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001. PARAMETERS: P_WERKS LIKE MARC-WERKS MEMORY ID WRK OBLIGATORY. SELECT-OPTIONS: S_VBELN FOR LIKP-VBELN, S_LFART FOR LIKP-LFART. "交货类型 "S_TDDAT FOR LIKP-TDDAT OBLIGATORY, "运输计划日期 "s_ERZET FOR LIKP-ERZET default '000000' to sy-uzeit no-extension OBLIGATORY, PARAMETERS: P_BLDATL LIKE LIKP-BLDAT DEFAULT SY-DATUM OBLIGATORY, P_ERZETL LIKE LIKP-ERZET DEFAULT '000000', P_BLDATH LIKE LIKP-BLDAT DEFAULT SY-DATUM OBLIGATORY, P_ERZETH LIKE LIKP-ERZET DEFAULT SY-UZEIT. SELECT-OPTIONS: "S_BLDAT FOR LIKP-BLDAT OBLIGATORY,"凭证日期 S_WADAT FOR LIKP-WADAT_IST, "实际发货日期 S_WBSTK FOR VBUK-WBSTK, S_KUNNR FOR LIKP-KUNNR, S_MATNR FOR LIPS-MATNR , S_VGBEL FOR LIPS-VGBEL, S_YYCAR FOR LIKP-YYCARNO MATCHCODE OBJECT YH_YTCARNUM, S_RESLO FOR EKPO-RESLO, "移出库位 S_LGORT FOR EKPO-LGORT, "移入库位 S_ERNAM FOR LIKP-ERNAM MATCHCODE OBJECT USER_COMP. SELECTION-SCREEN SKIP. PARAMETERS: P_DETAIL TYPE C AS CHECKBOX DEFAULT ''. SELECTION-SCREEN END OF BLOCK BLK1. *---------------------------------------------------------------------- * INITIALIZATION *---------------------------------------------------------------------- INITIALIZATION. * 初始化数据 PERFORM FRM_INITIAL. *---------------------------------------------------------------------- * AT SELECTION-SCREEN *---------------------------------------------------------------------- AT SELECTION-SCREEN. * 权限检查部分 PERFORM FRM_CHECK_AUTHOR. *====================================================================== * MAIN PROGRAM *====================================================================== * START-OF-SELECTION *---------------------------------------------------------------------- START-OF-SELECTION. *&S1: 取得数据: PERFORM FRM_GET_DATA. *BREAK AD_CAIXIANG. *&--->START ADD BY AD_CAIXIANG ON 20130111 ECDK907564. IF P_DETAIL IS NOT INITIAL. PERFORM FRM_DETAIL_DISP . ELSE. *---------------------------------------------------------------------- * END-OF-SELECTION *---------------------------------------------------------------------- *&S3: 输出数据: PERFORM FRM_ALV_OUTPUT. ENDIF. *&---<END ADD BY AD_CAIXIANG ON 20130111. *&---------------------------------------------------------------------* *& Form FRM_INITIAL *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_INITIAL. *&设定日期默认: * IF S_TDDAT[] IS INITIAL. * S_TDDAT-LOW = SY-DATUM. * S_TDDAT-HIGH = SY-DATUM + 5. * APPEND S_TDDAT. * ENDIF. * IF S_BLDAT[] IS INITIAL. * S_BLDAT-LOW = SY-DATUM - 5. * S_BLDAT-HIGH = SY-DATUM. * APPEND S_BLDAT. * ENDIF. ENDFORM. " FRM_INITIAL *&---------------------------------------------------------------------* *& Form FRM_CHECK_AUTHOR *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_CHECK_AUTHOR. * IF S_BLDAT-LOW IS INITIAL OR S_BLDAT-HIGH IS INITIAL. * MESSAGE I011 WITH '凭证日期应上限都输入!'. * STOP. * ENDIF. * IF s_ERZET-LOW IS NOT INITIAL AND S_ERZET-HIGH IS INITIAL. * MESSAGE I011 WITH '时间应上下限都输入!'. * STOP. * ELSE. * IF s_ERZET-LOW IS INITIAL AND s_ERZET-HIGH IS NOT INITIAL. * MESSAGE I011 WITH '时间应上下限都输入!'. * STOP. * endif. * ENDIF. * IF s_ERZET-LOW IS INITIAL OR S_ERZET-HIGH IS INITIAL. * MESSAGE I011 WITH '时间应上下限都输入!'. * STOP. * ENDIF. *&权限检查: AUTHORITY-CHECK OBJECT 'V_LIKP_VST' ID 'VSTEL' FIELD P_WERKS ID 'ACTVT' FIELD '03'. IF SY-SUBRC NE 0. MESSAGE I002 WITH P_WERKS . STOP. ENDIF. ENDFORM. " FRM_CHECK_AUTHOR *&---------------------------------------------------------------------* *& Form frm_get_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_GET_DATA . DATA: L_BZIRK LIKE T001W-BZIRK, L_NAME_FIRST LIKE ADRP-NAME_FIRST, L_WERKS LIKE T001W-WERKS, L_NAME_LAST LIKE ADRP-NAME_LAST, L_NAME_TEXT LIKE ADRP-NAME_FIRST. DATA: LT_ITAB LIKE GT_ITAB OCCURS 0 WITH HEADER LINE, LT_WTAB LIKE GT_ITAB OCCURS 0 WITH HEADER LINE. DATA: BEGIN OF LT_MADQ OCCURS 0, MATNR LIKE MARA-MATNR, WERKS LIKE MARC-WERKS, YUMREZ1 LIKE YTMADQ-YUMREZ1, END OF LT_MADQ. DATA: BEGIN OF LT_MEAN OCCURS 0, MATNR LIKE MARA-MATNR, EAN11 LIKE MEAN-EAN11, END OF LT_MEAN. * DATA: BEGIN OF LT_MARA OCCURS 0, * MATNR LIKE MARA-MATNR, * GROES LIKE MARA-GROES, * MATKL LIKE MARA-MATKL, * END OF LT_MARA. DATA: BEGIN OF LT_T001W OCCURS 0, WERKS LIKE T001W-WERKS, NAME1 LIKE T001W-NAME1, KUNNR LIKE T001W-KUNNR, END OF LT_T001W. DATA: BEGIN OF LT_T001L OCCURS 0, WERKS LIKE MARD-WERKS, LGORT LIKE MARD-LGORT, LGOBE LIKE T001L-LGOBE, END OF LT_T001L. DATA: BEGIN OF LT_TVLKT OCCURS 0, LFART LIKE TVLKT-LFART, VTEXT LIKE TVLKT-VTEXT, END OF LT_TVLKT . DATA: BEGIN OF LT_TAB OCCURS 0, VBELN LIKE LIKP-VBELN, LFART LIKE LIKP-LFART, VTEXT TYPE TVLKT-VTEXT, WERKS LIKE LIPS-WERKS, JINE TYPE EKPO-KZWI5, END OF LT_TAB. DATA: G_TEXT TYPE KBETR, C_TEXT(8) TYPE N. DATA: G_MWSKZ LIKE EKPO-MWSKZ, G_KZWI5 LIKE EKPO-KZWI5, G_KZWI1 LIKE VBRP-KZWI1, G_MENGE LIKE EKPO-MENGE, G_DMBTR LIKE MSEG-DMBTR, G_FKIMG LIKE VBRP-FKIMG. DATA: L_MENGE TYPE EKPO-MENGE, "订货数量 L_LFIMG TYPE LIPS-LFIMG, "实发数量 L_JINZH TYPE LIPS-NTGEW. "皮重 DATA: L_TIMEL(14) TYPE C, L_TIMEH(14) TYPE C. DATA:BEGIN OF LT_EORD OCCURS 0, WERKS LIKE EORD-WERKS, MATNR LIKE EORD-MATNR, LIFNR LIKE EORD-LIFNR, END OF LT_EORD. * DATA: BEGIN OF LT_MARA2 OCCURS 0, * MATNR LIKE MARA-MATNR, * SATNR LIKE MARA-MATNR, * END OF LT_MARA2. DATA:BEGIN OF LT_LFA1 OCCURS 0, LIFNR LIKE LFA1-LIFNR, NAME1 LIKE LFA1-NAME1, END OF LT_LFA1. DATA: BEGIN OF LT_KNA1 OCCURS 0, KUNNR LIKE KNA1-KUNNR, NAME1 LIKE KNA1-NAME1, END OF LT_KNA1. DATA: BEGIN OF LT_NAME OCCURS 0, BNAME LIKE V_USR_NAME-BNAME, NAME_TEXT LIKE V_USR_NAME-NAME_TEXT, END OF LT_NAME . DATA:BEGIN OF LT_EKPO OCCURS 0, EBELN LIKE EKPO-EBELN, EBELP LIKE EKPO-EBELP, TXZ01 LIKE EKPO-TXZ01, LGORT LIKE EKPO-LGORT, RESLO LIKE EKPO-RESLO, MWSKZ LIKE EKPO-MWSKZ, MENGE LIKE EKPO-MENGE, KZWI1 LIKE EKPO-KZWI1, KZWI5 LIKE EKPO-KZWI5, END OF LT_EKPO. DATA:BEGIN OF LT_EKKO OCCURS 0 , EBELN LIKE EKPO-EBELN, EBELP LIKE EKPO-EBELP, VBELN LIKE LIPS-VBELN, END OF LT_EKKO. DATA: LT_WEKO LIKE TABLE OF LT_EKKO WITH HEADER LINE. DATA:BEGIN OF LT_EKBE OCCURS 0, EBELN LIKE EKBE-EBELN, EBELP LIKE EKBE-EBELP, VBELN LIKE LIKP-VBELN, DMBTR LIKE EKBE-DMBTR, END OF LT_EKBE. DATA: BEGIN OF LT_VBFA OCCURS 0, VBELV LIKE VBFA-VBELV, POSNV LIKE VBFA-POSNV, VBELN LIKE VBFA-VBELN, POSNN LIKE VBFA-POSNN, END OF LT_VBFA. DATA: LT_TAB1 LIKE TABLE OF LT_VBFA WITH HEADER LINE. DATA: BEGIN OF LT_VBRP OCCURS 0, VBELN LIKE VBRP-VBELN, POSNR LIKE VBRP-POSNR, KZWI1 LIKE VBRP-KZWI1, FKIMG LIKE VBRP-FKIMG, END OF LT_VBRP. DATA: BEGIN OF LT_VBAP OCCURS 0, VBELN LIKE VBAP-VBELN, POSNR LIKE VBAP-POSNR, KWMENG LIKE VBAP-KWMENG, ARKTX LIKE VBAP-ARKTX, END OF LT_VBAP. DATA: LT_WVBAP LIKE TABLE OF LT_VBAP WITH HEADER LINE. DATA: BEGIN OF LT_VBUK OCCURS 0, VBELN LIKE VBUK-VBELN, KOSTK LIKE VBUK-KOSTK, WBSTK LIKE VBUK-WBSTK, END OF LT_VBUK. DATA: BEGIN OF LT_YTLBCJ OCCURS 0, YLBID LIKE YTLBCJ-YLBID, YLBNAME LIKE YTLBCJ-YLBNAME, END OF LT_YTLBCJ. DATA: BEGIN OF LT_MARA3 OCCURS 0, MATNR LIKE MARA-MATNR, ATTYP LIKE MARA-ATTYP, SATNR LIKE MARA-SATNR, GROES LIKE MARA-GROES, MATKL LIKE MARA-MATKL, LVORM LIKE MARA-LVORM, END OF LT_MARA3. DATA: BEGIN OF LT_A003 OCCURS 0, MWSKZ LIKE A003-MWSKZ, KBETR LIKE KONP-KBETR, END OF LT_A003. DATA: LT_MARA LIKE TABLE OF LT_MARA3 WITH HEADER LINE, LT_MARA2 LIKE TABLE OF LT_MARA3 WITH HEADER LINE. RANGES:R_LFARTN FOR LIKP-LFART. DATA: L_TIAN(5) TYPE N. DATA: L_COUNT TYPE I. DATA: L_LAST TYPE C. DATA: L_NMAX TYPE I. SELECT SINGLE TBMAXSEL INTO L_NMAX FROM YTMMREPNUM WHERE PROGNAME = SY-REPID AND ACTIVE = 'X'. IF SY-SUBRC NE 0. L_NMAX = 150000. ENDIF. *&->START CHANGE BY AD_CX ON 20130708 ECDK912680 L_TIAN = P_BLDATH - P_BLDATL. IF L_TIAN GT 37. MESSAGE S011 WITH '时间范围查询条件输入过大!请将时间段分开查询,谢谢!' DISPLAY LIKE 'E'. STOP. ENDIF. *&->END CHANGE. *&S1.默认交货单移动类型: PERFORM FRM_LFART. *&->START CHANGE BY AD_CX ON 20130725 ECDK913587. *&S1.1先取出单据类型: SELECT LFART VTEXT INTO TABLE LT_TVLKT FROM TVLKT WHERE SPRAS EQ SY-LANGU AND LFART IN S_LFART AND LFART IN R_LFART. SORT LT_TVLKT BY LFART. *&S1.2形成单据最终RANGE. LOOP AT LT_TVLKT. R_LFARTN(3) = 'IEQ'. R_LFARTN-LOW = LT_TVLKT-LFART. APPEND R_LFARTN. ENDLOOP. IF S_WBSTK[] IS NOT INITIAL . *&S2.1:数据表LIPS LIKP VBUK关联取数 SELECT A~VBELN A~ANZPK A~ERNAM "创建对象人员的名称 A~KUNNR "配入机构 A~LFART "交货单类型(加描述) A~TDDAT "计划发货日期 A~BLDAT "凭证日期 A~WADAT_IST"实际发货日期 A~YYCARNO A~LIFEX "融通单号 A~ERZET B~BWART B~POSNR "序号 B~WERKS "配出机构 B~VGBEL "参考凭证号 B~VGPOS "参考凭证项目 B~VGTYP B~MATNR "商品编码 B~MEINS "单位 B~VRKME B~LFIMG "实发数量 B~BRGEW "毛重 B~NTGEW "净重 B~LGORT C~KOSTK C~WBSTK INTO CORRESPONDING FIELDS OF TABLE GT_ITAB FROM LIKP AS A JOIN VBUK AS C ON ( A~VBELN EQ C~VBELN ) JOIN LIPS AS B ON ( A~VBELN EQ B~VBELN ) UP TO L_NMAX ROWS *&start changed by robin 20130514 ECDK910228 *&性能优化: WHERE A~BLDAT >= P_BLDATL AND A~BLDAT <= P_BLDATH AND A~LFART IN R_LFARTN AND B~WERKS EQ P_WERKS AND C~WBSTK IN S_WBSTK AND A~VBELN IN S_VBELN AND A~KUNNR IN S_KUNNR AND A~YYCARNO IN S_YYCAR AND A~WADAT_IST IN S_WADAT AND A~ERNAM IN S_ERNAM "AND B~WERKS EQ P_WERKS AND B~MATNR IN S_MATNR AND B~VGBEL IN S_VGBEL *&->START ADD AND B~LGORT IN S_LGORT. *&->END ADD. **&end changed by robin 20130514. ELSE. *&S2.2:数据表LIPS LIKP 关联取数,将VBUK取数移出 *&->START CHANGE BY AD_CX ON 20130725 ECDK913587. SELECT A~VBELN A~ANZPK A~ERNAM "创建对象人员的名称 A~KUNNR "配入机构 A~LFART "交货单类型(加描述) A~TDDAT "计划发货日期 A~BLDAT "凭证日期 A~WADAT_IST"实际发货日期 A~YYCARNO A~LIFEX "融通单号 A~ERZET B~BWART B~POSNR "序号 B~WERKS "配出机构 B~VGBEL "参考凭证号 B~VGPOS "参考凭证项目 B~VGTYP B~MATNR "商品编码 B~MEINS "单位 B~VRKME B~LFIMG "实发数量 B~BRGEW "毛重 B~NTGEW "净重 B~LGORT * C~KOSTK * C~WBSTK INTO CORRESPONDING FIELDS OF TABLE GT_ITAB FROM LIKP AS A * JOIN VBUK AS C * ON ( A~VBELN EQ C~VBELN ) JOIN LIPS AS B ON ( A~VBELN EQ B~VBELN ) UP TO L_NMAX ROWS *&start changed by robin 20130514 ECDK910228 *&性能优化: WHERE A~BLDAT >= P_BLDATL AND A~BLDAT <= P_BLDATH AND A~LFART IN R_LFARTN AND B~WERKS EQ P_WERKS AND A~VBELN IN S_VBELN AND A~KUNNR IN S_KUNNR AND A~YYCARNO IN S_YYCAR AND A~WADAT_IST IN S_WADAT AND A~ERNAM IN S_ERNAM AND B~MATNR IN S_MATNR AND B~VGBEL IN S_VGBEL *&->START ADD AND B~LGORT IN S_LGORT. *&->END ADD. * AND C~WBSTK IN S_WBSTK. *&->END CHANGE BY AD_CX. ENDIF. *&S2.3.内表排序 SORT GT_ITAB BY VBELN POSNR. *&S4.1当数量极大时提示: * IF G_LEN GT 80000. * MESSAGE E011 WITH '你查询的数据太多,请重新选择条件!'. * STOP. * ENDIF. *&S3.日期加时间点作为时间段查询数据 *&->START ADD BY AD_CAIXIANG ON 20121128. 增加按详细时间筛选数据逻辑: *&判断时间范围内的数据 LOOP AT GT_ITAB . CONCATENATE GT_ITAB-BLDAT GT_ITAB-ERZET INTO GT_ITAB-TIMMM. CONCATENATE P_BLDATL P_ERZETL INTO L_TIMEL. CONCATENATE P_BLDATH P_ERZETH INTO L_TIMEH. IF GT_ITAB-TIMMM > L_TIMEH OR GT_ITAB-TIMMM < L_TIMEL. GT_ITAB-FLAG = 'X'. DELETE GT_ITAB. CONTINUE. ENDIF. CHECK GT_ITAB-VGBEL IS NOT INITIAL. IF GT_ITAB-VGTYP = 'V'. *&S3.1 形成采购订单数据中间表 LT_EKKO-EBELN = GT_ITAB-VGBEL. LT_EKKO-EBELP = GT_ITAB-VGPOS. LT_EKKO-VBELN = GT_ITAB-VBELN. COLLECT LT_EKKO. CLEAR LT_EKKO. ELSE."销售凭证 LT_WVBAP-VBELN = GT_ITAB-VGBEL. LT_WVBAP-POSNR = GT_ITAB-VGPOS. COLLECT LT_WVBAP. ENDIF. * MODIFY GT_ITAB TRANSPORTING FLAG. ENDLOOP. *&S3.2 删除不满足条件的数据 DELETE GT_ITAB WHERE FLAG EQ 'X'. *& END ADD BY AD_CAIXIANG ON 20121128. *&->START ADD BY AD_CX ON 20130727. IF LINES( GT_ITAB ) = L_NMAX. MESSAGE I014(YH_FI1) WITH '条目的最大数值限制为' L_NMAX ',' '请分批查询!'. STOP. ENDIF. *&->END ADD. *&S4.检查是否取到数据: DESCRIBE TABLE GT_ITAB LINES G_LEN. IF G_LEN EQ 0. MESSAGE I011 WITH '没有查询到符合条件的数据!'. STOP. ENDIF. *&S5.VBUK表取数: *& 考虑用中间表: LT_WTAB[] = GT_ITAB[]. * SORT LT_WTAB BY VBELN. DELETE ADJACENT DUPLICATES FROM LT_WTAB COMPARING VBELN. IF S_WBSTK[] IS INITIAL . LOOP AT LT_WTAB. CLEAR L_LAST. AT LAST. L_LAST = 'X'. ENDAT. APPEND LT_WTAB TO LT_ITAB. ADD 1 TO L_COUNT. IF L_COUNT = 5000 OR L_LAST = 'X'. SELECT VBELN KOSTK WBSTK APPENDING TABLE LT_VBUK FROM VBUK FOR ALL ENTRIES IN LT_ITAB WHERE VBELN EQ LT_ITAB-VBELN. REFRESH LT_ITAB. CLEAR L_COUNT. ENDIF. ENDLOOP. SORT LT_VBUK BY VBELN. ENDIF. FREE LT_WTAB. *&S6.EKPO取数: IF LT_EKKO[] IS NOT INITIAL. LOOP AT LT_EKKO. CLEAR L_LAST. AT LAST. L_LAST = 'X'. ENDAT. APPEND LT_EKKO TO LT_WEKO. ADD 1 TO L_COUNT. IF L_COUNT = 5000 OR L_LAST = 'X'. *&S6.1.通过凭证号关联到EKPO取数 SELECT EBELN EBELP TXZ01 LGORT RESLO MWSKZ MENGE KZWI1 KZWI5 APPENDING TABLE LT_EKPO FROM EKPO FOR ALL ENTRIES IN LT_WEKO WHERE EBELN = LT_WEKO-EBELN AND EBELP = LT_WEKO-EBELP AND LOEKZ EQ SPACE. *&S7.采购凭证历史表取数: SELECT EBELN EBELP VBELN_ST AS VBELN DMBTR APPENDING TABLE LT_EKBE FROM EKBE FOR ALL ENTRIES IN LT_WEKO WHERE EBELN EQ LT_WEKO-EBELN AND EBELP EQ LT_WEKO-EBELP AND VGABE EQ '6' AND VBELN_ST EQ LT_WEKO-VBELN. REFRESH LT_WEKO. CLEAR L_COUNT. ENDIF. ENDLOOP. SORT LT_EKPO BY EBELN EBELP. SORT LT_EKBE BY EBELN EBELP VBELN. ENDIF. FREE: LT_WEKO,LT_EKKO. *&—>START 以下备注: **&S6.1.通过凭证号关联到EKPO取数 * SELECT EBELN EBELP * TXZ01 LGORT * RESLO MWSKZ * MENGE KZWI1 * KZWI5 * * INTO TABLE LT_EKPO * FROM EKPO * FOR ALL ENTRIES IN LT_EKKO * WHERE EBELN = LT_EKKO-EBELN * AND EBELP = LT_EKKO-EBELP * AND LOEKZ EQ SPACE. **&->START ADD BY AD_CAIXIANG ON 20130516 ECDK911439 ** AND RESLO IN S_RESLO ** AND LGORT IN S_LGORT. **&->EDN ADD 20130516. * SORT LT_EKPO BY EBELN EBELP. *&S6.2.关联到EKBE取数 * * BREAK AD_CAIXIANG. * SELECT SINGLE DMBTR * FROM EKBE * INTO G_DMBTR * WHERE EBELN EQ WA-VGBEL * AND EBELP EQ WA-VGPOS+1(5) * AND BWART EQ WA-BWART. * SELECT EBELN EBELP * DMBTR * INTO TABLE LT_EKBE * FROM EKBE * FOR ALL ENTRIES IN LT_EKKO * WHERE EBELN = LT_EKKO-EBELN * AND EBELP = LT_EKKO-EBELP * AND VGABE = '6'. *&->START CHANGE BY AD_CAIXIANG ON 20130603 * LT_ITAB[] = GT_ITAB[]. * SORT LT_ITAB BY VGBEL VGPOS VBELN. * DELETE ADJACENT DUPLICATES FROM LT_ITAB COMPARING VGBEL VGPOS VBELN. *&->END 备注 * IF LT_EKKO[] IS NOT INITIAL. **&S7.采购凭证历史表取数: * SELECT EBELN EBELP * VBELN_ST AS VBELN * DMBTR * INTO TABLE LT_EKBE * FROM EKBE * FOR ALL ENTRIES IN LT_EKKO * WHERE EBELN EQ LT_EKKO-EBELN * AND EBELP EQ LT_EKKO-EBELP * AND VGABE EQ '6' * AND VBELN_ST EQ LT_EKKO-VBELN. * SORT LT_EKBE BY EBELN EBELP VBELN. ** REFRESH LT_ITAB. **&->END CHANGE . * ENDIF. *&S8通过地点商品编码找对应大区件装数: LT_ITAB[] = GT_ITAB[]. SORT LT_ITAB BY MATNR WERKS. DELETE ADJACENT DUPLICATES FROM LT_ITAB COMPARING MATNR WERKS. SELECT A~MATNR B~WERKS A~YUMREZ1 INTO TABLE LT_MADQ FROM YTMADQ AS A JOIN T001W AS B ON ( A~BZIRK EQ B~BZIRK ) FOR ALL ENTRIES IN LT_ITAB WHERE A~MATNR EQ LT_ITAB-MATNR AND B~WERKS EQ LT_ITAB-WERKS. SORT LT_MADQ BY MATNR WERKS. *&S9通过货源找供应商: SELECT WERKS MATNR LIFNR INTO TABLE LT_EORD FROM YTMEORD FOR ALL ENTRIES IN LT_ITAB WHERE MATNR EQ LT_ITAB-MATNR AND WERKS EQ LT_ITAB-WERKS . SORT LT_EORD BY MATNR WERKS. * REFRESH LT_ITAB. *&S10:商品编码找条码: * LT_ITAB[] = GT_ITAB[]. * SORT LT_ITAB BY MATNR. DELETE ADJACENT DUPLICATES FROM LT_ITAB COMPARING MATNR. SELECT MATNR EAN11 INTO TABLE LT_MEAN FROM MEAN FOR ALL ENTRIES IN LT_ITAB WHERE MATNR EQ LT_ITAB-MATNR AND HPEAN EQ 'X'. SORT LT_MEAN BY MATNR. *S6.6:商品编码取规格: * SORT LT_ITAB BY MATNR. * DELETE ADJACENT DUPLICATES FROM LT_ITAB COMPARING MATNR. * SELECT MATNR GROES **&->START ADD BY AD_CAIXIANG ON 20130514 ECDK911331 * MATKL **&->END ADD BY AD_CAIXIANG. * INTO TABLE LT_MARA * FROM MARA * FOR ALL ENTRIES IN LT_ITAB * WHERE MATNR EQ LT_ITAB-MATNR * AND LVORM EQ SPACE. **&6.7分子母码找对应的商品编码: * SELECT MATNR SATNR * INTO TABLE LT_MARA2 * FROM MARA * FOR ALL ENTRIES IN LT_ITAB * WHERE MATNR EQ LT_ITAB-MATNR * AND ATTYP EQ '02' * AND SATNR NE ''. *&S11.MARA表取数 SELECT MATNR ATTYP SATNR GROES MATKL LVORM INTO TABLE LT_MARA3 FROM MARA FOR ALL ENTRIES IN LT_ITAB WHERE MATNR EQ LT_ITAB-MATNR. LT_MARA[] = LT_MARA3[]. DELETE LT_MARA WHERE LVORM NE SPACE. LT_MARA2[] = LT_MARA3[]. DELETE LT_MARA2 WHERE ATTYP NE '02' OR SATNR EQ ''. SORT LT_MARA BY MATNR. SORT LT_MARA2 BY MATNR. FREE LT_MARA3. *&->START ADD BY AD_CAIXIANG ON 20130514 ECDK911331 *&S12.取大类名称 SELECT YLBID YLBNAME INTO TABLE LT_YTLBCJ FROM YTLBCJ. * FOR ALL ENTRIES IN LT_MARA * WHERE YLBID EQ LT_MARA-MATKL+0(2). SORT LT_YTLBCJ BY YLBID. *&->END ADD BY AD_CAIXIANG. *&---? REFRESH LT_ITAB. *&S13:取机构名称: * LT_ITAB[] = GT_ITAB[]. * SORT LT_ITAB BY WERKS. * DELETE ADJACENT DUPLICATES FROM LT_ITAB COMPARING WERKS. SELECT WERKS NAME1 KUNNR INTO TABLE LT_T001W FROM T001W. * FOR ALL ENTRIES IN LT_ITAB * WHERE WERKS EQ LT_ITAB-WERKS. SORT LT_T001W BY WERKS. *&S14.找出库位描述: SELECT WERKS LGORT LGOBE INTO TABLE LT_T001L FROM T001L. * FOR ALL ENTRIES IN LT_ITAB * WHERE WERKS EQ LT_ITAB-WERKS. SORT LT_T001L BY WERKS LGORT. REFRESH LT_ITAB. *&->START CHANGE BY AD_CX ON 20130725 ECDK913587. *&S6.10取凭证类型描述: * SELECT LFART VTEXT * INTO TABLE LT_TVLKT * FROM TVLKT * WHERE SPRAS EQ SY-LANGU * AND LFART IN S_LFART * AND LFART IN R_LFART. * SORT LT_TVLKT BY LFART. *&->END CHANGE. *&S15.取供应商名称 * LT_ITAB[] = GT_ITAB[]. * SORT LT_ITAB BY LIFNR. * DELETE ADJACENT DUPLICATES FROM LT_LFA1 COMPARING LIFNR. SELECT LIFNR NAME1 INTO TABLE LT_LFA1 FROM LFA1 FOR ALL ENTRIES IN LT_EORD WHERE LIFNR EQ LT_EORD-LIFNR. SORT LT_LFA1 BY LIFNR. REFRESH LT_ITAB. *&S16.取客户名称: LT_ITAB[] = GT_ITAB[]. SORT LT_ITAB BY KUNNR. DELETE ADJACENT DUPLICATES FROM LT_ITAB COMPARING KUNNR. SELECT KUNNR NAME1 INTO TABLE LT_KNA1 FROM KNA1 FOR ALL ENTRIES IN LT_ITAB WHERE KUNNR EQ LT_ITAB-KUNNR. SORT LT_KNA1 BY KUNNR. REFRESH LT_ITAB. *&S17.取制单人名称 LT_ITAB[] = GT_ITAB[]. SORT LT_ITAB BY ERNAM. DELETE ADJACENT DUPLICATES FROM LT_ITAB COMPARING ERNAM. SELECT BNAME NAME_TEXT INTO TABLE LT_NAME FROM V_USR_NAME FOR ALL ENTRIES IN LT_ITAB WHERE BNAME EQ LT_ITAB-ERNAM. SORT LT_NAME BY BNAME. REFRESH LT_ITAB. *& 销售凭证 IF LT_WVBAP[] IS NOT INITIAL. LOOP AT LT_WVBAP. CLEAR L_LAST. AT LAST. L_LAST = 'X'. ENDAT. LT_TAB1-VBELV = LT_WVBAP-VBELN. LT_TAB1-POSNV = LT_WVBAP-POSNR. APPEND LT_TAB1. ADD 1 TO L_COUNT. IF L_COUNT = 5000 OR L_LAST = 'X'. *&S19.取销售凭证对应数量 SELECT VBELN POSNR KWMENG ARKTX APPENDING TABLE LT_VBAP FROM VBAP FOR ALL ENTRIES IN LT_TAB1 WHERE VBELN EQ LT_TAB1-VBELV AND POSNR EQ LT_TAB1-POSNV. *&S18.取销售凭证发票 SELECT VBELV POSNV VBELN POSNN APPENDING TABLE LT_VBFA FROM VBFA FOR ALL ENTRIES IN LT_TAB1 WHERE VBELV EQ LT_TAB1-VBELV AND POSNV EQ LT_TAB1-POSNV AND VBTYP_N EQ 'M'. IF SY-SUBRC = 0. SELECT VBELN POSNR KZWI1 FKIMG APPENDING TABLE LT_VBRP FROM VBRP FOR ALL ENTRIES IN LT_VBFA WHERE VBELN = LT_VBFA-VBELN AND POSNR = LT_VBFA-POSNN. ENDIF. REFRESH LT_TAB1. CLEAR L_COUNT. ENDIF. ENDLOOP. SORT LT_VBFA BY VBELV POSNV. SORT LT_VBAP BY VBELN POSNR. SORT LT_VBRP BY VBELN POSNR. ENDIF. FREE: LT_TAB1,LT_WVBAP. * LT_ITAB[] = GT_ITAB[]. * SORT LT_ITAB BY VGBEL VGPOS. * DELETE ADJACENT DUPLICATES FROM LT_ITAB COMPARING VGBEL VGPOS. * SELECT VBELV POSNV * VBELN POSNN * INTO TABLE LT_VBFA * FROM VBFA * FOR ALL ENTRIES IN LT_ITAB * WHERE VBELV EQ LT_ITAB-VGBEL * AND POSNV EQ LT_ITAB-VGPOS * AND VBTYP_N EQ 'M'. * SORT LT_VBFA BY VBELV POSNV. * * * **&S19.取销售凭证对应数量 * SELECT VBELN POSNR * KWMENG ARKTX * INTO TABLE LT_VBAP * FROM VBAP * FOR ALL ENTRIES IN LT_ITAB * WHERE VBELN EQ LT_ITAB-VGBEL * AND POSNR EQ LT_ITAB-VGPOS. * SORT LT_VBAP BY VBELN POSNR. * * REFRESH LT_ITAB. * **&S20.取发票数量与金额 * LT_TAB1[] = LT_VBFA[]. * SORT LT_TAB1 BY VBELN POSNN. * DELETE ADJACENT DUPLICATES FROM LT_TAB1 COMPARING VBELN POSNN. * IF LT_TAB1[] IS NOT INITIAL. * SELECT VBELN POSNR * KZWI1 FKIMG * INTO TABLE LT_VBRP * FROM VBRP * FOR ALL ENTRIES IN LT_TAB1 * WHERE VBELN = LT_TAB1-VBELN * AND POSNR = LT_TAB1-POSNN. * SORT LT_VBRP BY VBELN POSNR. * ENDIF. *&S21获取税率 SELECT A~MWSKZ B~KBETR INTO TABLE LT_A003 FROM A003 AS A JOIN KONP AS B ON A~KNUMH = B~KNUMH AND B~KOPOS = '01' WHERE A~KAPPL = 'TX' AND A~KSCHL = 'MWVS' AND A~ALAND = 'CN' AND B~LOEVM_KO = SPACE. SORT LT_A003 BY MWSKZ. *&S22,环取得其他表中取其它值 LOOP AT GT_ITAB. " INTO WA. G_TABIX = SY-TABIX. MOVE GT_ITAB TO WA. *&S检查ekpo中的库位: *&读取EKPO中金额,税码等数据 IF WA-VGBEL NE SPACE AND WA-VGTYP = 'V'. READ TABLE LT_EKPO WITH KEY EBELN = WA-VGBEL EBELP = WA-VGPOS+1(5) BINARY SEARCH. IF SY-SUBRC EQ 0. *& 取小计金额 和 数量 G_MWSKZ = LT_EKPO-MWSKZ. G_KZWI5 = LT_EKPO-KZWI5. G_KZWI1 = LT_EKPO-KZWI1. G_MENGE = LT_EKPO-MENGE. *&->ADD BY AD_CAIXIANG. WA-MENGE = LT_EKPO-MENGE. *&->END ADD. " WA-LGORT = LT_EKPO-LGORT. * WA-RESLO = LT_EKPO-RESLO. WA-RESLO = LT_EKPO-LGORT. *&->START CHANGE BY AD_CAIXIANG ON 20130516. WA-MAKTX = LT_EKPO-TXZ01. *&->END CHANGE BY AD_CAIXIANG. *&判断库位: *&IF WA-LGORT IN S_LGORT AND IF WA-RESLO IN S_RESLO. * WA-MAKTX = LT_EKPO-TXZ01. * WA-LGORT = LT_EKPO-LGORT. * WA-RESLO = LT_EKPO-RESLO. ELSE. CLEAR WA. DELETE GT_ITAB INDEX G_TABIX. CONTINUE. ENDIF. * ENDIF. **&->START CHANGE BY AD_CAIXIANG ON 20130513 ECDK911294. * ELSE. * CLEAR WA. * DELETE GT_ITAB INDEX G_TABIX. * CONTINUE. ENDIF. *&->END CHANGE BY AD_CAIXIANG ON 20130513. ENDIF. *&--->START CHANGE BY AD_CAIXIANG ON 20130406 ECDK910228 IF S_WBSTK[] IS INITIAL . READ TABLE LT_VBUK WITH KEY VBELN = GT_ITAB-VBELN BINARY SEARCH. IF SY-SUBRC = 0. GT_ITAB-KOSTK = LT_VBUK-KOSTK. GT_ITAB-WBSTK = LT_VBUK-WBSTK. WA-KOSTK = LT_VBUK-KOSTK. WA-WBSTK = LT_VBUK-WBSTK. ENDIF. ENDIF. *& 分子母码找对应的商品编码: * SELECT SINGLE SATNR * INTO WA-MATNR * FROM MARA * WHERE ATTYP = '02' * AND SATNR <> '' * AND MATNR = WA-MATNR. READ TABLE LT_MARA2 WITH KEY MATNR = WA-MATNR BINARY SEARCH. IF SY-SUBRC EQ 0. WA-MATNR = LT_MARA2-SATNR. ENDIF. *&读取供应商 READ TABLE LT_EORD WITH KEY MATNR = WA-MATNR WERKS = WA-WERKS BINARY SEARCH. IF SY-SUBRC EQ 0. WA-LIFNR = LT_EORD-LIFNR. ENDIF. *& 取供应商名称: READ TABLE LT_LFA1 WITH KEY LIFNR = WA-LIFNR BINARY SEARCH. IF SY-SUBRC = 0. WA-NAME3 = LT_LFA1-NAME1. ENDIF. AT NEW VBELN . CLEAR:L_NAME_TEXT. *&S1.5.1:获取制单人信息: READ TABLE LT_NAME WITH KEY BNAME = WA-ERNAM BINARY SEARCH. IF SY-SUBRC EQ 0. L_NAME_TEXT = LT_NAME-NAME_TEXT. ENDIF. *&S1.5.2:取客户描述: CLEAR KNA1-NAME1. READ TABLE LT_KNA1 WITH KEY KUNNR = WA-KUNNR BINARY SEARCH. IF SY-SUBRC = 0. KNA1-NAME1 = LT_KNA1-NAME1. ENDIF. *&S1.5.3:取出客户对应的工厂: CLEAR L_WERKS. READ TABLE LT_T001W WITH KEY KUNNR = WA-KUNNR. " BINARY SEARCH. IF SY-SUBRC = 0. L_WERKS = LT_T001W-WERKS. ENDIF. ENDAT. *&--->END CHANGE BY AD_CAIXIANG ON 20130406. *& 金额: WA-JINE = WA-JIAGE * GT_ITAB-LFIMG. *&---> START CHANGE BY AD_CAIXIANG ON 20130222 ECDK908753 IF WA-BWART EQ '641' OR WA-BWART EQ '643'. *&当交货单的凭证类型为‘641’ ‘643’时,取交货单凭证里的KZWI5 *& 当小计5不为0:价格= 小计5/数量 *& 当小计5为0: 通过交货单凭证中的税码EKPO-MWSKZ,计算税率,然后通 *& ( DMBTR * ( 1 + 税率 / 100 ) ) / 数量.计算价格。 *&---> END CHANGE BY AD_CAIXIANG. READ TABLE LT_EKBE WITH KEY EBELN = WA-VGBEL EBELP = WA-VGPOS+1(5) VBELN = WA-VBELN BINARY SEARCH. IF SY-SUBRC = 0. G_DMBTR = LT_EKBE-DMBTR. *& 当KZWI5不为0: IF G_KZWI5 NE 0. IF G_MENGE NE 0. WA-JIAGE = G_KZWI5 / G_MENGE. ELSE. WA-JIAGE = 0. ENDIF. *& 金额: WA-JINE = WA-JIAGE * GT_ITAB-LFIMG. ELSE. *&获取税率 *&->START CHANGE BY AD_CX ON 20130703 ECDK912680 READ TABLE LT_A003 WITH KEY MWSKZ = G_MWSKZ BINARY SEARCH. IF SY-SUBRC = 0. G_TEXT = LT_A003-KBETR / 10. *&剔除税率小数点后的零 C_TEXT = TRUNC( G_TEXT ). CONCATENATE C_TEXT '%' INTO C_TEXT. ENDIF. *&->START CHANGE BY AD_CAIXIANG ON 20130603 ECDK912048. WA-JINE = ( G_DMBTR * ( 1 + C_TEXT / 100 ) ) . IF G_MENGE NE 0. *&->START CHANGE BY AD_CAIXIANG ON 20130604. WA-JIAGE = WA-JINE / GT_ITAB-LFIMG. ELSE. WA-JIAGE = 0. ENDIF. *&函数注释 * CALL FUNCTION 'YH_PUB_TAX_VALUE_GET' * EXPORTING * I_KSCHL = 'MWVS' * I_MWSKZ = G_MWSKZ * IMPORTING * O_KBETR = G_TEXT. **&->START CHANGE BY AD_CAIXIANG ON 20130603 ECDK912048. * WA-JINE = ( G_DMBTR * ( 1 + G_TEXT / 100 ) ) . * IF G_MENGE NE 0. **&->START CHANGE BY AD_CAIXIANG ON 20130604. * WA-JIAGE = WA-JINE / GT_ITAB-LFIMG. ** WA-JIAGE = WA-JINE / G_MENGE. *&->END CHANGE BY AD_CX. **&->END CHANGE. * ELSE. * WA-JIAGE = 0. * ENDIF. * IF G_MENGE NE 0. * WA-JIAGE = ( G_DMBTR * ( 1 + G_TEXT / 100 ) ) / G_MENGE. * ELSE. * WA-JIAGE = 0. * ENDIF. *&->END CHANGE . ENDIF. ENDIF. ENDIF. *&---> START ADD BY AD_CAIXIANG ON 20130222 ECDK908753. *&当交货单移动类型为 ‘671’ ‘673’时, 小计1/数量 计算价格, IF WA-BWART EQ '671' OR WA-BWART EQ '673'. WA-JIAGE = G_KZWI1 / G_MENGE. *& 金额: WA-JINE = WA-JIAGE * GT_ITAB-LFIMG. ENDIF. *&---> END ADD BY AD_CAIXIANG ON 20130222. *&当移动类型为‘653’ ‘601’,通过交货凭证找到对应的开票凭证数据计算价格 IF WA-BWART EQ '653' OR WA-BWART EQ '601' . *&读取开票凭证 READ TABLE LT_VBFA WITH KEY VBELV = WA-VGBEL POSNV = WA-VGPOS BINARY SEARCH. IF SY-SUBRC EQ 0. VBFA-VBELN = LT_VBFA-VBELN. VBFA-POSNN = LT_VBFA-POSNN. ENDIF. READ TABLE LT_VBRP WITH KEY VBELN = VBFA-VBELN POSNR = VBFA-POSNN BINARY SEARCH. IF SY-SUBRC EQ 0. G_KZWI1 = LT_VBRP-KZWI1. G_FKIMG = LT_VBRP-FKIMG. ENDIF. *&计算价格 IF G_FKIMG NE SPACE. WA-JIAGE = G_KZWI1 / G_FKIMG. ELSE. WA-JIAGE = 0. ENDIF. *& 金额: WA-JINE = WA-JIAGE * GT_ITAB-LFIMG. ENDIF. **& 金额: * WA-JINE = WA-JIAGE * GT_ITAB-LFIMG. *& END ADD ON 20121128 *&S1.6.1: 读取条码: READ TABLE LT_MEAN WITH KEY MATNR = WA-MATNR * MEINH = WA-MEINS BINARY SEARCH. IF SY-SUBRC EQ 0. WA-EAN11 = LT_MEAN-EAN11. ENDIF. *S1.6.2:取规格: READ TABLE LT_MARA WITH KEY MATNR = WA-MATNR BINARY SEARCH. IF SY-SUBRC EQ 0. WA-GROES = LT_MARA-GROES. *&->ADD BY AD_CAIXIANG WA-YLBID1 = LT_MARA-MATKL+0(4). *&->END ADD. ENDIF. *&->ADD BY AD_CAIXIANG *&S1.6.2.1读取大类名称 READ TABLE LT_YTLBCJ WITH KEY YLBID = WA-YLBID1 BINARY SEARCH. IF SY-SUBRC EQ 0. WA-YDLNAM = LT_YTLBCJ-YLBNAME. ENDIF. *&->END ADD. *S1.6.3:取工厂描述: READ TABLE LT_T001W WITH KEY WERKS = WA-WERKS BINARY SEARCH. IF SY-SUBRC EQ 0. WA-NAME1 = LT_T001W-NAME1. ENDIF. *S1.6.5: 取件数: READ TABLE LT_MADQ WITH KEY MATNR = WA-MATNR WERKS = WA-WERKS BINARY SEARCH. IF SY-SUBRC EQ 0. WA-YUMREZ1 = LT_MADQ-YUMREZ1. ENDIF. *&S1.6.6:取数量: IF WA-LFART = 'ZLF' OR WA-LFART = 'ZLR' OR WA-LFART = 'ZLF2' OR WA-LFART = 'ZLR2'. READ TABLE LT_VBAP WITH KEY VBELN = WA-VGBEL POSNR = WA-VGPOS BINARY SEARCH. IF SY-SUBRC EQ 0. WA-MENGE = LT_VBAP-KWMENG. WA-MAKTX = LT_VBAP-ARKTX. ENDIF. * ELSE. ** WA-MENGE = EKPO-MENGE. ENDIF. *&皮重: WA-JINZH = WA-BRGEW - WA-NTGEW. *&订货件数 IF WA-YUMREZ1 NE 0. WA-DINH = WA-MENGE / WA-YUMREZ1. ENDIF. *&实发件数 IF WA-YUMREZ1 NE 0. WA-SHFA = WA-LFIMG / WA-YUMREZ1. ENDIF. *&找移入库位描述: IF WA-RESLO NE SPACE. READ TABLE LT_T001L WITH KEY WERKS = L_WERKS LGORT = WA-RESLO BINARY SEARCH. IF SY-SUBRC EQ 0. WA-LGOBE1 = LT_T001L-LGOBE. ENDIF. ENDIF. **S1.5.12:找移出库位描述: IF WA-LGORT NE SPACE. READ TABLE LT_T001L WITH KEY WERKS = WA-WERKS LGORT = WA-LGORT BINARY SEARCH. IF SY-SUBRC EQ 0. WA-LGOBE2 = LT_T001L-LGOBE. ENDIF. ENDIF. *& 找类型描述: READ TABLE LT_TVLKT WITH KEY LFART = WA-LFART BINARY SEARCH. IF SY-SUBRC EQ 0. WA-VTEXT = LT_TVLKT-VTEXT. ENDIF. *&S1.5.11:汇总数量: L_MENGE = L_MENGE + WA-MENGE. L_LFIMG = L_LFIMG + WA-LFIMG. L_JINZH = L_JINZH + WA-JINZH. WA-NAME2 = KNA1-NAME1. WA-NAME_TEXT = L_NAME_TEXT. *& 单位转换: CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING INPUT = WA-MEINS LANGUAGE = SY-LANGU IMPORTING OUTPUT = WA-MEINS EXCEPTIONS UNIT_NOT_FOUND = 1 OTHERS = 2. *&START ADD BY AD_CAIXIANG ON 201211206 MOVE-CORRESPONDING WA TO GT_DATA. GT_DATA-MENGE = L_MENGE. GT_DATA-LFIMG = L_LFIMG. GT_DATA-JINZH = L_JINZH. COLLECT GT_DATA. CLEAR GT_DATA. MODIFY GT_ITAB FROM WA. CLEAR: WA. CLEAR : L_MENGE, L_LFIMG, L_JINZH. ENDLOOP. *&END ADD BY AD_CAIXIANG ON ... *&筛选条件] *&->START ADD BY AD_CAIXIANG ON 20130513 ECDK911373 IF S_RESLO[] IS NOT INITIAL. DELETE GT_ITAB WHERE RESLO NOT IN S_RESLO. DELETE GT_DATA WHERE RESLO NOT IN S_RESLO. ENDIF. *&->EDN ADD BY AD_CX. *&S1.7: 检查是否取到数据: DESCRIBE TABLE GT_DATA LINES G_LEN. IF G_LEN EQ 0. MESSAGE I011 WITH '没有查询到符合条件的数据!'. STOP. ENDIF. ENDFORM. " frm_get_data *&---------------------------------------------------------------------* *& Form FRM_LFART *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_LFART . CLEAR:R_LFART[],R_LFART. R_LFART-SIGN = 'I'. R_LFART-OPTION = 'EQ'. R_LFART-LOW = 'NLR'. APPEND R_LFART. R_LFART-LOW = 'NL'. APPEND R_LFART. R_LFART-LOW = 'NLCC'. APPEND R_LFART. R_LFART-LOW = 'NCR'. APPEND R_LFART. R_LFART-LOW = 'ZLF'. APPEND R_LFART. R_LFART-LOW = 'ZLR'. APPEND R_LFART. *&->START ADD BY AD_CAIXIANG ON 20120126 ECDK907564 R_LFART-LOW = 'ZLF2'. APPEND R_LFART. R_LFART-LOW = 'ZLR2'. APPEND R_LFART. *&->END ADD BY AD_CAIXIANG ENDFORM. " FRM_LFART *&---------------------------------------------------------------------* *& Form frm_output_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_ALV_OUTPUT. CHECK G_LEN NE 0. *&S4.1: 设定输出字段: PERFORM FRM_FIELDCAT_GET. PERFORM FRM_EVENTS_SET. *&S4.2:设定输出格式: PERFORM FRM_LAYOUT_SET. G_LEN = LINES( GT_DATA[] ). MESSAGE S013 WITH '找到数据:' G_LEN '条'. *&调用ALV函数输出: CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = SY-REPID * I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS' I_CALLBACK_USER_COMMAND = 'USER_COMMAND' IS_LAYOUT = GS_LAYOUT IT_FIELDCAT = GT_FIELDCAT I_SAVE = 'A' * it_events = gt_event TABLES T_OUTTAB = GT_DATA EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2. ENDFORM. " FRM_ALV_OUTPUT. *&---------------------------------------------------------------------* *& Form USER_COMMAND *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD. DATA: LR_GRID TYPE REF TO CL_GUI_ALV_GRID. *&将变更的数据刷新 CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING E_GRID = LR_GRID. CALL METHOD LR_GRID->CHECK_CHANGED_DATA. RS_SELFIELD-REFRESH = 'X'. * break ad_taoxb. CLEAR WA. CASE R_UCOMM. WHEN '&IC1'. *&Double deal with: CLEAR GT_DATA. READ TABLE GT_DATA INDEX RS_SELFIELD-TABINDEX. IF SY-SUBRC EQ 0. PERFORM FRM_DETAIL_DISP. ENDIF. * CALL METHOD lr_grid->refresh_table_display. WHEN OTHERS. ENDCASE. ENDFORM. "USER_COMMAND *&---------------------------------------------------------------------* *& ALV EVENT Form f_pf_status_set *&---------------------------------------------------------------------* FORM F_PF_STATUS_SET USING EXTAB TYPE SLIS_T_EXTAB. SET PF-STATUS 'STANDARD' EXCLUDING EXTAB. ENDFORM. " f_pf_status_set *&---------------------------------------------------------------------* *& Form FRM_FIELDCAT_GET *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_FIELDCAT_GET . CLEAR GT_FIELDCAT. REFRESH GT_FIELDCAT. *&设定输出的相关字段结构: MAR_ADD_FIELDCAT 'VBELN' '交货单' '1' '' '10' 'X' '' ''. MAR_ADD_FIELDCAT 'WERKS' '配出机构' '2' '' '6' ' ' '' ''. MAR_ADD_FIELDCAT 'NAME1' '配出机构名称' '3' '' '15' ' ' '' ''. MAR_ADD_FIELDCAT 'KUNNR' '配入机构' '5' '' '6' ' ' '' 'X'. MAR_ADD_FIELDCAT 'NAME2' '配入机构名称' '6' '' '20' ' ' '' ''. MAR_ADD_FIELDCAT 'LGORT' '移出库位' '7' '' '6' ' ' '' ''. MAR_ADD_FIELDCAT 'LGOBE2' '移出库位描述' '8' '' '15' ' ' '' ''. MAR_ADD_FIELDCAT 'RESLO' '移入库位' '9' '' '6' ' ' '' ''. MAR_ADD_FIELDCAT 'LGOBE1' '移入库位描述' '10' '' '15' ' ' '' ''. MAR_ADD_FIELDCAT 'LIFEX' '融通单号' '12' '' '20' ' ' '' ''. MAR_ADD_FIELDCAT 'LFART' '类型' '13' '' '5' ' ' '' ''. MAR_ADD_FIELDCAT 'VTEXT' '交货类型描述' '14' '' '15' ' ' '' ''. MAR_ADD_FIELDCAT 'YYCARNO' '车辆号' '15' '' '10' ' ' '' ''. MAR_ADD_FIELDCAT 'BLDAT' '凭证日期' '17' '' '10' ' ' '' ''. MAR_ADD_FIELDCAT 'ERZET' '时间' '17' '' '10' ' ' '' ''. MAR_ADD_FIELDCAT 'WADAT_IST' '实际发货日期' '18' '' '10' ' ' '' ''. MAR_ADD_FIELDCAT 'MENGE' '订货数量' '20' '' '10' ' ' '' ''. MAR_ADD_FIELDCAT 'LFIMG' '实发数量' '21' '' '10' ' ' '' ''. MAR_ADD_FIELDCAT 'JINZH' '皮重' '22' '' '10' ' ' '' ''. MAR_ADD_FIELDCAT 'JINE' '金额' '22' '' '10' ' ' '' ''. MAR_ADD_FIELDCAT 'KOSTK' '总拣配状态' '23' '' '6' ' ' '' ''. MAR_ADD_FIELDCAT 'WBSTK' '移动总状态' '25' '' '8' ' ' '' ''. MAR_ADD_FIELDCAT 'NAME_TEXT' '制单人' '26' '' '10' ' ' '' ''. "MAR_ADD_FIELDCAT 'TDDAT' '计划日期' '16' '' '10' ' ' ' '. ENDFORM. " FRM_FIELDCAT_GET *&---------------------------------------------------------------------* *& Form FRM_EVENTS_SET *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_EVENTS_SET . ENDFORM. " FRM_EVENTS_SET *&---------------------------------------------------------------------* *& Form FRM_LAYOUT_SET *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_LAYOUT_SET . CLEAR GS_LAYOUT. MOVE: 'X' TO GS_LAYOUT-ZEBRA, 'X' TO GS_LAYOUT-COLWIDTH_OPTIMIZE, 'X' TO GS_LAYOUT-DETAIL_POPUP. ENDFORM. " FRM_LAYOUT_SET *&---------------------------------------------------------------------* *& Form FRM_DETAIL_DISP *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_DETAIL_DISP . DATA: LT_ITAB LIKE GT_ITAB OCCURS 0 WITH HEADER LINE. DATA: G_LEN2 TYPE SY-TABIX. *&T1.找到需显示的数据: LT_ITAB[] = GT_ITAB[]. IF P_DETAIL IS INITIAL. DELETE LT_ITAB WHERE VBELN NE GT_DATA-VBELN. SORT LT_ITAB BY MATNR. ENDIF. *&T2:获取结构: PERFORM FRM_FIELDCAT_GET2. G_LEN2 = LINES( LT_ITAB[] ). MESSAGE S013 WITH '找到数据:' G_LEN2 '条'. *&T3: 显示: CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = SY-CPROG * I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS' * I_CALLBACK_USER_COMMAND = 'USER_COMMAND' IS_LAYOUT = GS_LAYOUT IT_FIELDCAT = GT_FIELDCAT2 I_SAVE = 'A' * it_events = gt_event TABLES T_OUTTAB = LT_ITAB EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2. ENDFORM. " FRM_DETAIL_DISP *&---------------------------------------------------------------------* *& Form FRM_FIELDCAT_GET2 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_FIELDCAT_GET2 . CLEAR GT_FIELDCAT2. REFRESH GT_FIELDCAT2. *&设定输出的相关字段结构: MAR_ADD_FIELDCAT2 'VBELN' '交货单' '1' '' '10' 'X' '' ''. MAR_ADD_FIELDCAT2 'POSNR' '项次' '2' '' '5' 'X' ' ' ''. MAR_ADD_FIELDCAT2 'WERKS' '配出机构' '3' '' '6' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'NAME1' '配出机构名称' '4' '' '15' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'KUNNR' '配入机构' '5' '' '6' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'NAME2' '配入机构名称' '6' '' '20' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'LGORT' '移出库位' '7' '' '6' ' ' '' ''. MAR_ADD_FIELDCAT2 'LGOBE2' '移出库位描述' '8' '' '15' ' ' '' ''. MAR_ADD_FIELDCAT2 'RESLO' '移入库位' '9' '' '6' ' ' '' ''. MAR_ADD_FIELDCAT2 'LGOBE1' '移入库位描述' '10' '' '15' ' ' '' ''. * MAR_ADD_FIELDCAT2 'RESLO' '移出库位' '8' '' '6' ' ' ' ' ''. * MAR_ADD_FIELDCAT2 'LGOBE1' '移出库位描述' '9' '' '15' ' ' ' ' ''. * MAR_ADD_FIELDCAT2 'LGORT' '移入库位' '10' '' '6' ' ' ' ' ''. * MAR_ADD_FIELDCAT2 'LGOBE2' '移入库位描述' '11' '' '15' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'LFART' '类型' '13' '' '5' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'VTEXT' '交货类型描述' '14' '' '15' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'VGBEL' '参考凭证' '14' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'VGPOS' '参考项次' '14' '' '5' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'MATNR' '商品编码' '15' '' '18' ' ' ' ' 'X'. MAR_ADD_FIELDCAT2 'EAN11' '条码' '16' '' '15' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'MAKTX' '商品名称' '17' '' '30' ' ' ' ' ''. *&->START ADD BY AD_CAIXIANG ON 20130514 ECDK911331 MAR_ADD_FIELDCAT2 'YLBID1' '大类编码' '18' '' '15' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'YDLNAM' '大类名称' '18' '' '30' ' ' ' ' ''. *&->END ADD. MAR_ADD_FIELDCAT2 'MEINS' '单位' '19' '' '5' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'YYCARNO' '车辆号' '20' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'BLDAT' '凭证日期' '23' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'ERZET' '时间' '23' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'WADAT_IST' '实际发货日期' '24' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'ANZPK' '包数' '25' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'GROES' '规格' '26' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'YUMREZ1' '件装数' '28' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'DINH' '订货件数' '29' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'MENGE' '订货数量' '30' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'SHFA' '实发件数' '31' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'LFIMG' '实发数量' '32' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'JINZH' '皮重' '33' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'NAME_TEXT' '制单人' '36' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'LIFNR' '供应商编码' '37' '' '10' ' ' ' ' 'X'. MAR_ADD_FIELDCAT2 'NAME3' '供应商名称' '38' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'JIAGE' '价格' '38' '' '10' ' ' ' ' ''. MAR_ADD_FIELDCAT2 'JINE' '金额' '38' '' '10' ' ' ' ' ''. "MAR_ADD_FIELDCAT2 'TDDAT' '计划日期' '21' '' '10' ' ' ' ' ''. ENDFORM. " FRM_FIELDCAT_GET2