Tuesday, September 22, 2015

Process on Value and Help Request

Process on value request is an event and it is triggered when user press F4 for any particular field. It displays the possible set of values from the mentioned value table. The values will be displayed by a pop up window defined by SAP GUI.

After declaring the event (process on value request) we need to declare a module followed by the specific field. That field confirms the particular field where the user put cursor and press F4. The module will contain the logic which is going to happen behind the help value pop up window. The syntax is as follows.

PROCESS ON VALUE-REQUEST.
  FIELD inp1 MODULE value_for_customer.
  FIELD inp2 MODULE capture_date.
  FIELD inp3 MODULE capture_time.

Here we have declared three input fields in which we are creating the F4 value option.

Similarly we can create the help view for any particular field. We need to use the event process on help request which will be triggered when the user press F1 after having the cursor on that field.

PROCESS ON HELP-REQUEST.
  FIELD inp1 MODULE help_customer.

In this example we are creating the help document for a field and similarly we are creating the logic under module.

Now we are discussing the step by step approach for this process on value and help request.

Step – 1:
At first we have to create the include programs for the module pool.

INCLUDE mz_test_top                             .  " global Data
INCLUDE mz_test_o01                             .  " PBO-Modules
INCLUDE mz_test_i01                             .  " PAI-Modules
INCLUDE mz_test_f01                             .  " FORM-Routines

Step – 2:
Now we are declaring the top include to mention every possible fields and tables.

*------Structure for value table---------------------------------------*
TYPES: BEGIN OF ty_kna1,
        kunnr TYPE kna1-kunnr,
        name1 TYPE kna1-name1,
       END OF ty_kna1.

*-----Work area & internal table for help request----------------------*
DATA: it_kna1 TYPE TABLE OF ty_kna1,
      wa_kna1_ret TYPE ddshretval,
      it_kna1_ret TYPE TABLE OF ddshretval.

*-----Declaring OK code to capture user command------------------------*
DATA: ok_code1 TYPE sy-ucomm.

*-----Declaring custom date & time field to capture from screen--------*
DATA: inp1 TYPE char35,
      inp2 TYPE sy-datum,
      inp3 TYPE sy-uzeit.

Step – 3:
Now we are creating a screen where we are maintaining all the events of module pool.

PROCESS BEFORE OUTPUT.
  MODULE status_9001.

PROCESS AFTER INPUT.
  MODULE user_command_9001.

PROCESS ON VALUE-REQUEST.
  FIELD inp1 MODULE value_for_customer.
  FIELD inp2 MODULE capture_date.
  FIELD inp3 MODULE capture_time.

PROCESS ON HELP-REQUEST.
  FIELD inp1 MODULE help_customer.

Step – 4:
After that we are preparing the layout.



Here for the date and time field we have to mention the attribute format DATS and TIMS respectively.



Step – 5:
Now in PBO we are defining the GUI status as follows.

MODULE status_9001 OUTPUT.

  SET PF-STATUS 'PF_SELECT'.
  SET TITLEBAR 'TI_SELECT'.

ENDMODULE.                 " status_9001  OUTPUT

Step – 6:
After that in PAI we are creating the logic for user command.

MODULE user_command_9001 INPUT.

  CASE ok_code1.
    WHEN 'CLR'.
      CLEAR: inp1, inp2, inp3.

    WHEN 'BACK'.
      LEAVE PROGRAM.
  ENDCASE.

ENDMODULE.                 " user_command_9001  INPUT

Step – 7:
Now we have to create each and every module for process on value request.

MODULE value_for_customer INPUT.

  "The system will show only customer no. & name after pressing F4
  SELECT kunnr name1 FROM kna1 INTO TABLE it_kna1.

  "The table needs to be passed through this function module
  "for table value request
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
*     DDIC_STRUCTURE         = ' '
      retfield               = 'INP1'
*     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              = it_kna1
*     FIELD_TAB              =
     return_tab             = it_kna1_ret
*     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.

  ELSE.
    LOOP AT it_kna1_ret INTO wa_kna1_ret.

      "The selected field needs to be passed to the screen field
      inp1 = wa_kna1_ret-fieldval.
    ENDLOOP.
  ENDIF.

ENDMODULE.                 " value_for_customer  INPUT

MODULE capture_date INPUT.

  "This function module will export the calendar and import date
  CALL FUNCTION 'F4_DATE'
   EXPORTING
     date_for_first_month               = inp2
*   display                            = 'X'
*   FACTORY_CALENDAR_ID                = ' '
*   GREGORIAN_CALENDAR_FLAG            = ' '
*   HOLIDAY_CALENDAR_ID                = ' '
*   PROGNAME_FOR_FIRST_MONTH           = ' '
   IMPORTING
     select_date                        = inp2
*   SELECT_WEEK                        =
*   SELECT_WEEK_BEGIN                  =
*   SELECT_WEEK_END                    =
   EXCEPTIONS
     calendar_buffer_not_loadable       = 1
     date_after_range                   = 2
     date_before_range                  = 3
     date_invalid                       = 4
     factory_calendar_not_found         = 5
     holiday_calendar_not_found         = 6
     parameter_conflict                 = 7
     OTHERS                             = 8
            .
  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.                 " capture_date  INPUT

MODULE capture_time INPUT.

  CALL FUNCTION 'F4_CLOCK'
    EXPORTING
      start_time    = inp3
*      display       = 'X'
    IMPORTING
      selected_time = inp3.

ENDMODULE.                 " capture_time  INPUT

Step – 8:
Now before going to the process on help request event we need to create a help document by using Document Maintenance (SE61). We have created a test document ZTEST here with document class general text and English language.


Now we can write the help document inside the text area.


Step – 9:
After creating this document we can create the help request event module.

MODULE help_customer INPUT.

  CALL FUNCTION 'DSYS_SHOW_FOR_F1HELP'
    EXPORTING
*   APPLICATION              = 'SO70'
      dokclass                 = 'TX'
      doklangu                 = sy-langu
      dokname                  = 'ZTEST'
*   DOKTITLE                 = ' '
*   HOMETEXT                 = ' '
*   OUTLINE                  = ' '
*   VIEWNAME                 = 'STANDARD'
*   Z_ORIGINAL_OUTLINE       = ' '
*   CALLED_FROM_SO70         = ' '
*   SHORT_TEXT               = ' '
*   APPENDIX                 = ' '
* IMPORTING
*   APPL                     =
*   PF03                     =
*   PF15                     =
*   PF12                     =
* EXCEPTIONS
*   CLASS_UNKNOWN            = 1
*   OBJECT_NOT_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.                 " help_customer  INPUT

Here we have mentioned this function module where we need to pass the document class – TX for general text, system language and the document object name.

Step – 10:
Finally by creating a transaction code we can run the program.


By running the program we are getting the Customer name field where we can press F1 after having the cursor on there. The help request will show the following.


Now closing this we shall get back to the initial screen and then by pressing F4 we are getting the possible set of data as follows.


Similarly we are getting the calendar by pressing the F4 on the date field and then we can choose any date from the calendar. Here we have chosen 15th August, 2015.


Similarly we can enter time by pressing the F4 on the time field.


Finally we can prepare our screen by processing the value request event.


Now by clicking the Clear Customer button the screen will be cleared as follows.


We haven't prepared any function for Display Customer Button. 

2 comments:

Anonymous said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Hashishim said...

Hi, Thanks for sharing codes very helpful. I used almost same codes but
I cannot set selected cell to field.

LOOP AT g_retval INTO gs_retval.
&2 = gs_retval-fieldval. "&2 S_UID-LOW
ENDLOOP.