Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Validation in DropDown List box

Dear Experts,

I am having problem in validating a dropdown boxes on the selection screen.

I have 2 dropdown boxes for choosing values from a database table

<b>Drobdown List1</b> - to choose profile name from database table from z_profile.

<b>Drobdown List2</b> - to choose source name from database table from z_source <b>based on profile selected in the Drobdown List1.</b>

<u><b>My problem is</b></u>

<b>How can I choose only those "source names" depending on the "profile names" that I have chosen in droplist 1 only.</b>

<i>Also find the database tables and their values that need to be there to populate in Listbox 1 and 2</i>.

<b>Table - ZPROFILES</b>

MANDT PROFILE_NAME PROFILE_DESC

324   LOCATION     LOCATION MASTER
324   MATERIAL     MATERIAL MASTER
324   VENDOR       VENDOR MASTER

<b>Table - ZSOURCES</b>

MANDT PROFILE_NAME DBTABLE_NAME SOURCE_NAME

324   LOCATION     T001         PLANTS/BRANCHES
324   LOCATION     T001W        COMPANY CODES
324   MATERIAL     MAKT         MATERIAL DESCRIPTIONS
324   MATERIAL     MARA         GENERAL MATERIAL DATA

.. Please see the code that i have written.

REPORT ZTEST1 .

* Display Options for parameters
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE T01.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK 3 WITH FRAME TITLE T03.


PARAMETERS: I_PRO LIKE ZPROFILES-PROFILE_NAME
AS LISTBOX VISIBLE LENGTH 15 DEFAULT '' OBLIGATORY..


PARAMETERS: I_SRC LIKE ZSOURCES-SOURCE_NAME
AS LISTBOX VISIBLE LENGTH 15 DEFAULT '' OBLIGATORY.


SELECTION-SCREEN END OF BLOCK 3.
SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN END OF BLOCK 1.
*-----------------------------------------------



*-- Fill the dropdown list boxes before displaying them
AT SELECTION-SCREEN OUTPUT.
  PERFORM FILL_DROPDOWN_LIST USING 'I_PRO'.

  PERFORM FILL_DROPDOWN_LIST_SRC USING 'I_SRC'.


INITIALIZATION.
  T01 = 'Update DB Tables'.
  T03 = 'Browse Profile and Data Source'.

START-OF-SELECTION.

END-OF-SELECTION.


*---------------------------------------------------------------------*
*       FORM fill_dropdown_list                   *
*---------------------------------------------------------------------*
FORM FILL_DROPDOWN_LIST USING VALUE(F_PARAMETER).
  TYPE-POOLS: VRM. " For parameter drop down lists
*-- Definitions for parameter drop down lists
  DATA:
    NAME  TYPE VRM_ID,
    LIST  TYPE VRM_VALUES,
    VALUE LIKE LINE OF LIST.

  DATA : IT_PROFILES LIKE ZPROFILES OCCURS 0 WITH HEADER LINE.


  NAME = F_PARAMETER.
  CASE F_PARAMETER.
    WHEN 'I_PRO'.

      VALUE-KEY = 'TEST_PROFI'.
      VALUE-TEXT = 'TEST_PROFILE'.
      APPEND VALUE TO LIST.


      CLEAR : IT_PROFILES,
              IT_PROFILES[].

      SELECT * FROM ZPROFILES CLIENT SPECIFIED
      INTO TABLE IT_PROFILES
      WHERE MANDT = SY-MANDT .
      IF SY-SUBRC = 0.
        SORT IT_PROFILES BY PROFILE_NAME.

        CLEAR : IT_PROFILES.
        LOOP AT IT_PROFILES.
          VALUE-KEY = IT_PROFILES-PROFILE_NAME.
          VALUE-TEXT = IT_PROFILES-PROFILE_NAME.
          APPEND VALUE TO LIST.
        ENDLOOP.
      ENDIF.

    WHEN OTHERS.
  ENDCASE.
  CALL FUNCTION 'VRM_SET_VALUES'
       EXPORTING
            ID     = NAME
            VALUES = LIST.

ENDFORM." fill_dropdown_list


*&---------------------------------------------------------------------*
*&      Form  FILL_DROPDOWN_LIST_SRC
*&---------------------------------------------------------------------*
FORM FILL_DROPDOWN_LIST_SRC USING   VALUE(F_PARAMETER).

  TYPE-POOLS: VRM. " For parameter drop down lists
*-- Definitions for parameter drop down lists
  DATA:
    NAME  TYPE VRM_ID,
    LIST  TYPE VRM_VALUES,
    VALUE LIKE LINE OF LIST.

  DATA : IT_SOURCES LIKE ZSOURCES OCCURS 0 WITH HEADER LINE.


  NAME = F_PARAMETER.
  CASE F_PARAMETER.
    WHEN 'I_SRC'.

      CLEAR : IT_SOURCES,
              IT_SOURCES[].

      SELECT * FROM ZSOURCES CLIENT SPECIFIED
      INTO TABLE IT_SOURCES
      WHERE MANDT = SY-MANDT.

      IF SY-SUBRC = 0.
        SORT IT_SOURCES BY PROFILE_NAME SOURCE_NAME.

        CLEAR : IT_SOURCES.
        LOOP AT IT_SOURCES.
          VALUE-KEY  = IT_SOURCES-PROFILE_NAME.
          VALUE-TEXT = IT_SOURCES-SOURCE_NAME.
          APPEND VALUE TO LIST.
        ENDLOOP.
      ENDIF.

    WHEN OTHERS.
  ENDCASE.
  CALL FUNCTION 'VRM_SET_VALUES'
       EXPORTING
            ID     = NAME
            VALUES = LIST.

ENDFORM.                    " FILL_DROPDOWN_LIST_SRC

Please help.

Thanks

Tags:
replied

Hi ,

The previous source code had some bugs. I have modified that . Just check this error-free code.

tables: zprofiles, zsources.

type-pools : vrm.

data: begin of itab occurs 0,

PRO_NAME LIKE ZPROFILES-PROFILE_NAME,

SOU_NAME LIKE ZSOURCES-SOURCE_NAME,

end of itab.

DATA: DYNPRO_VALUES TYPE DYNPREAD OCCURS 1 WITH HEADER LINE.

data: field_value like line of dynpro_values.

data: progname type sy-repid,

dynnum type sy-dynnr.

data: it_val type vrm_values,

w_line like line of it_val.

parameters : PRO_NAME like zprofiles-profile_name as listbox visible

length 35 ,

SOU_NAME like zsources-source_name as listbox visible

length 35 .

initialization.

CLEAR it_val[].

CLEAR ITAB[].

SELECT PROFILE_NAME FROM ZPROFILES INTO TABLE ITAB.

LOOP AT ITAB.

W_LINE-TEXT = ITAB-PRO_NAME.

W_LINE-KEY = ITAB-PRO_NAME.

append w_line to it_val.

ENDLOOP.

progname = sy-repid.

dynnum = sy-dynnr.

field_value-fieldname = 'PRO_NAME'.

APPEND field_value TO dynpro_values.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

id = 'PRO_NAME'

values = it_val

EXCEPTIONS

ID_ILLEGAL_NAME = 1

OTHERS = 2

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

at selection-screen.

clear itab[].

clear it_val[].

SOU_NAME = ''.

CALL FUNCTION 'DYNP_VALUES_READ'

EXPORTING

dyname = progname

dynumb = dynnum

  • TRANSLATE_TO_UPPER = ' '

  • REQUEST = ' '

  • PERFORM_CONVERSION_EXITS = ' '

  • PERFORM_INPUT_CONVERSION = ' '

  • DETERMINE_LOOP_INDEX = ' '

tables

dynpfields = dynpro_values

EXCEPTIONS

INVALID_ABAPWORKAREA = 1

INVALID_DYNPROFIELD = 2

INVALID_DYNPRONAME = 3

INVALID_DYNPRONUMMER = 4

INVALID_REQUEST = 5

NO_FIELDDESCRIPTION = 6

INVALID_PARAMETER = 7

UNDEFIND_ERROR = 8

DOUBLE_CONVERSION = 9

STEPL_NOT_FOUND = 10

OTHERS = 11

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

SELECT PPROFILE_NAME QSOURCE_NAME INTO TABLE ITAB FROM

( ZPROFILES AS P INNER JOIN ZSOURCES AS Q ON P~PROFILE_NAME =

QPROFILE_NAME ) WHERE PPROFILE_NAME = DYNPRO_VALUES-FIELDVALUE.

LOOP AT ITAB.

W_LINE-KEY = ITAB-SOU_NAME.

W_LINE-TEXT = ITAB-SOU_NAME.

APPEND W_LINE TO IT_VAL.

ENDLOOP.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

id = 'SOU_NAME'

values = it_val

EXCEPTIONS

ID_ILLEGAL_NAME = 1

OTHERS = 2

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CLEAR IT_VAL[].

CLEAR ITAB[].

Regards,

SP.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question