Wednesday, August 27, 2014
You all know that function module F4IF_INT_TABLE_VALUE_REQUEST is used to display F4 help / Search help for PARAMETERS or SELECT-OPTIONS. But for SELECT-OPTIONS, you may need to enter multiple single values. To avoid multiple times opening F4 help, Use MULTIPLE_CHOICE parameter in the exporting parameters of F4IF_INT_TABLE_VALUE_REQUEST which will open check box for each record on F4 help.

Follow the sample program which illustrates the same.

REPORT ZTEST_F4_MULTICHOICE.
TABLES:
        P0001.
TYPES:
       BEGIN OF TY_PERNRS,
         PERNR TYPE P0001-PERNR,
         ENDDA TYPE P0001-ENDDA,
         BEGDA TYPE P0001-BEGDA,
         ENAME TYPE P0001-ENAME,
       END OF TY_PERNRS.

DATA:
      IT_MARK     TYPE DDSHMARKS,
      WA_MARK     LIKE LINE OF IT_MARK,
      IT_PERNRS   TYPE STANDARD TABLE OF TY_PERNRS,
      WA_PERNRS   TYPE TY_PERNRS.

SELECT-OPTIONS:
     S_PERNR FOR P0001-PERNR NO INTERVALS.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_PERNR-LOW.
  PERFORM F4_FOR_PERNR USING 'S_PERNR-LOW'.
*&---------------------------------------------------------------------*
*&      Form  F4_FOR_PERNR
*&---------------------------------------------------------------------*
FORM F4_FOR_PERNR  USING  P_SEL_FIELD.
  TYPES:
        LTY_DYNPREAD        TYPE DYNPREAD,
        LTY_RET_TAB         TYPE DDSHRETVAL,
        LTY_DFIES           TYPE DFIES.
  DATA:
        LT_DYNPREAD         TYPE STANDARD TABLE OF LTY_DYNPREAD,
        LT_RET_TAB          TYPE STANDARD TABLE OF LTY_RET_TAB,
        LT_DFIES            TYPE STANDARD TABLE OF LTY_DFIES.
  DATA:
        LS_DYNPREAD         TYPE LTY_DYNPREAD,
        LS_RET_TAB          TYPE LTY_RET_TAB,
        LS_DFIES            TYPE LTY_DFIES.

  DEFINE F4_FIELDS.
    LS_DFIES-FIELDNAME = &1.
    LS_DFIES-INTLEN    = &2.
    LS_DFIES-LENG      = &3.
    LS_DFIES-OUTPUTLEN = &4.
    LS_DFIES-OFFSET    = &5.
    LS_DFIES-SCRTEXT_S = &6.
    LS_DFIES-SCRTEXT_M = &7.
    LS_DFIES-SCRTEXT_L = &8.
    LS_DFIES-REPTEXT   = &9.
    APPEND LS_DFIES TO LT_DFIES.
    CLEAR  LS_DFIES.
  END-OF-DEFINITION.

  F4_FIELDS:
         'PERNR' '16' '16' '16' '000' 'PERNR'  'PERNR'  'PERNR'  'PERNR',
         'ENDDA' '16' '16' '16' '016' 'ENDDA'  'ENDDA'  'ENDDA'  'ENDDA',
         'BEGDA' '16' '16' '16' '032' 'BEGDA'  'BEGDA'  'BEGDA'  'BEGDA',
         'ENAME' '80' '80' '80' '048' 'ENAME'  'ENAME'  'ENAME'  'ENAME'.

  SELECT DISTINCT *
    FROM PA0001
    INTO CORRESPONDING FIELDS OF TABLE IT_PERNRS
  WHERE ENAME NE SPACE
    AND BEGDA LE SY-DATUM
    AND ENDDA GE SY-DATUM.
  SORT IT_PERNRS.
  DELETE ADJACENT DUPLICATES FROM IT_PERNRS COMPARING ALL FIELDS.

  SY-DYNNR = 1000.
*  PERFORM INIT_FIELD_TAB CHANGING LT_DFIES.
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      RETFIELD        = 'PERNR'
      DYNPPROG        = SY-REPID
      DYNPNR          = SY-DYNNR
      DYNPROFIELD     = P_SEL_FIELD
      VALUE_ORG       = 'S'
      MULTIPLE_CHOICE = 'X'
      MARK_TAB        = IT_MARK
    TABLES
      FIELD_TAB       = LT_DFIES
      VALUE_TAB       = IT_PERNRS
      RETURN_TAB      = LT_RET_TAB.
*  CLEAR S_pernr[].
  DATA LV_VALUE TYPE SHVALUE_D.
  CLEAR IT_MARK.
  LOOP AT LT_RET_TAB INTO LS_RET_TAB .
    READ TABLE IT_PERNRS INTO WA_PERNRS WITH KEY PERNR = LS_RET_TAB-FIELDVAL.
    IF SY-SUBRC EQ 0.
      WA_MARK = SY-TABIX.
      APPEND WA_MARK TO IT_MARK.
      CLEAR  WA_MARK.
    ENDIF.
    LV_VALUE = LS_RET_TAB-FIELDVAL.
    AT FIRST.
      S_PERNR-LOW    = LV_VALUE.
      S_PERNR-SIGN   = 'I'.
      S_PERNR-OPTION = 'EQ'.
      APPEND S_PERNR.
      CLEAR S_PERNR.
    ENDAT.
    S_PERNR-LOW    = LS_RET_TAB-FIELDVAL.
    S_PERNR-SIGN   = 'I'.
    S_PERNR-OPTION = 'EQ'.
    APPEND S_PERNR.
    CLEAR S_PERNR.

  ENDLOOP.
  CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE'.

ENDFORM.                    " F4_FOR_PERNR

Points to note


  1. Once you select values from F4 help, RETURN_TAB will return selected values. Populated Select-Option table with selected values. 
  2. Use function module  SAPGUI_SET_FUNCTIONCODE which refreshes the selection-screen.This module simulates user input in the command field. This enables you to run screen sequences without user input.

Output 

Selection Screen

F4 help screen
After values are selected.

5 comments:

  1. Hi
    I started my new agency and was looking for this kind of informative post right from the first day ! Glad that you could help me now.

    Regards
    Digital Marketing Services

    ReplyDelete
  2. Hi
    These were extremely easy to understand and grasp. I was going looking for such kind of articles from a very long time. Glad that I could find this atleast now. Keep going and nice stuffs indeed !


    Regards
    Digital Marketing Training

    ReplyDelete
  3. helpfull
    https://www.carejunk.in/

    ReplyDelete
  4. duplicates are getting in while selection

    ReplyDelete
  5. Get 50 Free Spins at Casino Roll
    Casino Roll has been around since 2007, 타이 산 카지노 making it the longest-running online 마틴 게일 casino in the UK. With an online m2슬롯 poker site, this site is 커뮤니티 사이트 not 슬롯가입쿠폰

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.