【ABAP】 alv练习2

*&---------------------------------------------------------------------*
 *& Report ZLJH091201
 *&---------------------------------------------------------------------*
 *&要求使用ALV展现数据,数据自取,添加标注按钮,实现复选功能,
 *&要求选中多条数据后,点击标注按钮,为这些数据添加颜色。
 *&---------------------------------------------------------------------*
 REPORT ZLJH091201.
 **********************************************************************
 *定义
 **********************************************************************
 
 TYPE-POOLS:SLIS.
 
 TYPES:BEGIN OF TYP_01,
  MATNR TYPE MARA-MATNR,
  MAKTX TYPE MAKT-MAKTX,
  CBOX  TYPE C,
  COLOR TYPE CHAR04,
  END OF TYP_01.
 
  DATA GT_01 TYPE STANDARD TABLE OF TYP_01.
 
  DATA GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
  DATA GS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
 
  DATA GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
  DEFINE FIELDCAT.
    CLEAR GS_FIELDCAT.
    GS_FIELDCAT-COL_POS  = &1.
    GS_FIELDCAT-FIELDNAME = &2.
    GS_FIELDCAT-SELTEXT_L = &3.
    APPEND GS_FIELDCAT TO GT_FIELDCAT.
  END-OF-DEFINITION.
 
 **********************************************************************
 *SELECTION SCREEN
 **********************************************************************
 
 
 **********************************************************************
 *AT SELECTION SCREEN
 **********************************************************************
 
 START-OF-SELECTION.
 SELECT MARA~MATNR
       MAKT~MAKTX
  FROM MARA
  INNER JOIN MAKT ON MARA~MATNR = MAKT~MATNR AND MAKT~SPRAS = SY-LANGU
  INTO TABLE GT_01 UP TO 50 ROWS.
  END-OF-SELECTION.
 
  IF GT_01 IS NOT INITIAL.
    PERFORM FRM_SHOW.
    ELSE.
      MESSAGE '无符合条件的数据' TYPE 'E' DISPLAY LIKE 'I'.
 
  ENDIF.
 
 *&---------------------------------------------------------------------*
 *&      Form  FRM_SHOW
 *&---------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        text
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FRM_SHOW.
  PERFORM FRM_LAYOUT.
  PERFORM FRM_FIELDCAT.
  PERFORM FRM_ALV_DISPLAY.
 ENDFORM.
 
 *&---------------------------------------------------------------------*
 *&      Form  FRM_FIELDCAT
 *&---------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        text
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FRM_FIELDCAT.
  FIELDCAT '1' 'MATNR' '物料编号'.
  FIELDCAT '2' 'MAKTX' '物料描述'.
  ENDFORM.
 
 *&---------------------------------------------------------------------*
 *&      Form  FRM_ALV_DISPLAY
 *&---------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        text
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FRM_ALV_DISPLAY.
  call function 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
 *     I_INTERFACE_CHECK                 = ' '
 *     I_BYPASSING_BUFFER                = ' '
 *     I_BUFFER_ACTIVE                   = ' '
     I_CALLBACK_PROGRAM                = SY-CPROG
     I_CALLBACK_PF_STATUS_SET          = 'FRM_STATUS'
     I_CALLBACK_USER_COMMAND           = 'FRM_USERCOMMAND'
 *     I_CALLBACK_TOP_OF_PAGE            = ' '
 *     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
 *     I_CALLBACK_HTML_END_OF_LIST       = ' '
 *     I_STRUCTURE_NAME                  =
 *     I_BACKGROUND_ID                   = ' '
 *     I_GRID_TITLE                      =
 *     I_GRID_SETTINGS                   =
     IS_LAYOUT                         = GS_LAYOUT
     IT_FIELDCAT                       = GT_FIELDCAT
 *     IT_EXCLUDING                      =
 *     IT_SPECIAL_GROUPS                 =
 *     IT_SORT                           =
 *     IT_FILTER                         =
 *     IS_SEL_HIDE                       =
 *     I_DEFAULT                         = 'X'
 *     I_SAVE                            = ' '
 *     IS_VARIANT                        =
 *     IT_EVENTS                         =
 *     IT_EVENT_EXIT                     =
 *     IS_PRINT                          =
 *     IS_REPREP_ID                      =
 *     I_SCREEN_START_COLUMN             = 0
 *     I_SCREEN_START_LINE               = 0
 *     I_SCREEN_END_COLUMN               = 0
 *     I_SCREEN_END_LINE                 = 0
 *     I_HTML_HEIGHT_TOP                 = 0
 *     I_HTML_HEIGHT_END                 = 0
 *     IT_ALV_GRAPHICS                   =
 *     IT_HYPERLINK                      =
 *     IT_ADD_FIELDCAT                   =
 *     IT_EXCEPT_QINFO                   =
 *     IR_SALV_FULLSCREEN_ADAPTER        =
 *   IMPORTING
 *     E_EXIT_CAUSED_BY_CALLER           =
 *     ES_EXIT_CAUSED_BY_USER            =
    tables
      t_outtab                          = GT_01
 *   EXCEPTIONS
 *     PROGRAM_ERROR                     = 1
 *     OTHERS                            = 2
            .
  if sy-subrc <> 0.
 * Implement suitable error handling here
  endif.
 
 
  ENDFORM.
 
 *----------------------------------------------------------------------*
 *       FORM  FRM_USERCOMMAND
 *----------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        TEXT
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FRM_USERCOMMAND USING P_CODE TYPE SYUCOMM
                     CHANGING SEL TYPE SLIS_SELFIELD.
 DATA LT_TAB TYPE STANDARD TABLE OF TYP_01.
 CASE P_CODE.
   WHEN '&IC1'.
  READ TABLE GT_01 INTO DATA(GS_01INDEX SEL-tabindex.
  SELECT  *
    FROM MARA
    INTO TABLE @DATA(GT_OUT)
    WHERE MATNR = @GS_01-MATNR.
   CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
     EXPORTING
           I_TITLE                       = '详细信息'
 *           I_SELECTION                   = 'X'
 *           I_ALLOW_NO_SELECTION          =
           I_ZEBRA                       = 'X'
 *           I_SCREEN_START_COLUMN         = 0
 *           I_SCREEN_START_LINE           = 0
 *           I_SCREEN_END_COLUMN           = 0
 *           I_SCREEN_END_LINE             = 0
 *           I_CHECKBOX_FIELDNAME          =
 *           I_LINEMARK_FIELDNAME          =
 *           I_SCROLL_TO_SEL_LINE          = 'X'
            i_tabname                     = 'MARA'
           I_STRUCTURE_NAME              = 'MARA'
 *           IT_FIELDCAT                   =
 *           IT_EXCLUDING                  =
 *           I_CALLBACK_PROGRAM            =
 *           I_CALLBACK_USER_COMMAND       =
 *           IS_PRIVATE                    =
 *         IMPORTING
 *           ES_SELFIELD                   =
 *           E_EXIT                        =
          tables
            t_outtab                      = GT_OUT
         EXCEPTIONS
           PROGRAM_ERROR                 = 1
           OTHERS                        = 2
                  .
        if sy-subrc <> 0.
 * Implement suitable error handling here
        endif.
        WHEN 'BZ'.
  LOOP AT GT_01 INTO GS_01 WHERE CBOX = 'X'.
  ENDLOOP.
  IF SY-SUBRC <> 0.
  MESSAGE '请至少选择一行' TYPE 'I'.
  ELSE.
  LOOP AT GT_01 INTO GS_01 WHERE CBOX = 'X'.
    IF GS_01-COLOR IS NOT INITIAL.
    CLEAR GS_01-COLOR.
    ELSE.
    GS_01-COLOR = 'C610'.
    ENDIF.
 
    MODIFY GT_01 FROM GS_01 INDEX SY-TABIX.
 
  ENDLOOP.
  ENDIF.
 
 ENDCASE.
  SEL-REFRESH = 'X'.
  ENDFORM.
 
 *----------------------------------------------------------------------*
 *       FORM .......
 *----------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        text
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FRM_STATUS USING EXTAB.
  SET PF-STATUS 'MENU'.
  ENDFORM.
 *&---------------------------------------------------------------------*
 *&      Form  FRM_LAYOUT
 *&---------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        text
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FRM_LAYOUT .
 GS_LAYOUT-INFO_FIELDNAME = 'COLOR'.
 GS_LAYOUT-box_fieldname    = 'CBOX'.
 ENDFORM.
【ABAP】 alv练习2

人已赞赏
ABAPSAP

【ABAP】ALV练习1

2019-9-12 14:40:23

ABAPSAP

【ABAP】 ALV练习3

2019-9-12 18:05:13

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索