10-25-2006 9:46 PM
hi all,
i created a functional module the purpose of this is to send an email to the distribution list when ever there is an error in processing the item.
every thing is working fine but a PO can have a number of items so in my program if the first item is error it is not processing the second item.
so can any one help me with logic how to process all the items in the PO if there is an error in some of the items.
here is my program.
"----
""Local Interface:
*" IMPORTING
*" VALUE(GOODSMVT_HEADER) LIKE BAPI2017_GM_HEAD_01 STRUCTURE
*" BAPI2017_GM_HEAD_01
*" VALUE(GOODSMVT_CODE) LIKE BAPI2017_GM_CODE STRUCTURE
*" BAPI2017_GM_CODE
*" VALUE(TESTRUN) LIKE BAPI2017_GM_GEN-TESTRUN DEFAULT SPACE
*" EXPORTING
*" VALUE(GOODSMVT_HEADRET) LIKE BAPI2017_GM_HEAD_RET STRUCTURE
*" BAPI2017_GM_HEAD_RET
*" VALUE(MATERIALDOCUMENT) TYPE BAPI2017_GM_HEAD_RET-MAT_DOC
*" VALUE(MATDOCUMENTYEAR) TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR
*" TABLES
*" GOODSMVT_ITEM STRUCTURE BAPI2017_GM_ITEM_CREATE
*" GOODSMVT_SERIALNUMBER STRUCTURE BAPI2017_GM_SERIALNUMBER
*" OPTIONAL
*" RETURN STRUCTURE BAPIRET2
*"----
ET PLANT AND STORAGE LOC TO THE INTERNAL TABLE.
DESCRIBE TABLE goodsmvt_item LINES w_no_lines.
IF w_no_lines > 0.
SELECT ebeln ebelp werks lgort
FROM ekpo
INTO TABLE t_ekpo FOR ALL ENTRIES IN goodsmvt_item
WHERE
ebeln = goodsmvt_item-po_number AND
ebelp = goodsmvt_item-po_item.
ENDIF.
GET THE VENDOR NUMBER.
CLEAR w_lifnr.
SELECT SINGLE lifnr INTO w_lifnr
FROM ekko
WHERE ebeln = goodsmvt_item-po_number.
MODIFY THE ITEMS TABLE.
LOOP AT goodsmvt_item.
CLEAR t_ekpo.
READ TABLE t_ekpo WITH KEY ebeln = goodsmvt_item-po_number
ebelp = goodsmvt_item-po_item.
IF sy-subrc = 0.
goodsmvt_item-plant = t_ekpo-werks.
goodsmvt_item-stge_loc = t_ekpo-lgort.
MODIFY goodsmvt_item TRANSPORTING plant stge_loc.
ENDIF.
endloop.
Execute Goods Receipt for PO
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = goodsmvt_header
goodsmvt_code = '01' "from table t158g for mb01
TESTRUN = ' '
IMPORTING
goodsmvt_headret = goodsmvt_headret
materialdocument = materialdocument
matdocumentyear = matdocumentyear
TABLES
goodsmvt_item = goodsmvt_item
goodsmvt_serialnumber = goodsmvt_serialnumber
return = t_return.
CHECK WHETHER MAT DOC NO IS CREATED.
IF materialdocument = space.
CLEAR w_lv_fname.
w_lv_fname = goodsmvt_item-entry_qnt.
SHIFT w_lv_fname LEFT DELETING LEADING space.
CLEAR w_temp_flag.
MOVE THE ERROR MESSAGE TO THE INTERNAL TABLE.
LOOP AT t_return WHERE type = 'E'.
IF w_temp_flag NE t_return-row.
READ TABLE goodsmvt_item INDEX w_temp_flag.
CONCATENATE 'The following errors were detected when posting GR For'
'PO NO' goodsmvt_item-po_number
'PLANT' goodsmvt_item-plant
'STORAGE LOC' goodsmvt_item-stge_loc
'MATERIAL' goodsmvt_item-material
'MOVEMENT TYPE' goodsmvt_item-move_type
'QUANTITY' w_lv_fname
'SERIAL NO' goodsmvt_serialnumber-serialno
'PO ITEM NO' goodsmvt_item-po_item
INTO t_msg SEPARATED BY space.
APPEND t_msg.
w_temp_flag = t_return-row.
ENDIF.
MOVE t_return TO t_msg.
APPEND t_msg.
ENDLOOP.
EMAIL SUBJECT.
w_subject = .gr fail'.
CHECK THE NAME OF THE SAP SYSTEM.
IF sy-sysid = 'PRD'.
Get vendor-specific distribution list
CALL FUNCTION 'Z_GET_DISTRIBUTION'
EXPORTING
application = c_application
application_group = w_lifnr
IMPORTING
address_list = w_address_list.
ELSE.
Get test user group distribution list
CALL FUNCTION 'Z_GET_DISTRIBUTION'
EXPORTING
application = c_application
application_group = c_test
IMPORTING
address_list = w_address_list.
ENDIF.
SEND EMAIL TO THE DISTRIBUTION LIST.
CALL FUNCTION 'Z_UNIX_MAIL'
EXPORTING
ux_receivers = w_address_list
ux_subject = w_subject
UX_FROM =
TABLES
ux_lines = t_msg.
ELSE.
COMMIT WORK AND WAIT.
ENDIF.
ENDFUNCTION.
10-25-2006 10:19 PM
Well this is the the way SAP transactions and BAPIS work. I think it will just stop at the first error.
It would take longer, but you could send each item separately to the BAPI with TESTRUN checked. If any fail then send all that failed to the e-mail routine; otherwise, run the full bapi with all of the items.
Since this is a duplicate post on the data transfer forum, would you please close one or the other of them.
Rob
10-25-2006 10:40 PM
hey rob thank you very much for the reply
can you send me the code for this.
10-25-2006 10:44 PM
You just use the code you have for each line item.
But this will just pick up the first error for each item (or the header).
And if there is an error in the header, all line items would fail, so in this case you probably wouldn't want to test the rest of the items.
Rob
10-25-2006 10:48 PM
thanks rob
can u send me the code how would i send each item seperatley to bapi.
10-25-2006 10:53 PM
Well, I don't have the code, but like I say, it would be very easy for you to adapt the code you have.
Rob
10-25-2006 10:56 PM
10-25-2006 10:58 PM
Why don't you try to make the changes and if you run into problems, ask for more help at that time.
Rob
10-25-2006 11:01 PM