2024 Mar 06 9:07 AM
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":
and here's the code on file "zcl_09_call_bapi_k" to call the BAPIs:
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:
did i missed something on the code?
2024 Mar 06 3:33 PM
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
2024 Mar 07 8:36 AM
i already typed this code:
and i got this error:
is that has to do with the "Behavior Definition" or "Metadata Extentions"?
2024 Mar 07 1:16 PM - edited 2024 Mar 12 1:45 PM
You forgot to pass some mandatory field values (here notification type)
Also note that
So, correct your code
2024 Mar 11 12:54 PM
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:
is there any way that i could fill this empty key with unique value?
2024 Mar 11 12:57 PM
here what i did on the "Behavior Definitions" for "ZR_NOTIFICATION_KTP":
and i made another "Behavior Definitions" for the actual create "ZC_NOTIFICATION_KTP":