Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP: Smartform exception handling

aneel_munawar
Participant
0 Kudos

Dear Abap Experts ,

How can I handle exception  while calling the smartform and when incorrect parameters are sent to the smartfom.

I have used following code but problem not resolved.

             EXCEPTIONS

           formatting_error     = 1

           internal_error       = 2

           send_error           = 3

           user_canceled        = 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.

Thanks,

Aneel

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Aneel,

What do you want when a smartform exception happens, I mean apart from the fact that what you have mentioned. What you have written is correct to handle exceptions.

Simply put you can insert a message i.e.,

IF SY-SUBRC <> 0.

     MESSAGE 'Incorrect Parameters' TYPE S DISPLAY LIKE 'E'.

     EXIT.

ENDIF.

Cheers,

Varun

9 REPLIES 9

Former Member
0 Kudos

Hi Aneel.

After each generated FM call, make sure you get the errors as well whenever there is any exception. Call FM SSF_READ_ERRORS to retrieve the error message. Pass these message back to the NAST protocol if the SmartForm is being called from the Output control.

Check the below code.Hope this will help you.

CALL FUNCTION lf_fm_name

     EXPORTING

                archive_index        = toa_dara

                archive_parameters   = arc_params

                control_parameters   = ls_control_param

                mail_recipient       = ls_recipient

                mail_sender          = ls_sender

                output_options       = ls_composer_param

                user_settings        = SPACE

     IMPORTING  job_output_info      = ls_job_info

     EXCEPTIONS formatting_error     = 1

                internal_error       = 2

                send_error           = 3

                user_canceled        = 4

                OTHERS               = 5.

IF sy-subrc <> 0.

*

  DATA: LT_ERRORTAB             TYPE TSFERROR.

  FIELD-SYMBOLS: <FS_ERRORTAB>  TYPE LINE OF TSFERROR.

*

* get smart form protocoll

  CALL FUNCTION 'SSF_READ_ERRORS'

    IMPORTING

      ERRORTAB = LT_ERRORTAB.

*

* add smartform protocoll to nast protocoll

  LOOP AT LT_ERRORTAB ASSIGNING <FS_ERRORTAB>.

    CALL FUNCTION 'NAST_PROTOCOL_UPDATE'

         EXPORTING

              MSG_ARBGB = <FS_ERRORTAB>-MSGID

              MSG_NR    = <FS_ERRORTAB>-MSGNO

              MSG_TY    = <FS_ERRORTAB>-MSGTY

              MSG_V1    = <FS_ERRORTAB>-MSGV1

              MSG_V2    = <FS_ERRORTAB>-MSGV2

              MSG_V3    = <FS_ERRORTAB>-MSGV3

              MSG_V4    = <FS_ERRORTAB>-MSGV4

         EXCEPTIONS

              OTHERS    = 1.

  ENDLOOP.

ELSE.

*

*   

ENDIF.

Thanks

KH

Former Member
0 Kudos

Hi Aneel,

What do you want when a smartform exception happens, I mean apart from the fact that what you have mentioned. What you have written is correct to handle exceptions.

Simply put you can insert a message i.e.,

IF SY-SUBRC <> 0.

     MESSAGE 'Incorrect Parameters' TYPE S DISPLAY LIKE 'E'.

     EXIT.

ENDIF.

Cheers,

Varun

0 Kudos

Dear Varun,

This is not working.

Regards

Aneel

0 Kudos

Hi Aneel,

What exactly do you want to acheive? Pleas explain in brief and if possible send in the screen shots of the behavior that you are experiencing.

Cheers,

Varun

0 Kudos

Dear Varun,

I want to get a message that a parameter was not sent.

My problem is that, while programming when I forget to send  any parameter to smartform, an unhandled exception occurs and programming window closed.

I want a message  but not  a dump screen.

Thanks

Aneel

0 Kudos

Hi Aneel,

What you are asking is not possible!!! You can't possibly know as to which parameters are missing! We all shall receive dumps if we don't pass parameters according to function module in our driver programs


As suggested by Katrice if your output is being called via output control i.e., printing forms through standard transaction Sales order - VA01/02/03, Purchase order - ME21N/22N/23N, Invoice - VA41/42/43, etc then you can read if any errors via message.

But if your output is not called via output control, either you can check the variables in your driver program using IF... ELSE statements or check the optional check box for variables in Form Interface of Smartforms.

By going for second approach (Optional Check Box), you can have the smart-form generated and also minimize the dumps!

Cheers,

Varun

0 Kudos

Hi,

Play around with the following code:

DATA: g_fm_name TYPE rs38l_fnam .

DATA: go_ex TYPE REF TO cx_sy_dyn_call_param_missing .

TRY .

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

      EXPORTING

        formname_          = 'ZJBTT1'

      IMPORTING

        fm_name            = g_fm_name

      EXCEPTIONS

        no_form            = 1

        no_function_module = 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.

  CATCH cx_sy_dyn_call_param_missing INTO go_ex.

    BREAK-POINT .

    cl_message_helper=>set_msg_vars_for_if_msg( go_ex ).

    MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno

               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDTRY .

GO_EX will hold the name of missing parameter... The rest of handleable system exceptions for call function can be found in ABAP help.

cheers

Janis

Message was edited by: Jānis B (added converting exception to sy variables)

0 Kudos

Hi Janis,

I like your idea of catching the exceptions! Many thanks for sharing it out!

Cheers,

Varun

0 Kudos

Thanks Janis.

It solved my problem.

Regards,

Aneel