Thursday, May 9, 2013

F4 Help for Parameter and Select Option

Here is a Program which defines the F4 help on Selection Screen. On the screen there are two fields 1. Company Code and 2. Project Definition. Here the company code is the Parameter and the project definition is the Select Option. In this program there is no manual entry. Every input will be given by using F4 help. 

The company codes will be coming uniquely by using F4 help. In database one company code contains lot of Projects. Hence unique company code is necessary while pressing the F4 button.

Then the Project Definition Low field will also have to be selected by using F4 help. Here in the value table all project definition will not come. Only the projects which are under selected company code will come for the Low field. Other projects will not come in value table. Similarly the High field will have to be selected by using F4 help. High filed will show the value table data which are greater than the low field and under that selected company. Other projects will not come on this value table. 


REPORT  zabap_gui1.

*---------PROJ & PRPS Tables Declaration-------------------------------*
*----------------------------------------------------------------------*
TABLES: proj, prps.

*---------Structure Declaration for different Internal Tables----------*
*----------------------------------------------------------------------*
TYPES:
       "Structure to create F4 Help for Company Code
       BEGIN OF ty_vbukr,
        vbukr TYPE proj-vbukr, "Company code
       END OF ty_vbukr,

       "Structure to create F4 Help for Project definition
       BEGIN OF ty_pspid,
        pspid TYPE proj-pspid, "Project definition
       END OF ty_pspid.

DATA:
      "Internal Tables of Value Table for F4 Help
      it_vbukr   TYPE STANDARD TABLE OF ty_vbukr,
      it_pspid   TYPE STANDARD TABLE OF ty_pspid,
      it_pspid1  TYPE STANDARD TABLE OF ty_pspid,

      "Internal Tables of Return Table for F4 Help
      wa_return1 TYPE ddshretval,
      wa_return2 TYPE ddshretval,
      wa_return3 TYPE ddshretval,
      it_return1 TYPE STANDARD TABLE OF ddshretval,
      it_return2 TYPE STANDARD TABLE OF ddshretval,
      it_return3 TYPE STANDARD TABLE OF ddshretval.

CONSTANTS:
           "Constants for F4IF_INT_TABLE_VALUE_REQUEST
           c_vbukr     TYPE dfies-fieldname VALUE 'P_VBUKR',
           c_pspid_l   TYPE dfies-fieldname VALUE 'P_PSPID-LOW',
           c_pspid_h   TYPE dfies-fieldname VALUE 'P_PSPID-HIGH',
           c_vorg      TYPE char1  VALUE 'S'.

*---------SELECTION SCREEN---------------------------------------------*
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_vbukr LIKE proj-vbukr.
SELECT-OPTIONS s_pspid FOR proj-pspid.
SELECTION-SCREEN END OF BLOCK b1.

*---------AT SELECTION-SCREEN ON VALUE-REQUEST for COMPANY CODE--------*
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vbukr.
  SELECT DISTINCT vbukr FROM proj INTO TABLE it_vbukr.
  IF sy-subrc = 0.
    SORT it_vbukr BY vbukr.
  ENDIF.

  "Function Module to create F4 help
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = c_vbukr
      value_org       = c_vorg
    TABLES
      value_tab       = it_vbukr
      return_tab      = it_return1
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

  IF it_return1 IS NOT INITIAL.
    LOOP AT it_return1 INTO wa_return1.
      p_vbukr = wa_return1-fieldval.
    ENDLOOP.
    SELECT pspid FROM proj INTO TABLE it_pspid
    WHERE vbukr = p_vbukr.
    IF sy-subrc = 0.
      SORT it_pspid BY pspid.
    ENDIF.
  ENDIF.

*-----AT SELECTION-SCREEN ON VALUE-REQUEST for PROJECT DEFINITION------*
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_pspid-low.

  "Function Module to create F4 help
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = c_pspid_l
      value_org       = c_vorg
    TABLES
      value_tab       = it_pspid
      return_tab      = it_return2
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

  IF it_return2 IS NOT INITIAL.
    LOOP AT it_return2 INTO wa_return2.
      s_pspid-low = wa_return2-fieldval.
    ENDLOOP.
    SELECT pspid FROM proj INTO TABLE it_pspid1
      WHERE pspid GT s_pspid-low
        AND vbukr = p_vbukr.
    IF sy-subrc = 0.
      SORT it_pspid1 BY pspid.
    ENDIF.
  ENDIF.

*-----AT SELECTION-SCREEN ON VALUE-REQUEST for PROJECT DEFINITION------*
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_pspid-high.

  "Function Module to create F4 help
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = c_pspid_h
      value_org       = c_vorg
    TABLES
      value_tab       = it_pspid1
      return_tab      = it_return3
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

  IF it_return3 IS NOT INITIAL.
    LOOP AT it_return3 INTO wa_return3.
      s_pspid-high = wa_return3-fieldval.
    ENDLOOP.
  ENDIF.


Below is the Output:

1. Selection Screen:




2. F4 on Company Code:




3. F4 on Project Definition Low Field (All projects are coming from company 0142): Total 2598 Entries




4. F4 on Project Definition High Field (All projects will be Greater than Low field with company 0142): Total 2589 Entries



5. Finally Data have been Selected:



5 comments:

yektek training said...

good post really thanks

Unknown said...

Thanks for your info...Here THE CREATING EXPERTS provide hands on training with real time scenarios

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

contact +91-08122241286

Harimoto said...

HI there,

Thank you for this post.I followed your instructions but there is a problem. After i put a value in first parameter ,then i can see the correct list in the select-options. The issue is that my program is continuously loading and doesn`t do anything else. Please see below my code:

Dear Bertrand ,

I did as you advised me and i thank you for this . When i put a value in s_klart , after i can see in s_atinn the list accordingly to what i put in s_klart,which is good.The problem is that immediatly after my report gets blocked,enters in a sort of loop ,it countinuously loading without being able do anything else. Please find below my code:

"Internal Tables of Return Table for F4 Help

wa_return1 TYPE ddshretval,

wa_return2 TYPE ddshretval,

wa_return3 TYPE ddshretval,

it_return1 TYPE STANDARD TABLE OF ddshretval,

it_return2 TYPE STANDARD TABLE OF ddshretval,

it_return3 TYPE STANDARD TABLE OF ddshretval.



CONSTANTS:

"Constants for F4IF_INT_TABLE_VALUE_REQUEST

c_klart TYPE dfies-fieldname VALUE 'S_KLART',

c_pspid_l TYPE dfies-fieldname VALUE 'P_PSPID-LOW',

c_pspid_h TYPE dfies-fieldname VALUE 'P_PSPID-HIGH',

c_vorg TYPE char1 VALUE 'S'.





* ALV data declarations

data: it_sortcat type slis_sortinfo_alv occurs 1,

wa_sort like line of it_sortcat.



DATA: it_filter TYPE slis_t_filter_alv.

Data: ls_filter TYPE slis_filter_alv.



*selection screen

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: s_klart LIKE klah-klart. "Tip clasa ,SELECT-OPTIONS: s_klart FOR klah-klart NO INTERVALS NO-EXTENSION.

SELECT-OPTIONS :s_class FOR klah-class OBLIGATORY MATCHCODE OBJECT clas DEFAULT 'Z_MEDIU'."Nume clasa NO INTERVALS NO-EXTENSION



SELECT-OPTIONS: s_matkl FOR mara-matkl. "Grup Material

SELECT-OPTIONS: s_mtart FOR t134t-mtart. "NO INTERVALS NO-EXTENSION DEFAULT '3010'. "Grup Material

SELECT-OPTIONS: s_matnr FOR mara-matnr." NO INTERVALS NO-EXTENSION. "Numar Material

SELECT-OPTIONS: s_atinn FOR cabn-atinn NO INTERVALS NO-EXTENSION. "Caracteristici

SELECTION-SCREEN END OF BLOCK b1.







*SELECTION-SCREEN SKIP 1.



*START-OF-SELECTION.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_klart.

SELECT DISTINCT class klart FROM klah INTO TABLE i_class1.

IF sy-subrc = 0.

SORT i_class1 BY klart.

ENDIF.



"Function Module to create F4 help

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

EXPORTING

retfield = c_klart

value_org = c_vorg

TABLES

value_tab = i_class1

return_tab = it_return1

EXCEPTIONS

parameter_error = 1

no_values_found = 2

OTHERS = 3.



IF it_return1 IS NOT INITIAL.

LOOP AT it_return1 INTO wa_return1.

s_klart = wa_return1-fieldval.

ENDLOOP.

SELECT imerk clint klart FROM ksml INTO TABLE i_ksml

WHERE klart = s_klart.

IF sy-subrc = 0.

SORT i_ksml BY imerk.

ENDIF.

ENDIF.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_atinn-low.



"Function Module to create F4 help

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

EXPORTING

retfield = c_pspid_l

value_org = c_vorg

TABLES

value_tab = i_ksml

return_tab = it_return2

EXCEPTIONS

parameter_error = 1

no_values_found = 2

OTHERS = 3.



IF it_return2 IS NOT INITIAL.

LOOP AT it_return2 INTO wa_return2.

s_atinn-low = wa_return2-fieldval.

ENDLOOP.

SELECT imerk clint klart FROM ksml INTO TABLE i_ksml

WHERE imerk GT s_atinn-low

AND klart = s_klart.

IF sy-subrc = 0.

SORT i_ksml BY imerk.

ENDIF.

ENDIF.

Unknown said...

wow really superb you had posted one nice information through this. Definitely it will be useful for many people. So please keep update like this.

sap hr abap classes

Anonymous said...

Here we have a better way to use FM F4IF_INT_TABLE_VALUE_REQUEST:

http://zevolving.com/2014/06/various-ways-implement-abap-f4-help-value-request/