La primera vez que intente crear un pedido de venta utilizando BAPIS tuve dificultades con las condiciones ya que solo creaba la condición de la primera posición, por tal motivo me gustaría compartir la forma como finalmente me funcionó.
Espero sea de utilidad para ustedes.
Form f_pedido_venta.
Data: ls_header Type bapisdhd1,
lt_partners Type Standard Table Of bapiparnr,
ls_partner Type bapiparnr,
lt_items Type Standard Table Of bapisditm,
ls_item Type bapisditm,
lt_schedule Type Standard Table Of bapischdl,
ls_schedule Type bapischdl,
lt_condiciones Type Standard Table Of bapicond,
ls_condicion Type bapicond,
lt_return Type Standard Table Of bapiret2,
ls_return Type bapiret2,
posicion(6) Type n,
lv_documento Like BAPIVBELN-VBELN.
Data: lv_exception Type Ref To cx_root,
lv_exception_text Type String.
Clear: ls_header,
lt_items[],
lt_condiciones[],
lt_partners[],
lt_schedule[],
lt_return[].
Loop At i_tab_hdr.
ls_header-doc_type = i_tab_hdr-auart.
ls_header-sales_org = i_tab_hdr-vkorg.
ls_header-distr_chan = i_tab_hdr-vtweg.
ls_header-division = i_tab_hdr-spart.
ls_header-sales_off = i_tab_hdr-vkbur.
ls_header-sales_grp = i_tab_hdr-vkgrp.
ls_header-purch_no_c = i_tab_hdr-bstkd.
ls_header-purch_date = i_tab_hdr-bstdk.
ls_partner-partn_role = 'AG'.
ls_partner-partn_numb = i_tab_hdr-kunnr.
Append ls_partner To lt_partners.
posicion = 0.
Loop At i_tab_dtl Where bstkd = i_tab_hdr-bstkd And auart = i_tab_hdr-auart.
Clear: ls_item, ls_condicion, ls_schedule.
posicion = posicion + 10.
ls_item-itm_number = posicion.
ls_item-material = i_tab_dtl-matnr.
ls_item-target_qty = i_tab_dtl-kwmeng.
ls_item-plant = i_tab_dtl-werks.
ls_item-ship_point = i_tab_dtl-vstel.
ls_item-store_loc = i_tab_dtl-lgort.
ls_item-incoterms1 = i_tab_dtl-inco1.
ls_item-Currency = i_tab_dtl-koein.
ls_item-target_qu = i_tab_dtl-kmein.
"ls_item-sales_unit = i_tab_dtl-koein.
"ls_item-profit_ctr = i_tab_dtl-prctr.
Append ls_item To lt_items.
"Condiciones
Data: lv_monto Like bapicurr-bapicurr,
lv_base_cond type BAPIKAWRT1.
Call Function 'BAPI_CURRENCY_CONV_TO_EXTERNAL'
Exporting Currency = i_tab_dtl-koein amount_internal = i_tab_dtl-kbetr
Importing amount_external = lv_monto.
ls_condicion-itm_number = posicion.
ls_condicion-cond_type = 'ZP01'.
ls_condicion-cond_value = lv_monto.
ls_condicion-Currency = i_tab_dtl-koein.
ls_condicion-cond_unit = i_tab_dtl-kmein.
ls_condicion-cond_p_unt = 1.
Append ls_condicion To lt_condiciones.
ls_schedule-itm_number = posicion.
ls_schedule-req_qty = 1.
Append ls_schedule To lt_schedule.
Endloop.
Clear lv_documento.
Try .
Call Function 'BAPI_SALESORDER_CREATEFROMDAT2'
Exporting
order_header_in = ls_header
behave_when_error = space
Importing
salesdocument = lv_documento
Tables
Return = lt_return
order_items_in = lt_items
order_partners = lt_partners
order_schedules_in = lt_schedule
order_conditions_in = lt_condiciones .
If lv_documento Is Not Initial.
Call Function 'BAPI_TRANSACTION_COMMIT' Exporting Wait = 'X' Importing Return = ls_return.
"Pedido de Venta grabado
Perform f_delete_cond Using lv_documento.
Loop At lt_return Into ls_return Where Type = 'S'.
Write: ls_return-Message.
gs_output-texto = ls_return-Message.
Append gs_output To gt_output.
Endloop.
Else.
Loop At lt_return Into ls_return Where Type = 'E'.
Write: ls_return-Message.
gs_output-texto = ls_return-message.
Append gs_output TO gt_output.
Endloop.
Endif.
Catch cx_root Into lv_exception.
lv_exception_text = lv_exception->get_text( ).
Message s000(fb) With lv_exception_text.
Endtry.
Endloop.
Endform. "f_pedido_venta
Me parece bien....la solució.
ResponderEliminarCómo es posible hacer que la unidad de medida del material no tome la que tiene por defecto? No he podido lograrlo, ni con unit_sales, ni con la unidad ISO, podrían guíarme?
ResponderEliminar