1

I created a report with some selections using ABAP screen listbox.

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.

I need to change the value of articulo when the value of grupo is blank.

When I've set a value for grupo and articulo and then set grupo to blank articulo is not changing

enter image description here

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
usr1990
  • 21
  • 2
  • 7

3 Answers3

2

You're mistaken about the behavior of the event "Process On Value-Request" (POV, in the case of a Selection Screen it corresponds to the event block AT SELECTION-SCREEN ON VALUE-REQUEST FOR ..., in dynpros it's the event block PROCESS ON VALUE-REQUEST), which is very specific when used with dropdown listbox fields.

In that case, and only in that case, the POV is called during the "Process Before Output" (PBO, before the screen is displayed), and not when the dropdown button is pressed as it is usually the case with other types of fields.

It means that your code initializes the possible values of the field Articulo twice when the screen is displayed for the first time.

There are several solutions to propose a list of possible values in the list box, one of them is to define them during the PBO by calling the function module VRM_SET_VALUES. No need of the POV. Here is a solution that works (can run in any ABAP-based system):

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.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
1

If you only want to empty the 'articulo' after the 'grupo' has been emptied, then you can implement an if-block at the AT SELECTION-SCREEN OUTPUT event block.

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

Read this SAP wiki entry for further information on report selection-screen event processing.

Legxis
  • 886
  • 7
  • 19
  • Good! but now when articulo is set with a value and i change grupo i want to clear the content of articulo listbox and charge again depending of grupo value – usr1990 Mar 06 '20 at 07:51
0

Several convictions about your code:

  1. Many variables are redundant, like value, aux etc., all concatenations can be done on-the-fly. VRM types declaration is also redundant. No need to define listbox names in separate variable because this worsens code readability.
  2. Sandra is absolutely right stating that POV event here will not work, you need simple AT SELECTION-SCREEN OUTPUT
  3. All DB selects can be wiped out into INITIALIZATION event and can be done only once, not to abuse performance. So you make all operations on internal tables, you do not have to clear master itab each OUTPUT, but use i_aux var for filling listbox.

Here is the simplified version of your code with simulating ztart_mtoXX types as local

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.

Though Sandra's solution is more elegant, this is just as an option more similar to your logic.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90