Problems with multiple selection screens

半腔热情 提交于 2020-01-17 03:21:05

问题


START-OF-SELECTION is not getting triggered in my program. I am trying to fetch book details based on book name and book author using multiple selection screens in ABAP. There are two pushbuttons and based on those selection screens are opened. When I click any of the push buttons, then selection screens are opened. But after I select entries from the dropdown list and click execute button, then the transaction goes to the initial screen with the pushbuttons. The book details are not displayed at all. START-OF-SELECTION is not triggered. Please help, I am a newbie in ABAP. Here is my program

 REPORT y_multiple_screen.

    TABLES: sscrfields.
    TYPE-POOLS: vrm.
    DATA: param    TYPE vrm_id,
          values   TYPE vrm_values,
          wa_value LIKE LINE OF values.



    DATA: it_ybook TYPE TABLE OF ybook,
          wa_ybook TYPE ybook.


    FIELD-SYMBOLS: <fs_book> TYPE ybook.


    SELECTION-SCREEN BEGIN OF BLOCK blocker WITH FRAME TITLE text-001 NO INTERVALS.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN PUSHBUTTON (30)  w_butn1 USER-COMMAND but1.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN PUSHBUTTON (30)  w_butn2 USER-COMMAND but2.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN SKIP.

    SELECTION-SCREEN END OF BLOCK blocker.

    SELECTION-SCREEN BEGIN OF SCREEN 1100.
    PARAMETERS: p_author TYPE char255 AS LISTBOX VISIBLE LENGTH 20.


    SELECTION-SCREEN END OF SCREEN 1100.

    SELECTION-SCREEN BEGIN OF SCREEN 1200.

    PARAMETERS: p_bname TYPE char255 AS LISTBOX VISIBLE LENGTH 20.


    SELECTION-SCREEN END OF SCREEN 1200.

    INITIALIZATION.

      w_butn1 = 'Search by author name'.
      w_butn2 = 'Search by book name'.

      "At selection-screen output.

    AT SELECTION-SCREEN.
      IF sscrfields-ucomm EQ 'BUT1'.

        CALL SELECTION-SCREEN 1100.


      ELSEIF sscrfields-ucomm EQ 'BUT2'.

        CALL SELECTION-SCREEN 1200.
      ENDIF.

    AT SELECTION-SCREEN OUTPUT.

      CLEAR it_ybook.
      SELECT *
      FROM ybook
      INTO TABLE it_ybook.
      CLEAR values.
      CLEAR wa_ybook.
      CLEAR wa_value.
      LOOP AT it_ybook INTO wa_ybook.


        wa_value-key = wa_ybook-book_author.
        wa_value-text = wa_ybook-book_author.

        APPEND  wa_value TO values.
        CLEAR wa_ybook.
        CLEAR wa_value.
      ENDLOOP.



      CLEAR it_ybook.



      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id              = 'P_AUTHOR'
          values          = values
        EXCEPTIONS
          id_illegal_name = 1
          OTHERS          = 2.


      CLEAR it_ybook.
      SELECT *
      FROM ybook
      INTO TABLE it_ybook.

      "CLEAR values.
      CLEAR wa_ybook.
      CLEAR wa_value.

      LOOP AT it_ybook INTO wa_ybook.


        wa_value-key = wa_ybook-book_name.
        wa_value-text = wa_ybook-book_name.

        APPEND  wa_value TO values.
        CLEAR wa_ybook.
        CLEAR wa_value.
      ENDLOOP.



      CLEAR it_ybook.



      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id              = 'P_BNAME'
          values          = values
        EXCEPTIONS
          id_illegal_name = 1
          OTHERS          = 2.


    START-OF-SELECTION.
        WRITE:/10 'Book ID',40 'Book Name',70 'Book Author',100 'Book Price'.

        CLEAR it_ybook.
        CLEAR wa_ybook.
        SELECT *
        FROM ybook
        INTO TABLE it_ybook
        WHERE book_name = p_bname.
        LOOP AT it_ybook INTO wa_ybook.
          WRITE:/10 wa_ybook-book_id,40 wa_ybook-book_name,70 wa_ybook-book_author,100 wa_ybook-book_price.
          CLEAR wa_ybook.
        ENDLOOP.


        WRITE:/10 'Book ID',40 'Book Name',70 'Book Author',100 'Book Price'.

        CLEAR it_ybook.
        CLEAR wa_ybook.
        SELECT *
        FROM ybook
        INTO TABLE it_ybook
        WHERE book_author = p_author.
        LOOP AT it_ybook INTO wa_ybook.
          WRITE:/10 wa_ybook-book_id,40 wa_ybook-book_name,70 wa_ybook-book_author,100 wa_ybook-book_price.
          CLEAR wa_ybook.
        ENDLOOP.

回答1:


START-OF-SELECTION will only trigger off your main screen (when you hit execute on the first screen).

You can force the event by changing the AT SELECTION-SCREEN block:

AT SELECTION-SCREEN.
  IF sscrfields-ucomm EQ 'BUT1'.

    CALL SELECTION-SCREEN 1100.
    if sy-subrc = 0.  "the user clicked the execute button
      sscrfields-ucomm = 'ONLI'.  "set the system command for the next screen to execute
    endif.

  ELSEIF sscrfields-ucomm EQ 'BUT2'.

    CALL SELECTION-SCREEN 1200.
    if sy-subrc = 0.  "the user clicked the execute button
      sscrfields-ucomm = 'ONLI'.  "set the system command for the next screen to execute
    endif.

  ENDIF.



回答2:


You can achieve this without START-OF-SELECTION block at all.
Firstly, add user commands to your parameters:

PARAMETERS: p_author TYPE char255 AS LISTBOX VISIBLE LENGTH 20 USER-COMMAND auth.
PARAMETERS: p_bname TYPE char255 AS LISTBOX VISIBLE LENGTH 20 USER-COMMAND name.

Afterwards move your dropdown coding to INITIALIZATION block:

INITIALIZATION.

  w_butn1 = 'Search by author name'.
  w_butn2 = 'Search by book name'.

  CLEAR it_ybook.
  SELECT *
  FROM ybook
  ...
  ...
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id              = 'P_BNAME'
      values          = values
    EXCEPTIONS
      id_illegal_name = 1
      OTHERS          = 2.

Then correct AT-SELECTION-SCREEN event like this:

AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
    WHEN 'BUT1'.
      CALL SELECTION-SCREEN 1100.
    WHEN 'BUT2'.
      CALL SELECTION-SCREEN 1200.
    WHEN 'AUTH'.
      LEAVE TO LIST-PROCESSING.
      SET PF-STATUS space.
      SUPPRESS DIALOG.
    WHEN 'NAME'.
      LEAVE TO LIST-PROCESSING.
      SET PF-STATUS space.
      SUPPRESS DIALOG.
    WHEN OTHERS.
  ENDCASE.

And place your output coding here as well. Your lists will be output right on selecting value in dropdown list.

Remember that selection screen parameters are converted to uppercase by default, consequently your output selects will return no rows in the above given form. So for proper use you should convert them to lowercase like this:

TRANSLATE p_author TO LOWER CASE.

UPDATE:
LEAVE-TO-LIST-PROCESSING statement interrupts the current Dynpro sequence processing (but finishes the current Dynpro!) and switches to lists that were buffered on AS until that moment. You should learn more about list processing here. This technique is treated obsolete, but, as you chose it, you should definitely know it:) SET PF-STATUS space sets default dialog status for lists. You can learn about dialog statuses from the documentation.
What concerns your code, you can merge 2 loop statements into one. Another suggestion is to eliminate DB selects during output at all: you don't do any data modifications here so data won't change after INITIALIZATION block. And finally, you can intensify using of field-symbols as they consume less resourcess comparing to work areas. So your code should look like:

INITIALIZATION.

TYPE-POOLS: vrm.
DATA: it_ybook TYPE TABLE OF ybook.
DATA: param    TYPE vrm_id,
      values_auth   TYPE vrm_values,
      values_name   TYPE vrm_values,
      wa_value_auth TYPE LINE OF vrm_values,
      wa_value_name TYPE LINE OF vrm_values.

FIELD-SYMBOLS: <fs_ybook> TYPE ybook.

  w_butn1 = 'Search by author name'.
  w_butn2 = 'Search by book name'.

  CLEAR: it_ybook, wa_value_auth, wa_value_name.

  SELECT *
    FROM ybook
    INTO TABLE it_ybook.

  LOOP AT it_ybook ASSIGNING <fs_ybook>.

    wa_value_auth-key = <fs_ybook>-book_author.
    wa_value_auth-text = <fs_ybook>-book_author.

    wa_value_name-key = <fs_ybook>-book_name.
    wa_value_name-text = <fs_ybook>-book_name.

    APPEND wa_value_auth TO values_auth.
    APPEND wa_value_name TO values_name.

  ENDLOOP.

  CALL FUNCTION 'VRM_SET_VALUES' "for authors

  CALL FUNCTION 'VRM_SET_VALUES' "for names

AT SELECTION-SCREEN.

    CASE sscrfields-ucomm.
     ...
    ENDCASE.

    TRANSLATE P_BNAME TO LOWER CASE.
    LOOP AT it_ybook ASSIGNING <fs_ybook> WHERE book_name = P_BNAME.
      WRITE:/10 'Book ID',40 'Book Name',70 'Book Author',100 'Book Price'.
      WRITE:/10 <fs_ybook>-book_id,40 <fs_ybook>-book_name,70 <fs_ybook>-book_author,100 <fs_ybook>-book_price.
    ENDLOOP.

    TRANSLATE P_AUTHOR TO LOWER CASE.
    LOOP AT it_ybook ASSIGNING <fs_ybook> WHERE book_author = P_AUTHOR.
      WRITE:/10 'Book ID',40 'Book Name',70 'Book Author',100 'Book Price'.
      WRITE:/10 <fs_ybook>-book_id,40 <fs_ybook>-book_name,70 <fs_ybook>-book_author,100 <fs_ybook>-book_price.
    ENDLOOP.


来源:https://stackoverflow.com/questions/34840584/problems-with-multiple-selection-screens

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!