*********************************************************************** * Title : YHLMR007 * * Application : LM * * Subject : 服装PDA验货差异报表 * * Requested by : Yang_zhenglian (YH_LM) * * Execution : Online when required * * Ref no: : ERPS0543 * * Author : AD_CAIXIANG * * Req Date : 20121006 * *********************************************************************** * 服装PDA验货差异报表 * *********************************************************************** * 设计主要逻辑与原理说明 * *********************************************************************** *1.取数:按用户输入的交货凭证、验货日期查询自定义表获取交货单号 * * (有重复取单一值),不包含删除记录 * * 通过查询条件,先在自建表YTPDAIN中取得交货单号,然后通过交货单号, * * 去标准表里取得商品,然后回到自建表中找数量。 * *2.输出: 进行alv显示查询的那段时间里的交货单号对应的商品验货差异信息 * *********************************************************************** * MODIFICATIONS (latest entry at the top) * * ------------------------------------------------------------------- * * REL DATE NAME (COMPANY) DESCRIPTION TASK-NO * * --- ---- ---- --------- ----------- ------- * * ERPS0558 * *********************************************************************** REPORT YHLMR007 NO STANDARD PAGE HEADING MESSAGE-ID YH_LM01 LINE-SIZE 132 LINE-COUNT 65. *---------------------------------------------------------------------- * TYPE-POOLS *---------------------------------------------------------------------- TYPE-POOLS: SLIS. "ALV *---------------------------------------------------------------------- * TABLES/Structure *---------------------------------------------------------------------- TABLES: LIKP, LIPS, T001W, MARA, YTPDAIN. *---------------------------------------------------------------------- * DAGTA /Internal table *---------------------------------------------------------------------- DATA: BEGIN OF GT_DATA OCCURS 0, VBELN LIKE LIKP-VBELN, KUNNR LIKE LIKP-KUNNR, ARKTX LIKE LIPS-ARKTX, LFIMG LIKE LIPS-LFIMG, MATNR LIKE LIPS-MATNR, MEINS LIKE LIPS-MEINS, NAME1 LIKE T001W-NAME1, EAN11 LIKE MARA-EAN11, DATUM LIKE YTPDAIN-DATUM, MENGE LIKE YTPDAIN-MENGE, CHSHU LIKE YTPDAIN-MENGE, END OF GT_DATA. DATA: WA_DATA LIKE GT_DATA. DATA:GT_DATA1 LIKE TABLE OF GT_DATA. *---------------------------------------------------------------------- * Data parameters for alv report use *---------------------------------------------------------------------- DATA: G_PROGRAM TYPE SY-REPID, GW_LAYOUT TYPE SLIS_LAYOUT_ALV, GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV, GT_EVENT TYPE SLIS_T_EVENT, WA_EVENT TYPE SLIS_ALV_EVENT. DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID. DATA L_LEN TYPE I. *====================================================================== * SELECTION-SCREEN *====================================================================== SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001. *PARAMETERS: p_werks LIKE mseg-werks OBLIGATORY MEMORY ID wrk. ”PARAMETER 单值选项框定义 *SELECTION-SCREEN PUSHBUTTON pb1 UNIT_NOT_FOUND USER-COMMAND pb1. “PUSHBUTTON 选项框定义 *SELECTION-SCREEN COMMENT 04(20) TEXT-001. ”选择界面文本定义 SELECT-OPTIONS: S_VBELN FOR YTPDAIN-VBELN, S_DATUM FOR YTPDAIN-DATUM OBLIGATORY, S_WERKS FOR LIPS-WERKS OBLIGATORY. *& ADD 增加的条件选项,显示差异不为零的条目: SELECTION-SCREEN SKIP 1. SELECTION-SCREEN BEGIN OF LINE. PARAMETERS: P_GB TYPE C AS CHECKBOX DEFAULT 'X' . "界面勾选框定义 SELECTION-SCREEN END OF LINE. 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. *&获取数据 PERFORM FRM_GET_DATA. *&ALV展示输出 PERFORM FRM_ALV_OUTPUT. *---------------------------------------------------------------------- * END-OF-SELECTION *---------------------------------------------------------------------- *&---------------------------------------------------------------------* *& Form FRM_INITIAL *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_INITIAL. IF S_DATUM[] IS INITIAL. S_DATUM-LOW = SY-DATUM . S_DATUM-HIGH = SY-DATUM . APPEND S_DATUM. ENDIF. ENDFORM. " FRM_INITIAL *&---------------------------------------------------------------------* *& Form FRM_CHECK_AUTHOR *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_CHECK_AUTHOR. DATA: BEGIN OF LT_T001W OCCURS 0, WERKS LIKE T001W-WERKS, END OF LT_T001W. SELECT WERKS INTO TABLE LT_T001W FROM T001W WHERE WERKS IN S_WERKS. IF SY-SUBRC NE 0. MESSAGE I011 WITH '没有任何地点!'. ENDIF. LOOP AT LT_T001W. AUTHORITY-CHECK OBJECT 'M_MATE_WRK' ID 'WERKS' FIELD LT_T001W-WERKS "S_WERKS-LOW ID 'ACTVT' FIELD '03'. IF SY-SUBRC NE 0. MESSAGE I004 WITH '没有地点' LT_T001W-WERKS '权限!'. STOP. ENDIF. ENDLOOP. ENDFORM. " FRM_CHECK_AUTHOR *&---------------------------------------------------------------------* *& Form frm_get_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_GET_DATA . DATA: BEGIN OF LT_VBELN OCCURS 0 , VBELN LIKE YTPDAIN-VBELN, END OF LT_VBELN. DATA: BEGIN OF LT_MATNR OCCURS 0 , VBELN LIKE LIKP-VBELN, KUNNR LIKE LIKP-KUNNR, LFART LIKE LIKP-LFART, ARKTX LIKE LIPS-ARKTX, LFIMG LIKE LIPS-LFIMG, MATNR LIKE LIPS-MATNR, MEINS LIKE LIPS-MEINS, VGBEL LIKE LIPS-VGBEL, VGPOS LIKE LIPS-VGPOS, NAME1 LIKE T001W-NAME1, EAN11 LIKE MARA-EAN11, DATUM LIKE YTPDAIN-DATUM, MENGE LIKE YTPDAIN-MENGE, END OF LT_MATNR. DATA: BEGIN OF LT_EKPO OCCURS 0, EBELN LIKE EKPO-EBELN, EBELP LIKE EKPO-EBELP, LGORT LIKE EKPO-LGORT, RESLO LIKE EKPO-RESLO, END OF LT_EKPO. DATA: BEGIN OF LT_T001W OCCURS 0, WERKS LIKE T001W-WERKS, NAME1 LIKE T001W-NAME1, END OF LT_T001W. DATA: BEGIN OF LT_MARA OCCURS 0, MATNR LIKE MARA-MATNR, EAN11 LIKE MARA-EAN11, END OF LT_MARA. DATA: LT_TAB LIKE TABLE OF LT_MATNR WITH HEADER LINE. *&G1.通过输入的时间条件在服装PDA提交表中找到交货单号: SELECT DISTINCT VBELN INTO TABLE LT_VBELN FROM YTPDAIN WHERE DATUM IN S_DATUM AND VBELN IN S_VBELN. IF SY-SUBRC NE 0. MESSAGE I011 WITH '没有查询到符合条件的数据!'. STOP. ENDIF. *&G2.通过找到的交货单号在交货单数据表中取得商品信息: SELECT A~KUNNR A~VBELN A~LFART B~MATNR B~MEINS B~ARKTX B~LFIMG B~VGBEL B~VGPOS INTO CORRESPONDING FIELDS OF TABLE LT_MATNR FROM LIKP AS A JOIN LIPS AS B ON A~VBELN EQ B~VBELN FOR ALL ENTRIES IN LT_VBELN WHERE A~VBELN EQ LT_VBELN-VBELN AND B~WERKS IN S_WERKS. **&G3. 交货数量汇总: *LOOP AT LT_MATNR. * COLLECT LT_MATNR. *ENDLOOP. LT_TAB[] = LT_MATNR[]. SORT LT_MATNR BY VGBEL VGPOS. DELETE ADJACENT DUPLICATES FROM LT_MATNR COMPARING VGBEL VGPOS. *&取送达方值 SELECT EBELN EBELP LGORT RESLO INTO TABLE LT_EKPO FROM EKPO FOR ALL ENTRIES IN LT_TAB WHERE EBELN EQ LT_TAB-VGBEL AND EBELP EQ LT_TAB-VGPOS+1(5). SORT LT_EKPO BY EBELN EBELP. REFRESH LT_TAB. *&取送达方地点名称 SELECT WERKS NAME1 INTO TABLE LT_T001W FROM T001W. * FOR ALL ENTRIES IN LT_TAB. * WHERE WERKS EQ LT_TAB-KUNNR. SORT LT_T001W BY WERKS. LT_TAB[] = LT_MATNR[]. SORT LT_TAB BY MATNR. DELETE ADJACENT DUPLICATES FROM LT_TAB COMPARING MATNR. *&取商品条码 SELECT MATNR EAN11 INTO TABLE LT_MARA FROM MARA FOR ALL ENTRIES IN LT_TAB WHERE MATNR EQ LT_TAB-MATNR. SORT LT_MARA BY MATNR. REFRESH LT_TAB. *&G4.循环内表,对单位送达方信息处理 LOOP AT LT_MATNR. *&G4.1 转换单位: CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING INPUT = LT_MATNR-MEINS LANGUAGE = '1' IMPORTING * LONG_TEXT = OUTPUT = LT_MATNR-MEINS * SHORT_TEXT = EXCEPTIONS UNIT_NOT_FOUND = 1 OTHERS = 2. *&G4.2 如果移库配送 LIKP- LFART=‘NL’ 则 送达方的值取EKPO-LGORT IF LT_MATNR-LFART = 'NL'. READ TABLE LT_EKPO WITH KEY EBELN = LT_MATNR-VGBEL EBELP = LT_MATNR-VGPOS+1(5) BINARY SEARCH. IF SY-SUBRC EQ 0. LT_MATNR-KUNNR = LT_EKPO-LGORT. ENDIF. ELSE. *&G4.3 如果移库返配LIKP- LFART=‘NLR’则送达方的值取EKPO-RESLO IF LT_MATNR-LFART = 'NLR'. READ TABLE LT_EKPO WITH KEY EBELN = LT_MATNR-VGBEL EBELP = LT_MATNR-VGPOS+1(5) BINARY SEARCH. IF SY-SUBRC EQ 0. LT_MATNR-KUNNR = LT_EKPO-RESLO. ENDIF. ENDIF. ENDIF. *&G4.4. 取得送达方名称:(KNA1) READ TABLE LT_T001W WITH KEY WERKS = LT_MATNR-KUNNR BINARY SEARCH. IF SY-SUBRC EQ 0. LT_MATNR-NAME1 = LT_T001W-NAME1. ENDIF. *&G4.5. 取的商品条码: READ TABLE LT_MARA WITH KEY MATNR = LT_MATNR-MATNR BINARY SEARCH. IF SY-SUBRC EQ 0. LT_MATNR-EAN11 = LT_MARA-EAN11. ENDIF. *&G4.6 赋值已扫描数量: LT_MATNR-MENGE = 0. MODIFY LT_MATNR. ENDLOOP. *&G5. 内表LT_MATNR 的值给入GT_DATA. LOOP AT LT_MATNR. MOVE-CORRESPONDING LT_MATNR TO GT_DATA. APPEND GT_DATA. ENDLOOP. *&G6. 最终显示的内表循环,差异数量处理 "BREAK AD_CAIXIANG. LOOP AT GT_DATA. SELECT SINGLE SUM( MENGE ) INTO GT_DATA-MENGE FROM YTPDAIN WHERE VBELN EQ GT_DATA-VBELN AND MATNR EQ GT_DATA-MATNR AND DATUM IN S_DATUM AND DELMK NE 'X' GROUP BY VBELN MATNR. *&G6.1 计算差异数量: GT_DATA-CHSHU = GT_DATA-LFIMG - GT_DATA-MENGE. MODIFY GT_DATA. ENDLOOP. *& ADD G6.1.1 只显示差异数量按钮,取得数据,当此条件时,则筛选出差异数量不为零的值: IF P_GB IS NOT INITIAL. DELETE GT_DATA WHERE CHSHU = '0'. ENDIF. *&G7. 获取条目数 DESCRIBE TABLE GT_DATA LINES L_LEN. *&G8. 判断是否取得数据 IF L_LEN EQ 0. MESSAGE I001 WITH '没有查询到数据!'. STOP. ENDIF. *&G9. 内表排序: SORT GT_DATA BY VBELN MATNR. ENDFORM. " frm_get_data *&---------------------------------------------------------------------* *& Form frm_alv_output *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_ALV_OUTPUT . DATA: L_NN TYPE I. DEFINE ADD_FIELDCAT. CLEAR WA_FIELDCAT. WA_FIELDCAT-FIELDNAME = &1. WA_FIELDCAT-SELTEXT_L = &2. WA_FIELDCAT-KEY = &3. WA_FIELDCAT-COL_POS = L_NN + 1. WA_FIELDCAT-JUST = &4. WA_FIELDCAT-OUTPUTLEN = &5. WA_FIELDCAT-FIX_COLUMN = &6. WA_FIELDCAT-NO_ZERO = &7. WA_FIELDCAT-EDIT = &8. APPEND WA_FIELDCAT TO GT_FIELDCAT. END-OF-DEFINITION. CLEAR GT_FIELDCAT. REFRESH GT_FIELDCAT. ADD_FIELDCAT 'VBELN' '交货单号' '' '' '' '' '' ''. ADD_FIELDCAT 'KUNNR' '送达方' '' '' '' '' '' ''. ADD_FIELDCAT 'NAME1' '送达方名称' '' '' '' '' '' ''. ADD_FIELDCAT 'EAN11' '商品条码' '' '' '' '' '' ''. ADD_FIELDCAT 'MATNR' '商品编码' '' '' '' '' 'X' ''. ADD_FIELDCAT 'ARKTX' '商品名称' '' '' '' '' '' ''. ADD_FIELDCAT 'LFIMG' '交货数量' '' '' '' '' '' ''. ADD_FIELDCAT 'MENGE' '已扫描数量' '' '' '' '' '' ''. ADD_FIELDCAT 'CHSHU' '差异数量' '' '' '' '' '' ''. ADD_FIELDCAT 'MEINS' '单位' '' '' '' '' '' ''. GW_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. * gw_layout-box_fieldname = 'SEL'. *& 调用函数显示ALV列表 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = G_PROGRAM I_SAVE = 'A' IS_LAYOUT = GW_LAYOUT IT_FIELDCAT = GT_FIELDCAT IT_EVENTS = GT_EVENT TABLES T_OUTTAB = GT_DATA EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2. ENDFORM. " frm_alv_output