Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Dynamic Selection screen popup using FM - POPUP_GET_VALUES_USER_HELP & data extraction

Summary

This Post narrates the sample code for creating dynamic selection screen popup based on based on dictionary table and subsequent data extraction based on user input.

Author(s):  Vinod Kumar T

   
Company:     NIIT Technologies Limited
Created on:    30.11.2012
Author(s) Bio
Vinod Kumar is an ABAP consultant working with NIIT Technologies Limited. 

Function modules used in the report

Sr. No

Function Module

Description

1

POPUP_GET_VALUES_SET_MAX_FIELD

Dialog box for setting the maximum no. of fields per dialog box

2

POPUP_GET_VALUES_USER_HELP

Dialog box for requesting values, call of user exits and help

 

Global Class & methods used in the report

Sr.No

Class

Method

Description

1

CL_RECA_DDIC_TABL

GET_FIELD_LIST_X

Column list of Dictionary Table

2

CL_SALV_TABLE

FACTORY

Create Instance of ALV

3

CL_SALV_TABLE

DISPLAY

Display ALV Grid

 

Sample Code
Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT  zvk_screen1.
*----------------------------------------------------------------------*
*       CLASS lcl_exception DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcx_exception DEFINITION INHERITING FROM cx_static_check.
  PUBLIC SECTION.
    METHODS : get_text REDEFINITION.
    CLASS-DATA : lv_result TYPE string.
ENDCLASS.                    "lcl_exception DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_exception IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcx_exception IMPLEMENTATION.
  METHOD  get_text.
    result = lv_result.
  ENDMETHOD.                    "get_text
ENDCLASS.                    "lcl_exception IMPLEMENTATION
*----------------------------------------------------------------------*
*       CLASS lcl_local DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_local DEFINITION FINAL.
  PUBLIC SECTION.
    METHODS : get_data IMPORTING table_name TYPE tabname
                                 key_yn     TYPE char01
                       RAISING lcx_exception.
  PRIVATE SECTION.
    METHODS : get_tab_columns IMPORTING table_name TYPE tabname
                                        key_yn     TYPE char01
                              RAISING lcx_exception,
              create_sel_popup RAISING lcx_exception,
              extract_display  IMPORTING table_name TYPE tabname
                               RAISING lcx_exception.

    TYPES : BEGIN OF ty_where,
               where_clause TYPE char72,
            END OF ty_where.

    DATA : field_list_tab TYPE dd03ttyp,
           field_list     TYPE dd03p,
           fields_tab     TYPE STANDARD TABLE OF sval,
           fields         TYPE sval,
           lt_where       TYPE STANDARD TABLE OF ty_where,
           ls_where       TYPE ty_where.

    DATA : lt_cond        TYPE STANDARD TABLE OF hrcond,
           ls_cond        TYPE hrcond.

    DATA : lv_return      TYPE char01,
           lv_value       TYPE char100,
           lv_val         TYPE char100,
           lv_func        TYPE char30,
           lv_tabix       TYPE sy-tabix,
           lv_rows        TYPE char03.

    DATA : ref_table TYPE REF TO data,
           gr_table  TYPE REF TO cl_salv_table.

    CONSTANTS : lv_quote   TYPE char01 VALUE `'`.

ENDCLASS.                    "lcl_local DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_local IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_local IMPLEMENTATION.
  METHOD get_data.

    REFRESH : lt_where.
    CLEAR : lv_func, lv_value.
    TRY.
        get_tab_columns( table_name = table_name
                         key_yn     = key_yn ).
        create_sel_popup( ).

        LOOP AT fields_tab INTO fields WHERE value IS NOT INITIAL.
          CLEAR : field_list, ls_where.
          READ TABLE field_list_tab INTO field_list
                                    WITH KEY fieldname = fields-fieldname.
          IF sy-subrc EQ 0.
            IF field_list-convexit IS NOT INITIAL.
              CONCATENATE 'CONVERSION_EXIT_'
                           field_list-convexit
                           '_INPUT' INTO lv_func.
              CALL FUNCTION lv_func
                EXPORTING
                  input  = fields-value
                IMPORTING
                  output = lv_value.
            ELSE.
              lv_value = fields-value.
            ENDIF.
            CONDENSE lv_value.
            CASE field_list-inttype.
              WHEN 'C' OR 'N' OR 'D' OR 'T'.
                CONCATENATE lv_quote lv_value lv_quote
                    INTO lv_val.
            ENDCASE.
            IF lv_tabix EQ 0.
              CONCATENATE fields-fieldname
                          'EQ'
                          lv_val INTO ls_where-where_clause
                                   SEPARATED BY space.
              APPEND ls_where TO lt_where.
            ELSE.
              CONCATENATE 'AND' fields-fieldname
                          'EQ'
                          lv_val INTO ls_where-where_clause
                                   SEPARATED BY space.
              APPEND ls_where TO lt_where.
            ENDIF.
            IF lv_tabix EQ 0.
              MOVE 1 TO lv_tabix.
            ENDIF.
          ENDIF.
        ENDLOOP.
        extract_display( table_name ).
      CATCH lcx_exception.
        RAISE EXCEPTION TYPE lcx_exception.
    ENDTRY.
  ENDMETHOD.                    "get_data
  METHOD extract_display.
    FIELD-SYMBOLS : <fs_tab> TYPE ANY TABLE.
    IF lt_where[] IS NOT INITIAL.
      CREATE DATA ref_table TYPE TABLE OF (table_name).
      ASSIGN ref_table->* TO <fs_tab>.
      SELECT * FROM (table_name)  INTO TABLE <fs_tab>
        WHERE (lt_where).
      IF sy-subrc NE 0.
        lcx_exception=>lv_result = 'No Records selected'.
        RAISE EXCEPTION TYPE lcx_exception.
      ELSE.
        TRY.
            cl_salv_table=>factory(
              IMPORTING
                r_salv_table = gr_table
              CHANGING
                t_table      = <fs_tab> ).
            gr_table->display( ).
          CATCH cx_salv_msg .
            lcx_exception=>lv_result = 'Error Displaying records'.
            RAISE EXCEPTION TYPE lcx_exception.
        ENDTRY.
      ENDIF.
    ELSE.
      lcx_exception=>lv_result = 'No Selection criteria found'.
      RAISE EXCEPTION TYPE lcx_exception.
    ENDIF.
  ENDMETHOD.                    "get_data

  METHOD get_tab_columns.
    REFRESH : field_list_tab, fields_tab.
    cl_reca_ddic_tabl=>get_field_list_x(
      EXPORTING
        id_name            = table_name
        if_suppress_mandt  = abap_true
        if_suppress_nonkey = key_yn
      IMPORTING
        et_field_list_x    = field_list_tab
      EXCEPTIONS
        not_found          = 1
        OTHERS             = 2 ).
    IF sy-subrc <> 0.
      lcx_exception=>lv_result = 'Error getting column list'.
      RAISE EXCEPTION TYPE lcx_exception.
    ENDIF.

    LOOP AT field_list_tab INTO field_list.
      MOVE-CORRESPONDING field_list TO fields.
      APPEND fields TO fields_tab.
    ENDLOOP.
  ENDMETHOD.                    "get_tab_columns

  METHOD create_sel_popup.
    lv_rows = lines( fields_tab ).
    IF lv_rows GT 30.
      lv_rows = 30.
    ENDIF.
    CALL FUNCTION 'POPUP_GET_VALUES_SET_MAX_FIELD'
      EXPORTING
        number_of_fields = lv_rows
      EXCEPTIONS
        out_of_range     = 1
        OTHERS           = 2.
    IF sy-subrc <> 0.
        lv_rows = 10.  "Default
    ENDIF.

    CALL FUNCTION 'POPUP_GET_VALUES_USER_HELP'
      EXPORTING
        popup_title     = 'Input screen'
        start_column    = '5'
        start_row       = '4'
      IMPORTING
        returncode      = lv_return
      TABLES
        fields          = fields_tab
      EXCEPTIONS
        error_in_fields = 1
        OTHERS          = 2.

    IF sy-subrc <> 0.
      lcx_exception=>lv_result = 'Error Generating selection screen'.
      RAISE EXCEPTION TYPE lcx_exception.
    ELSE.
      IF lv_return = 'A'.
        lcx_exception=>lv_result = 'Action cancelled by user'.
        RAISE EXCEPTION TYPE lcx_exception.
      ENDIF.
    ENDIF.

  ENDMETHOD.                    "create_sel_popup
ENDCLASS.                    "lcl_local IMPLEMENTATION

DATA : gr_local TYPE REF TO lcl_local,
       gr_exception TYPE REF TO lcx_exception.

DATA : lv_result TYPE string.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS : p_tab TYPE dd02l-tabname.
PARAMETERS : p_key TYPE char01 AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.
  CREATE OBJECT gr_local.
  TRY.
      gr_local->get_data( table_name = p_tab
                          key_yn     = p_key ).
    CATCH lcx_exception INTO gr_exception.
      lv_result = gr_exception->get_text( ).
      WRITE :/ lv_result.
  ENDTRY.
  
  
Remarks
    • Data extraction has been done with "Equal to" condition, implementation of data extraction using selection table will require more changes in above program.