SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Dynamic F4 Help



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Search Help, Match Code
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Wed Sep 05, 2007 7:24 pm    Post subject: Dynamic F4 Help Reply with quote

Author: Sekhar Pullabhatla

Let's say the selection screen has two input fields. One is plant i.e., PA_WERKS and other one is object(PA_OBJ). While executing the report, User will first enter the plant name in the WERKS field. Then, he will press F4 at the PA_OBJ field. It should dynamically take the value from PA_WERKS and display the possible values on F4 dialog box by searching in the table ZAIS_MMG.

Solution is written below and all the comments were provided at necessary places. Table need not be necessarily ZAIS_MMG. This logic is used for any table where you just need to change the table name.

Below is the subroutine that needs to be called at selection screen

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_obj.

Code:

*&---------------------------------------------------------------------*
*&      Form  object_f4help
*&---------------------------------------------------------------------*
*  Provides the possible values for pa_obj
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM object_f4help.

* Refresh the internal table. This helps in reusing these tables and variables in * other subroutines.
  CLEAR:   tb_dynpfields,
           tb_object_range.
  REFRESH: tb_dynpfields,
           tb_object_range.

* Define Internal tables.
  DATA: tb_dynpfields LIKE dynpread OCCURS 0 WITH HEADER LINE.

* Define constants.
  CONSTANTS: co_retfield  TYPE  dfies-fieldname VALUE 'OBJECT',
             co_dynprog   LIKE sy-repid
                                 VALUE '/DCSEA/Z_AIS_NUM_RESET_PAJERO',
             co_s         TYPE c VALUE 'S',
             co_field(27) TYPE c VALUE 'PA_OBJ'.

* Assigning the values of program name and screen to the variables.
  wf_dyname = sy-repid.   " PROGRAM NAME
  wf_dynumb = sy-dynnr.   " SCREEN NUMBER
  wf_dynpro = co_field. 

* Move the field name to tb_dynpfields.
  MOVE 'PA_WERKS' TO
            tb_dynpfields-fieldname.
  APPEND tb_dynpfields.

* Read screen field values before PAI field transport. This FM is used for dynamically * reading a value from the selection screen field .
  CALL FUNCTION 'DYNP_VALUES_READ'
       EXPORTING
            dyname               = wf_dyname
            dynumb               = wf_dynumb
       TABLES
            dynpfields           = tb_dynpfields
       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.

* Read the tbale tb_dynpfields to read the dynamic value of pa_werks
  READ TABLE tb_dynpfields INDEX 1.
  IF sy-subrc = 0.
    wf_werks = tb_dynpfields-fieldvalue.
  ENDIF.

* Populate the table tb_object_range. Make sure that we filter out null values as it * might appear on the screen.
  SELECT werks object
    INTO TABLE tb_object_range
    FROM zais_mmg
    WHERE werks  EQ wf_werks
      and object NE ' '.

* Sorting is always done before dlete adjacent duplicate.
  sort tb_object_range.
* This will delete all duplicate entries. Or else when you press F4, it will display * the duplicates also.
  delete adjacent duplicates from tb_object_range comparing object.

* F4 help also returning the value to be displayed in internal table. If the internal table is empty, it will display the message saying 'Values are not found'.
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
       EXPORTING
            retfield        = co_retfield
            dynpprog        = co_dynprog
            dynpnr          = sy-dynnr
            dynprofield     = wf_dynpro
            value_org       = co_s
       TABLES
            value_tab       = tb_object_range
       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.

ENDFORM.                    " object_f4help
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Search Help, Match Code All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.