zoukankan      html  css  js  c++  java
  • YHMMR003 农户基本信息的维护程序

    ***********************************************************************
    * Title           :                                           *
    * Application     : MM                                               *
    * Subject         : 农户基本信息的维护程序                            *
    * Requested by    :        (YH_MM)                                    *
    * Execution       : Online when required                              *
    * Ref no:         :                                          *
    * Author          :                                          *
    * Req Date        : 20120709                                          *
    ***********************************************************************
    *              农户信息及商品关系维护程序                         *
    ***********************************************************************
    *              设计主要逻辑与原理说明   :::                    *
    ***********************************************************************
    * 1.程序流程及功能:自建农户基表创建农户基本信息的新增,修改,及查询  *
    * 2,取数:从自建农户基本信息表中取得需要展示的数据用ALV显示.          *
    * 3.输入:农户名称,身份证号码。                                      *
    * 4.输出:农户编码, 农户名称,身份证号码,状态。                     *
    * 5.事件:用Tabel Control实现自建表的新增功能用ALV实现自建表的修改功能*
    ***********************************************************************
    ***********************************************************************
    * MODIFICATIONS (latest entry at the top)                             *
    * ------------------------------------------------------------------- *
    * REL  DATE    NAME (COMPANY)   DESCRIPTION               TASK-NO     *
    * ---  ----    ---- ---------     -----------             -------     *
    *                                                                     *
    ***********************************************************************
    REPORT  YHMMR003 NO STANDARD PAGE HEADING
                     LINE-SIZE  132
                     LINE-COUNT 65(1)
                     MESSAGE-ID YH_MM1.
    
    
    
    *---------------------------------------------------------------------------------
    *---------------------- 声明类型池----------------------*
    *---------------------------------------------------------------------------------
    TYPE-POOLS: SLIS,
                VRM.
    
    *---------------------------------------------------------------------------------
    *----------------------声明数据字典---------------------*
    *---------------------------------------------------------------------------------
    TABLES: YTNAH,
            YTNHCG.
    
    *---------------------------------------------------------------------------------
    *--------------------- 结构定义-------------------------*
    *---------------------------------------------------------------------------------
    TYPES: BEGIN OF TY_YTNAH,
           NHBM  TYPE YTNAH-NHBM,
           NHMC  TYPE YTNAH-NHMC,
           SFZHM TYPE YTNAH-SFZHM,
           ZHTA  TYPE YTNAH-ZHTA,
           CPUTM TYPE YTNAH-CPUTM,
           AEDAT TYPE YTNAH-AEDAT,
           USNAM TYPE YTNAH-USNAM,
           END OF TY_YTNAH.
    TYPES: TY_TAB_YTNAH TYPE TY_YTNAH OCCURS 0.
    DATA: G_LINE TYPE I.
    DATA :BEGIN OF GT_ITAB OCCURS 0.
            INCLUDE STRUCTURE YTNAH.
    DATA:  SEL TYPE C,
           UPD.
    DATA: END OF GT_ITAB.
    
    DATA: WA_TAB LIKE GT_ITAB.
    DATA: WA_TAB1 LIKE GT_ITAB.
    
    DATA :BEGIN OF GT_ITAB1 OCCURS 0.
            INCLUDE STRUCTURE YTNAH.
    DATA:  SEL TYPE C,
           UPD.
    DATA: END OF GT_ITAB1.
    
    *---------------------------------------------------------------------------------
    *----------------------- 内表定义 -----------------------*
    *---------------------------------------------------------------------------------
    
    DATA: BEGIN OF GT_DATA OCCURS 0.
            INCLUDE STRUCTURE YTNAH.
    DATA: ROWCOLOR(4) TYPE C,
          CELLCOLOR TYPE LVC_T_SCOL,
          PEYPE_DD_HNDL TYPE INT4.
    DATA: END OF GT_DATA.
    DATA: WA_DATA LIKE GT_DATA.
    
    DATA: GT_CHANGE    TYPE TABLE OF YTNAH WITH HEADER LINE,
          GT_CH  TYPE TABLE OF YTNAH WITH HEADER LINE,
          WA_CHANGE    TYPE YTNAH.
    DATA: GT_YTNAH   TYPE TABLE OF YTNAH WITH HEADER LINE,
          WA_YTNAH   TYPE YTNAH.
    
    *---------------------------------------------------------------------------------
    *---------------------- ALV参数定义 ---------------------*
    *---------------------------------------------------------------------------------
    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: G_LINNO  LIKE SY-TABIX,
          G_LINES  TYPE I,
          G_LINES1 TYPE I,
          G_CREA   TYPE C,
          G_COUNT  TYPE I.
    
    *&SPWIZARD: LINES OF TABLECONTROL 'TC_ITEM'
    DATA:     G_TC_ITEM_LINES  LIKE SY-LOOPC.
    *&SPWIZARD: LINES OF TABLECONTROL 'TC_ITEM1'
    DATA:     G_TC_ITEM1_LINES  LIKE SY-LOOPC.
    *---------------------------------------------------------------------------------
    *--------------------- 全局变量定义 ----------------------*
    *---------------------------------------------------------------------------------
    DATA: G_INDEX    TYPE SY-TABIX.
    DATA: OK_CODE    TYPE SY-UCOMM,
          G_DUP_FLAG TYPE C.
    DATA  G_ANSWER   TYPE C.
    DATA: VID        TYPE VRM_ID,
          VLIST      TYPE VRM_VALUES,
          WA_VALUE   LIKE LINE OF VLIST.
    *---------------------------------------------------------------------------------
    *--------------------- 屏幕定义 --------------------------*
    *---------------------------------------------------------------------------------
    *&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_ITEM' ITSELF
    CONTROLS: TC_ITEM TYPE TABLEVIEW USING SCREEN 0100.
    *&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_ITEM1' ITSELF
    CONTROLS: TC_ITEM1 TYPE TABLEVIEW USING SCREEN 0200.
    
    
    *=================================================================================
    *                                SELECTION-SCREEN
    *=================================================================================
    SELECTION-SCREEN BEGIN OF BLOCK BLK0 WITH FRAME TITLE TEXT-001.
    SELECTION-SCREEN SKIP 1.
    *& 农户编码
    *& 身份证号码
    SELECT-OPTIONS: S_NHBM   FOR YTNAH-NHBM  MATCHCODE OBJECT YH_NHBM NO-EXTENSION NO INTERVALS,
                    S_SFZHM  FOR YTNAH-SFZHM MATCHCODE OBJECT YH_SFZHM ,
    *& 农户采购组织区分标识:
                    S_NHSIG  FOR YTNHCG-NHSIG NO INTERVALS NO-EXTENSION
                    MATCHCODE OBJECT YH_NHSIG ." OBLIGATORY. "农户对应的采购组织信息。
    
    *& 查询
    *& 修改
    *& 新增
    PARAMETERS:     RB_QUERY  RADIOBUTTON GROUP G1,
                    RB_CHANG  RADIOBUTTON GROUP G1,
                    RB_ADD    RADIOBUTTON GROUP G1. " DEFAULT 'X'.
    
    SELECTION-SCREEN END OF BLOCK BLK0.
    
    *----------------------------------------------------------------------
    *  INITIALIZATION
    *----------------------------------------------------------------------
    INITIALIZATION.
    
    * 初始化数据
    *  PERFORM frm_initial.
    
    *----------------------------------------------------------------------
    *  AT SELECTION-SCREEN
    *----------------------------------------------------------------------
    AT SELECTION-SCREEN.
    
      PERFORM FRM_INIT_DATA.
    * 权限检查部分
      PERFORM FRM_CHECK_AUTHOR.
    
    *=================================================================================
    *                                MAIN PROGRAM
    *=================================================================================
    *---------------------------------------------------------------------------------
    *  START-OF-SELECTION
    *---------------------------------------------------------------------------------
    START-OF-SELECTION.
    *&S1 查询时
      IF RB_QUERY IS NOT INITIAL.
    *&S1.1取数
        PERFORM FRM_GET_DATA.
    *&S1.2ALV显示
        PERFORM FRM_OUTPUT_DATA.
      ENDIF.
    
    *&S2 修改时
      IF RB_CHANG IS NOT INITIAL.
        CLEAR: GT_DATA, WA_DATA.
    *&S2.1获取修改数据
        PERFORM GET_DATA_MODIFY.
    *&S2.2数据修改操作
        PERFORM FRM_MODIFY_DATA.
      ENDIF.
    
    
    
    *&S3 TB维护农户表
      IF RB_ADD NE SPACE.
    *& 以采购组织对农户进行区分:
        IF S_NHSIG IS INITIAL.
          MESSAGE I006 WITH  '请选择创建农户对应的采购组织!!!'.
          STOP.
        ENDIF.
    
        TC_ITEM-LINES = 0 .
        TC_ITEM-TOP_LINE = 1.
    
    *& 进行维护的时候,锁定数据表。
        PERFORM FRM_LOCK_YTNAH USING SY-MANDT.
        CALL SCREEN 0100.
      ENDIF.
    *---------------------------------------------------------------------------------
    *  END-OF-SELECTION
    *---------------------------------------------------------------------------------
    
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_INIT_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_INIT_DATA .
    *& 查询时候的必输条件:
      IF RB_QUERY IS NOT INITIAL.
        IF S_NHBM IS INITIAL.
          MESSAGE I006 WITH '请输入农户编码作为查询条件!'.
          STOP.
        ENDIF.
      ENDIF.
    
    *& 修改时候的必输条件:
      IF RB_CHANG IS NOT INITIAL.
        IF S_NHBM IS INITIAL.
          MESSAGE I006 WITH '请输入农户编码作为查询条件!'.
          STOP.
        ENDIF.
      ENDIF.
    
    ENDFORM.                    " FRM_INIT_DATA
    
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_CHECK_AUTHOR
    *&---------------------------------------------------------------------*
    *  *& 权限检查
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_CHECK_AUTHOR .
    
    *    AUTHORITY-CHECK OBJECT 'M_MATE_WGR'
    *                 ID 'ADD' FIELD RB_ADD
    *                 ID 'ACTVT' FIELD '01'.
    *  IF SY-SUBRC <> 0.
    *    MESSAGE i012 with '没有农户信息' RB_ADD '创建的权限!'.
    *    stop.
    *  ENDIF.
    
    ENDFORM.                    " FRM_CHECK_AUTHOR
    
    *&---------------------------------------------------------------------*
    *&      Form  frm_get_data
    *&---------------------------------------------------------------------*
    *       从数据表中取数(从自建表ytnah中取数到gt_data)
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_GET_DATA .
    
    *&S1.1.1从农户表中取得数据
      SELECT NHBM
             NHMC
             SFZHM
             ZHTA
             CPUTM
             AEDAT
             USNAM
        INTO CORRESPONDING FIELDS OF  TABLE GT_DATA
        FROM YTNAH
       WHERE NHBM  IN S_NHBM
         AND SFZHM IN S_SFZHM.
    
    *&S1.1.2检查有没有数据
      DESCRIBE TABLE GT_DATA LINES G_LINES.
      IF G_LINES = 0.
        MESSAGE I001 WITH '根据查询条件未找到数据!'.
        STOP.
      ENDIF.
    
    *&S1.1.3内表排序:
      SORT GT_DATA BY NHBM.
    
    ENDFORM.                    " frm_get_data
    
    
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_OUTPUT_DATA
    *&---------------------------------------------------------------------*
    *        ALV显示
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_OUTPUT_DATA .
    
      DEFINE 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-CHECKBOX     =  &7.
    
        APPEND WA_FIELDCAT TO GT_FIELDCAT.
      END-OF-DEFINITION.
    
      CLEAR GT_FIELDCAT.
    
      ADD_FIELDCAT  'NHBM'       '农户编码'    1  'L'  7  ''  ''.
      ADD_FIELDCAT  'NHMC'       '农户名称'    2  'L'  40 ''  ''.
      ADD_FIELDCAT  'SFZHM'      '身份证号码'  3  'L'  18 ''  ''.
      ADD_FIELDCAT  'ZHTA'       '状态'        4  'R'  3  ''  ''.
      ADD_FIELDCAT  'CPUTM'      '输入时间'    5  'L'  6  ''  ''.
      ADD_FIELDCAT  'AEDAT'      '更改时间'    6  'L'  8  ''  ''.
      ADD_FIELDCAT  'USNAM'      '用户名'      7  'L'  12 ''  ''.
    
    
      GW_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.  "优化列
    
      G_PROGRAM = SY-REPID.
    
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM = G_PROGRAM
          IS_LAYOUT          = GW_LAYOUT
          IT_FIELDCAT        = GT_FIELDCAT[]
          I_SAVE             = 'A'
        TABLES
          T_OUTTAB           = GT_DATA.
    
    
    ENDFORM.                    " FRM_OUTPUT_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  GET_DATA_MODIFY
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM GET_DATA_MODIFY .
    
    
    *&S2.1.1从农户表中取得数据
      SELECT NHBM
             NHMC
             SFZHM
             ZHTA
             CPUTM
             AEDAT
             USNAM
        INTO CORRESPONDING FIELDS OF  TABLE GT_CHANGE
        FROM YTNAH
       WHERE NHBM  IN S_NHBM
         AND SFZHM IN S_SFZHM.
    
    *&2.1.2检查有没有数据
      DESCRIBE TABLE GT_CHANGE LINES G_LINES.
      IF G_LINES = 0.
        MESSAGE E001 WITH '根据查询条件未找到数据!'.
        STOP.
      ENDIF.
    *&2.1.3内表排序:
      SORT GT_CHANGE BY NHBM.
    
    ENDFORM.                    " GET_DATA_MODIFY
    
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_MODIFY_DATA
    *&---------------------------------------------------------------------*
    *       ALV显示,然后用ALV界面进行修改
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_MODIFY_DATA .
    
      CLEAR WA_EVENT.
      MOVE 'PF_STATUS_SET' TO WA_EVENT-NAME.
      MOVE 'F_PF_STATUS_SET' TO WA_EVENT-FORM.
      APPEND WA_EVENT TO GT_EVENT.
    
      CLEAR WA_EVENT.
      MOVE 'USER_COMMAND' TO WA_EVENT-NAME.
      MOVE 'F_USER_COMMAND' TO WA_EVENT-FORM.
      APPEND WA_EVENT TO GT_EVENT.
    
      DEFINE 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-CHECKBOX     =  &7.
        WA_FIELDCAT-EDIT         =  &8.
        WA_FIELDCAT-EDIT_MASK    =  &9.
    *    wa_fieldcat-datatype     =  &10.
    
        APPEND WA_FIELDCAT TO GT_FIELDCAT.
      END-OF-DEFINITION.
    
      CLEAR GT_FIELDCAT.
    
      ADD_FIELDCAT  'NHBM'       '农户编码'    1  'L'  7  ''  '' ''   '' .
      ADD_FIELDCAT  'NHMC'       '农户名称'    2  'L'  40 ''  '' 'X'  '' .
      ADD_FIELDCAT  'SFZHM'      '身份证号码'  3  'L'  18 ''  '' 'X'  '' .
      ADD_FIELDCAT  'ZHTA'       '状态'        4  'R'  3  ''  '' 'X'  '' .
      ADD_FIELDCAT  'CPUTM'      '输入时间'    5  'L'  6  ''  ''  ''  '' .
      ADD_FIELDCAT  'AEDAT'      '更改时间'    6  'L'  8  ''  ''  ''  '' .
      ADD_FIELDCAT  'USNAM'      '用户名'      7  'L'  12 ''  ''  ''  ' '.
    
    
      GW_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.  "优化列
      GW_LAYOUT-BOX_FIELDNAME = 'ZSEL'.
      G_PROGRAM = SY-REPID.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM       = G_PROGRAM
          I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
          I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
          IS_LAYOUT                = GW_LAYOUT
          IT_FIELDCAT              = GT_FIELDCAT
          I_SAVE                   = 'A'
          IT_EVENTS                = GT_EVENT
        TABLES
          T_OUTTAB                 = GT_CHANGE
        EXCEPTIONS
          PROGRAM_ERROR            = 1
          OTHERS                   = 2.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    ENDFORM.                     "FRM_MODIFY_DATA
    
    
    *&---------------------------------------------------------------------*
    *&      ALV EVENT Form  FRM_SET_LAYOUT
    *&      ALV状态栏事件  状态:STATUS
    *&---------------------------------------------------------------------*
    FORM F_PF_STATUS_SET  USING EXTAB TYPE SLIS_T_EXTAB.
    
      SET PF-STATUS '0200' EXCLUDING EXTAB.
    
    ENDFORM.                     "f_pf_status_set
    
    
    *&---------------------------------------------------------------------*
    *&      ALV EVENT Form f_user_command
    *&---------------------------------------------------------------------*
    FORM F_USER_COMMAND USING RF_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.
      CALL METHOD LR_GRID->REFRESH_TABLE_DISPLAY.
    
      RS_SELFIELD-REFRESH = 'X'.
    
      CASE RF_UCOMM.
    
    **& 删除操作
    *    WHEN 'DELETE'.
    *      CLEAR OK_CODE.
    *      PERFORM FRM_DELETE_DATA_ALV.
    
    *& 保存操作
        WHEN 'SAVE'.
          CLEAR OK_CODE.
          PERFORM FRM_SAVE_DATA_ALV.
    
    *& 退出操作
        WHEN 'BACK'.
          CLEAR OK_CODE.
          PERFORM FRM_UNLOCK  USING SY-MANDT.
          LEAVE TO SCREEN 0.
    
        WHEN OTHERS.
    
          CLEAR OK_CODE.
    
      ENDCASE.
    ENDFORM.                    " f_user_command
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_DELETE_DATA_ALV
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_DELETE_DATA_ALV .
      DATA: L_INDEX  TYPE SY-TABIX.
    *& 检查数据是否存在:
        PERFORM FRM_CHECK_YTNAM.
    
      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          TITLEBAR              = '确认'
          TEXT_QUESTION         = '确定删除此信息吗?'
          TEXT_BUTTON_1         = ''
          TEXT_BUTTON_2         = ''
          DEFAULT_BUTTON        = '1'
          DISPLAY_CANCEL_BUTTON = ' '
          START_COLUMN          = 25
          START_ROW             = 6
          POPUP_TYPE            = 'ICON_MESSAGE_WARNING'
        IMPORTING
          ANSWER                = G_ANSWER
        EXCEPTIONS
          TEXT_NOT_FOUND        = 1
          OTHERS                = 2.
      CHECK G_ANSWER EQ  '1'.
    
    *& 修改时候删除记录操作:
      LOOP AT GT_CHANGE INTO WA_CHANGE WHERE ZSEL <> SPACE.
        L_INDEX = SY-TABIX.
    *    DELETE GT_CHANGE INDEX L_INDEX.
        DELETE ytnah FROM GT_CHANGE.
       IF SY-SUBRC EQ 0.
          DELETE GT_CHANGE INDEX L_INDEX.
       ENDIF.
    
      ENDLOOP.
    
    ENDFORM.                    " FRM_DELETE_DATA_ALV
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_SAVE_DATA_ALV
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_SAVE_DATA_ALV .
      PERFORM FRM_LOCK_YTNAH USING SY-MANDT.
    
    
      PERFORM FRM_CHECK_ZHTA.
    
      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          TITLEBAR              = '确认'
          TEXT_QUESTION         = '你真的要保存修改农户信息吗?'
          TEXT_BUTTON_1         = ''
          TEXT_BUTTON_2         = ''
          DEFAULT_BUTTON        = '1'
          DISPLAY_CANCEL_BUTTON = ' '
          START_COLUMN          = 25
          START_ROW             = 6
          POPUP_TYPE            = 'ICON_MESSAGE_WARNING'
        IMPORTING
          ANSWER                = G_ANSWER
        EXCEPTIONS
          TEXT_NOT_FOUND        = 1
          OTHERS                = 2.
      CHECK G_ANSWER EQ  '1'.
    
    *& 时间,日期,用户赋值:
      LOOP AT GT_CHANGE WHERE NHBM IS NOT INITIAL.
        MOVE: SY-UZEIT TO GT_CHANGE-CPUTM,
              SY-DATUM TO GT_CHANGE-AEDAT,
              SY-UNAME TO GT_CHANGE-USNAM.
        MODIFY  GT_CHANGE.
      ENDLOOP.
    
    *&888:通过内表更新数据表:
      MODIFY YTNAH FROM TABLE GT_CHANGE.
      IF SY-SUBRC EQ 0.
        COMMIT WORK.
        MESSAGE S006 WITH '数据保存成功!'.
      ELSE.
        ROLLBACK WORK.
        MESSAGE S006 WITH '数据保存失败!'.
      ENDIF.
    
    
    ENDFORM.                    " FRM_SAVE_DATA_ALV
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_CHECK_ZHTA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_CHECK_ZHTA .
    
      DATA: BEGIN OF LT_NHBM OCCURS 0,
            NHBM LIKE YTNAH-NHBM,
            END OF LT_NHBM.
    
      DATA: L_NHBM LIKE YTNAH-NHBM,
            L_NHMC LIKE YTNAH-NHMC.
    
      DATA: L_LINES TYPE I.
    *& 身份证重复性检查
      IF   GT_CHANGE-NHMC  NE SPACE
       AND GT_CHANGE-SFZHM NE SPACE
       AND GT_CHANGE-ZHTA  NE SPACE.
    
    *& 取得内表
        GT_CH[] = GT_CHANGE[].
        DESCRIBE TABLE GT_CHANGE LINES G_LINES.
    
        SORT GT_CH BY SFZHM."  NHBM.
    
        DELETE ADJACENT DUPLICATES FROM GT_CH COMPARING SFZHM.
        DESCRIBE TABLE GT_CH LINES L_LINES.
    
    *&判定记录是否存在:
        IF G_LINES NE L_LINES.
          MESSAGE E012 WITH '身份证号码重复输入,请检查!'.
          CLEAR G_LINES.
          STOP.
        ENDIF.
    
    *&---检查身份证位数是否正常:
        G_LINE = STRLEN( GT_CHANGE-SFZHM ).
        IF G_LINE <> 18." AND G_LINE <> 15.
          MESSAGE E012 WITH '请输入18位身份证号码!' GT_CHANGE-SFZHM.
        ENDIF.
    
      DATA: BEGIN OF LT_YTNAH OCCURS 0,
             NHBM LIKE YTNAH-NHBM,
            END OF LT_YTNAH.
    
     BREAK AD_CAIXIANG.
    *&---输入状态值进行检查
      LOOP AT GT_CHANGE INTO WA_CHANGE.
       CLEAR: LT_YTNAH, LT_YTNAH[].
       IF WA_CHANGE-ZHTA NE 'A' AND WA_CHANGE-ZHTA NE 'B'.
        MESSAGE E006 WITH '请输入合适的状态,A代表正常,B代表不正常!'.
        LEAVE TO SCREEN 0100 .
       ENDIF.
    
      IF WA_CHANGE-ZHTA EQ 'B'.
    *& 修改农户状态时,先要检查农户商品对应关系信息:
        SELECT NHBM
          INTO TABLE LT_YTNAH
          FROM YTNAM
         WHERE NHBM EQ WA_CHANGE-NHBM
           AND ZHTA EQ 'A'.
    
        IF SY-SUBRC EQ 0.
         MESSAGE E012 WITH '此农户正常商品对应关系信息记录存在,请检查!' WA_CHANGE-NHBM.
        ENDIF.
      ENDIF.
     ENDLOOP.
    
      ELSE.
        MESSAGE I013 WITH '请保持农户基本信息的完整!'.
        STOP.
      ENDIF.
    
    ENDFORM.                    " FRM_CHECK_ZHTA
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_UNLOCK_YTNAh
    *&---------------------------------------------------------------------*
    *       *&对自建表ytanh进行解锁
    *----------------------------------------------------------------------*
    *      -->P_SY_MANDT  text
    *----------------------------------------------------------------------*
    FORM FRM_UNLOCK_YTNAH  USING    P_SY_MANDT.
    
    *& -解锁表YTNAH
      CALL FUNCTION 'DEQUEUE_EYTNAH'
        EXPORTING
          MODE_YTNAH     = 'E'
          MANDT          = SY-MANDT
        EXCEPTIONS
          FOREIGN_LOCK   = 1
          SYSTEM_FAILURE = 2
          OTHERS         = 3.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    ENDFORM.                    " FRM_UNLOCK_YTNAh
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_LOCK_YTNAH
    *&---------------------------------------------------------------------*
    *       *&对自建表ytanh进行锁定
    *----------------------------------------------------------------------*
    *      -->P_SY_MANDT  text
    *----------------------------------------------------------------------*
    FORM FRM_LOCK_YTNAH  USING    P_SY_MANDT.
    
    *& -锁表YTNAH
      CALL FUNCTION 'ENQUEUE_EYTNAH'
        EXPORTING
          MODE_YTNAH     = 'E'
          MANDT          = SY-MANDT
        EXCEPTIONS
          FOREIGN_LOCK   = 1
          SYSTEM_FAILURE = 2
          OTHERS         = 3.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    ENDFORM.                    " FRM_LOCK_YTNAH
    
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS '0100'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE USER_COMMAND_0100 INPUT.
    
      CASE OK_CODE.
    *& 删除
          WHEN'DELETE'.
          CLEAR OK_CODE.
          PERFORM FRM_DELETE_DATA.
    
    *& 保存操作处理
        WHEN 'SAVE'.
          CLEAR OK_CODE.
          PERFORM FMR_CREA_DATA.
    
    *& 返回,删除,退出处理
        WHEN 'BACK' OR 'CANC' OR 'EXIT'.
          CLEAR OK_CODE.
          CLEAR: GT_ITAB.
          REFRESH: GT_ITAB.
          PERFORM FRM_UNLOCK USING SY-MANDT.
          LEAVE TO SCREEN 0.
    
    *& 全选处理
        WHEN 'ALL'.
          CLEAR OK_CODE.
          WA_TAB-SEL = 'X'.
          MODIFY GT_ITAB FROM WA_TAB TRANSPORTING SEL
                                      WHERE SEL = ' '.
    
    *& 取消全选处理
        WHEN 'RSAL'.
          CLEAR OK_CODE.
          WA_TAB-SEL = ' '.
          MODIFY GT_ITAB FROM WA_TAB TRANSPORTING SEL
                                      WHERE SEL = 'X'.
    
        WHEN 'P-' OR 'P--'  OR 'P+' OR 'P++'.
          CLEAR OK_CODE.
          PERFORM FRM_TURN_PAGE_100.
    
        WHEN OTHERS.
          CLEAR OK_CODE.
    
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    
    *&---------------------------------------------------------------------*
    *&      Module  PAI_MODIFY_DATA_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE PAI_MODIFY_DATA_0100 INPUT.
    
    *&---数据改变处理逻辑流
      DESCRIBE TABLE GT_ITAB LINES G_LINES.
      G_COUNT = SY-LOOPC.
      TC_ITEM-LINES = G_LINES + 1.
      CLEAR GT_ITAB.
    ENDMODULE.                 " PAI_MODIFY_DATA_0100  INPUT
    
    *&---------------------------------------------------------------------*
    *&      Module  PAI_EXIT_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE PAI_EXIT_0100 INPUT.
    
      CASE OK_CODE.
        WHEN 'EXIT' OR 'CANC'.
          CLEAR OK_CODE.
          LEAVE TO SCREEN 0.
    
    *&解锁数据表:
          PERFORM FRM_UNLOCK USING SY-MANDT.
    
      ENDCASE.
    ENDMODULE.                 " PAI_EXIT_0100  INPUT
    
    *&---------------------------------------------------------------------*
    *&      Module  PAI_CHECK_DATA_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE PAI_CHECK_DATA_0100 INPUT.
      DATA L_NHBM LIKE YTNAH-NHBM.
      DATA WA_ITAB LIKE GT_ITAB.
    
      IF GT_ITAB-NHMC  NE SPACE
         AND  GT_ITAB-SFZHM NE SPACE
         AND  GT_ITAB-ZHTA  NE SPACE.
    
    *&G1 身份证重复性检查
        SELECT SINGLE  NHBM INTO L_NHBM
                FROM YTNAH
                WHERE SFZHM EQ GT_ITAB-SFZHM.
        IF SY-SUBRC EQ 0.
          MESSAGE E014 WITH '此身份证:' GT_ITAB-SFZHM '已对应农户:' L_NHBM.
          LEAVE TO SCREEN 0100.
        ENDIF.
    
    * BREAK AD_CAIXIANG.
    *&G2 身份证长度检查
        G_LINE = STRLEN( GT_ITAB-SFZHM ).
        IF G_LINE <> 18." AND G_LINE <> 15.
          MESSAGE E012 WITH '请输入18位身份证号码!' GT_ITAB-SFZHM.
        ENDIF.
    
        CHECK SY-SUBRC <> 0.
    
    *&G3 身份证号码重复性检查:
        READ TABLE GT_ITAB INTO WA_TAB1 WITH KEY SFZHM = GT_ITAB-SFZHM.
        IF SY-SUBRC = 0.
          MESSAGE E012 WITH '身份证号码重复输入,请检查输入的身份证号码!' GT_ITAB-SFZHM.
        ENDIF.
    
       IF GT_ITAB-ZHTA NE 'A' AND GT_ITAB-ZHTA NE 'B'.
            MESSAGE E006 WITH '请输入农户状态信息,A代表正常,B代表不正常!'.
    
            "LEAVE TO SCREEN 0100 .
       ENDIF.
    
        CHECK SY-SUBRC <> 0.
    
        COLLECT GT_ITAB.
    
      ELSE.
        MESSAGE I006 WITH ' 请输入完整的农户信息进行保存!!!'.
    
      ENDIF.
    
    
      CHECK GT_ITAB-SFZHM  NE SPACE.
    ENDMODULE.                 " PAI_CHECK_DATA_0100  INPUT
    
    
    *&---------------------------------------------------------------------*
    *&      Module  INIT_LISTBOX_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE INIT_LISTBOX_0100 OUTPUT.
      CLEAR VID.
      CLEAR VLIST.
      CLEAR WA_VALUE.
    *&---下拉框设置
      MOVE 'GT_ITAB-ZHTA'  TO  VID.
      MOVE 'A'   TO   WA_VALUE-KEY.
      MOVE 'A' TO   WA_VALUE-TEXT.
      APPEND  WA_VALUE TO VLIST .
    
      MOVE 'GT_ITAB-ZHTA'  TO  VID.
      MOVE 'B'    TO   WA_VALUE-KEY.
      MOVE 'B' TO   WA_VALUE-TEXT.
      APPEND  WA_VALUE TO VLIST .
    
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          ID     = VID
          VALUES = VLIST.
    
    ENDMODULE.                 " INIT_LISTBOX_0100  OUTPUT
    **&---------------------------------------------------------------------*
    **&      Module  INIT_LISTBOX_0100  OUTPUT
    **&---------------------------------------------------------------------*
    **       text
    **----------------------------------------------------------------------*
    *MODULE init_listbox_0100 OUTPUT.
    
    *ENDMODULE.                 " INIT_LISTBOX_0100  OUTPUT
    
    *&---------------------------------------------------------------------*
    *&      Form  frm_delete_data
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_DELETE_DATA .
    
      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          TITLEBAR              = '确认'
          TEXT_QUESTION         = '要删除准备创建的农户信息吗?'
          TEXT_BUTTON_1         = ''
          TEXT_BUTTON_2         = ''
          DEFAULT_BUTTON        = '1'
          DISPLAY_CANCEL_BUTTON = ' '
          START_COLUMN          = 25
          START_ROW             = 6
          POPUP_TYPE            = 'ICON_MESSAGE_WARNING'
        IMPORTING
          ANSWER                = G_ANSWER
        EXCEPTIONS
          TEXT_NOT_FOUND        = 1
          OTHERS                = 2.
    *& 维护时候农户信息的删除操作:
      CHECK G_ANSWER EQ  '1'.
    
     LOOP AT GT_ITAB INTO WA_TAB WHERE SEL = 'X'.
    
    *& 删除内表数据:
        DELETE GT_ITAB WHERE "NHBM EQ WA_TAB-NHBM
                             SFZHM EQ WA_TAB-SFZHM
                         AND NHMC EQ WA_TAB-NHMC.
        IF SY-SUBRC EQ 0.
          MESSAGE S011 WITH '成功删除记录!'.
        ELSE.
          MESSAGE S011 WITH '删除记录失败!'.
        ENDIF.
    
      ENDLOOP.
    
    *  stop.
      LEAVE TO SCREEN 0100.
    
    ENDFORM.                    " frm_delete_data
    
    *&---------------------------------------------------------------------*
    *&      Form  FMR_CREA_DATA
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FMR_CREA_DATA .
      DATA: L_NUMBER(8).
      DATA :BEGIN OF LT_YTNAH OCCURS 0.
              INCLUDE STRUCTURE YTNAH.
      DATA: END OF LT_YTNAH.
    
      CLEAR: G_ANSWER.
      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          TITLEBAR              = '确认'
          TEXT_QUESTION         = '需要进行农户信息保存吗?'
          TEXT_BUTTON_1         = ''
          TEXT_BUTTON_2         = ''
          DEFAULT_BUTTON        = '1'
          DISPLAY_CANCEL_BUTTON = ' '
          START_COLUMN          = 25
          START_ROW             = 6
          POPUP_TYPE            = 'ICON_MESSAGE_WARNING'
        IMPORTING
          ANSWER                = G_ANSWER
        EXCEPTIONS
          TEXT_NOT_FOUND        = 1
          OTHERS                = 2.
      CHECK G_ANSWER EQ  '1'.
    
    *&准备数据:
      LOOP AT GT_ITAB WHERE NHBM EQ SPACE OR NHBM EQ ' ' .
    
        CLEAR L_NUMBER.
    *& 生成农户编码流水号:
        PERFORM FRM_NHBM_NO CHANGING L_NUMBER.
        MOVE: L_NUMBER TO GT_ITAB-NHBM,
              SY-MANDT TO GT_ITAB-MANDT.
        MOVE: SY-UZEIT TO GT_ITAB-CPUTM,
              SY-DATUM TO GT_ITAB-AEDAT,
              SY-UNAME TO GT_ITAB-USNAM.
        MOVE GT_ITAB TO LT_YTNAH.
        MODIFY GT_ITAB .
        APPEND LT_YTNAH.
        CLEAR GT_ITAB.
    
      ENDLOOP.
    
      MODIFY YTNAH FROM TABLE LT_YTNAH.
    
      IF SY-SUBRC EQ 0.
        COMMIT WORK.
        MESSAGE S012 WITH '成功更新记录:' G_LINES.
        LEAVE TO SCREEN 100.
      ELSE.
        ROLLBACK WORK.
        MESSAGE I011 WITH '更新失败!'.
        PERFORM FRM_UNLOCK USING  SY-MANDT.
        LEAVE TO SCREEN 0.
      ENDIF.
    
    ENDFORM.                    " FMR_CREA_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_NAHU_NO
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_NHBM_NO  CHANGING H_NUMBER.
    
    *&---获取农户编码流水号
      DATA: L_NUMBER(5).
    
      CALL FUNCTION 'NUMBER_GET_NEXT'
        EXPORTING
          NR_RANGE_NR             = '01'
          OBJECT                  = 'YH_MM_03'
        IMPORTING
          NUMBER                  = L_NUMBER
        EXCEPTIONS
          INTERVAL_NOT_FOUND      = 01
          NUMBER_RANGE_NOT_INTERN = 02
          OBJECT_NOT_FOUND        = 03
          QUANTITY_IS_0           = 04.
    
      IF SY-SUBRC NE 0.
        MESSAGE I011 WITH '产生对账流水吗失败!'.
        EXIT.
      ELSE.
        CONCATENATE S_NHSIG+3(3) L_NUMBER INTO H_NUMBER.
      ENDIF.
    
    ENDFORM.                    " FRM_NAHU_NO
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_turn_page_300
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_TURN_PAGE_100 .
    
      CALL FUNCTION 'FI_CUST_SCROLL'
        EXPORTING
          I_INPUT = '1'
          I_LNFIR = TC_ITEM-TOP_LINE
          I_LNMAX = G_LINES
          I_LOOPC = G_COUNT
          I_OKCOD = SY-UCOMM
        IMPORTING
          E_LNFIR = TC_ITEM-TOP_LINE
        EXCEPTIONS
          OTHERS  = 1.
    
    ENDFORM.                    " FRM_turn_page_300
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_UNLOCK
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_SY_MANDT  text
    *----------------------------------------------------------------------*
    FORM FRM_UNLOCK  USING H_MANDT.
    
      CALL FUNCTION 'DEQUEUE_EYTNAH'
        EXPORTING
          MODE_YTNAH     = 'E'
          MANDT          = H_MANDT
        EXCEPTIONS
          FOREIGN_LOCK   = 1
          SYSTEM_FAILURE = 2
          OTHERS         = 3.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    ENDFORM.                    " FRM_UNLOCK
    
    *&---------------------------------------------------------------------*
    *&      Form  FRM_CHECK_YTNAM
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM FRM_CHECK_YTNAM .
    
      DATA: BEGIN OF LT_YTNAM OCCURS 0,
            NHBM LIKE YTNAM-NHBM,
            END OF LT_YTNAM.
    
    *& 删除数据时,需要检查要删除的数据在YTNAM表里面是否有条目:有的话,不允许删除:
     LOOP AT GT_CHANGE WHERE ZSEL <> SPACE.
        SELECT NHBM
               INTO TABLE LT_YTNAM
               FROM YTNAM
               WHERE NHBM = GT_CHANGE-NHBM.
    
       IF SY-SUBRC EQ 0.
         MESSAGE I012 WITH '此农户的商品对应关系信息已经存在,请检查!' GT_CHANGE-NHBM.
        " STOP.
       ENDIF.
    
    ENDLOOP.
    
    ENDFORM.                    " FRM_CHECK_YTNAM
  • 相关阅读:
    初始化类的对象时代码的执行顺序
    非原子的 64 位操作
    守护线程
    Redis
    Redis
    Redis
    Redis
    好听美文随手记
    往服务器数据库插入数据报错,在本地数据库测试却无错误。
    关于云服务器中发送邮件,出现无法从传输连接中读取数据:
  • 原文地址:https://www.cnblogs.com/rainysblog/p/6094010.html
Copyright © 2011-2022 走看看