Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

dropdown list box display

Former Member
0 Likes
2,630

I want to display some information in a drop down list box. In the back end it will take the values from another table. Suppose If I want to display the shipping ports as "Mumbai,Karachi,Cape Town,Malmo" etc and in back it will pick the values as MUM,KAR,CPT,MLM from a table. Now my question is based upon the authorization object defined for different countries it will populate the dropdown listbox. Suppose if the goods is delivered from south Africa it will populate only cape town and not the others. Please tell me how to do this? Also how will I use the VRM type pool to do this.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,085

The problem is ->

I am getting the cities corresponding to a customer from the table. In case of multiple city the number of cities will be determined only at runtime. So how can I make provision for the number of entries of city?

Edited by: Sudipto Chakrabarty on Mar 31, 2008 8:08 AM

14 REPLIES 14
Read only

Former Member
0 Likes
2,085

check this link for drop down list

http://sap.niraj.tripod.com/id38.html

Read only

Former Member
0 Likes
2,085

Hi,

You can populate the list box in this manner:

  • Display this only for reason code screen

IF pv_reason IS NOT INITIAL.

wa_field_catalog-col_pos = 7.

wa_field_catalog-fieldname = 'REASON'.

wa_field_catalog-inttype = 'C'.

wa_field_catalog-drdn_hndl = '1'.

wa_field_catalog-outputlen = '30'.

wa_field_catalog-edit = '1'.

wa_field_catalog-coltext = 'Reason'(032).

APPEND wa_field_catalog TO pv_field_catalog.

wa_field_catalog-col_pos = 8.

wa_field_catalog-fieldname = 'STATUS'.

wa_field_catalog-inttype = 'C'.

wa_field_catalog-drdn_hndl = '2'.

wa_field_catalog-outputlen = '30'.

wa_field_catalog-edit = '1'.

wa_field_catalog-coltext = 'Equipment Status'(068).

APPEND wa_field_catalog TO pv_field_catalog.

But, change it as per your requirement and get in touch with me for more info.

Thanks,

Anil

Read only

0 Likes
2,085

Hi Anil,

I am using VRM to populate the dropdown list box. It would be useful if you can customize your answer in this context. I also want to populate the dropdown listbox according to geographical location of the customer. In any case your answer was helpful and please try to give me some insight in the problem I am facing.

Thanks in advance,

Sudipto

Read only

0 Likes
2,085

I assume you have the following fields for input in the screen.

Customer Number (g_kunnr)

City (g_city)

On inputting the customer number, the customer goes to City field and presses F4. So you expect only those cities to be visible in the dropdown whose country is the same as the customer.

If my assumption/understanding is right, do the following.


if g_kunnr is not initial.
  select land1 from kna1 into kna1-land1 where kunnr = g_kunnr.
  if sy-subrc = 0.
    <<get the cities corresponding to KNA1=KUNNR from T005G table 
        and populate the same in your drop down listbox>>
  else.  "this means the customer is invalid.
    message e000(zz) with 'Customer Invalid'.
  endif.
else.
  <<get all the cities and ppopulate the same in the list box>>
endif.

Hope this is helpful. Rwd points if helpful.

Thanks,

Balaji

Read only

Former Member
0 Likes
2,085

Hi,

See the sample coding.

process before output.
  module drop_down


module drop_down output.
  if mem = 'S'.
    name = 'MODE'.
    value-key = '1'.value-text = 'By Lorry-LCV'.
    append value to list.
    value-key = '2'.value-text = 'By Lorry-FTL'.
    append value to list.
    value-key = '3'.value-text = 'By Lorry-Speed'.
    append value to list.
    value-key = '4'.value-text = 'By Courier'.
    append value to list.
    value-key = '5'.value-text = 'By Air'.
    append value to list.
    value-key = '6'.value-text = 'By Train'.
    append value to list.
    value-key = '7'.value-text = 'By Car'.
    append value to list.
    value-key = '8'.value-text = 'By Hand'.
    append value to list.
    value-key = '9'.value-text = 'By own Vehicle'.
    append value to list.
    value-key = '10'.value-text = 'By MRT-BUS'.
    append value to list.

    call function 'VRM_SET_VALUES'
      exporting
        id     = name
        values = list.
    if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    mem = 'R'.
  endif.


endmodule.                 " DROP_DOWN  OUTPUT.

where mode is the screen field .should be of type checkbox.

Regards,

Morris Bond.

Reward Points if Helpful.

Read only

Former Member
0 Likes
2,085

Hi,

If you want drop down list box in the selection screen, check the below link.

http://sap.niraj.tripod.com/id38.html

If you are looking at drop down list box in the ALV output, then follow the below steps.

Certainly, it will be nice to make some fields as dropdown menus. The procedure for making a field as a dropdown menu is quite simple. We do not give our table filled with handles directly to the method

“set_table_for_first_display”. The table for values must be of type “LVC_T_DROP” and we will use the method “set_drop_down_table” to register our handles table. To make an entire column as dropdown, just while generating the field catalog; pass the handle number to field “DRDN_HNDL” for that field.

e.g. ps_fcat-drdn_hndl = '1' .

To make individual cells as dropdown, you must add a new field to contain the handle, for each column field to be as dropdown. While filling your list data or somewhere separate where you modify it, you fill these new fields with handles. To match the fields containing handle information with the columns, we use again the field catalog. We pass the name of our new field to the field “DRDN_FIELD” of the field catalog structure for the column.

ps_fcat-drdn_field = 'PTYP_DD_HNDL'. 

Adding a new field to contain handle for drilldown values


*--- Internal table holding list data
DATA BEGIN OF gt_list OCCURS 0 .
INCLUDE STRUCTURE SFLIGHT .
DATA ptype_dd_hndl TYPE int4 .
DATA END OF gtlist .

Preparing values for the dropdown menu with the handle ‘1’


*--- Drilldown values
FORM prepare_drilldown_values.
 DATA lt_ddval TYPE lvc_t_drop .
 DATA ls_ddval TYPE lvc_s_drop .

ls_ddval-handle = '1' .
ls_ddval-value = 'JFK-12' .
APPEND ls_ddval TO lt_ddval .

ls_ddval-handle = '1' .
ls_ddval-value = 'JSF-44' .
APPEND ls_ddval TO lt_ddval .

ls_ddval-handle = '1' .
ls_ddval-value = 'KMDA-53' .
APPEND ls_ddval TO lt_ddval .

ls_ddval-handle = '1' .
ls_ddval-value = 'SS3O/N' .
APPEND ls_ddval TO lt_ddval .

CALL METHOD gr_alvgrid->set_drop_down_table
EXPORTING
it_drop_down = lt_ddval .

ENDFORM. " prepare_drilldown_values

Hope this helps. Rwd points if helpful.

Thanks,

Balaji

Read only

Former Member
0 Likes
2,086

The problem is ->

I am getting the cities corresponding to a customer from the table. In case of multiple city the number of cities will be determined only at runtime. So how can I make provision for the number of entries of city?

Edited by: Sudipto Chakrabarty on Mar 31, 2008 8:08 AM

Read only

0 Likes
2,085

Hi,

You mean to say that, if you get multiple countries entered by user how do you put them on the screen right? For example, if i enter India and Australia, you will fetch the cities from a table. Now you want to put them into the list box?

Is that right?

Thanks,

Anil

Read only

0 Likes
2,085

yes,u got my point.

Read only

0 Likes
2,085

Hi,

Let's say you have two countries India and SA and suppose if there are 4 cities MUM, DEL, CHN and CPT.

Now your internal table will be populated with these four cities. All you have to do is to put them into the drop down. If i'm wrong please explain the requirement. I'm a bit unclear about it.

Thanks,

Anil.

Read only

0 Likes
2,085

I have fetched the country and populated the internal table. Now how will I populate the dropdown listbox using VRM? In the front end the port name will be displayed and in the backend the corresponding database entry from the internal table will be selected.

Port name: CAPE TOWN database entry: CTW.

Read only

0 Likes
2,085

check this


LIST BOX                      
Drop down list box can be created in a dialog screen(SE51) as well as selection screen.
  The sap list box allows to select a value from the list but we cannot enter our own value in the list box .The value list that will be displayed consists of two
fields TEXT field of TYPE 80(C) and internal KEY field of TYPE 40(C).
 
 In screen painter to create a input/output field into list box we use 
 'L" as a value for dropdown attribute for the i/o field.
 In screen painter to determine the type of method that will be used to fill the value
list we use the attribute value list.
If it is blank  the value list will be filled by the first column of the input help assigned to the screen field.This input help can be defined in the ABAP Dictionary, on screen using SELECT,VALUES screen statements or in event POV (PROCESS ON VALUE-REQUEST ) and the input help that will be passed to the field should consists of 2 columns ,the key column is filled automatically by the system.SAP recommends value list field should be blank.
or
The value  can be 'A' meaning that the value list will be filled in the event PBO(PROCESS BEFORE OUTPUT) or before the screen is displayed.In this method we use function module VRM_SET_VALUES to fill the values and pass it to the i/o field.
 If a function code is attached to the list box the selection of a value triggers a PAI
otherwise PAI will not trigger. 


LIST BOX in SELECTION SCREEN
  List Box is created in selection screen using PARAMETERS staement 
with AS LISTBOX addition other attributes like VISIBLE LENGTH (width of listbox)
can be specified with the declaration.
PARAMETERS name(n) AS LISTBOX VISIBLE LENGTH n.
 Here n is an integer and name is the name of parameter.
 To populate the value list we use the FM VRM_SET_VALUES  and the 
selection screen event AT SELECTION-SCREEN OUTPUT is used to write the code to fill it. 

VRM_SET_VALUES     
 The function module VRM_SET_VALUES is used to fill the value list associated with a List Box .This FM uses types which are declared in type group VRM. So 
we should declare TYPE-POOLS VRM before using this FM.
 
 Some important types declared in the VRM type group are
VRM_ID
   It refers to the name of the input/output field associated with list box
VRM_VALUES
  It refers to the internal table consisting of two fields TEXT(80C) and KEY(40)C
that will be used to create the list values.
 
CALL FUNCTION 'VRM_SET_VALUES'
  EXPORTING
      ID                =  name of screen element ,it is of TYPE VRM_ID
      VALUES      =  internal table containing values,of TYPE VRM_VALUES  
 
  
LIST BOX with value list from input help
 In this example the screen element attribute value list is set to blank as such the value list will be filled with the 1st column of the input help,We use PROCESS ON VALUE-REQUEST event to pass the value list  to the listbox.In the MODULE call used to fill the value list we can use FM like F4IF_INT_TABLE_VALUE_REQUEST to create input help as explained in the input help.The value of first column will be shown in the field when selected.
 
PROCESS ON VALUE-REQUEST
FIELD list MODULE fill_list_100
 
FIELD list MODULE fill_list_100 INPUT
SELECT f1 f2 FROM table INTO int 
 
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
       EXPORTING
            retfield        = 'input/output screen field'
            value_org       = 'S'
       TABLES
            value_tab       = itab "it contains 2 fields that will be shown in the list box
       EXCEPTIONS
            parameter_error = 1
            no_values_found = 2
            OTHERS          = 3.
  IF sy-subrc <> 0.
    ...
ENDIF.
ENDMODULE. 
 
VALUE LIST CREATED IN PBO
 
In this method we set the value list attribute to 'A'.The value list will be filled in the PBO by using FM VRM_SET_VALUES .
 
TYPE-POOLS : VRM
DATA : field_id TYPE VRM_ID ,
            values  TYPE VRM_VALUES,
             value   LIKE LINE OF values.
 
PROCESS BEFORE OUTPUT
MODULE list_fill_100
 
MODULE list_fill_100 OUTPUT
SELECT f1 f2 f3  FROM tab WHERE condition.
value-KEY = f1.
value-TEXT = f2
APPEND value TO VALUES
 
CALL FUNCTION 'VRM_SET_VALUES'
       EXPORTING
            id     = 'i/o screen field' 
            values = values.
 
ENDMODULE. 

LIST BOX with Selection Screen
 For this the FM VRM_SET_VALUES is used to fill the value table and is passed to the parameter created with TYPE LISTBOX in the selection screen event
AT SELECTION-SCREEN.
 
PROGRAM zlist
TYPE-POOLS : VRM.
DATA: param TYPE vrm_id, 
       values     TYPE vrm_values, 
       value LIKE LINE OF values. 

PARAMETERS: p_name(10) AS LISTBOX VISIBLE LENGTH 10.
AT SELECTION-SCREEN OUTPUT. 
  param = 'P_NAME'. 
  value-key = '1'.
  value-text = 'JOHN'.
  APPEND value TO values.
  value-key = '2'. 
  value-text = 'PETER'.
  APPEND value TO values. 
  CALL FUNCTION 'VRM_SET_VALUES' 
    EXPORTING id     = param 
              values = values. 

Read only

0 Likes
2,085

Try the below code.



tables: ztable, t005g.

TYPE-POOLS : VRM.

parameters: p_kunnr type kunnr,
            p_city type t005g-cityc as listbox visible length 10.

types: begin of ty_ztable,
         land1 type kna1-land1,
       end of ty_ztable.

types: begin of ty_t005g,
         cityc type t005g-cityc,
       end of ty_t005g.

data: it_ztable type standard table of ty_ztable with header line,
      it_t005g type standard table of ty_t005g with header line.


at selection-screen output.

  ranges: r_land1 for t005g-land1.

  clear: r_land1[].
  if p_kunnr is not initial.
    select land1 from ztable into table it_ztable where kunnr = p_kunnr.
    if sy-subrc = 0 .
      loop at it_ztable.
        r_land1-sign = 'I'.
        r_land1-option = 'EQ'.
        r_land1-low = it_ztable-land1.
        append r_land1.
      endloop.
    endif.
  endif.
 
DATA: name TYPE vrm_id,
        list  TYPE vrm_values,
        value type vrm_value.

  name = 'P_CITY'.

  select cityc from t005g into table it_t005g where land1 in r_land1.
  if sy-subrc = 0.
    loop at it_t005g.
      value-key = it_t005g-cityc.
      value-text = '   '.  "populate the city desc from t005h table
      append value to list.
    endloop.
  endif.

*at selection-screen on value-request for p_cityc.
  call function 'VRM_SET_VALUES'
    EXPORTING
      id     = name
      values = list.

Hope this solves your issue.

Thanks,

Balaji

Read only

0 Likes
2,085

thanks, It solved my point....

points rewarded