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: 

How to get a BAPI return message in ABAP while it is not returning as a parameter?

Antonio_Lopez
Explorer
0 Kudos

Hi experts, hope you'all are doing really good!!

I came here with a question since I'm still new on ABAP, the question is:

How to get a BAPI header return message in ABAP program since the BAPI is not returning back this message variable in the importing parameter variables or in changing variables in ABAP when calling this BAPI,,, but when testing the BAPI in SE37 TCode it shows it in the header section..

Hope anyone can help me or give me any idea how to solve it, thanks in advance.

Have a good one!!

The highlighted message in yellow is what i wanna get/catch in ABAP program and show it to users:

This is the name of the BAPI: MEASUREM_DOCUM_RFC_SINGLE_001

8 REPLIES 8

matt
Active Contributor

If it has not parameter containing any messages then it isn't a bapi. Why haven't you told us which FM it is? Seems a fairly obvious piece of information to give.

Anyway, when you call this RFC FM, use the EXCEPTIONS and react to VALUE_UNFIT.

matt
Active Contributor
0 Kudos

Thank you for adding the function module name. And as I said before. It isn't a BAPI. It's just an RFC enabled FM. All BAPIs are RFC enabled function modules, but not all RFC enabled function modules are BAPIs.

Hi Sergio,

The message you are getting is not returning as a header or item parameter from FM but rather thrown as exception from the FM.

Just like IMPORTING or EXPORTING parameters you would have EXCEPTIONS parameters in your FM, so if you want to get this message in your program then when you are calling this FM, un-comment EXCEPTIONS parameters if any and add below code after that:

IF sy-subrc <> 0.
   MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

Sandra_Rossi
Active Contributor

To complete other good answers:

ABAP Documentation - CALL FUNCTION, parameter_list - EXCEPTIONS ...

CALL FUNCTION 'MEASUREM_DOCUM_CREATE_SINGLE'
  EXPORTING
    ... " send input values to function module
  IMPORTING
    ... " receive values returned by function module
  EXCEPTIONS
    ...
    value_unfit          = 12
    ...
    OTHERS               = 20.
IF sy-subrc <> 0.
  CASE sy-subrc.
    WHEN 12. " VALUE_UNFIT
      " Handle specifically if needed
    WHEN OTHERS.
      IF sy-msgid IS NOT INITIAL.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        " Handle in case it was RAISE without message & ID was never set before
      ENDIF.
  ENDCASE.
ENDIF.
Note that some function modules may return modern exceptions, so you won't use EXCEPTIONS, but you'll use TRY ... CATCH ... ENDTRY (exceptions not specific to function modules).Note that in some cases you may need to add special exceptions like ERROR_MESSAGE for error message without exception, COMMUNICATION_FAILURE for RFC, etc. (see documentation).

raymond_giuseppi
Active Contributor
0 Kudos

This fm isn't a BAPI so why would it return the RETURN parameter (execute transaction ,BAPI and read the documentation)

  • Nevertheless it's a RFC enabled reeleased Fm 🙂 but that('s not enough 😞
  • So look at the returned exceptions, sometimes they com with an error message (analyze FM source for RAISE or MESSAGE RAISING) so hanfle it in your call with EXCEPTIONS.

Antonio_Lopez
Explorer

Thank y'all for your help!!! and sorry if my question wasn't clear I'm still trying to get the difference between FM and BAPI and how to handle each one, I'm still newbie in this world of ABAP but keeping learning a lot!

So this is what I did and it's working:

CALL FUNCTION 'MEASUREM_DOCUM_RFC_SINGLE_001'
EXPORTING
measurement_point = lv_point_number " value passed as paramerer
secondary_index = ''
reading_date = sy-datum
reading_time = sy-uzeit
short_text = ' '
reader = sy-uname
origin_indicator = 'A'
reading_after_action = ' '
recorded_value = lv_recorded_value " " value passed as paramerer
recorded_unit = ' '
difference_reading = ' '
IMPORTING
measurement_document = lv_doc
complete_document = ls_complete_doc
notification = lv_notificacion
custom_duprec_occured = lv_custom_duprec
linear_data_exp = ls_linear_data
EXCEPTIONS
no_authority = 1
point_not_found = 2
index_not_unique = 3
type_not_found = 4
point_locked = 5
point_inactive = 6
timestamp_in_future = 7
timestamp_duprec = 8
unit_unfit = 9
value_not_fltp = 10
value_overflow = 11
value_unfit = 12
value_missing = 13
code_not_found = 14
notif_type_not_found = 15
notif_prio_not_found = 16
notif_gener_problem = 17
update_failed = 18
invalid_time = 19
invalid_date = 20
OTHERS = 21.


CASE sy-subrc.
WHEN 0.
wa_alv-mdocm = ls_complete_doc-mdocm.
wa_alv-log = 'Document created Succesfully'.
WHEN 1.
WHEN 2.
" ...
" ...
WHEN 12.
IF sy-msgid IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
INTO lv_error.

wa_alv-mdocm = ''.
wa_alv-log = |{ 'VALUE_UNFIT: ' } { lv_error } |.

APPEND wa_alv TO gt_alv.
"... more logic
ENDIF.

WHEN 20.
" ...
ENDCASE.

0 Kudos

Thanks for the feedback.

jack_graus2
Active Contributor
0 Kudos

Not sure you are aware and just to make sure:

All exceptions different from 12 are now being ignored. You might catch these by replacing WHEN 12 by WHEN OTHERS to catch all exceptions different from 0 (0 = Succes).