【ABAP】ALV练习1

*&---------------------------------------------------------------------*
 *& Report ZLJH091101
 *&---------------------------------------------------------------------*
 *&要求使用ALV展现数据,数据自取。
 *&ALV要求实现最后一列添加复选框,并且在第一行和最后一行添加颜色。
 *&---------------------------------------------------------------------*
 REPORT ZLJH091101.
 **********************************************************************
 *定义
 **********************************************************************
 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_CAHGE_DATA.
  PERFORM FRM_FIELDCAT.
  PERFORM FRM_LAYOUT.
  PERFORM FRM_ALV_DISPLAY.
 ENDFORM.
 
 *&---------------------------------------------------------------------*
 *&      Form  FRM_FIELDCAT
 *&---------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        text
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FRM_FIELDCAT.
  FIELDCAT '1' 'MATNR' '物料编号' .
  FIELDCAT '2' 'MAKTX' '物料描述' .
  FIELDCAT '3' 'CBOX' '复选' .
  LOOP AT  GT_FIELDCAT INTO GS_FIELDCAT.
    IF GS_FIELDCAT-FIELDNAME = 'CBOX'.
       GS_FIELDCAT-CHECKBOX = 'X'.
       GS_FIELDCAT-EDIT = 'X'.
       MODIFY GT_FIELDCAT FROM GS_FIELDCAT INDEX SY-TABIX.
    ENDIF.
  ENDLOOP.
 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 "SY-REPID
 *     I_CALLBACK_PF_STATUS_SET          = ' '
    I_CALLBACK_USER_COMMAND           = 'FRM_UESRCOMMAND'
 *     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.
 
  ENDCASE.
  ENDFORM.
 *&---------------------------------------------------------------------*
 *&      Form  FRM_LAYOUT
 *&---------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        text
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FRM_LAYOUT.
  GS_LAYOUT-INFO_FIELDNAME = 'COLOR'.
  ENDFORM.
 
 *&---------------------------------------------------------------------*
 *&      Form  FRM_CAHGE_DATA
 *&---------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        text
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FRM_CAHGE_DATA.
  DATA LV_COLOR TYPE CHAR01.
  LOOP AT  GT_01 INTO DATA(GS).
 
    IF  SY-TABIX = 1.
      GS-COLOR = 'C610'.
      ENDIF.
      AT LAST.
        LV_COLOR = 'C601'.
        ENDAT.
        IF LV_COLOR IS NOT INITIAL .
          GS-COLOR = LV_COLOR.
 
        ENDIF.
          MODIFY GT_01 FROM GS INDEX SY-TABIX.
 
 
  ENDLOOP.
   ENDFORM.
【ABAP】ALV练习1

人已赞赏
ABAPSAP

【ABAP】ALV练习

2019-9-11 20:53:37

ABAPSAP

【ABAP】 alv练习2

2019-9-12 17:03:53

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