1

我使用 ABAP 屏幕列表框创建了一个包含一些选择的报告。

REPORT z_prueba.

TYPE-POOLS: vrm.

DATA : name    TYPE vrm_id,
       list    TYPE vrm_values,
       value   LIKE LINE OF list,
       aux(85) TYPE c.

DATA: i_grupo     TYPE STANDARD TABLE OF ztart_mto_1,
      i_material  TYPE STANDARD TABLE OF ztart_mto_2,
      i_aux       TYPE STANDARD TABLE OF ztart_mto_2,
      wa_grupo    TYPE ztart_mto_1,
      wa_material TYPE ztart_mto_2,
      wa_aux      TYPE ztart_mto_2.


SELECTION-SCREEN BEGIN OF BLOCK cab WITH FRAME TITLE tcab.
PARAMETERS:
  grupo TYPE ztart_mto_1-grupo AS LISTBOX VISIBLE LENGTH 80 USER-COMMAND gr.
SELECTION-SCREEN END OF BLOCK cab.

SELECTION-SCREEN BEGIN OF BLOCK art WITH FRAME TITLE tart.
PARAMETERS:
  articulo TYPE ztart_mto_2-refn AS LISTBOX VISIBLE LENGTH 80 USER-COMMAND art.
SELECTION-SCREEN END OF BLOCK art.

INITIALIZATION.
  tcab = 'Grupo de artículos'.
  tart = 'Artículo del grupo'.

  SELECT * INTO TABLE i_grupo FROM ztart_mto_1.
  CLEAR list.
  REFRESH list.
  LOOP AT i_grupo INTO wa_grupo.
    CLEAR value.
    CLEAR aux.
    CONCATENATE wa_grupo-grupo ` - `  wa_grupo-denom INTO aux.
    value-key = wa_grupo-grupo.
    value-text = aux.
    APPEND value TO list.
  ENDLOOP.

  name = 'grupo'.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = name
      values = list.

  CLEAR name.
  CLEAR list.
  CLEAR i_grupo.
  CLEAR wa_grupo.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR grupo.
  IF grupo = ''.

    "HERE I NEED TO PUT THE VALUE OF articulo IN BLANK

  ELSE.

    SELECT * FROM ztart_mto_2 WHERE grupo = @grupo INTO TABLE @i_material.

    LOOP AT i_material INTO wa_material.
      CLEAR value.
      CLEAR aux.
      CONCATENATE wa_material-refn ` - `  wa_material-descr INTO aux.
      value-key = wa_material-refn.
      value-text = aux.
      APPEND value TO list.
    ENDLOOP.

    name = 'articulo'.

    CALL FUNCTION 'VRM_SET_VALUES'
      EXPORTING
        id     = name
        values = list.

    articulo = ''.

    CLEAR grupo.
    CLEAR aux.
    CLEAR name.
    CLEAR list.
    CLEAR i_material.
    CLEAR wa_material.
    REFRESH i_material.

  ENDIF.

articulo当值为grupo空白时,我需要更改值。

当我设置了一个值grupo然后articulo设置grupo为空白时articulo不会改变

在此处输入图像描述

4

3 回答 3

2

您对事件“处理值请求”的行为有误(POV,在选择屏幕的情况下,它对应于事件块AT SELECTION-SCREEN ON VALUE-REQUEST FOR ...,在 dynpros 中它是事件块PROCESS ON VALUE-REQUEST),这在与下拉列表一起使用时非常具体列表框字段。

在这种情况下,并且仅在这种情况下,在“输出前处理”(PBO,在屏幕显示之前)期间调用 POV,而不是在按下下拉按钮时调用,因为其他类型的字段通常是这种情况.

这意味着您的代码在第一次显示屏幕时Articulo 两次初始化该字段的可能值。

有几种解决方案可以在列表框中提出可能值的列表,其中之一是在 PBO 期间通过调用函数模块来定义它们VRM_SET_VALUES。不需要 POV。这是一个可行的解决方案(可以在任何基于 ABAP 的系统中运行):

TABLES sscrfields.

PARAMETERS country TYPE land1 AS LISTBOX VISIBLE LENGTH 20 USER-COMMAND country_changed.
PARAMETERS carrid TYPE s_carr_id AS LISTBOX VISIBLE LENGTH 20.

AT SELECTION-SCREEN OUTPUT.
  DATA(lt_value) = VALUE vrm_values(
      ( key = 'FR' text = 'France' )
      ( key = 'DE' text = 'Allemagne' ) ).
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id              = 'COUNTRY'
      values          = lt_value
    EXCEPTIONS
      id_illegal_name = 1
      OTHERS          = 2.
  lt_value = switch #( COUNTRY
        when '' then VALUE #( )
        when 'FR' then VALUE #(
              ( key = 'AF' text = 'Air France' )
              ( key = 'TO' text = 'Transavia' ) )
        when 'DE' then value #(
              ( key = 'EW' text = 'Eurowings' )
              ( key = 'LH' text = 'Lufthansa' ) ) ).
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id              = 'CARRID'
      values          = lt_value
    EXCEPTIONS
      id_illegal_name = 1
      OTHERS          = 2.

AT SELECTION-SCREEN.
  IF sscrfields-ucomm = 'COUNTRY_CHANGED'.
    carrid = ''.
  ENDIF.
于 2020-03-05T18:17:50.153 回答
1

如果您只想在“grupo”被清空后清空“articulo”,那么您可以在AT SELECTION-SCREEN OUTPUT事件块中实现一个 if 块。

AT SELECTION-SCREEN OUTPUT.
  IF grupo IS INITIAL.
    CLEAR articulo.
  ENDIF.

阅读此SAP wiki 条目以获取有关报告选择屏幕事件处理的更多信息

于 2020-03-05T17:40:17.113 回答
0

关于您的代码的几个信念:

  1. 许多变量是多余的,例如等valueaux所有连接都可以即时完成。VRM 类型声明也是多余的。无需在单独的变量中定义列表框名称,因为这会降低代码的可读性。
  2. Sandra 完全正确地说 POV 事件在这里不起作用,你需要简单AT SELECTION-SCREEN OUTPUT
  3. 所有 DB 选择都可以被清除到 INITIALIZATION 事件中,并且只能执行一次,而不是滥用性能。所以你对内部表进行所有操作,你不必清除master itab每个OUTPUT,而是使用i_auxvar填充列表框。

这是您的代码的简化版本,其中将 ztart_mtoXX 类型模拟为本地

TYPES: BEGIN OF ztart_mto_1,
         grupo TYPE char100,
         denom TYPE char100,
       END OF ztart_mto_1,
       BEGIN OF ztart_mto_2,
         refn  TYPE char100,
         descr TYPE char100,
         grupo TYPE char100,
       END OF ztart_mto_2.

DATA: i_grupo    TYPE TABLE OF ztart_mto_1 WITH EMPTY KEY,
      i_material TYPE TABLE OF ztart_mto_2 WITH EMPTY KEY,
      i_aux      TYPE TABLE OF ztart_mto_2 WITH EMPTY KEY,
      list       TYPE vrm_values.

PARAMETERS: grupo    TYPE char100 AS LISTBOX VISIBLE LENGTH 80 USER-COMMAND gr,
            articulo TYPE char100 AS LISTBOX VISIBLE LENGTH 80 USER-COMMAND art.

INITIALIZATION.
  i_grupo    = VALUE #( ( grupo = '' denom = '' ) ( grupo = 'AGROUP' denom = 'AGROUP_DENOM' ) ( grupo = 'BGROUP' denom = 'BGROUP_DENOM' ) ( grupo = 'CGROUP' denom = 'CGROUP_DENOM' ) ).
  i_material = VALUE #( ( refn = 'A119' descr = 'A material' grupo = 'AGROUP' ) ( refn = 'B119' descr = 'B material' grupo = 'BGROUP' ) ( refn = 'C119' descr = 'C material' grupo = 'CGROUP' ) ).

  LOOP AT i_grupo INTO DATA(wa_grupo).
    APPEND VALUE vrm_value( key = wa_grupo-grupo text = wa_grupo-grupo && ` - ` && wa_grupo-denom ) TO list.
  ENDLOOP.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'grupo'
      values = list.
  CLEAR list.

AT SELECTION-SCREEN.

  CHECK sy-ucomm = 'GR'.
  CLEAR articulo.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'articulo'
      values = list.
  CLEAR list.

AT SELECTION-SCREEN ON grupo.

  CHECK sy-ucomm = 'GR' AND grupo IS NOT INITIAL.

  i_aux = VALUE #( FOR ls_mat IN i_material WHERE ( grupo = grupo ) ( ls_mat ) ).
  LOOP AT i_aux INTO DATA(wa_material).
    APPEND VALUE vrm_value( key = wa_material-refn text = wa_material-refn && ` - ` && wa_material-descr ) TO list.
  ENDLOOP.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'articulo'
      values = list.

尽管 Sandra 的解决方案更优雅,但这只是一个更类似于您的逻辑的选项。

于 2020-03-11T16:20:45.040 回答