Report to provide F4 Help for Directory Names (Not File Names)

Requirement:
             To display the Directory names of AL11 in Search help for the (Parameter) field on Screen.

Type: Classical Report

Logic:
  1. Data declarations
  2. Selection Screen
  3. Initialization event:
    1. Execute the 'MAIN' subroutine in Standard program 'RSWATCH0' to get the directory names
    2. Move the directory names to an internal table (due to data type mismatch on the fetched data) for Search help
  4. At Selection Screen Event:
    1. F4 help has to be provided for the field so we have to use ON VALUE REQUEST FOR the FIELD
    2. Use Function Module: F4IF_INT_TABLE_VALUE_REQUEST for displaying the search help
    3. On double clicking the required directory, the same will be displayed in the input field
Report:

*&---------------------------------------------------------------------*
*& Report  ZAG_TRYTWO_NEW_FM2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zag_trytwo_new_fm2.

*==================
* Data Declarations
*==================
 
* For Standard Program RSWATCH0 Data
DATAI_OUTTAB   TYPE STANDARD TABLE OF CST_RSWATCH01_ALV,
      WA_OUTTAB   TYPE CST_RSWATCH01_ALV,
      LW_FNAME TYPE CHAR80 VALUE '(RSWATCH0)GT_OUTTAB'.
FIELD-SYMBOLS <LT_OUTTAB> TYPE STANDARD TABLE.

* Structure for Directory Name
TYPESBEGIN OF T_OUTTAB1,
        DIRNAME TYPE SHVALUE_D,
       END OF T_OUTTAB1.

* Declaration of variables for FM - F4IF_INT_TABLE_VALUE_REQUEST
DATAI_OUTTAB1   TYPE STANDARD TABLE OF T_OUTTAB1,
      WA_OUTTAB1   TYPE T_OUTTAB1,
      I_RETURN LIKE DDSHRETVAL OCCURS WITH HEADER LINE.

* Inputs
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
  PARAMETERSP_DIR TYPE CST_RSWATCH01_ALV-DIRNAME LOWER CASE.
SELECTION-SCREEN END OF BLOCK B1.

*======================
* Initialization Event
*======================
INITIALIZATION.

* Fetch Directory Names from RSWATCH0
    PERFORM MAIN IN PROGRAM RSWATCH0.

    ASSIGN (LW_FNAMETO <LT_OUTTAB>.

    CHECK SY-SUBRC EQ 0.

    I_OUTTAB <LT_OUTTAB>.

* Move the fetched directory names from I_OUTTAB to I_OUTTAB1 which supports Search Help logic
LOOP AT I_OUTTAB INTO WA_OUTTAB.
  WA_OUTTAB1-DIRNAME WA_OUTTAB-DIRNAME.
  APPEND WA_OUTTAB1 TO I_OUTTAB1.
  CLEARWA_OUTTAB1WA_OUTTAB.
ENDLOOP.


*=============================
* At Selection-screen event
*=============================

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_DIR.
  CLEARI_RETURN.
* Function Module for F4 Help
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
  EXPORTING
   RETFIELD               'DIRNAME'
   DYNPPROG               SY-CPROG
   DYNPNR                 SY-DYNNR
   DYNPROFIELD            'P_DIR'
   VALUE_ORG              'S'

  TABLES
    VALUE_TAB              I_OUTTAB1
    RETURN_TAB             I_RETURN

 EXCEPTIONS
   PARAMETER_ERROR        1
   NO_VALUES_FOUND        2
   OTHERS                 3.

 IF SY-SUBRC <> 0.
   MESSAGE 'Error' TYPE 'E'.
 ENDIF.

Comments

Popular posts from this blog

EWM PPF Trigger the existing PPF Action through Custom Program

ABAP 7.5 - FILTER Statement

Useful Transaction Codes / Tools in OData ABAP Service / SAP UI5/ SAP Fiori