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

Select Listbox Entry

Former Member
0 Likes
1,008

Hi there,

i am trying to set the Listbox to a default value after having it filled PBO.

How does it work?

I set the content directly, but then only another value is added to the LB-Entries...

Thx in advance

J Leo

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
902

Hi Jan,


AT SELECTION-SCREEN OUTPUT.
     REFRESH it_listobx_table.   "refresh the lisbox each time before populating the table
     "fill the table in ....
     
     "now set the default value here, but note that each time screen is repdislpayed this will be set
     read table it_listbox_table INDEX X INTO your_listbox.   "specify which entry you wan to read i.e. with INDEX

Usually populating listbox with values takes place in POV not PBO so after user drops down the listbox.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR your_listbox.
     REFRESH it_listbox_table.
     "fill the table here

Regards

Marcin

7 REPLIES 7
Read only

MarcinPciak
Active Contributor
0 Likes
903

Hi Jan,


AT SELECTION-SCREEN OUTPUT.
     REFRESH it_listobx_table.   "refresh the lisbox each time before populating the table
     "fill the table in ....
     
     "now set the default value here, but note that each time screen is repdislpayed this will be set
     read table it_listbox_table INDEX X INTO your_listbox.   "specify which entry you wan to read i.e. with INDEX

Usually populating listbox with values takes place in POV not PBO so after user drops down the listbox.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR your_listbox.
     REFRESH it_listbox_table.
     "fill the table here

Regards

Marcin

Read only

0 Likes
902

Hi Marcin,

thanx 4 your incredibly fast answer.

I guess I should have provided more details:

I don't use selection screens - i use a normal dynpro. So usually i'd say i don't use AT SELECTION_SCREEN and such Events.

Am i wrong?

Cheers

Jan

Read only

0 Likes
902

You then switch AT SELECTION SCREEN ... events with appropriate module pool in flow logic of screen.

i.e. in flow logic you write


PROCESS ON VALUE-REQUEST.            "POV of the screen
  FIELD your_listbox MODULE pov_list.

now in your program...


data your_listbox type ...  "to transfer data b/w screen and program

MODULE pov_list INPUT.
    refresh ...
    "fill the table here
ENDMODULE.

Regards

Marcin

Read only

0 Likes
902

Hi Marcin,

<-You then switch AT SELECTION SCREEN ... events with appropriate module pool in flow logic of -

<- screen.

-> ok, it see what u mean here

<- i.e. in flow logic you write

<- PROCESS ON VALUE-REQUEST. "POV of the screen

<- FIELD your_listbox MODULE pov_list.

-> So i add this line to the POV (or PAI as i call it) processing. my_listbox is then my input-field on the --> dynpro (which i marked as listbox).

<- now in your program...

<- data your_listbox type ... "to transfer data b/w screen and program

-> The type should be equal to my_Listboxes type, right?

<- MODULE pov_list INPUT.

<- refresh ...

<- "fill the table here

<- ENDMODULE.

-> So here i gather the list entries. How do i attach them to my listbox?

<- Regards

<- Marcin

-> You got my regards sincerely

Read only

0 Likes
902

Hi Jan,

See my comments below

<-You then switch AT SELECTION SCREEN ... events with appropriate module pool in flow logic of -

<- screen.

-> ok, it see what u mean here

that's fine:)

PROCESS ON VALUE-REQUEST. "POV of the screen

<- FIELD your_listbox MODULE pov_list.

-> So i add this line to the POV (or PAI as i call it) processing.

Use POV rather than PAI. It will then only trigger this module when you try too pick up the value from list box.

my_listbox is then my input-field on the --> dynpro (which i marked as listbox).

Yes, your lisbox is input-field here (yes setting it as listbox is crucial here;) )


FIELD input-field MODULE pov_list.

So here i gather the list entries. How do i attach them to my listbox?

Here you populate it in two ways. If entries are fetched from DB table and you use DB fields in internal table storing data for listbox then use this:


MODULE  pov_list INPUT.

"here internal table must have two fields, one is the key field, which will be visible in program when entry from
"listobx is picked, and second should be a text for it (as you want to display it in the screen)
"both fields must be of DDIC type (must be from ABAP Dictionary) i.e.

TYPES: BEGIN OF type_carrid,
         carrid type spfli-carrid,
         carrname type scarr-carrname,
       END OF type_carrid.

DATA itab_carrid TYPE STANDARD TABLE
     OF type_carrid WITH HEADER LINE.

SELECT * ... into table  IT_CARRID...

"now you show the results in the listbox,
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
       EXPORTING
            retfield        = 'CARRID'   "your key field (value which will be returned when selecting the entry)
            value_org       = 'S'    
       TABLES
            value_tab       = itab_carrid
       EXCEPTIONS
            parameter_error = 1
            no_values_found = 2
            OTHERS          = 3.
  IF sy-subrc <> 0.
      "here input-field will contain key of the entry (CARRID)
   endif.
ENDMOFULE

Don't forget to declare data obejct to transfer data between screen and program. Do this in declaration part of program (not in module!)


data: input-field type ...

"or if input is globaly visible structure
tables: input.   "all components of the structre will be visible then

Go also [through this link|http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbabe435c111d1829f0000e829fbfe/frameset.htm]. It will give you idea how to use listobx both with DDIC fields and custom ones.

Regards

Marcin

PS: If your listbox is based on field which already has input help defined for it, you can use this FM:


 CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
       EXPORTING
            TABNAME           = 'TABLE_FOR_THE_FIELD'
            FIELDNAME         = 'FIELD_WCHICH_HAS_F4_KEY_DEFINED'
            DYNPPROG          =  sy-repid
            DYNPNR            =  s-dynnr
            DYNPROFIELD       = 'NAME_OF_THE_FIELD_WERE_VALEU_IS_TO_BE_RETURNED'.  " 'INPUT-FIELD' in your case

Anyhow I believe first solution is appropirate in your case or if INPUT-FIELD is not DDIC type, second example in the link I send you will be the solution.

Regards

Marcin

Edited by: Marcin Pciak on Feb 25, 2009 8:23 PM

Read only

Former Member
0 Likes
902

Hi

You can fill the list box in 2 ways: using 'F4IF_INT_TABLE_VALUE_REQUEST' in POV or in PBO using 'VRM_SET_VALUES'. But you can't use both in same program. Check out the following code. Comment out PBO or POV and check it.

*&---------------------------------------------------------------------*
*& Report  YJAN22_LIST1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  YJAN22_LIST1.

TYPE-POOLS : VRM.

DATA :  field_id TYPE VRM_ID ,
        values TYPE VRM_VALUES,
        value LIKE LINE OF values.

TYPES:  BEGIN OF STRUCT1,
        ID LIKE YSTUDENT-ID,
        NAME LIKE YSTUDENT-NAME,
        END OF STRUCT1.

TYPES:  BEGIN OF STRUCT2,
        ID LIKE YSTUDENT-ID,
        MARK LIKE YSTUDENT-MARK,
        END OF STRUCT2.

DATA: ITAB1 TYPE TABLE OF STRUCT1,
      ITAB2 TYPE TABLE OF STRUCT2 WITH HEADER LINE,
      OK_CODE LIKE SY-UCOMM.
CALL SCREEN 2300.
*&---------------------------------------------------------------------*
*&      Module  FILL_LIST  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module FILL_LIST input.

  SELECT ID NAME FROM YSTUDENT INTO TABLE ITAB1.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
*     DDIC_STRUCTURE         = ' '
      retfield               = 'L_LIST1'
*     PVALKEY                = ' '
*     DYNPPROG               = ' '
*     DYNPNR                 = ' '
*     DYNPROFIELD            = ' '
*     STEPL                  = 0
*     WINDOW_TITLE           =
*     VALUE                  = ' '
     VALUE_ORG              = 'S'
*     MULTIPLE_CHOICE        = ' '
*     DISPLAY                = ' '
*     CALLBACK_PROGRAM       = ' '
*     CALLBACK_FORM          = ' '
*     MARK_TAB               =
*   IMPORTING
*     USER_RESET             =
    tables
      value_tab              = ITAB1
*     FIELD_TAB              =
*     RETURN_TAB             =
*     DYNPFLD_MAPPING        =
*   EXCEPTIONS
*     PARAMETER_ERROR        = 1
*     NO_VALUES_FOUND        = 2
*     OTHERS                 = 3
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


endmodule.                 " FILL_LIST  INPUT

*&---------------------------------------------------------------------*
*&      Module  STATUS_2300  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module STATUS_2300 output.
  SET PF-STATUS 'BACK'.
*  SET TITLEBAR 'xxx'.

endmodule.                 " STATUS_2300  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_2300  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module USER_COMMAND_2300 input.

ok_code = SY-UCOMM.
case ok_code.
  when 'BACK'.
    LEAVE PROGRAM.
ENDCASE.
endmodule.                 " USER_COMMAND_2300  INPUT

*&---------------------------------------------------------------------*
*&      Module  FILL_WITH_KEY_LIST  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module FILL_WITH_KEY_LIST output.

  SELECT ID MARK FROM YSTUDENT INTO TABLE ITAB2.
  LOOP AT ITAB2.
    value-KEY = ITAB2-ID.
    value-TEXT = ITAB2-MARK.
    APPEND value TO VALUES.
  ENDLOOP.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id                    = 'L_LIST2'
      values                = VALUES
*   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.

endmodule.                 " FILL_WITH_KEY_LIST  OUTPUT

Flow Logic:
PROCESS BEFORE OUTPUT.
 MODULE STATUS_2300.
 MODULE FILL_WITH_KEY_LIST.
*
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_2300.

PROCESS ON VALUE-REQUEST.
*  FIELD L_LIST1 MODULE FILL_LIST.

Hope this helps

Regards,

Jayanthi.K

Read only

Former Member
0 Likes
902

Hello,

Thanks to Marcin, i now use the POV event to process my listboxes.

Works quite fine. I set the default value simply by writing the key into the listbox-field.

Works too

Cheers Leo