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

Problem in Populating a listbox

Former Member
0 Likes
1,624

hello everyone,

In my report prog, there are two parameters:

p_matno LIKE mara-matnr OBLIGATORY,
p_s_loc TYPE mard-lgort AS LISTBOX VISIBLE LENGTH 8.

When I input p_matno and press enter, the listbox P_S_LOC is populated with the corresponding values by triggering followingselect query:

SELECT lgort FROM mard INTO CORRESPONDING FIELDS OF TABLE it_storeloc WHERE matnr = p_matno AND werks = '1501'.

This works fine .. But now the condition is, if I dont select any value populated in the listbox and execute the prog(press F8), it should give an error msg ..

I wrote that piece of code as this in the STARTt-OF-SELECTION

IF P_S_LOC is INITIAL.
    message 'Storage Location Needs to be Entered.' type 'S'.
ENDIF:

but when the error message is generated, the values in the listbox go away and it becomes empty .. How can i retain this values in the listbox ??

Kindly help .. any input will be apprecitaed ..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,583

Hi

I would suggest the following way:

Parameters: 	p_matno LIKE mara-matnr OBLIGATORY,
		p_s_loc TYPE mard-lgort AS LISTBOX VISIBLE LENGTH 8.

AT SELECTION-SCREEN ON p_matno.	
	IF p_matno IS NOT INITIAL.
		SELECT lgort FROM mard INTO CORRESPONDING FIELDS OF TABLE it_storeloc 
		WHERE matnr = p_matno AND werks = '1501'.
		CALL FUNCTION 'VRM_SET_VALUES'
		    EXPORTING
		      id              = 'P_S_LOC'
		      values          = it_storeloc
		    EXCEPTIONS
		      id_illegal_name = 1
		      OTHERS          = 2.
	ENDIF.
AT SELECTION-SCREEN ON p_s_loc.	
	IF P_S_LOC is INITIAL.
	    message 'Storage Location Needs to be Entered.' type 'E'.
	ENDIF.
START-OF-SELECTION.
	..... Rest of processing......

Best regards

Anand

17 REPLIES 17
Read only

venkat_o
Active Contributor
0 Likes
1,583

Hi , I have tried to replicate your problem. Its seems to be ok. Check it out.


REPORT ztest_program.
PARAMETERS:
p_matno LIKE mara-matnr OBLIGATORY,
list AS LISTBOX VISIBLE LENGTH 20.
TYPE-POOLS vrm.
DATA: g_name  TYPE vrm_id,
      it_list TYPE vrm_values,
      wa_list LIKE LINE OF it_list.

AT SELECTION-SCREEN OUTPUT.
  IF NOT p_matno IS  INITIAL.
    IF it_list[] IS INITIAL.
      wa_list-key  = '1'.
      wa_list-text = '1 is selected'.
      APPEND wa_list TO it_list.
      CLEAR wa_list.
      wa_list-key  = '2'.
      wa_list-text = '2 is selected'.
      APPEND wa_list TO it_list.
      CLEAR wa_list.
      wa_list-key  = '3'.
      wa_list-text = '3 is selected'.
      APPEND wa_list TO it_list.
      CLEAR wa_list.
      wa_list-key  = '4'.
      wa_list-text = '4 is selected'.
      APPEND wa_list TO it_list.
      CLEAR wa_list.
    ENDIF.
    g_name = 'LIST'.
  ENDIF.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id              = g_name
      values          = it_list
    EXCEPTIONS
      id_illegal_name = 1
      OTHERS          = 2.

AT SELECTION-SCREEN.
  IF list IS INITIAL.
    MESSAGE 'Storage Location Needs to be Entered.' TYPE 'S'.
  ENDIF.

START-OF-SELECTION.
  WRITE 'xyz'.
Thanks Venkat.O

Read only

Former Member
0 Likes
1,583

Hey venkat,

Thanks for the reply ..

But the problem is, I have to populate the listbox based on the material number that is entered in the p_matno .. So I cant call this FM in AT SELECTION-SCREEN OUTPUT.

I need to first enter the material number in p_matno .. press enter .. and then this FM should be called .. This all works fine .. the only problem is that ke after I execute the program adn error msg is displayed, listbox values just vanish ..

Read only

0 Likes
1,583

Why don't you simply make it also mandatory


p_s_loc TYPE mard-lgort AS LISTBOX VISIBLE LENGTH 8 OBLIGATORY.

System will take care of validating data (non empty field) itselft. You don't have to worry about that anymore.

Regards

Marcin

Read only

Former Member
0 Likes
1,583

Hey,

If I make it obligatory then after inputting material number in p_matno when I will press enter, the system will display an error message as the listbox is empty and the listbox will never get populated based on my select query..

Read only

Former Member
0 Likes
1,583

Hi,

Change the message type to 'E' and check now.Hope it should work now for you.

Read only

Former Member
0 Likes
1,584

Hi

I would suggest the following way:

Parameters: 	p_matno LIKE mara-matnr OBLIGATORY,
		p_s_loc TYPE mard-lgort AS LISTBOX VISIBLE LENGTH 8.

AT SELECTION-SCREEN ON p_matno.	
	IF p_matno IS NOT INITIAL.
		SELECT lgort FROM mard INTO CORRESPONDING FIELDS OF TABLE it_storeloc 
		WHERE matnr = p_matno AND werks = '1501'.
		CALL FUNCTION 'VRM_SET_VALUES'
		    EXPORTING
		      id              = 'P_S_LOC'
		      values          = it_storeloc
		    EXCEPTIONS
		      id_illegal_name = 1
		      OTHERS          = 2.
	ENDIF.
AT SELECTION-SCREEN ON p_s_loc.	
	IF P_S_LOC is INITIAL.
	    message 'Storage Location Needs to be Entered.' type 'E'.
	ENDIF.
START-OF-SELECTION.
	..... Rest of processing......

Best regards

Anand

Read only

0 Likes
1,583

Hey anand,

Naah .. It's not working ..

When I press enter after inpitting material number in p_matno, it gives the error msg that storage location needs to be entered but the list is not getting populated ..

Read only

0 Likes
1,583

Please paste the code you are approaching .

Thanks

Venkat.O

Read only

0 Likes
1,583

Hey Venkat,

Here is the code:Do check out the comments beside every line for better understanding.

*---------for drop down list --------------------*
TYPE-POOLS: vrm.
*
DATA: it_val TYPE vrm_values,
      w_line LIKE LINE OF it_val,

      it_storeloc TYPE TABLE OF mard,
      w_storeloc LIKE LINE OF it_storeloc,

      v_name TYPE vrm_id VALUE 'P_S_LOC'.

*------------------------------------------------*

// List of Parameters

PARAMETERS :  p_matno LIKE mara-matnr OBLIGATORY,
              p_werks LIKE marc-werks OBLIGATORY DEFAULT '1501',
              p_s_loc TYPE mard-lgort AS LISTBOX VISIBLE LENGTH 8,
              p_erdat TYPE vbap-erdat,
              p_netwr TYPE lips-netwr,
              p_qty TYPE i.

AT SELECTION-SCREEN OUTPUT.


  LOOP AT SCREEN.  "Only Material Number is to be inputted. Other ields will be populated on the basis of material number.

    IF screen-name = 'P_ERDAT' OR screen-name = 'P_NETWR' OR screen-name = 'P_QTY'.
       screen-input = 0.
    
    ENDIF.

    MODIFY SCREEN.

  ENDLOOP.

AT SELECTION-SCREEN.

*  CLEAR : p_erdat,p_netwr,p_qty.

  PERFORM matnr_validation. "Validation of Material Number
  PERFORM fetch_mat_description. "Getting material description
  PERFORM fetch_data. "fetching data - here I have called the FM to populate the listbox
  PERFORM fetch_mrp_value. "Fetching MRP value nad putting it on the p_netwr

START-OF-SELECTION.
  
  PERFORM call_smartform. "here I'm calling the smartform 


FORM fetch_data .

SELECT lgort FROM mard INTO CORRESPONDING FIELDS OF TABLE it_storeloc WHERE matnr = p_matno AND werks = '1501'.

  LOOP AT it_storeloc INTO w_storeloc.
    w_line-key = w_storeloc-lgort.
    APPEND w_line TO it_val.
  ENDLOOP.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id                    = v_name
      values                = it_val

  p_erdat = sy-datum.

  clear: it_val.

ENDFORM.                    " FETCH_DATA


FORM Call_smartform
IF P_S_LOC is INITIAL.
*MESSAGE s000(zwm_msg) with 'Storage Location Needs to be Entered.'.
    message 'Storage Location is missing : Enter the material again and choose the storage location.' type 'S'.

    
ELSE.

  output_options-tdcopies = p_labels.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = v_layout
    IMPORTING
      fm_name            = v_form_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 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.



  CALL FUNCTION v_form_name
    EXPORTING
      control_parameters = control_parameters
      output_options     = output_options
            p_exp            = p_exp
    EXCEPTIONS
      formatting_error = 1
      internal_error   = 2
      send_error       = 3
      user_canceled    = 4
      OTHERS           = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDIF.

ENDFORM.                    "

Edited by: sohamshah on Sep 30, 2009 12:00 PM

Read only

0 Likes
1,583

Sorry buddy,

Try this,

TYPE-POOLS: vrm.
DATA: lt_storeloc TYPE TABLE OF mard-lgort,
      lv_store    TYPE mard-lgort.
DATA: lt_tab      TYPE vrm_values,
      ls_tab      TYPE vrm_value.
PARAMETERS:   p_matno LIKE mara-matnr OBLIGATORY,
              p_s_loc TYPE mard-lgort AS LISTBOX VISIBLE LENGTH 8.

AT SELECTION-SCREEN ON p_matno.
  SELECT lgort FROM mard INTO TABLE lt_storeloc WHERE matnr = p_matno AND werks = '1501'.
  LOOP AT lt_storeloc INTO lv_store.
    ls_tab-key = lv_store.
    ls_tab-text = 'DUMMY'.
    APPEND ls_tab TO lt_tab.
  ENDLOOP.
  IF p_matno IS NOT INITIAL.
    CALL FUNCTION 'VRM_SET_VALUES'
      EXPORTING
        id              = 'P_S_LOC'
        values          = lt_tab
      EXCEPTIONS
        id_illegal_name = 1
        OTHERS          = 2.
  ENDIF.

START-OF-SELECTION.
  IF p_s_loc IS INITIAL.
    MESSAGE 'Storage Location Needs to be Entered.' TYPE 'S' DISPLAY LIKE 'E'.
    STOP.
  ENDIF.

When you press F8, the validation in start of selection will stop with an error message. Once you press enter, the error message will go and the values populated in the list will also remain. I have tries this code now in my system.

Regards

Anand.

Edited by: Anand Shankar on Sep 30, 2009 3:46 PM

Read only

0 Likes
1,583

Hi, Try to change this part of code.


*&---------------------------------------------------------------------*
*&      Form  fetch_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM fetch_data .

  SELECT lgort FROM mard INTO CORRESPONDING FIELDS OF TABLE it_storeloc WHERE matnr = p_matno AND werks = p_werks.

  LOOP AT it_storeloc INTO w_storeloc.
    w_line-key = w_storeloc-lgort.
    APPEND w_line TO it_val.
  ENDLOOP.
  IF p_s_loc IS INITIAL.
    READ TABLE it_val INTO w_line INDEX 1.
    p_s_loc = w_line-key.
  ENDIF.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id      = v_name
      values  = it_val
      p_erdat = sy-datum.

  CLEAR: it_val.

ENDFORM.                    " FETCH_DATA
Thanks Venkat.O

Read only

0 Likes
1,583

Brilliant Venkat ..

It works !! ..

Thanks a ton !!

Read only

0 Likes
1,583

Brilliant Anand ..

Your solution works fine too but the solution that venkat has posted gives me less code-change in my program so I might have to go with his solution ..

But I would like to appreciate your effort and concern to help me ..

Now I have two solutions for the same problem so it may help people in the future ..

Thanks a ton buddy ..

Read only

0 Likes
1,583

you are welcome .Now you can close thread.

Thanks

Venkat.O

Read only

0 Likes
1,583

Hey anand,

Your solution works fine .. Hurraaayyy !!

Venkat too has provided one other solution which also works fine .. You might want to check that out ..

Thanks a lot buddy .. I apprciate your help and concern ..

Read only

Former Member
0 Likes
1,583

Hi,

Before giving the error message just populate the filed p_matno again...hope it shud work..Thanks

Read only

0 Likes
1,583

Hi balaji,

Ho can I populate the field p_matno once again just before giving the error message?? .. please explain ..