2007 Sep 26 9:37 AM
I use the Bapi to create a (PM) Maintenance Notification, see below:
FUNCTION BAPI_ALM_NOTIF_CREATE .
*"----
""Lokale Schnittstelle:
*" IMPORTING
*" VALUE(EXTERNAL_NUMBER) LIKE BAPI2080_NOTHDRE-NOTIF_NO OPTIONAL
*" VALUE(NOTIF_TYPE) LIKE BAPI2080-NOTIF_TYPE
*" VALUE(NOTIFHEADER) LIKE BAPI2080_NOTHDRI STRUCTURE
*" BAPI2080_NOTHDRI
*" VALUE(TASK_DETERMINATION) LIKE BAPIFLAG STRUCTURE BAPIFLAG
*" DEFAULT SPACE
*" VALUE(SENDER) LIKE BAPI_SENDER STRUCTURE BAPI_SENDER OPTIONAL
*" VALUE(ORDERID) LIKE BAPI2080_NOTHDRE-ORDERID OPTIONAL
*" EXPORTING
*" VALUE(NOTIFHEADER_EXPORT) LIKE BAPI2080_NOTHDRE STRUCTURE
*" BAPI2080_NOTHDRE
*" TABLES
*" NOTITEM STRUCTURE BAPI2080_NOTITEMI OPTIONAL
*" NOTIFCAUS STRUCTURE BAPI2080_NOTCAUSI OPTIONAL
*" NOTIFACTV STRUCTURE BAPI2080_NOTACTVI OPTIONAL
*" NOTIFTASK STRUCTURE BAPI2080_NOTTASKI OPTIONAL
*" NOTIFPARTNR STRUCTURE BAPI2080_NOTPARTNRI OPTIONAL
*" LONGTEXTS STRUCTURE BAPI2080_NOTFULLTXTI OPTIONAL
*" KEY_RELATIONSHIPS STRUCTURE BAPI2080_NOTKEYE OPTIONAL
*" RETURN STRUCTURE BAPIRET2 OPTIONAL
I want to transfer a "wbs" field within creating the Notification, but there is not such field in the transfer parameter table in the Bapi, how can I do to include it?
I use the Bapi to create a (PM) Maintenance Notification, see below:
FUNCTION BAPI_ALM_NOTIF_CREATE .
*"----
""Lokale Schnittstelle:
*" IMPORTING
*" VALUE(EXTERNAL_NUMBER) LIKE BAPI2080_NOTHDRE-NOTIF_NO OPTIONAL
*" VALUE(NOTIF_TYPE) LIKE BAPI2080-NOTIF_TYPE
*" VALUE(NOTIFHEADER) LIKE BAPI2080_NOTHDRI STRUCTURE
*" BAPI2080_NOTHDRI
*" VALUE(TASK_DETERMINATION) LIKE BAPIFLAG STRUCTURE BAPIFLAG
*" DEFAULT SPACE
*" VALUE(SENDER) LIKE BAPI_SENDER STRUCTURE BAPI_SENDER OPTIONAL
*" VALUE(ORDERID) LIKE BAPI2080_NOTHDRE-ORDERID OPTIONAL
*" EXPORTING
*" VALUE(NOTIFHEADER_EXPORT) LIKE BAPI2080_NOTHDRE STRUCTURE
*" BAPI2080_NOTHDRE
*" TABLES
*" NOTITEM STRUCTURE BAPI2080_NOTITEMI OPTIONAL
*" NOTIFCAUS STRUCTURE BAPI2080_NOTCAUSI OPTIONAL
*" NOTIFACTV STRUCTURE BAPI2080_NOTACTVI OPTIONAL
*" NOTIFTASK STRUCTURE BAPI2080_NOTTASKI OPTIONAL
*" NOTIFPARTNR STRUCTURE BAPI2080_NOTPARTNRI OPTIONAL
*" LONGTEXTS STRUCTURE BAPI2080_NOTFULLTXTI OPTIONAL
*" KEY_RELATIONSHIPS STRUCTURE BAPI2080_NOTKEYE OPTIONAL
*" RETURN STRUCTURE BAPIRET2 OPTIONAL
I want to transfer a "wbs" field within creating the Notification, but there is not such field in the transfer parameter table in the Bapi, how can I do to include it?
2007 Sep 26 12:26 PM
Sad but true, there is no extension structure for this BAPI. When we had a requirement to update few custom fields on the notification we wrote a custom function module do so (even though I dint like the idea).
I am pasting the code of that FM here, hope it helps.
*"----
""Local Interface:
*" IMPORTING
*" REFERENCE(X_QMNUM) TYPE QMNUM
*" REFERENCE(ZQMEL) TYPE CI_QMEL
*" REFERENCE(X_COMMIT) TYPE CHAR1
*" EXCEPTIONS
*" NOTIF_DOES_NOT_EXIST
*" NOTIF_LOCKED
*" NO_CHANGE_REQUIRED
*" UPDATE_FAILED
*"----
DATA:
l_count TYPE i, "--Offset Calculation
l_viqmel LIKE viqmel, "--Notification header
l_qmel LIKE qmel, "--Notification Header
l_tab_fields TYPE STANDARD TABLE OF rfc_fields, "Table Fields
l_data TYPE STANDARD TABLE OF c, "Dummy Value
l_fieldname TYPE rfc_fields, "Structure to get field name
l_position TYPE rfc_fields, "Structure to get field position
l_qmel_new TYPE qmel. "New structure for checking if
"update is required
FIELD-SYMBOLS: <fs_zfield> TYPE ANY, "Field in CI_QMEL
<fs_qmel> TYPE ANY. "Field in QMEL
Read notification---------------------------------------
CALL FUNCTION 'READ_NOTIFICATION'
EXPORTING
qmnum = x_qmnum
IMPORTING
iviqmel = l_viqmel
EXCEPTIONS
invalid_number = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE notif_does_not_exist.
ENDIF.
*Lock the Notification
CALL FUNCTION 'ENQUEUE_EIQMEL'
EXPORTING
qmnum = l_viqmel-qmnum
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
RAISE notif_locked.
ENDIF.
*Add LOGIC for Custom Fields update.
MOVE-CORRESPONDING l_viqmel TO l_qmel.
l_qmel_new = l_qmel.
*Get the first field name from the include
CALL FUNCTION 'DP_GET_FIELDS_FROM_TABLE'
EXPORTING
tabname = 'CI_QMEL'
TABLES
data = l_data
fields = l_tab_fields
EXCEPTIONS
dp_invalid_table = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
READ TABLE l_tab_fields INDEX 1
INTO l_fieldname TRANSPORTING fieldname.
IF sy-subrc = 0.
*Get postion of the obtained field in QMEL
CALL FUNCTION 'DP_GET_FIELDS_FROM_TABLE'
EXPORTING
tabname = 'QMEL'
TABLES
data = l_data
fields = l_tab_fields
EXCEPTIONS
dp_invalid_table = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
*Read the position
READ TABLE l_tab_fields
WITH KEY fieldname = l_fieldname-fieldname
INTO l_position TRANSPORTING position.
ENDIF.
DO.
*Calculate the offset.
l_count = sy-index + l_position-position - 1.
*Dynamically assign field value to QMEL
ASSIGN COMPONENT sy-index OF STRUCTURE zqmel TO <fs_zfield>.
IF sy-subrc <> 0.
*Exit the do - enddo if the assignment fails
EXIT.
ELSE.
*Check if the field is initial
IF <fs_zfield> IS NOT INITIAL.
*If value is filled assign FS to QMEL field with offset.
ASSIGN COMPONENT l_count OF STRUCTURE l_qmel_new TO <fs_qmel>.
IF sy-subrc = 0.
*If assign is successful, move value to QMEL
<fs_qmel> = <fs_zfield>.
UNASSIGN <fs_qmel>.
ENDIF.
ENDIF.
UNASSIGN <fs_zfield>.
ENDIF.
ENDDO.
*Check if update is required
IF l_qmel_new <> l_qmel.
l_qmel = l_qmel_new.
--Get date of change
*If required: Update the changed by name, and changed date
CALL FUNCTION 'ISU_OPENING_DATA_UPDATE'
EXPORTING
x_ernam = l_qmel-ernam
x_erdat = l_qmel-erdat
x_upd_mode = 'U'
IMPORTING
y_erdat = l_qmel-erdat
y_ernam = l_qmel-ernam
y_aedat = l_qmel-aedat
y_aenam = l_qmel-aenam
EXCEPTIONS
not_changed = 1.
--Update QMEL to set the custom Fields
UPDATE qmel FROM l_qmel.
IF sy-subrc <> 0.
*Unlock the table.
CALL FUNCTION 'DEQUEUE_EIQMEL'
EXPORTING
qmnum = l_viqmel-qmnum.
RAISE update_failed.
ENDIF.
ENDIF.
*Unlock the table.
CALL FUNCTION 'DEQUEUE_EIQMEL'
EXPORTING
qmnum = l_viqmel-qmnum.
--Save work and finish
IF x_commit = 'X'.
COMMIT WORK.
ENDIF.
2007 Sep 26 1:07 PM
thank you, Srihari Hebbar
your answer is the similar as a senior ABAPer has ever answered to me, while your FM code is a very good reference.
George
2007 Sep 26 1:13 PM
George,
Please be careful when you are using the FM as it involves a direct table update and may not be approved for use.
If you want to explore options , you can try finding a BADI which can be used to update the custom field value. You will have to develop a mechanism of understanding when the BADI is being called and if the call is due to your BAPI then update the required field.
Hope it helps.
2007 Sep 26 12:33 PM
Hi George,
I think for creating the Notification, WBS element is not required, its required in Service Order creation.
Give point if helpfull.