Modify search help behavior at runtime

Modify search help behavior at runtime for transporting different fields or changing the SELOPT structure without writing field exits with this function module.

Sometimes I needed to modify a search help behaviour at runtime for transporting different fields or changing the

SELOPT structure without writing (and changing, and changing, and changing, ...) field exits, so I wrote this function module in a couple of hours to do it easy. I think this can be a good start to work on, if you are interested, and there's a little sample report to show how it works.

Structure ZBC_SEARCH_HELP

HELP_FIELD TYPE DDSHLPSFLD (Name of the help parameter) VIDEO_FIELD TYPE DDSHLPDFLD (Name of the screen field) READ_FROM_VIDEO TYPE FLAG (Read initial value from video) WRITE_TO_VIDEO TYPE FLAG (Write selected value to video) INITIAL_VALUE TYPE SEOVALUE (Initial value) CONSTANT TYPE FLAG (Initial value can't be changed)
Code: FUNCTION zbc_f4.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(HELP) TYPE SHLPNAME
*" VALUE(SHLPTYPE) TYPE DDSHLPTYP DEFAULT 'SH'
*" TABLES
*" INFO_HELP STRUCTURE ZBC_SEARCH_HELP
*" SELOPT STRUCTURE DDSHSELOPT OPTIONAL
*" RETURN_VALUES STRUCTURE DDSHRETVAL OPTIONAL
*" EXCEPTIONS
*" ERROR_READING_VIDEO
*" ERROR_WRITING_VIDEO
*"----------------------------------------------------------------------

TYPE-POOLS:
shlp.

* Type of an input help (SHLPTYPE)
* SH Search help
* CH Check table
* CT Check table with text table
* FV Fixed values for domains
* DV Fixed values from flow logic
* CA Calendar help
* CL Time help
* SR Search help for data element (temporary)
* MC Matchcode
* MI Matchcode ID

DATA:
i_dynpfields LIKE dynpread OCCURS 0 WITH HEADER LINE,
w_ddshretval LIKE ddshretval,
l_shlp TYPE shlp_descr_t,
l_interface LIKE ddshiface,
w_info_help LIKE info_help,
rc LIKE sy-subrc
.

CALL FUNCTION 'F4IF_GET_SHLP_DESCR'
EXPORTING
shlpname = help
shlptype = shlptype
IMPORTING
shlp = l_shlp.

* Some parameter can be importing only!
LOOP AT info_help.
READ TABLE l_shlp-interface INTO l_interface
WITH KEY shlpfield = info_help-help_field.
IF sy-subrc <> 0.
CLEAR l_interface.
l_interface-shlpfield = info_help-help_field.
APPEND l_interface TO l_shlp-interface.
ENDIF.
ENDLOOP.

* Read values from video
REFRESH i_dynpfields.
LOOP AT info_help
INTO w_info_help
WHERE read_from_video = 'X'.
i_dynpfields-fieldname = w_info_help-video_field.
APPEND i_dynpfields.
ENDLOOP.
IF NOT i_dynpfields[] IS INITIAL.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-cprog
dynumb = sy-dynnr
TABLES
dynpfields = i_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 e398 WITH text-001 RAISING error_reading_video.
ENDIF.
ENDIF.

LOOP AT l_shlp-interface INTO l_interface.
READ TABLE info_help
INTO w_info_help
WITH KEY help_field = l_interface-shlpfield.
IF sy-subrc = 0.
CLEAR l_interface.
l_interface-shlpfield = w_info_help-help_field.
l_interface-valfield = w_info_help-video_field.
IF NOT w_info_help-read_from_video IS INITIAL.
READ TABLE i_dynpfields
WITH KEY fieldname = w_info_help-video_field.
l_interface-value = i_dynpfields-fieldvalue.
ELSEIF NOT w_info_help-initial_value IS INITIAL.
l_interface-value = w_info_help-initial_value.
ENDIF.
l_interface-dispfield = w_info_help-constant.
MODIFY l_shlp-interface FROM l_interface.
ENDIF.
ENDLOOP.

APPEND LINES OF selopt TO l_shlp-selopt.

CALL FUNCTION 'F4IF_START_VALUE_REQUEST'
EXPORTING
shlp = l_shlp
IMPORTING
rc = rc
TABLES
return_values = return_values.

CHECK rc = 0.
REFRESH i_dynpfields.
LOOP AT info_help
INTO w_info_help
WHERE write_to_video = 'X'.
READ TABLE return_values
INTO w_ddshretval
WITH KEY retfield = w_info_help-video_field.
IF sy-subrc = 0.
i_dynpfields-fieldname = w_info_help-video_field.
i_dynpfields-fieldvalue = w_ddshretval-fieldval.
APPEND i_dynpfields.
ENDIF.
ENDLOOP.

* Write values to video
IF NOT i_dynpfields[] IS INITIAL.
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = sy-cprog
dynumb = sy-dynnr
TABLES
dynpfields = i_dynpfields
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE e398 WITH text-002 RAISING error_writing_video.
ENDIF.
ENDIF.

ENDFUNCTION.

Here's a sample report:

REPORT zsample_f4.

PARAMETERS:
p_bukrs LIKE t001-bukrs,
p_butxt LIKE t001-butxt,
p_ort01 LIKE t001-ort01,
p_land1 LIKE t001-land1,
p_waers LIKE t001-waers DEFAULT 'EUR'.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.
IF screen-name = 'P_WAERS'.
screen-input = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_bukrs.
PERFORM f4_t001.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_butxt.
PERFORM f4_t001.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ort01.
PERFORM f4_t001.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_waers.
PERFORM f4_t001.

*&---------------------------------------------------------------------*
*& Form f4_t001
*&---------------------------------------------------------------------*
FORM f4_t001.

DATA:
help_name TYPE shlpname,
selopt LIKE TABLE OF ddshselopt WITH HEADER LINE,
help_info LIKE TABLE OF zbc_search_help WITH HEADER LINE
.

* Search help parameters
help_name = 'H_T001'.
REFRESH help_info.
CLEAR help_info.
help_info-help_field = 'BUKRS'.
help_info-video_field = 'P_BUKRS'.
help_info-write_to_video = 'X'.
help_info-read_from_video = 'X'.
APPEND help_info.
CLEAR help_info.
help_info-help_field = 'BUTXT'.
help_info-video_field = 'P_BUTXT'.
help_info-write_to_video = 'X'.
APPEND help_info.
CLEAR help_info.
help_info-help_field = 'ORT01'.
help_info-video_field = 'P_ORT01'.
help_info-write_to_video = 'X'.
APPEND help_info.
CLEAR help_info.
help_info-help_field = 'WAERS'.
help_info-video_field = 'P_WAERS'.
help_info-read_from_video = 'X'.
help_info-constant = 'X'.
APPEND help_info.

* Other fields
IF NOT p_land1 IS INITIAL.
selopt-shlpname = help_name.
selopt-shlpfield = 'LAND1'.
selopt-sign = 'I'.
selopt-option = 'EQ'.
selopt-low = p_land1.
APPEND selopt.
ENDIF.

CALL FUNCTION 'ZBC_F4'
EXPORTING
help = help_name
shlptype = 'SH'
TABLES
info_help = help_info
selopt = selopt
EXCEPTIONS
error_reading_video = 1
error_writing_video = 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.
CHECK 1 = 1.

ENDFORM. " f4_t001

This was first published in May 2004

Dig deeper on SAP Basis administration and NetWeaver administration

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close