SAP ABAP-ALV选择屏幕字段按需显示demo—自用详解编程语言

*&---------------------------------------------------------------------* 
*& Report ZPPR_TEST 
*&---------------------------------------------------------------------* 
*& 
*&---------------------------------------------------------------------* 
REPORT ZPPR_TEST. 
 
TYPE-POOLS:SLIS. 
TABLES:MSEG,SSCRFIELDS. 
*----------------------------------------------------------------------* 
*       ALV定义 
*----------------------------------------------------------------------* 
DATA: GW_FIELDCAT TYPE SLIS_FIELDCAT_ALV, 
      GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, 
      G_LAYOUT    TYPE SLIS_LAYOUT_ALV. 
*----------------------------------------------------------------------* 
* 内表和工作区定义 
*----------------------------------------------------------------------* 
TYPES:BEGIN OF TY_ALV, 
        SEL    TYPE CHAR1, 
        MBLNR  TYPE MSEG-MBLNR, 
        BUDAT  TYPE MSEG-BUDAT_MKPF, 
      END OF TY_ALV. 
 
 
DATA:GT_ALV TYPE TABLE OF TY_ALV, 
     WA_ALV TYPE TY_ALV. 
 
*----------------------------------------------------------------------* 
* 选择屏幕 
*----------------------------------------------------------------------* 
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. 
 
SELECTION-SCREEN SKIP. 
 
SELECTION-SCREEN BEGIN OF LINE. 
PARAMETERS:RB_1 RADIOBUTTON GROUP G1 USER-COMMAND U1 DEFAULT 'X'. 
SELECTION-SCREEN COMMENT 3(29) TEXT-002. 
PARAMETERS:RB_2 RADIOBUTTON GROUP G1 . 
SELECTION-SCREEN COMMENT 36(40) TEXT-003. 
SELECTION-SCREEN END OF LINE. 
SELECTION-SCREEN SKIP. 
 
 
SELECT-OPTIONS:S_MATNR1 FOR MSEG-MATNR MODIF ID M1."RB_1显示的字段 
SELECT-OPTIONS:S_MATNR2 FOR MSEG-MATNR MODIF ID M2."RB_2显示的字段 
 
SELECTION-SCREEN END OF BLOCK B1. 
*----------------------------------------------------------------------* 
* Initialization 
*----------------------------------------------------------------------* 
INITIALIZATION. 
*----------------------------------------------------------------------* 
* at selection screen 
*----------------------------------------------------------------------* 
AT SELECTION-SCREEN OUTPUT. 
 
  "屏幕修改 
  PERFORM FRM_MODIFY_SCREEN. 
 
 
AT SELECTION-SCREEN. 
*----------------------------------------------------------------------* 
* Event top of page 
*----------------------------------------------------------------------* 
TOP-OF-PAGE. 
*----------------------------------------------------------------------* 
* event Start of Selection 
*----------------------------------------------------------------------* 
START-OF-SELECTION. 
  PERFORM FRM_GET_DATA. 
  PERFORM FRM_LAYOUT_BUILD. 
  PERFORM FRM_FIELD_BUILD. 
  PERFORM FRM_DATA_OUT. 
*----------------------------------------------------------------------* 
*EVENT End-of selection 
*----------------------------------------------------------------------* 
END-OF-SELECTION. 
*----------------------------------------------------------------------* 
*EVENT  End-of page 
*----------------------------------------------------------------------* 
END-OF-PAGE. 
*----------------------------------------------------------------------* 
 
*----------------------------------------------------------------------* 
** forms 
*----------------------------------------------------------------------* 
*&---------------------------------------------------------------------* 
*& Form FRM_MODIFY_SCREEN 
*&---------------------------------------------------------------------* 
*& 屏幕修改 
*&---------------------------------------------------------------------* 
FORM FRM_MODIFY_SCREEN . 
  IF RB_1 = 'X'. 
    LOOP AT SCREEN. 
      IF SCREEN-GROUP1 = 'M2'. 
        SCREEN-ACTIVE = 0. 
      ENDIF. 
      MODIFY SCREEN. 
    ENDLOOP. 
  ELSE. 
    LOOP AT SCREEN. 
      IF SCREEN-GROUP1 = 'M1'. 
        SCREEN-ACTIVE = 0. 
      ENDIF. 
      MODIFY SCREEN. 
    ENDLOOP. 
  ENDIF. 
 
ENDFORM. 
*&---------------------------------------------------------------------* 
*&      Form  FRM_LAYOUT_BUILD 
*&---------------------------------------------------------------------* 
*       "  设置表格样式 
*----------------------------------------------------------------------* 
FORM FRM_LAYOUT_BUILD . 
  G_LAYOUT-BOX_FIELDNAME        = 'SEL'.  " 选择模式,在最左端有选择按钮 
  G_LAYOUT-COLWIDTH_OPTIMIZE    = 'X'.    " 自动调整列宽 
  G_LAYOUT-ZEBRA                = 'X'.    " 表格斑马线 
  "G_LAYOUT-EDIT = 'X'.                     "可编辑 
  G_LAYOUT-INFO_FIELDNAME       = 'CLR'. 
ENDFORM. 
*&---------------------------------------------------------------------* 
*&      Form  FRM_FIELD_BUILD 
*&---------------------------------------------------------------------* 
*       "  建立表头数据 
*----------------------------------------------------------------------* 
FORM FRM_FIELD_BUILD . 
  CLEAR GT_FIELDCAT. 
  IF RB_1 = 'X'. 
  PERFORM FIELD_SET: 
                     USING 'MBLNR'  '物料凭证1'   '15' '' , 
                     USING 'BUDAT'  '过账日期'   '15' '' . 
  ELSEIF RB_2 = 'X'. 
  PERFORM FIELD_SET: 
                     USING 'MBLNR'  '物料凭证2'   '15' '' , 
                     USING 'BUDAT'  '过账日期'   '15' '' . 
  ENDIF. 
ENDFORM. 
 
*&---------------------------------------------------------------------* 
*&      Form  FRM_DATA_OUT 
*&---------------------------------------------------------------------* 
*       输出数据 
*----------------------------------------------------------------------* 
FORM FRM_DATA_OUT. 
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 
    EXPORTING 
      I_CALLBACK_PROGRAM       = SY-REPID 
      IS_LAYOUT                = G_LAYOUT 
      IT_FIELDCAT              = GT_FIELDCAT 
      I_SAVE                   = 'X' 
      I_CALLBACK_PF_STATUS_SET = 'FRM_STATE' 
    TABLES 
      T_OUTTAB                 = GT_ALV 
    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. 
*&---------------------------------------------------------------------* 
*&      Form  FRM_SET_PF_STATUS 
*&---------------------------------------------------------------------* 
FORM FRM_STATE USING RT_EXTAB TYPE SLIS_T_EXTAB. 
  SET PF-STATUS 'STANDARD'. 
ENDFORM. 
 
 
*&---------------------------------------------------------------------* 
*&      Form  FIELD_SET 
*&---------------------------------------------------------------------* 
FORM FIELD_SET USING P_FIELDNAME 
                     P_SELTEXT_L 
                     P_OUTPUTLEN 
                     P_HOTSPOT. 
  GW_FIELDCAT-FIELDNAME     = P_FIELDNAME . 
  GW_FIELDCAT-SELTEXT_L     = P_SELTEXT_L . 
  GW_FIELDCAT-OUTPUTLEN     = P_OUTPUTLEN . 
  GW_FIELDCAT-HOTSPOT   = P_HOTSPOT. 
  APPEND GW_FIELDCAT TO GT_FIELDCAT. 
  CLEAR GW_FIELDCAT. 
ENDFORM. 
*&---------------------------------------------------------------------* 
*&      Form  FRM_GET_DATA 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
*  -->  p1        text 
*  <--  p2        text 
*----------------------------------------------------------------------* 
FORM FRM_GET_DATA . 
IF RB_1 = 'X'. 
  SELECT 
    MBLNR 
    BUDAT_MKPF AS BUDAT 
    INTO CORRESPONDING FIELDS OF TABLE GT_ALV 
    FROM MSEG 
    WHERE MATNR IN S_MATNR1 
    AND WERKS = '1090' 
    AND LGORT = '1001'. 
ELSEIF RB_2 = 'X'. 
   SELECT 
    MBLNR 
    BUDAT_MKPF AS BUDAT 
    INTO CORRESPONDING FIELDS OF TABLE GT_ALV 
    FROM MSEG 
    WHERE MATNR IN S_MATNR2 
    AND WERKS = '1090' 
    AND LGORT NE '1001'. 
ENDIF. 
ENDFORM.

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19549.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论