Monday 17 June 2013

How to get the value of the internal table in F4 help - SAP ABAP?

In this tutorial we will see how to get the value of the internal table in the F4 help.

Case-I:
  • In the above program, we have declared a parameter of type BUKRS (Company Code). Upon pressing the F4 in the selection screen we will get a popup listing all company codes as shown below.
  • This will happen because of the standard Search Help - C_T001 associated with data element BUKRS.



Case-II:
Sometimes the functional requirement will be such that upon pressing the F4, it should display only few company codes (say AC01, AC02, AC03 and US01).

To achieve the above requirement we need to follow below steps.
  • Populate the required values (AC01, AC02, AC03 and US01) of company code into internal table (T_BUKRS)
  • Call FM F4IF_INT_TABLE_VALUE_REQUEST in AT SELECTION-SCREEN ON VALUE-REQUEST section to get the values of internal tables. Refer the below code for the same.
*&---------------------------------------------------------------------*
REPORT ZVENU_TEST3.

*--Declaration of Structures
TYPESBEGIN OF ty_bukrs,
        bukrs TYPE knb1-bukrs,
       END OF ty_bukrs.

*--Declaration of data
DATA: t_bukrs  TYPE STANDARD TABLE OF ty_bukrs,
      x_bukrs  TYPE ty_bukrs,
      t_return TYPE STANDARD TABLE OF ddshretval,
      x_return TYPE ddshretval.

REFRESH: t_bukrs, t_return.
CLEAR:   x_bukrs, x_return.

*--Selecetion Screen Parameter
PARAMETERS: p_bukrs TYPE bukrs.

*--Populatin the values to internal table
INITIALIZATION.
  x_bukrs-bukrs = 'AC01'.
  APPEND x_bukrs TO t_bukrs.
  CLEAR x_bukrs.

  x_bukrs-bukrs = 'AC02'.
  APPEND x_bukrs TO t_bukrs.
  CLEAR x_bukrs.

  x_bukrs-bukrs = 'AC03'.
  APPEND x_bukrs TO t_bukrs.
  CLEAR x_bukrs.

  x_bukrs-bukrs = 'US01'.
  APPEND x_bukrs TO t_bukrs.
  CLEAR x_bukrs.
*--Upon pressing the F4 buttion following code will be called
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_bukrs.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  EXPORTING
   RETFIELD               = 'BUKRS'   " Field Name Structure
   DYNPPROG               = sy-repid  " Program Name
   DYNPNR                 = sy-dynnr  " Current Screen Number
   DYNPROFIELD            = 'P_BUKRS' " Selection Screen Field
   VALUE_ORG              = 'S'       " Structure
   CALLBACK_PROGRAM       = sy-repid  " Program Name
  TABLES
   VALUE_TAB              = t_bukrs   " Internal table containing values
   RETURN_TAB             = t_return  " Return Table
 EXCEPTIONS
   PARAMETER_ERROR        = 1
   NO_VALUES_FOUND        = 2
   OTHERS                 = 3.
IF SY-SUBRC NE 0.
  MESSAGE 'Error in F4 help.' TYPE 'E'.
ENDIF.
*&---------------------------------------------------------------------*

Upon pressing the F4 in selection screen we'll get below pop-up as below.


Regards,
Venugopal M N


No comments:

Post a Comment