美文网首页
ALV自动刷新

ALV自动刷新

作者: SmalltalkVoice | 来源:发表于2016-05-04 13:56 被阅读490次
    
    
    *&---------------------------------------------------------------------*
    *& Report  ZRPP015
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*
    
    REPORT zrpp015.
    TYPE-POOLS:vrm,slis.
    TABLES: resb,ztpp015,mard.
    TYPES: BEGIN OF ty_data,
             rsnum         TYPE resb-rsnum ,"调拨单号
             matnr         TYPE resb-matnr ,"物料编码
             maktx         TYPE makt-maktx ,"物料描述
             lgort         TYPE resb-lgort ,"调出仓库
             umlgo         TYPE resb-umlgo ,"调入仓库
             bdmng         TYPE resb-bdmng,  "需求数量
             enmng         TYPE resb-enmng  ,"计划数量
             rspos         TYPE resb-rspos,
             zzsysl        TYPE resb-bdmng,
             menge(8)       ,"实际数量输入的值
             l_mess        TYPE string,"检测消息
             line_color(4),
           END OF ty_data.
    DATA:  itab_data TYPE TABLE OF ty_data WITH HEADER LINE.
    
    TYPES: BEGIN OF ty_tmp,
             pdatu TYPE pbed-pdatu,"日期
             entli TYPE pbed-entli,"日期类型
             bedae LIKE pbim-bedae,              "需求类型 成品 BSF ;其他 VSF
             matnr LIKE pbim-matnr,
             werks LIKE pbim-werks,
             plnmg TYPE pbed-plnmg,"数量
           END OF ty_tmp.
    DATA:  itab_tmp TYPE TABLE OF ty_tmp WITH HEADER LINE.
    * 定义ALV相关变量
    DATA: f_repid LIKE sy-repid.
    DATA: f_title TYPE lvc_title.
    DATA: gs_layout TYPE slis_layout_alv.
    DATA: it_fields TYPE slis_t_fieldcat_alv.
    DATA: wa_fields TYPE LINE OF slis_t_fieldcat_alv.
    DATA: zflag.
    ****************************
    ****************定义相关BAPI
    
    **MB1B
    DATA: goodsmvt_header TYPE                   bapi2017_gm_head_01,
    **行项目
          goodsmvt_item   TYPE STANDARD TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
    **返回消息表
          return2         TYPE STANDARD TABLE OF bapiret2  WITH HEADER LINE.
    **  修改计划订单
    CONSTANTS: vactive(2)      VALUE '00', vsimu(2) VALUE '01', vdisp(2) VALUE '03'. "激活版本,模拟版本,显示版本
    
    DATA: wa_out  LIKE bapisitemr,
          return1 LIKE bapireturn1 OCCURS 10 WITH HEADER LINE ,
          sshdin  LIKE bapisshdin OCCURS 10 WITH HEADER LINE .
    *   MB22
    DATA:reservation               TYPE          bapi2093_res_key-reserv_no,
         reservationitems_changed  LIKE TABLE OF bapi2093_res_item_change WITH HEADER LINE,
         reservationitems_changedx LIKE TABLE OF bapi2093_res_item_changex WITH HEADER LINE,
         return_mb22               LIKE TABLE OF bapiret2 WITH HEADER LINE.
    ***************************
    CONSTANTS: co_color_red(4)         VALUE 'C600',      " alv 红色标记
               co_color_yellow(4)      VALUE 'C400'.   " alv 蓝色标记
    *定义屏幕输入参数
    SELECTION-SCREEN BEGIN OF BLOCK zbsy008 WITH FRAME TITLE text-003.
    *SELECTION-SCREEN PUSHBUTTON /2(12) text_but USER-COMMAND bld.
    SELECTION-SCREEN SKIP.
    PARAMETERS:  p_werks TYPE marc-werks  DEFAULT '6000'  OBLIGATORY,
                 p_rsnum TYPE  ztpp015-zdbd OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK zbsy008.
    
    INITIALIZATION.
    
    AT SELECTION-SCREEN.
    
    START-OF-SELECTION.
      "通过上载获得物料数据的创建或者修改数据
      PERFORM get_data.
      PERFORM proc_data.
    
      IF itab_data[] IS NOT INITIAL.
        PERFORM alv_display.
      ELSE.
        MESSAGE s001(00) WITH '没有查询到数据'.
      ENDIF.
    *&---------------------------------------------------------------------*
    *&      Form  GET_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM get_data .
      SELECT resb~rsnum resb~matnr  resb~lgort resb~umlgo resb~bdmng resb~enmng resb~rspos  INTO CORRESPONDING FIELDS OF TABLE itab_data
        FROM resb   INNER JOIN ztpp015  ON  resb~rsnum = ztpp015~rsnum   AND resb~rspos = ztpp015~rspos
        WHERE  resb~werks = p_werks AND ztpp015~zdbd = p_rsnum AND resb~xloek = '' AND resb~kzear = '' AND ztpp015~zflag = ' '.
      IF itab_data[]  IS NOT INITIAL.
        SELECT        pbed~pdatu pbed~entli  pbim~bedae   pbim~matnr  pbim~werks pbed~plnmg  INTO CORRESPONDING FIELDS OF TABLE itab_tmp
              FROM pbed INNER JOIN pbim ON   pbed~bdzei = pbim~bdzei
            FOR ALL ENTRIES IN itab_data  WHERE pbim~matnr = itab_data-matnr AND  pbim~werks = p_werks.
        SORT itab_tmp[]  BY werks  matnr pdatu.
      ENDIF.
    ENDFORM.                    " GET_DATA
    *&---------------------------------------------------------------------*
    *&      Form  PROC_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM proc_data .
      LOOP  AT itab_data.
        itab_data-zzsysl = itab_data-bdmng - itab_data-enmng.
        SELECT  SINGLE maktx  INTO itab_data-maktx  FROM  makt  WHERE matnr = itab_data-matnr AND spras = sy-langu.
        MODIFY itab_data. "TRANSPORTING maktx.
        CLEAR:itab_data .
      ENDLOOP.
      DELETE itab_data WHERE zzsysl = 0.
    ENDFORM.                    " PROC_DATA
    *&---------------------------------------------------------------------*
    *&      Form  ALV_DISPLAY
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM alv_display .
      f_repid = sy-repid.
      f_title = '配件计划导入的过账和冲销'.
      gs_layout-colwidth_optimize = 'X'.
      gs_layout-info_fieldname = 'LINE_COLOR'.
      DEFINE populate.
        wa_fields-fieldname    = &1.
        wa_fields-seltext_m    = &2.
        wa_fields-checkbox     = &3.
        wa_fields-edit         = &4.
        append wa_fields to it_fields.
        clear wa_fields.
      END-OF-DEFINITION.
      populate  'RSNUM'     '预留号'  '' ''.
      populate  'MATNR'     '物料'  '' ''.
      populate  'MAKTX'     '物料描述'  '' ''.
      populate  'LGORT'     '调出仓库'  '' ''.
      populate  'UMLGO'     '调入仓库'  '' ''.
      populate  'ZZSYSL'     '计划数量'  '' ''.
      populate  'MENGE' '实际数量' '' 'X'.
      " populate  'ZCOLOR' '颜色' '' ''.
      populate  'L_MESS' '返回值消息文本' '' ''.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = f_repid
          i_callback_pf_status_set = 'STATUS_SET'
          i_callback_user_command  = 'USER_COM'
          i_grid_title             = f_title
          is_layout                = gs_layout
          it_fieldcat              = it_fields
        TABLES
          t_outtab                 = itab_data[].
    ENDFORM.                    " ALV_DISPLAY
    *&---------------------------------------------------------------------*
    *&      Form  STATUS_SET
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->EXTAB      text
    *----------------------------------------------------------------------*
    FORM status_set USING  extab TYPE slis_t_extab.
    
      SET PF-STATUS 'ZRPP015'.
    ENDFORM.                    "STATUS_SET
    *&---------------------------------------------------------------------*
    *&      Form  USER_COM
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->R_UCOMM      text
    *      -->RS_SELFIELD  text
    *----------------------------------------------------------------------*
    FORM user_com USING r_ucomm LIKE sy-ucomm
                 rs_selfield TYPE slis_selfield.
      DATA: l_grid TYPE REF TO cl_gui_alv_grid.
      DATA: line_index TYPE sy-tabix.
    * 刷新ALV####
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          e_grid = l_grid.
    * 将EDIT数据更新回内表GT_RESULT中.
      CALL METHOD l_grid->check_changed_data.
      CASE r_ucomm.
        WHEN 'POS'.
          CLEAR:zflag.
          LOOP  AT itab_data .
    
            IF itab_data-menge > itab_data-zzsysl.
              itab_data-l_mess = '实际数量大于计划数量/'.
            ENDIF.
    
            CLEAR:mard.
            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
              EXPORTING
                input  = itab_data-matnr
              IMPORTING
                output = itab_data-matnr.
            SELECT SINGLE *  FROM  mard  WHERE  werks = p_werks AND lgort = itab_data-lgort AND  matnr = itab_data-matnr.
            IF mard-labst < itab_data-menge.
              CONCATENATE itab_data-l_mess '库存不足!' INTO itab_data-l_mess .
            ENDIF.
            IF itab_data-l_mess IS NOT INITIAL.
              itab_data-line_color = co_color_red.
              MODIFY itab_data  TRANSPORTING l_mess line_color .
              zflag = 'X'.
            ENDIF.
            CLEAR:itab_data .
          ENDLOOP.
    
          IF zflag <> 'X'.
            LOOP  AT itab_data .
              CLEAR: goodsmvt_header,goodsmvt_item,return2.
              REFRESH: return2, goodsmvt_item.
    *        IF itab_data-menge > itab_data-zzsysl.
    *          itab_data-l_mess = '实际数量大于计划数量'.
    *          itab_data-line_color = co_color_red.
    *          MODIFY itab_data  TRANSPORTING l_mess line_color .
    *          CONTINUE.
    *        ENDIF.
    
    ***批处理抬头部分
              goodsmvt_header-pstng_date = sy-datum."凭证日期
              goodsmvt_header-doc_date = sy-datum."记账日期
              " goodsmvt_header-header_txt = itab_data-rsnum.
              goodsmvt_header-header_txt = p_rsnum.
    ***批处理其他行项目
              goodsmvt_item-entry_qnt = itab_data-menge.
              IF itab_data-umlgo <> '5001'.
                goodsmvt_item-reserv_no = itab_data-rsnum.
                goodsmvt_item-res_item = itab_data-rspos.
                goodsmvt_item-move_type = '311'.
              ELSE.
                CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                  EXPORTING
                    input  = itab_data-matnr
                  IMPORTING
                    output = itab_data-matnr.
                goodsmvt_item-material = itab_data-matnr.
                goodsmvt_item-plant = p_werks.
                goodsmvt_item-move_type = '411'.
                goodsmvt_item-stge_loc = itab_data-lgort."
                goodsmvt_item-move_stloc  = itab_data-umlgo."收货
              ENDIF.
              " goodsmvt_item-mvt_ind = 'F'.
              APPEND goodsmvt_item.
              IF  itab_data-menge = '0'  OR itab_data-menge = ' '.
              ELSE.
                CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
                  EXPORTING
                    goodsmvt_header = goodsmvt_header
                    goodsmvt_code   = '04'
                  TABLES
                    goodsmvt_item   = goodsmvt_item
                    return          = return2.
              ENDIF.
              READ TABLE return2  WITH KEY  type = 'E'.
              IF  sy-subrc = 0.
                CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
                itab_data-l_mess = '过账过程出错:'.
                LOOP  AT return2  WHERE  type = 'E'.
                  CONCATENATE   itab_data-l_mess return2-message '请手工处理' INTO itab_data-l_mess.
                ENDLOOP.
                itab_data-line_color = co_color_red.
              ELSE.
                IF  itab_data-menge = '0'  OR itab_data-menge = ' '.
                ELSE.
                  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                    EXPORTING
                      wait = 'X'.
                ENDIF.
                itab_data-l_mess = '处理成功'.
                itab_data-line_color = co_color_yellow.
    
                UPDATE ztpp015  SET zflag = 'G' WHERE zdbd = p_rsnum AND rsnum = itab_data-rsnum AND rspos = itab_data-rspos.
                COMMIT WORK.
                IF  itab_data-umlgo = '5001' .
    *  给预留打删除标记
                  CLEAR:reservation  , reservationitems_changed  , reservationitems_changedx , return_mb22  ,
                        reservationitems_changed[]  , reservationitems_changedx[] , return_mb22[] .
                  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                    EXPORTING
                      input  = itab_data-rsnum
                    IMPORTING
                      output = itab_data-rsnum.
                  reservation = itab_data-rsnum.
    
                  reservationitems_changed-res_item = itab_data-rspos.
                  reservationitems_changed-delete_ind = 'X'.
                  APPEND reservationitems_changed.
    
                  reservationitems_changedx-res_item = itab_data-rspos.
                  reservationitems_changedx-delete_ind = 'X'.
                  APPEND reservationitems_changedx.
    
                  CALL FUNCTION 'BAPI_RESERVATION_CHANGE'
                    EXPORTING
                      reservation               = reservation
    *                 TESTRUN                   =
    *                 ATPCHECK                  =
                    TABLES
                      reservationitems_changed  = reservationitems_changed[]
                      reservationitems_changedx = reservationitems_changedx[]
    *                 RESERVATIONITEMS_NEW      =
                      return                    = return_mb22[]
    *                 EXTENSIONIN               =
                    .
                  READ TABLE return_mb22 WITH KEY  type = 'E'.
                  IF  sy-subrc = 0.
                    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
                  ELSE.
                    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                      EXPORTING
                        wait = 'X'.
                  ENDIF.
    
                ENDIF.
              ENDIF.
    
              MODIFY itab_data  TRANSPORTING l_mess line_color .
              IF    itab_data-line_color = co_color_yellow.
                DELETE itab_data.
              ENDIF.
              CLEAR:   itab_data.
            ENDLOOP.
          ENDIF.
    
          IF  itab_data[]  IS INITIAL.
            MESSAGE :  '处理成功'   TYPE 'S'.
          ENDIF.
        WHEN '&F03' OR  '&F12' OR '&F15'.
          LEAVE TO  TRANSACTION sy-tcode.
      ENDCASE.
    * 将EDIT数据更新到前台
      CALL METHOD l_grid->refresh_table_display.
    ENDFORM.                    "USER_COM                                               " DIS_DATA2
    
    

    相关文章

      网友评论

          本文标题:ALV自动刷新

          本文链接:https://www.haomeiwen.com/subject/tlbrrttx.html