根据数据库表字段动态生成选择画面[FREE_SELECTIONS_DIALOG]

介绍两个SAP函数FREE_SELECTIONS_DIALOG和FREE_SELECTIONS_INIT,通过这两个函数能生成基于某个数据库表的动态选择屏幕。

比如要根据销售订单抬头表VBAK生成动态屏幕,

对应的完整代码:

REPORT ztest_selection_dyn.

DATA: lv_selection_id TYPE rsdynsel-selid,
      lt_tables_tab   TYPE STANDARD TABLE OF rsdstabs,
      ls_tables_tab   TYPE rsdstabs.
DATA: lt_fields_tab    TYPE STANDARD TABLE OF rsdsfields,
      lt_where_clauses TYPE rsds_twhere.

ls_tables_tab-prim_tab = 'VBAK'.  "数据库表名
APPEND ls_tables_tab TO lt_tables_tab.
CALL FUNCTION 'FREE_SELECTIONS_INIT'
  EXPORTING
    kind                     = 'T'
  IMPORTING
    selection_id             = lv_selection_id
  TABLES
    tables_tab               = lt_tables_tab
  EXCEPTIONS
    fields_incomplete        = 1
    fields_no_join           = 2
    field_not_found          = 3
    no_tables                = 4
    table_not_found          = 5
    expression_not_supported = 6
    incorrect_expression     = 7
    illegal_kind             = 8
    area_not_found           = 9
    inconsistent_area        = 10
    kind_f_no_fields_left    = 11
    kind_f_no_fields         = 12
    too_many_fields          = 13
    dup_field                = 14
    field_no_type            = 15
    field_ill_type           = 16
    dup_event_field          = 17
    node_not_in_ldb          = 18
    area_no_field            = 19
    OTHERS                   = 20.
IF sy-subrc EQ 0.
  CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
    EXPORTING
      selection_id    = lv_selection_id
      title           = '选择'
      frame_text      = '查询条件'
      as_window       = ''                "不显示成窗口
    IMPORTING
      where_clauses   = lt_where_clauses  "返回选择条件
    TABLES
      fields_tab      = lt_fields_tab     "选择画面中选中字段
    EXCEPTIONS
      internal_error  = 1
      no_action       = 2
      selid_not_found = 3
      illegal_status  = 4
      OTHERS          = 5.
  IF sy-subrc EQ 0.

  ENDIF.
ENDIF.

运行结果:

<img class="alignnone size-full wp-image-4024" src="http://www.baidusap.com/wp-content/uploads/2017-03-21_13-31-25.png" alt="" width="799" height="298" srcset="http://www.baidusap.com/wp-content/uploads/2017-03-21_13-31-25.png 799w, http://www.baidusap.com/wp-content/uploads/2017-03-21_13-31-25-740x276.png 740w, http://www.baidusap.com/wp-content/uploads/2017-03-21_13-31-25-768x286.png 768w" sizes="(max-width: 799px) 100vw, 799px" />

然后可以按需要将左侧的vbak中的字段,选到右边生成选择屏幕。

<img class="alignnone size-full wp-image-4023" src="http://www.baidusap.com/wp-content/uploads/2017-03-21_13-28-44.png" alt="" width="969" height="615" srcset="http://www.baidusap.com/wp-content/uploads/2017-03-21_13-28-44.png 969w, http://www.baidusap.com/wp-content/uploads/2017-03-21_13-28-44-740x470.png 740w, http://www.baidusap.com/wp-content/uploads/2017-03-21_13-28-44-768x487.png 768w" sizes="(max-width: 969px) 100vw, 969px" />

以上。

转载于:https://www.cnblogs.com/datie/p/11435423.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值