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: 

the create function does not working by using (business API) in RAP application

K1mo130
Explorer
0 Kudos

Hello

I'm trying to use BAPI_ALM_NOTIF_CREATE to implement the create function but it doesn't work for me, i tried this code in "Behavior Implementation":

K1mo130_0-1709715550387.png

and here's the code on file "zcl_09_call_bapi_k" to call the BAPIs:

K1mo130_2-1709715704520.png

and i already added the field by using the UI annotations but i when i create a data then i got an empty data field:

Schermafbeelding 2024-03-05 134248.png

did i missed something on the code?

5 REPLIES 5

raymond_giuseppi
Active Contributor
0 Kudos

After the call of the BAPI, you have to loop at the RETURN table looking for 'E' Error or 'A' Abort type message, if none found it's okay else an error was triggerred - Calling BAPIs from ABAP

0 Kudos

i already typed this code:

K1mo130_0-1709800415737.png

and i got this error:

K1mo130_1-1709800523472.png

is that has to do with the "Behavior Definition" or "Metadata Extentions"?

0 Kudos

You forgot to pass some mandatory field values (here notification type)

Also note that

  • In case of success message (type S) or even warning message (type W) then RETURN is not empty but the call was correct. (if you receive a temporary notification number, then the call was correct)
    BAPI_ALM_NOTIF_SAVE can also fill the RETURN table.
  • Read also 3379615 - BAPI_ALM_NOTIF_SAVE doesn't return notification number 

So, correct your code

  • In case of Success or Warning message, you don't look for Error or Abort Message and don't map the temporary notification number.
  • In case of Error or Abort message, you continue with the next call.
  • You didn' check RETURN parameter after the second BAPI call.

 

K1mo130
Explorer
0 Kudos

well it finally works, here what i did:

CLASS zcl_09_call_bapi_k DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .

PUBLIC SECTION.
METHODS call_bapi.

PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.

CLASS zcl_09_call_bapi_k IMPLEMENTATION.
METHOD call_bapi.
DATA: ls_notifheader TYPE bapi2080_nothdri,
lt_return TYPE TABLE OF bapiret2,
lt_notitem TYPE TABLE OF bapi2080_notitemi,
lv_notif_type TYPE qmart,
lv_notification_key TYPE qmnum. " Add this variable
* lt_number TYPE qmnum.

* ls_notifheader-notif_date = 'Q1'. " Notification types
* ls_notifheader-short_text = 'Test notification'. " Short text for the notification
* ls_notifheader-funct_loc = '1000'. " Functional location
*
lv_notif_type = 'Y8'.
DATA:ls_new_notification_header type bapi2080_nothdre.
TRY.
CALL FUNCTION 'BAPI_ALM_NOTIF_CREATE'
EXPORTING
notifheader = ls_notifheader
notif_type = lv_notif_type
IMPORTING
notifheader_export = ls_new_notification_header
TABLES
notitem = lt_notitem
return = lt_return.

IF lt_return IS INITIAL.
WRITE: / 'Notification created successfully.'.
" Save the notification data
CALL FUNCTION 'BAPI_ALM_NOTIF_SAVE'
EXPORTING
number = ls_new_notification_header-notif_no
IMPORTING
notifheader = ls_new_notification_header
TABLES
return = lt_return.

" Store the notification key
lv_notification_key = ls_new_notification_header-notif_no.
WRITE: / 'Notification key:', lv_notification_key.

ELSE.
LOOP AT lt_return INTO DATA(ls_message).
IF ls_message-type = 'E' OR ls_message-type = 'A'.
" Handle error or abort message
WRITE: / 'Error type:', ls_message-type, ', Error:', ls_message-message.
ENDIF.
ENDLOOP.
ENDIF.

CATCH cx_sy_dyn_call_param_missing INTO DATA(lx_param_missing).
" Handle the exception
WRITE: / 'Exception raised:', lx_param_missing->get_text( ).

CATCH cx_sy_itab_duplicate_key INTO DATA(lx_duplicate_KEY).
" Handle the exception
WRITE: / 'Exception raised:', lx_duplicate_KEY->get_text( ).

CATCH cx_sy_no_handler INTO DATA(lx_no_handler).
" Handle the exception
WRITE: / 'Exception raised:', lx_no_handler->get_text( ).

ENDTRY.

ENDMETHOD.

ENDCLASS.

 

but right now if i create a new data then i got an empty key:

K1mo130_0-1710161626559.png

is there any way that i could fill this empty key with unique value?

0 Kudos

here what i did on the "Behavior Definitions" for "ZR_NOTIFICATION_KTP":

K1mo130_1-1710161744725.png

and i made another "Behavior Definitions" for the actual create "ZC_NOTIFICATION_KTP":

K1mo130_2-1710161788832.png