‎2006 Oct 18 3:57 PM
Hi, All I am new to BAPI can one suggest me how to do this,
i need to create a function module Z_BAPI_GOODSMVT_CREATE in which i should call BAPI_GOODSMVT_CREATE .
the reason for this is,
Whenever a file is received, SAP XI will call the new function module Z_BAPI_GOODSMVT_CREATE to accomplish a goods movement and equipment record creation. this function will, in large part, consist of simply passing parameters to and from BAPI_GOODSMVT_CREATE. In addition, this process will need to derive the plant and storage location prior to calling the BAPI, and Z_BAPI_GOODSMVT_CREATE need to send an email alert to a distribution list should the BAPI fail for any reason.
The program should process every item on the file, when there is an error in processing any of the items, an email (subject and email content) should send out according to the alias in the email table. Then the program should continue to process the items in the file until the end of the program.
Thanks.
‎2006 Oct 18 4:03 PM
Hi Ars,
The algorithm would be something like this:
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = header
goodsmvt_code = c_gmcode
TESTRUN = 'X'
TABLES
goodsmvt_item = items
return = lt_return.
if not lt_return[] is initial.
Error in creating mat doc
*Create the text in the it_htm internal table.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = w_doc_data
put_in_outbox = 'X'
COMMIT_WORK = 'X'
tables
object_content = it_htm
receivers = t_receivers
exceptions
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
endif.
Regards,
ravi
‎2006 Oct 18 4:03 PM
Design the Z_BAPI_GOODSMVT_CREATE with all the import/export/table as like that of BAPI_GOODSMVT_CREATE.
Check the below code for how to call BAPI_GOODSMVT_CREATE:
Header Data
v_header-pstng_date = sy-datum.
v_header-doc_date = sy-datum.
Code Group
v_gm_code-gm_code = '03'.
******Mandatory fields passed into BAPI***
CLEAR i_items[].
wa_items-material = wa_mseg1-matnr.
wa_items-plant = wa_mseg1-werks.
wa_items-stge_loc = wa_mseg1-lgort.
wa_items-move_type = wa_mseg1-bwart.
wa_items-entry_qnt = wa_mseg1-lossquantity.
wa_items-costcenter = 'SC120300'.
APPEND wa_items TO i_items.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = v_header
goodsmvt_code = v_gm_code
TESTRUN = ' '
IMPORTING
goodsmvt_headret = wa_headret
materialdocument = wa_matdoc
matdocumentyear = wa_matdocyr
TABLES
goodsmvt_item = i_items
GOODSMVT_SERIALNUMBER =
return = i_return_goods .
Check the code for mailing to distribution list:
FM <b>'SO_NEW_DOCUMENT_ATT_SEND_API1'</b> is used to send mails to distribution list with rec_type = 'C'.
*Sending mails to distribution list*
PERFORM f1001_mail_distribution_list.
&----
*& Form f1001_mail_Distribution_list
&----
text
----
--> p1 text
<-- p2 text
----
FORM f1001_mail_distribution_list .
DATA: lws_docdata LIKE sodocchgi1,
li_objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
li_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
li_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
li_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
li_objhex LIKE solix OCCURS 10 WITH HEADER LINE,
li_reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
DATA: lws_tab_lines TYPE i,
lws_doc_size TYPE i,
lws_att_type LIKE soodk-objtp.
CLEAR: lws_docdata, li_objpack, li_objhead, li_objtxt, li_objbin,
li_objhex, li_reclist, lws_tab_lines, lws_doc_size, lws_att_type.
REFRESH: li_objpack, li_objhead, li_objtxt, li_objbin, li_objhex,
li_reclist.
lws_docdata-obj_name = text-019. "EUC
CONCATENATE co_01 text-018 co_10 text-018 ws_conf_year
INTO ws_conf_date.
CONCATENATE text-006 ws_conf_date INTO lws_docdata-obj_descr
SEPARATED BY space.
CONCATENATE text-007 ws_conf_date text-008 INTO li_objtxt
SEPARATED BY space.
APPEND li_objtxt.
CONCATENATE text-009 text-010 ws_conf_date INTO li_objtxt
SEPARATED BY space.
APPEND li_objtxt.
DESCRIBE TABLE li_objtxt LINES lws_tab_lines.
READ TABLE li_objtxt INDEX lws_tab_lines.
lws_docdata-doc_size = ( lws_tab_lines - 1 ) * 255 +
STRLEN( li_objtxt ).
CLEAR li_objpack-transf_bin.
li_objpack-head_start = 1.
li_objpack-head_num = 0.
li_objpack-body_start = 1.
li_objpack-body_num = lws_tab_lines.
li_objpack-doc_type = text-020. "RAW
APPEND li_objpack.
li_reclist-receiver = text-014. "SGD_BUS_ANLT
li_reclist-rec_type = text-021. "C
APPEND li_reclist.
li_reclist-receiver = text-013. "SGD_SAL_MNGR
li_reclist-rec_type = text-021. "C
APPEND li_reclist.
li_reclist-receiver = text-012. "SGD_SAL_SUPT
li_reclist-rec_type = text-021. "C
APPEND li_reclist.
li_reclist-receiver = sy-uname.
li_reclist-rec_type = text-022. "B
APPEND li_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lws_docdata
put_in_outbox = c_x
commit_work = c_x
TABLES
packing_list = li_objpack
object_header = li_objhead
contents_bin = li_objbin
contents_txt = li_objtxt
receivers = li_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
wa_idoc_status-status = co_stat_appl_err.
wa_idoc_status-msgty = c_stat_err.
wa_idoc_status-msgid = c_msg_class_spa.
wa_idoc_status-msgno = co_001.
wa_idoc_status-msgv1 = text-023.
CASE sy-subrc.
WHEN 1.
wa_idoc_status-msgv2 = text-024.
WHEN 2.
wa_idoc_status-msgv2 = text-025.
WHEN 3.
wa_idoc_status-msgv2 = text-026.
WHEN 4.
wa_idoc_status-msgv2 = text-027.
WHEN 5.
wa_idoc_status-msgv2 = text-028.
WHEN 6.
wa_idoc_status-msgv2 = text-029.
WHEN 7.
wa_idoc_status-msgv2 = text-030.
ENDCASE.
wa_idoc_status-msgv3 = space.
wa_idoc_status-msgv4 = space.
ws_flag = c_x.
EXIT.
ENDIF.
ENDFORM. " f1001_mail_Distribution_list
Hope it is helpful.
Regards,
Prakash.