Función para realizar movimientos de mercancía

Creación de función SM37
function zsd_create_mov_merc.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" VALUE(FECHA_CONTAB) TYPE BUDAT
*" VALUE(FECHA_CREACION) TYPE BLDAT
*" VALUE(DOCUMENTO_REF) TYPE XBLNR
*" VALUE(HACER_COMMIT) TYPE BOOLEAN OPTIONAL
*" 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
*" ITEMS STRUCTURE BAPI2017_GM_ITEM_CREATE
*" SERIAL STRUCTURE BAPI2017_GM_SERIALNUMBER OPTIONAL
*" RETURN STRUCTURE BAPIRET2
*"----------------------------------------------------------------------
data: goodsmvt_header like bapi2017_gm_head_01,
goodsmvt_code like bapi2017_gm_code.

goodsmvt_header-pstng_date = fecha_contab.
goodsmvt_header-doc_date = fecha_creacion.
goodsmvt_header-ref_doc_no = documento_ref.

goodsmvt_code-gm_code = '04'.
* GMCODE Table T158G
* 01 - MB01 - Recepción de mcía desde orden de compras
* 02 - MB31 - Entrada de mercancías para orden de fabricación
* 03 - MB1A - Registrar salida de mcía.
* 04 - MB1B - Registrar traspaso
* 05 - MB1C - Entrada mercancías p.otras operaciones
* 06 - MB11 - Movimientos de mercancía



call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = goodsmvt_header
goodsmvt_code = goodsmvt_code
testrun = ''
importing
goodsmvt_headret = goodsmvt_headret
materialdocument = materialdocument
matdocumentyear = matdocumentyear
tables
goodsmvt_item = items
goodsmvt_serialnumber = serial
return = return.

"Hacer commit o no
if hacer_commit = 'X'.
if sy-subrc eq 0.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
else.
call function 'BAPI_TRANSACTION_ROLLBACK'.
endif.
endif.

endfunction.

Implementación Ej.:
data: goodsmvt_headret type bapi2017_gm_head_ret,
materialdocument type bapi2017_gm_head_ret-mat_doc,
matdocumentyear type bapi2017_gm_head_ret-doc_year,
items type standard table of bapi2017_gm_item_create,
wa_items type bapi2017_gm_item_create,
serial type standard table of bapi2017_gm_serialnumber,
wa_serial type bapi2017_gm_serialnumber,
return type standard table of bapiret2,
wa_return type bapiret2.

"Armar datos para traspaso
clear wa_lips.
loop at ct_xlips into wa_lips.
entrega = wa_lips-vbeln.

clear: wa_items.
wa_items-material = wa_lips-matnr.
wa_items-plant = wa_lips-werks.
wa_items-stge_loc = wa_lips-lgort.
wa_items-batch = wa_lips-charg.
wa_items-move_type = 'Z44'.
wa_items-entry_qnt = wa_lips-lfimg.
append wa_items to items.

clear: wa_serial.
wa_serial-matdoc_itm = wa_lips-lfimg.
wa_serial-serialno = wa_lips-equnr.
append wa_serial to serial.

clear wa_lips.
endloop.

"Crear Movimiento Z44
call function 'ZSD_CREATE_MOV_MERC'
exporting
fecha_contab = sy-datum
fecha_creacion = sy-datum
documento_ref = entrega
importing
goodsmvt_headret = goodsmvt_headret
materialdocument = materialdocument
matdocumentyear = matdocumentyear
tables
items = items
serial = serial
return = return.

Comentarios

Entradas populares de este blog

Direcciones en SAP

Funcion MD_CONVERT_MATERIAL_UNIT