//--线条 //3-----点击文字特效---

1,在package项目下创建新ABAP类

 

 2,自动创建类的对应方法

 

 3,定义结构,方法和对应传入参数

 1 CLASS ZCL_ZSDR034 DEFINITION
 2   PUBLIC
 3   FINAL
 4   CREATE PUBLIC .
 5 
 6   PUBLIC SECTION.
 7    INTERFACES IF_AMDP_MARKER_HDB .
 8    TYPES: BEGIN OF TY_DATA,
 9             BANFN        TYPE    EBAN-BANFN,   " 采购申请单号
10             CREATIONDATE TYPE    EBAN-CREATIONDATE,   " 申请单制单日期
11             MATNR        TYPE    EBAN-MATNR,   " 物料编码
12            MEINS        TYPE    EBAN-MEINS,   " 基本计量单位
13            LFDAT        TYPE    EBAN-LFDAT,   " 交货日期
14            MENGE        TYPE    EBAN-MENGE,   " 申请数量
15            WERKS        TYPE    EBAN-WERKS,   " 要货公司
16            LGORT        TYPE    EBAN-LGORT,   " 收货仓库
17            LIFNR        TYPE    EBAN-LIFNR,   " 供货公司
18            ERNAM        TYPE    EBAN-ERNAM,   " 申请单制单人
19          END OF TY_DATA .
20  TYPES :  TT_EBANX TYPE STANDARD TABLE OF TY_DATA .
21 
22      CLASS-METHODS GET_DATA_MX
23          IMPORTING
24           VALUE(IV_CLIENT)        TYPE SY-MANDT "客户端
25           VALUE(IV_BANFN)         TYPE  STRING "过滤条件-select-option
26      EXPORTING
27          VALUE(ET_DATA_MX) TYPE TT_EBANX.
28 
29   PROTECTED SECTION.
30   PRIVATE SECTION.
31 ENDCLASS.
32 
33 CLASS ZCL_ZSDR034 IMPLEMENTATION.
34 
35 METHOD GET_DATA_MX  BY DATABASE PROCEDURE
36                           FOR HDB
37                           LANGUAGE SQLSCRIPT
38                           OPTIONS  READ-ONLY
39                           USING  EBAN .
40 
41                   TAB_DATA_MX =  SELECT
42                                 BANFN,
43                                 CREATIONDATE,
44                                 MATNR,
45                                 MEINS,
46                                 LFDAT,
47                                 MENGE,
48                                 WERKS,
49                                 LGORT,
50                                 LIFNR,  -- 供货公司
51                                 ERNAM  --申请单制单人
52                                   FROM EBAN ;
53           /*-----------------   过滤   -------------------------*/
54      ET_DATA_MX = APPLY_FILTER(:TAB_DATA_MX, :IV_BANFN) ;
55 
56    ENDMETHOD.
57 ENDCLASS.
View Code

 

 4,SAP模式引用对应的类

 

 

  1 FORM FRM_CREATE_MINGXI .
  2 
  3   TYPES: BEGIN OF TY_DATA_M,
  4            BANFN        TYPE    EBAN-BANFN,   " 采购申请单号
  5            CREATIONDATE TYPE    EBAN-CREATIONDATE,   " 申请单制单日期
  6            MATNR        TYPE    EBAN-MATNR,   " 物料编码
  7 *           MAKTX        TYPE    MAKT-MAKTX,   " 物料名称
  8            MEINS        TYPE    EBAN-MEINS,   " 基本计量单位
  9            LFDAT        TYPE    EBAN-LFDAT,   " 交货日期
 10            MENGE        TYPE    EBAN-MENGE,   " 申请数量
 11            WERKS        TYPE    EBAN-WERKS,   " 要货公司
 12            LGORT        TYPE    EBAN-LGORT,   " 收货仓库
 13            LIFNR        TYPE    EBAN-LIFNR,   " 供货公司
 14            ERNAM        TYPE    EBAN-ERNAM,   " 申请单制单人
 15          END OF TY_DATA_M.
 16 
 17   DATA : LT_EBANX TYPE TABLE OF TY_DATA_M,
 18          LS_EBANX TYPE TY_DATA_M.
 19   DATA:LT_EBAN TYPE TABLE OF TY_DATA_MX,
 20        LS_EBAN TYPE TY_DATA_MX.
 21 
 22 
 23   DATA : GT_DATA_MX TYPE TABLE OF TY_DATA_MX,
 24          GS_DATA_MX TYPE TY_DATA_MX.
 25 
 26 
 27 
 28   TYPES: BEGIN OF TY_DATA,
 29            BANFN TYPE    EBAN-BANFN,   " 采购申请单号
 30          END OF TY_DATA.
 31   DATA:LT_DATA TYPE TABLE OF TY_DATA,
 32        LS_DTA  TYPE TY_DATA.
 33 
 34   DATA: LR_BANFN      TYPE RANGE OF EBAN-BANFN, " 公司代码
 35         LR_BANFN_LINE LIKE LINE OF LR_BANFN.
 36   CLEAR: LR_BANFN ,LR_BANFN[] .
 37   CLEAR:GT_DATA_MX,GT_DATA_MX[].
 38   LOOP AT GT_ALV INTO GS_ALV WHERE CHECK = 'X' .
 39     LS_DTA-BANFN = GS_ALV-BANFN.
 40     LR_BANFN_LINE-SIGN = 'I' .
 41     LR_BANFN_LINE-OPTION = 'EQ' .
 42     LR_BANFN_LINE-LOW = GS_ALV-BANFN.
 43     LR_BANFN_LINE-HIGH = GS_ALV-BANFN .
 44     APPEND LR_BANFN_LINE TO LR_BANFN .
 45     APPEND LS_DTA TO LT_DATA .
 46     CLEAR LR_BANFN_LINE .
 47     CLEAR LS_DTA.
 48     CLEAR GS_ALV.
 49   ENDLOOP.
 50 
 51   DATA LF_WHERE TYPE STRING .
 52   CLEAR LF_WHERE .
 53   TRY.
 54       LF_WHERE = CL_SHDB_SELTAB=>COMBINE_SELTABS( IT_NAMED_SELTABS = VALUE #(
 55       ( NAME = 'BANFN'        DREF = REF #( LR_BANFN[]  ) ) " 采购申请单号
 56       ) ).
 57     CATCH CX_SHDB_EXCEPTION.
 58   ENDTRY.
 59 
 60 
 61   CALL METHOD ZCL_ZSDR034=>GET_DATA_MX
 62     EXPORTING
 63       IV_CLIENT  = SY-MANDT
 64       IV_BANFN   = LF_WHERE
 65     IMPORTING
 66       ET_DATA_MX = LT_EBANX.
 67 
 68 
 69   IF LT_DATA IS NOT INITIAL .
 70     SELECT
 71     EBAN~BANFN   " 采购申请单号
 72     EBAN~CREATIONDATE   " 申请单制单日期
 73     EBAN~MATNR   " 物料编码
 74     EBAN~MEINS   " 基本计量单位
 75     EBAN~LFDAT   " 交货日期
 76     EBAN~MENGE   " 申请数量
 77     EBAN~WERKS   " 要货公司
 78     EBAN~LGORT   " 收货仓库
 79     EBAN~LIFNR   " 供货公司
 80     EBAN~ERNAM   " 申请单制单人
 81     INTO CORRESPONDING FIELDS OF TABLE LT_EBAN  FROM EBAN
 82     FOR ALL ENTRIES IN LT_DATA
 83     WHERE EBAN~BANFN = LT_DATA-BANFN.
 84   ENDIF.
 85 
 86 *  CALL METHOD ZCL_ZWZH001=>GET_DATA_MX
 87 *    EXPORTING
 88 *      BANFN      = '1300002453'
 89 *    IMPORTING
 90 *      ET_DATA_MX = LT_EBANX.
 91 
 92 
 93   LOOP AT LT_EBAN INTO LS_EBAN  .
 94     SELECT SINGLE MAKTX INTO  LS_EBAN-MAKTX  FROM MAKT WHERE  MATNR = LS_EBAN-MATNR .
 95     SELECT SINGLE MEINSX INTO  LS_EBAN-MEINSX  FROM ZMMT065 WHERE  MATNR = LS_EBAN-MATNR AND WERKS = LS_EBAN-WERKS.
 96     IF SY-SUBRC = 0.
 97       SELECT SINGLE  UMREN,UMREZ INTO  @DATA(LF_DATA)  FROM MARM WHERE  MATNR = @LS_EBAN-MATNR AND MEINH   = @LS_EBAN-MEINSX.
 98       IF SY-SUBRC = 0.
 99         LS_EBAN-MENGEX =   LS_EBAN-MENGE *  LF_DATA-UMREN / LF_DATA-UMREZ .  "拆算数量
100       ENDIF.
101     ENDIF.
102     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
103       EXPORTING
104         INPUT  = LS_EBAN-MATNR
105       IMPORTING
106         OUTPUT = LS_EBAN-MATNR.
107     APPEND LS_EBAN TO GT_DATA_MX.
108     CLEAR LS_EBAN.
109   ENDLOOP.
110 
111 ENDFORM.
View Code

 

posted on 2021-07-27 17:20  雨水果冻  阅读(147)  评论(0编辑  收藏  举报