Filtering F4 Help Values in Table Control, Based On Other Field Value

来源:互联网 发布:sql求和保留两位小数 编辑:程序博客网 时间:2024/05/23 14:36

This BoK provides info on how to create an F4 help by filtering the values based on the value entered in another field (By capturing the values entered in the fieldwithout hitting the enter key) in a table control.
 
The regular procedure of fetching theF4 help values does help here But only when <enter> key is pressed after entering the value in the first field. To avoid hitting the <enter> key we need to capture the value entered in the first field dynamically.

Let's consider a scenario where I have two fields in my table control & the F4 help values for the second field depends on the value entered in the first field.

 1. Airline code (SFLIGHT-CARRID)

 2. Flight connection number (SFLIGHT-CONNID)

Let’s select an Airline code

Now the F4 help should be filtered for second field ‘Flight connection number’ based on the ‘Airline code’ selected (without hitting the enter key)

Before selecting the airline code:

 

After filtering,based on the value selected in first field

The procedure toaccomplish the same is detailed below

1.    In the PAI of the table control dynpro, Use the event 'Process onvalue-request'. Under this event use the syntax shown below.

           PROCESS ON VALUE-REQUEST.
                       FIELD <table control field name> MODULE <module name>

           Example:

           PROCESS ON VALUE-REQUEST.
               FIELDwa_add-connid MODULE f4help.

                Where wa_add-connid is my tablecontrol field name.

Note: All thecode shown below is to be written in module ‘f4help’ as mentioned in theprevious step

2.    We need to determine the cursor position to know at which row the F4 help ispressed. To know the row index, use the Function module 'DYNP_GET_STEPL'. ThisFM returns the current line index (Row Index where the F4 help is pressed). Usethe following code in the POV module

       CALL FUNCTION 'DYNP_GET_STEPL'
          IMPORTING
             povstepl =v_index.   (v_index  is a  variable  to hold  the  index  value)

3.    To hold the current screen values i.e. the value entered in the first fieldCARRID, declare an internal table and a work area of type 'dynpread' structure.The ‘stepl’ field of the structure is used to store the row index where the f4help is needed and the field ‘fieldname’ is used to store the field name whosevalues are to be read dynamically.

4.    Pass the current line index to the work area field 'stepl' and the field name bywhich the f4 help needs to be filtered to 'fieldname' to the internal table(Code in f4help module).

    Wa_dynpread-stepl = v_index.

    Wa_dynpread-fieldname = 'WA_ADD-CARRID'.

    Append wa_dynpread TO it_dynpread.

5.    Use FM 'DYNP_VALUES_READ' by passing the report name: 'sy-repid' to dyname ,screen number : 'sy-dynnr' to dynumb and the dynpread internal table to'Tables' to read field contents on screen and transport field to help processor.

       CALL FUNCTION 'DYNP_VALUES_READ'
                  EXPORTING
                     dyname              = sy-repid
                     dynumb              = sy-dynnr
                     translate_to_upper   = 'X'
                 TABLES
                     dynpfields           = 
it_dynpread .

6.    The FM 'DYNP_VALUES_READ' fetches the value entered in the field 'Legreg'. Select the flight connection number based onthe value in ‘FIELDVALUE’ in IT_DYNPREAD.

 READ TABLE it_dynpread INTO wa_dynpread WITH KEY stepl = v_dynindex.

   IF sy-subrc IS INITIAL.


     SELECTDISTINCT connid FROM sflight 

        INTO TABLE it_connid 

  WHERE carrid = wa_dynpread-fieldvalue

   ENDIF.

7.     Pass the internal table IT_CONNID to theFM 'F4IF_INT_TABLE_VALUE_REQUEST'.

        CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
          EXPORTING
             retfield    = 'CONNID'
             dynpprog    = sy-repid
              dynpnr       = sy-dynnr
              dynprofield ='WA_ADD-CONNID'
             value_org   = 'S'
         TABLES
             value_tab   = it_connid.

Now the f4 helpvalues for the field 'connid' will be filtered based on the value entered in'carrid'.

 

 

 

0 0