Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Thursday, February 21, 2008

Generating your own standard F4 help using sap abap

To avoid the standard F4 help to be show, insert the event PROCESS ON-VALUE-REQUEST request in the program and add a field statement for the field that should trigger the F4 help. In the module called from PROCESS ON-VALUE-REQUEST request, call function module F4IF_FIELD_VALUE_REQUEST.

Example:

process before output.

.....

process after input.

.....

PROCESS ON VALUE-REQUEST. FIELD sflight-carrid MODULE f4_help_for_carrid.

MODULE f4_help_for_carrid INPUT.

* NOTE:

* Tabname/fieldname is the name of the table and field

* for which F4 should be shown.

*

* Dynprog/Dynpnr/Dynprofield are the names of the Progran/Dynpro/Field

* in which the f4 value should be returned.

*

* Value: The value of the Dynpro field when calling the F4 help.

* You can limit the values shown, by inseting a value in this parameter

* e.g 'A*' to show only values beginning with A

CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
        tabname     = 'SFLIGHT'
        fieldname   = 'CARRID'
*        SEARCHHELP  = ' '
*        SHLPPARAM   = ' '
        dynpprog    = 'ZDANY_F4_OWN_CALL'
        dynpnr      = '0100'
        dynprofield = 'SFLIGHT-CARRID'
*        STEPL       = 0
        value       = 'A*'
*        MULTIPLE_CHOICE     = ' '
*        DISPLAY             = ' '
*        SUPPRESS_RECORDLIST = ' '
*        CALLBACK_PROGRAM    = ' '
*        CALLBACK_FORM       = ' '
*    TABLES
*        RETURN_TAB =
*    EXCEPTIONS
*        FIELD_NOT_FOUND   = 1
*        NO_HELP_FOR_FIELD = 2
*        INCONSISTENT_HELP = 3
*        NO_VALUES_FOUND   = 4
*        OTHERS            = 5
.
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. " F4_help_for_carrid INPUT

To control F4 help in a selection screen use the AT SELECTION-SCREEN ON VALUE-REQUEST FOR

event.

Note that for ranges both the low and high value of the field must have there own ON VALUE-REQUEST

Example:

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

PERFORM f4_help_carrid.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_prctr-high.

PERFORM f4_help_carrid.

To avoid the standard F4 help to be show, insert the event PROCESS ON-VALUE-REQUEST request in the program and add a field statement for the field that should trigger the F4 help. In the module called from PROCESS ON-VALUE-REQUEST request, call function module F4IF_FIELD_VALUE_REQUEST.

Example:

process before output.

.....

process after input.

.....

PROCESS ON VALUE-REQUEST. FIELD sflight-carrid MODULE f4_help_for_carrid.

MODULE f4_help_for_carrid INPUT.

* NOTE:

* Tabname/fieldname is the name of the table and field

* for which F4 should be shown.

*

* Dynprog/Dynpnr/Dynprofield are the names of the Progran/Dynpro/Field

* in which the f4 value should be returned.

*

* Value: The value of the Dynpro field when calling the F4 help.

* You can limit the values shown, by inseting a value in this parameter

* e.g 'A*' to show only values beginning with A

CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
        tabname     = 'SFLIGHT'
        fieldname   = 'CARRID'
*        SEARCHHELP  = ' '
*        SHLPPARAM   = ' '
        dynpprog    = 'ZDANY_F4_OWN_CALL'
        dynpnr      = '0100'
        dynprofield = 'SFLIGHT-CARRID'
*        STEPL       = 0
        value       = 'A*'
*        MULTIPLE_CHOICE     = ' '
*        DISPLAY             = ' '
*        SUPPRESS_RECORDLIST = ' '
*        CALLBACK_PROGRAM    = ' '
*        CALLBACK_FORM       = ' '
*    TABLES
*        RETURN_TAB =
*    EXCEPTIONS
*        FIELD_NOT_FOUND   = 1
*        NO_HELP_FOR_FIELD = 2
*        INCONSISTENT_HELP = 3
*        NO_VALUES_FOUND   = 4
*        OTHERS            = 5
.
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. " F4_help_for_carrid INPUT

To control F4 help in a selection screen use the AT SELECTION-SCREEN ON VALUE-REQUEST FOR

event.

Note that for ranges both the low and high value of the field must have there own ON VALUE-REQUEST

Example:

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

PERFORM f4_help_carrid.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_prctr-high.

PERFORM f4_help_carrid.

Manipulating Timestamps using abap

Actually, we should use time stamp in our abap programs instead of the traditional date and time fields.

When we have to do some calculation on a time stamp is not as easy as on a date field.

For example, to add an hour to a timestamp, many people will:

  1. convert the time stamp into a standard date and field

  2. add an hour

  3. convert back the date and time to a timestamp

However, it is the slowest method you can use.

Instead, use class CL_ABAP_TSTMP.

It enables you to make whatever calculation you want on a time stamp.

In the following example, 1 hour is added

REPORT zdany_tstamp.
DATA : l_tstamp         TYPE timestamp,
       l_tstamp_out TYPE timestamp.
     
 GET TIME STAMP FIELD l_tstamp.
TRY.
  CALL METHOD cl_abap_tstmp=>add
     EXPORTING
        tstmp = l_tstamp
        secs = 3600 <<<===--- 1 hour = 3600 seconds
     RECEIVING
                r_tstmp = l_tstamp_out.
  CATCH cx_parameter_invalid_range .
                WRITE 'invalid range'.
                EXIT.
  CATCH cx_parameter_invalid_type .
                WRITE 'invalid type'.
                EXIT.
ENDTRY.
     
WRITE l_tstamp time zone 'UTC '.
SKIP.
WRITE l_tstamp_out time zone 'UTC '.

Actually, we should use time stamp in our abap programs instead of the traditional date and time fields.

When we have to do some calculation on a time stamp is not as easy as on a date field.

For example, to add an hour to a timestamp, many people will:

  1. convert the time stamp into a standard date and field

  2. add an hour

  3. convert back the date and time to a timestamp

However, it is the slowest method you can use.

Instead, use class CL_ABAP_TSTMP.

It enables you to make whatever calculation you want on a time stamp.

In the following example, 1 hour is added

REPORT zdany_tstamp.
DATA : l_tstamp         TYPE timestamp,
       l_tstamp_out TYPE timestamp.
     
 GET TIME STAMP FIELD l_tstamp.
TRY.
  CALL METHOD cl_abap_tstmp=>add
     EXPORTING
        tstmp = l_tstamp
        secs = 3600 <<<===--- 1 hour = 3600 seconds
     RECEIVING
                r_tstmp = l_tstamp_out.
  CATCH cx_parameter_invalid_range .
                WRITE 'invalid range'.
                EXIT.
  CATCH cx_parameter_invalid_type .
                WRITE 'invalid type'.
                EXIT.
ENDTRY.
     
WRITE l_tstamp time zone 'UTC '.
SKIP.
WRITE l_tstamp_out time zone 'UTC '.

No comments:

Post a Comment

Content

Recent Topics