欢迎来到萧静默的博客

书山有路勤为径,学海无涯苦作舟。

ABAP-ALV-双击界面弹出窗口

此文引用自寒武青峰大姑 原文https://blog.csdn.net/lmf496891416/article/details/124249915?spm=1001.2014.3001.5502

ALV界面

 

 双击行任一地方 跳出新的窗口

 

 弹窗是使用SALV的简单展示,有标准的按钮与简单设置,使用起来蛮方便的,写个例子记录一下。
详细设置可以我参考寒武青峰大姑的另外一篇博客 简单SALV

TYPE-POOLS: slis.
TYPE-POOLS: kcde.

*&---------------------------------------------------------------------*
*&      TABLES
*&---------------------------------------------------------------------*
TABLES: vbap,vbak.

*----------------------------------------------------------------------*
* GLOBAL INTERNAL TABLES DECLARATION
*----------------------------------------------------------------------*
DATA: gt_file TYPE filetable.

*----------------------------------------------------------------------*
* GLOBAL VARIANTS DECLARATION
*----------------------------------------------------------------------*
DATA: g_repid TYPE sy-repid.
DATA: gt_field TYPE slis_t_fieldcat_alv.
*定义读入EXCEL的内表

TYPES : BEGIN OF typ_alv ,
          vbeln TYPE vbak-vbeln,
          erdat TYPE vbak-erdat, "创建日期
          vkorg TYPE vbak-vkorg, "销售组织
          vkbur TYPE vbak-vkbur, "销售办事处
          ernam TYPE vbak-ernam, "创建人
          sel   TYPE c , "    复选框
        END OF typ_alv .
DATA : gs_alv   TYPE typ_alv,
       gt_print TYPE TABLE OF typ_alv,
       gt_alv   TYPE TABLE OF typ_alv.

*创建字段宏定义
DEFINE add_field.
  ls_fieldcat-fieldname = '&1' .  "字段名称
  ls_fieldcat-ref_table = &2. "关联表格
  ls_fieldcat-ref_field = &3."参考字段
  ls_fieldcat-coltext = &4. "描述文本
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
END-OF-DEFINITION.


*--------选择条件
SELECTION-SCREEN BEGIN OF BLOCK bl01 WITH FRAME TITLE TEXT-001.

  SELECT-OPTIONS:
                    s_vkorg  FOR     vbak-vkorg OBLIGATORY,"销售组织
                    s_vkbur  FOR     vbak-vkbur ,"销售办公室
                    s_ernam  FOR     vbak-ernam."创建人
SELECTION-SCREEN END OF BLOCK bl01.

* ALV 用
DATA:
  gs_layout   TYPE lvc_s_layo,
  gv_repid    TYPE repid,
  gt_fieldcat TYPE lvc_t_fcat,
  ls_fieldcat TYPE lvc_s_fcat.
DATA: g_grid TYPE REF TO cl_gui_alv_grid.
*DATA: GT_ALVDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
*DATA: G_LIGHTS_NAME TYPE LVC_CIFNM VALUE 'LIGHT'.
*&---------------------------------------------------------------------*
*&   EVENT AT INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION .

AT SELECTION-SCREEN OUTPUT .

*----------------------------------------------------------------------*
* EVENT OCCURS AFTER THE SELECTION SCREEN HAS BEEN PROCESSED
*----------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM frm_auth_check.  "权限检查
  PERFORM frm_getdata .    "获取数据  --GETTING DATA
  PERFORM frm_display_data.  "展示ALV

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& FORM FRM_AUTH_CHECK
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM frm_auth_check .

ENDFORM.
*&---------------------------------------------------------------------*
*& FORM FRM_GETDATA
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM frm_getdata .

  SELECT vbak~vbeln,
         vbak~erdat,"创建日期
         vbak~vkorg,"销售组织
         vbak~vkbur, "销售办事处
         vbak~ernam
    FROM vbak
   WHERE vbak~vkorg IN @s_vkorg
    AND  vbak~vkbur IN @s_vkbur
    AND  vbak~ernam IN @s_ernam
    INTO CORRESPONDING FIELDS OF TABLE @gt_alv.

ENDFORM.
*&---------------------------------------------------------------------*
*& FORM FRM_DISPLAY_DATA
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM frm_display_data .
  DATA : lv_html_header TYPE slis_formname  .
*定义输出模式
  CLEAR:gs_layout,gt_fieldcat.
  gs_layout-cwidth_opt         = 'X'.
  gs_layout-zebra              = 'X'.
  gs_layout-box_fname              = 'SEL'.
  gv_repid = sy-repid.
  PERFORM frm_set_fieldcat.
  .
*  TRY .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = gv_repid
      i_callback_user_command  = 'FRM_USER_COMMAND'
      i_callback_pf_status_set = 'FRM_PF_STATUS'
      is_layout_lvc            = gs_layout
      it_fieldcat_lvc          = gt_fieldcat
      i_save                   = 'A'
    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_FIELDCAT
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM frm_set_fieldcat .
  add_field:
          vbeln   'VBAK'   'VBELN' '销售订单',
          erdat   'VBAK'   'ERDAT' '创建日期',
          vkorg   'VBAK'   'VKORG' '销售组织',
          vkbur   'VBAK'   'VKBUR' '销售办事处',
          ernam   'VBAK'   'ERNAM' '创建人'.
ENDFORM.

FORM frm_pf_status USING extab TYPE slis_t_extab.
  DATA: fcode TYPE TABLE OF sy-ucomm.
  CLEAR:fcode[].

  SET PF-STATUS 'STANDARD' EXCLUDING fcode[] .
ENDFORM.
*&---------------------------------------------------------------------*
*&      FORM  FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*       自定义用户动作
*----------------------------------------------------------------------*
*  -->  P1        TEXT
*  <--  P2        TEXT
*----------------------------------------------------------------------*

*自定义用户动作
FORM frm_user_command USING p_ucomm TYPE sy-ucomm rs_selfield TYPE slis_selfield.
  DATA : l_ucomm TYPE sy-ucomm  .
  IF g_grid IS INITIAL.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = g_grid.
  ENDIF.
  "失去焦点触发更新内表
  CALL METHOD g_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_modified.

  CALL METHOD g_grid->check_changed_data.
  rs_selfield-refresh     = 'X'.
  rs_selfield-col_stable  = 'X'.
  rs_selfield-row_stable  = 'X'.
  l_ucomm = p_ucomm .
  CLEAR p_ucomm .
  DATA : l_uname TYPE sy-uname,
         l_datum TYPE sy-datum,
         l_uzeit TYPE sy-uzeit.

  CASE l_ucomm.


    WHEN '&IC1'. "双击
      READ TABLE gt_alv INDEX rs_selfield-tabindex INTO DATA(wa_sel_temp).  "双击行
      IF sy-subrc = 0 .
*        SET PARAMETER ID 'VL' FIELD WA_SEL_TEMP-VBELN .
*        CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN ."SKIP FIRST SCREEN 忽略SELECTION SCREEN
        PERFORM displat_item USING wa_sel_temp-vbeln.
      ENDIF.
      CLEAR:wa_sel_temp.
    WHEN OTHERS.
  ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& FORM DISPLAT_ITEM
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM displat_item  USING p_vbeln.
  DATA: go_alv    TYPE REF TO cl_salv_table,
        go_funlst TYPE REF TO cl_salv_functions_list.
  DATA: cxroot TYPE REF TO cx_root,
        excmsg TYPE c.
  CLEAR:go_alv,go_funlst.

  SELECT vbap~vbeln,
         vbap~posnr,
         vbap~matnr,
         vbap~ZMENG,
         makt~maktx
    FROM vbap
    LEFT JOIN makt ON makt~matnr EQ vbap~matnr AND makt~spras = '1'
   WHERE vbeln = @p_vbeln
    INTO TABLE @DATA(lt_item).
  IF sy-subrc = 0.
    TRY.
        cl_salv_table=>factory(
        IMPORTING
        r_salv_table = go_alv   "导出ALV的容器对象
        CHANGING
        t_table = lt_item[] ).  "内容表
      CATCH cx_root INTO cxroot.
        excmsg = cxroot->get_text( ).
        MESSAGE e000(oo) WITH excmsg.
    ENDTRY.

    go_funlst = go_alv->get_functions( ).
    go_funlst->set_all( 'X' ).

    "重新设置列名称
    go_alv->get_columns( )->get_column( 'MAKTX' )->set_long_text( 'TES删除' )."


    IF go_alv IS BOUND."设置窗口大小与位置-
      go_alv->set_screen_popup(
      start_column = 30
      end_column = 160
      start_line = 5
      end_line = 20 ).
      go_alv->display( ).
    ENDIF.

  ENDIF.
ENDFORM.

代码直接复制就能用了。

另外自己扩展下,

PERFORM displat_item USING wa_sel_temp-vbeln.  这里的形式参数可以扩展为任意的字段取弹出需要的新的ALV,

分享使我快乐,我试萧静默。

posted @ 2022-06-02 13:37  萧静默  阅读(1577)  评论(0编辑  收藏  举报