FUNCTION CREATE_DELIVERY.
*"----------------------------------------------------------------------
*"*"Interface local:
*" IMPORTING
*" VALUE(IS_OUTB) TYPE BAPIFLAG-BAPIFLAG DEFAULT ' '
*" VALUE(T_HEADER) LIKE Z_HEADER STRUCTURE Z_HEADER
*" OPTIONAL
*" VALUE(IS_TRANSFER) TYPE BAPIFLAG-BAPIFLAG DEFAULT ' '
*" TABLES
*" T_ITENS STRUCTURE Z_ITEM OPTIONAL
*" T_ITENS_CREATED STRUCTURE Z_ITEM OPTIONAL
*" T_MESSAGE STRUCTURE Z_MESSAGE OPTIONAL
*"----------------------------------------------------------------------
DATA: TI_VBSK TYPE VBSK.
IF IS_OUTB EQ 'X'.
*** OutBound
DATA: DELIVERY LIKE BAPIVBELN-VBELN.
DATA: C_REF_NF TYPE XBLNR_V_LONG.
DATA: TI_CREATED_ITEMS TYPE BAPIDLVITEMCREATED OCCURS 0 WITH HEADER LINE,
TI_MSGRETURN TYPE BAPIRET2 OCCURS 0 WITH HEADER LINE,
EI_DUE_DATE LIKE BAPIDLVCREATEHEADER-DUE_DATE.
EI_DUE_DATE = T_HEADER-DATA.
IF IS_TRANSFER EQ 'X'.
**** Carregando os Itens - Delivery OutBound de Pedido de Transfência
DATA: TI_STOCK_TRANS_ITEMS TYPE BAPIDLVREFTOSTO OCCURS 0 WITH HEADER LINE.
LOOP AT T_ITENS.
TI_STOCK_TRANS_ITEMS-REF_DOC = T_ITENS-REFDOC.
TI_STOCK_TRANS_ITEMS-REF_ITEM = T_ITENS-REFITEM.
TI_STOCK_TRANS_ITEMS-DLV_QTY = T_ITENS-QUANTIDADE.
TI_STOCK_TRANS_ITEMS-SALES_UNIT = T_ITENS-UOM.
TI_STOCK_TRANS_ITEMS-SALES_UNIT_ISO = T_ITENS-UOM.
C_REF_NF = T_ITENS-OBSERVACAO.
APPEND TI_STOCK_TRANS_ITEMS.
ENDLOOP.
**** Criando a Delivery OutBound Transferencia - VL10B -- SD - Entrega Recebimento
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_STO'
EXPORTING
SHIP_POINT = T_HEADER-PLANTA
DUE_DATE = EI_DUE_DATE
DEBUG_FLG = ' '
NO_DEQUEUE = 'X'
TABLES
STOCK_TRANS_ITEMS = TI_STOCK_TRANS_ITEMS
RETURN = TI_MSGRETURN
CREATED_ITEMS = TI_CREATED_ITEMS
EXCEPTIONS
OTHERS = 1.
ELSE.
**** Carregando os Itens - Delivery OutBound Pedido de Venda
DATA: TI_BAPIDLVREFTOSALESORDER TYPE BAPIDLVREFTOSALESORDER OCCURS 0 WITH HEADER LINE.
LOOP AT T_ITENS.
TI_BAPIDLVREFTOSALESORDER-REF_DOC = T_ITENS-REFDOC.
TI_BAPIDLVREFTOSALESORDER-REF_ITEM = T_ITENS-REFITEM.
TI_BAPIDLVREFTOSALESORDER-DLV_QTY = T_ITENS-QUANTIDADE.
TI_BAPIDLVREFTOSALESORDER-SALES_UNIT = T_ITENS-UOM.
TI_BAPIDLVREFTOSALESORDER-SALES_UNIT_ISO = T_ITENS-UOM.
C_REF_NF = T_ITENS-OBSERVACAO.
APPEND TI_BAPIDLVREFTOSALESORDER.
ENDLOOP.
**** Criando a Delivery OutBound -- VL01N -- SD - Entrega Recebimento
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
EXPORTING
DUE_DATE = EI_DUE_DATE
NO_DEQUEUE = 'X'
TABLES
SALES_ORDER_ITEMS = TI_BAPIDLVREFTOSALESORDER
RETURN = TI_MSGRETURN
CREATED_ITEMS = TI_CREATED_ITEMS
EXCEPTIONS
OTHERS = 1.
ENDIF.
**** Carregando os Itens de saída - Delivery OutBound
LOOP AT TI_CREATED_ITEMS.
T_ITENS_CREATED-MATERIAL = TI_CREATED_ITEMS-MATERIAL.
T_ITENS_CREATED-QUANTIDADE = TI_CREATED_ITEMS-DLV_QTY.
T_ITENS_CREATED-UOM = TI_CREATED_ITEMS-SALES_UNIT.
T_ITENS_CREATED-REFDOC = TI_CREATED_ITEMS-REF_DOC.
T_ITENS_CREATED-REFITEM = TI_CREATED_ITEMS-REF_ITEM.
T_ITENS_CREATED-REFDOC_OUT = TI_CREATED_ITEMS-DELIV_NUMB.
T_ITENS_CREATED-REFITEM_OUT = TI_CREATED_ITEMS-DELIV_ITEM.
DELIVERY = TI_CREATED_ITEMS-DELIV_NUMB. "Remessa sempre será o mesmo
APPEND T_ITENS_CREATED.
ENDLOOP.
**** Carregando as mensagens de saída - Delivery OutBound
LOOP AT TI_MSGRETURN.
IF TI_MSGRETURN-TYPE NE 'S'.
T_MESSAGE-TYPE = TI_MSGRETURN-TYPE.
T_MESSAGE-ID = TI_MSGRETURN-ID.
T_MESSAGE-NUMBER = TI_MSGRETURN-NUMBER.
T_MESSAGE-MESSAGE = TI_MSGRETURN-MESSAGE.
APPEND T_MESSAGE.
ENDIF.
ENDLOOP.
ELSE.
*** InBound
**** Carregando o Cabeçalho - Delivery Inbound
TI_VBSK-SMART = T_HEADER-TIPOGRUPO.
TI_VBSK-ERNAM = T_HEADER-RESPONSAVEL.
TI_VBSK-ERDAT = T_HEADER-DATA.
TI_VBSK-UZEIT = T_HEADER-HHMMSS.
TI_VBSK-VSTEL = T_HEADER-PLANTA.
TI_VBSK-PROGRAMM = T_HEADER-PROGRAMA.
TI_VBSK-BRGEW = T_HEADER-PESO_TOTAL.
**** Carregando os Itens - Delivery Inbound
DATA: TI_KOMDLGN TYPE KOMDLGN OCCURS 0 WITH HEADER LINE.
LOOP AT T_ITENS.
TI_KOMDLGN-LFART = T_ITENS-TIPO.
TI_KOMDLGN-WERKS = T_ITENS-PLANTA.
TI_KOMDLGN-LFDAT = T_ITENS-DATA.
TI_KOMDLGN-WADAT_IST = T_ITENS-DATA.
TI_KOMDLGN-MATNR = T_ITENS-MATERIAL.
TI_KOMDLGN-EMATN = T_ITENS-MATERIAL.
TI_KOMDLGN-LFIMG = T_ITENS-QUANTIDADE.
TI_KOMDLGN-VRKME = T_ITENS-UOM.
TI_KOMDLGN-MEINS = T_ITENS-UOM.
TI_KOMDLGN-GEWEI = T_ITENS-UOM.
TI_KOMDLGN-VGBEL = T_ITENS-REFDOC.
TI_KOMDLGN-VGPOS = T_ITENS-REFITEM.
TI_KOMDLGN-LGORT = T_ITENS-DEPOSITO.
TI_KOMDLGN-VGTYP = T_ITENS-CATEGORIA1.
TI_KOMDLGN-PSTYV = T_ITENS-CATEGORIA2.
TI_KOMDLGN-LIFNR = T_ITENS-FORNECEDOR.
TI_KOMDLGN-BWART = T_ITENS-MOVIMENTO.
TI_KOMDLGN-LIFEX = T_ITENS-OBSERVACAO.
TI_KOMDLGN-UMVKZ = T_ITENS-NUMERADOR.
TI_KOMDLGN-UMVKN = T_ITENS-DENOMINADOR.
TI_KOMDLGN-NOWAB = 'X'. "Não permite entrada de mercadoria pela Remessa
TI_KOMDLGN-KZAZU = 'X'. "Para agrupar as remessas
TI_KOMDLGN-VSBED = T_ITENS-ITINERARIO.
TI_KOMDLGN-INCO1 = T_ITENS-INCOTERMS.
TI_KOMDLGN-TRAID = T_ITENS-VEICULO.
APPEND TI_KOMDLGN.
ENDLOOP.
**** Criando a Delivery Inbound -- VL31N -- MM - Recebimento
DATA: TI_LIPS TYPE LIPS OCCURS 0 WITH HEADER LINE,
TI_XVBFS TYPE VBFS OCCURS 0 WITH HEADER LINE,
TI_XVBLS TYPE VBLS OCCURS 0 WITH HEADER LINE,
TI_ET_SPE_VBFS TYPE /SPE/VBFS OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'GN_DELIVERY_CREATE'
EXPORTING
VBSK_I = TI_VBSK
NO_COMMIT = 'X'
IF_SYNCHRON = 'X'
if_create_dec = ' '
IF_NO_DEQUE = ' '
IF_CHECK_UOM = ' '
IF_NO_PARTNER_DIALOG = 'X'
TABLES
XKOMDLGN = TI_KOMDLGN
XVBFS = TI_XVBFS
XVBLS = TI_XVBLS
ET_SPE_VBFS = TI_ET_SPE_VBFS
XXLIPS = TI_LIPS
EXCEPTIONS
OTHERS = 1.
**** Carregando os itens de saída - Delivery Inbound
LOOP AT TI_LIPS.
T_ITENS_CREATED-REFDOC = TI_LIPS-VGBEL.
T_ITENS_CREATED-REFITEM = TI_LIPS-VGPOS.
T_ITENS_CREATED-REFDOC_OUT = TI_LIPS-VBELN.
T_ITENS_CREATED-REFITEM_OUT = TI_LIPS-POSNR.
T_ITENS_CREATED-QUANTIDADE = TI_LIPS-LFIMG.
T_ITENS_CREATED-UOM = TI_LIPS-MEINS.
APPEND T_ITENS_CREATED.
ENDLOOP.
**** Carregando as mensagens de saída - Delivery OutBound
LOOP AT TI_ET_SPE_VBFS.
IF TI_ET_SPE_VBFS-MSGTY NE 'S'.
T_MESSAGE-TYPE = TI_ET_SPE_VBFS-MSGTY.
T_MESSAGE-ID = TI_ET_SPE_VBFS-MSGID.
T_MESSAGE-NUMBER = TI_ET_SPE_VBFS-MSGNO.
T_MESSAGE-MESSAGE = TI_ET_SPE_VBFS-MSGV1.
APPEND T_MESSAGE.
ENDIF.
ENDLOOP.
ENDIF.
ENDFUNCTION.
Nenhum comentário:
Postar um comentário