Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3154114
  • 博文数量: 238
  • 博客积分: 864
  • 博客等级: 军士长
  • 技术积分: 2940
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-08 23:01
个人简介

Mobile: 135 8576 5961 / WeChat: IM_WILLIAM_C / Mail: william.chen.cn@outlook.com /

文章分类

全部博文(238)

文章存档

2018年(2)

2016年(35)

2015年(47)

2014年(104)

2013年(38)

2012年(12)

分类: 其他平台

2015-03-22 20:02:00

需求:在ALV Grid的函数中加入下来列表,其实SAP已经考虑了大家的需求,用户的需求是可以实现的。

代码仅供参考。

代码如下:

REPORT.
************************************************************************
*                     DATEN DEFINITION   ;                         ;    *
************************************************************************
TYPE-POOLS: slis.

TYPES:
       BEGIN OF t_data,
         matnr   TYPE makt-matnr,
         maktx   TYPE makt-maktx,
         spras   TYPE makt-spras,
       END   OF t_data,
       BEGIN OF t_alv,
         matnr     TYPE makt-matnr,
         maktx     TYPE makt-maktx,
         spras     TYPE makt-spras,
         dd_handle TYPE int4,
       END   OF t_alv.
DATA:
      gt_fieldcatalog      TYPE lvc_t_fcat,
      gw_fieldcatalog      TYPE lvc_s_fcat,
*定义存储下拉列表的数据     
      gt_ddval             TYPE lvc_t_drop,
      gw_ddval             TYPE lvc_s_drop,
     
      gt_events            TYPE slis_t_event,
      gw_events            TYPE slis_alv_event,
      gt_data              TYPE TABLE OF t_data,
      gw_data              TYPE    ;      t_data,
      gt_alv               TYPE TABLE OF t_alv,
      gw_alv               TYPE   ;       t_alv,
      g_repid              TYPE sy-repid VALUE sy-repid.
************************************************************************
*                     SELECTION SCREEN   ;                         ;     *
************************************************************************
SELECT-OPTIONS: s_matnr FOR gw_data-matnr .

************************************************************************
*                     START-OF-SELECTION  ;                         ;    *
************************************************************************
START-OF-SELECTION.
  SELECT matnr maktx spras
  INTO TABLE gt_data up to 50 rows
  FROM makt
  WHERE matnr IN s_matnr
    and SPRAS = 'EN'.

  LOOP AT gt_data INTO gw_data.
    MOVE-CORRESPONDING gw_data TO gw_alv.
    APPEND gw_alv TO gt_alv.
  ENDLOOP.

  PERFORM creat_fieldcat.
  PERFORM creat_dropdown_values.
  PERFORM creat_event_exits.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program = g_repid
      it_fieldcat_lvc    = gt_fieldcatalog
      it_events          = gt_events
    TABLES
      t_outtab           = gt_alv.
*---------------------------------------------------------------------*
* 设置输出字段的格式
*---------------------------------------------------------------------*
FORM creat_fieldcat.
  CLEAR gw_fieldcatalog.
  gw_fieldcatalog-fieldname = 'MATNR'.
  gw_fieldcatalog-ref_field = 'MATNR'.
  gw_fieldcatalog-ref_table = 'MAKT'.
  APPEND gw_fieldcatalog TO gt_fieldcatalog.

  CLEAR gw_fieldcatalog.
  gw_fieldcatalog-fieldname = 'MAKTX'.
  gw_fieldcatalog-ref_field = 'MAKTX'.
  gw_fieldcatalog-ref_table = 'MAKT'.
  APPEND gw_fieldcatalog TO gt_fieldcatalog.

  CLEAR gw_fieldcatalog.
  gw_fieldcatalog-fieldname  = 'SPRAS'.
  gw_fieldcatalog-OUTPUTLEN = '7'.
  gw_fieldcatalog-dd_outlen = '7'.
  gw_fieldcatalog-intlen    = '2'.
  gw_fieldcatalog-inttype   = 'C'.
  gw_fieldcatalog-coltext   = 'Language'.
  gw_fieldcatalog-tooltip   = 'Language'.
  gw_fieldcatalog-seltext   = 'Language'.
  gw_fieldcatalog-drdn_field = 'DD_HANDLE'.
  gw_fieldcatalog-EDIT       = 'X'.
  APPEND gw_fieldcatalog TO gt_fieldcatalog.
ENDFORM.                    " creat_fieldcat
*---------------------------------------------------------------------*
*根据物料的所有的语言生成不同的生成下拉列表
*---------------------------------------------------------------------*
FORM creat_dropdown_values.
  DATA: l_spras TYPE makt-spras,
        l_count TYPE i.
  LOOP AT gt_alv INTO gw_alv.
    ADD 1 TO l_count.
    SELECT spras
       INTO l_spras
    FROM makt
    WHERE matnr = gw_alv-matnr.
      CLEAR gw_ddval.
      gw_ddval-handle = l_count.
      gw_ddval-value  = l_spras.
      APPEND gw_ddval TO gt_ddval.
    ENDSELECT.

    CLEAR gw_ddval.
    gw_ddval-handle = l_count.
    gw_ddval-value  = '                 '.
    APPEND gw_ddval TO gt_ddval.
*设置对应
    gw_alv-dd_handle = l_count.
    MODIFY gt_alv FROM gw_alv.
  ENDLOOP.
ENDFORM.                    " creat_dropdown_values
*---------------------------------------------------------------------*
*      Form  creat_event_exits
*---------------------------------------------------------------------*
FORM creat_event_exits .
  gw_events-name = 'CALLER_EXIT'.
  gw_events-form = 'CALLER_EXIT'.
  APPEND gw_events TO gt_events.
ENDFORM.                    " creat_event_exits
*---------------------------------------------------------------------*
*设置下拉列表,使Grid和内表能链接上
*---------------------------------------------------------------------*
FORM caller_exit USING ls_data TYPE slis_data_caller_exit.
  DATA: l_ref_alv TYPE REF TO cl_gui_alv_grid.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = l_ref_alv.
  CALL METHOD l_ref_alv->set_drop_down_table
    EXPORTING
      it_drop_down = gt_ddval.
ENDFORM.                    "CALLER_EXIT

***************************
在这里感谢一位朋友小财童鞋*
*************************** 

阅读(4245) | 评论(1) | 转发(0) |
0

上一篇:FI/CO 上线准备

下一篇:统驭科目概念

给主人留下些什么吧!~~

恩典祝福满满2017-05-15 16:22:34

可以实现一个alv两个下拉框吗