bapi_po_create

Colapsar
X
 
  • Tiempo
  • Mostrar
Limpiar Todo
nuevos mensajes
  • WgaviriaStuva
    Junior Member
    • jun
    • 12

    #1

    bapi_po_create

    Estoy intentando crear una orden de compra de servicio, me esta dando muchos problemas ¿alguien tiene un ejemplo con este caso? .... gracias
  • Carlos J. Ortega González
    Junior Member
    • jun
    • 28

    #2
    Este es parte de un código que yo utilice, espero té de una ayuda

    Saludos
    Carlos



    *&---------------------------------------------------------------------*
    *& Form f_genera_documentos
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    FORM f_genera_documentos.

    DATA: vl_lifnr(10) TYPE c,
    vl_posnr(4) TYPE n,
    vl_posnr_c(4) TYPE c.


    * Se preparan las tablas para que los datos sean procesados por el BAPI
    vl_lifnr = space.

    WRITE sy-datum TO v_datum.

    FREE: itab_doc_item,
    itab_item_update,
    itab_doc_sched,
    itab_schd_update,
    itab_doc_cond,
    itab_cond_update,
    wa_doc_header.

    CLEAR: itab_doc_item,
    itab_item_update,
    itab_doc_sched,
    itab_schd_update,
    itab_doc_cond,
    itab_cond_update,
    wa_head_update.

    * Se pobla las tablas para que los datos sean procesados por el BAPI
    LOOP AT itab_layout.

    IF vl_lifnr NE itab_layout-lifnr.

    IF vl_lifnr NE space.
    PERFORM f_ejecuta_bapi.

    FREE: itab_doc_item,
    itab_item_update,
    itab_doc_sched,
    itab_schd_update,
    itab_doc_cond,
    itab_cond_update,
    wa_doc_header.

    CLEAR: itab_doc_item,
    itab_item_update,
    itab_doc_sched,
    itab_schd_update,
    itab_doc_cond,
    itab_cond_update,
    wa_head_update.
    ENDIF.

    * Header
    wa_doc_header-doc_type = itab_layout-bsart.
    wa_doc_header-creat_date = v_datum.
    wa_doc_header-vendor = itab_layout-lifnr.
    wa_doc_header-purch_org = itab_layout-ekorg.
    wa_doc_header-pur_group = itab_layout-ekgrp.
    wa_doc_header-currency = itab_layout-waers.

    wa_head_update-doc_type = c_x.
    wa_head_update-creat_date = c_x.
    wa_head_update-vendor = c_x.
    wa_head_update-purch_org = c_x.
    wa_head_update-pur_group = c_x.
    wa_head_update-currency = c_x.

    ENDIF.

    vl_posnr = itab_layout-ebelp.

    WRITE vl_posnr TO vl_posnr_c.

    * Item
    itab_doc_item-po_item = vl_posnr_c.
    itab_doc_item-material = itab_layout-ematn.
    itab_doc_item-short_text = itab_layout-txz01.
    itab_doc_item-quantity = itab_layout-menge.
    itab_doc_item-po_unit = itab_layout-meins.
    itab_doc_item-gr_to_date = v_datum.
    itab_doc_item-net_price = itab_layout-netpr.
    itab_doc_item-plant = itab_layout-name1.
    itab_doc_item-matl_group = itab_layout-wgbez.
    itab_doc_item-stge_loc = itab_layout-lgobe.
    APPEND itab_doc_item.

    itab_item_update-po_item = vl_posnr_c.
    itab_item_update-material = c_x.
    itab_item_update-short_text = c_x.
    itab_item_update-quantity = c_x.
    itab_item_update-po_unit = c_x.
    itab_item_update-gr_to_date = c_x.
    itab_item_update-net_price = c_x.
    itab_item_update-plant = c_x.
    itab_item_update-matl_group = c_x.
    itab_item_update-stge_loc = c_x.
    APPEND itab_item_update.

    * Schedul
    itab_doc_sched-po_item = vl_posnr_c.
    itab_doc_sched-sched_line = vl_posnr_c.
    itab_doc_sched-del_datcat_ext = itab_layout-elpei.
    itab_doc_sched-delivery_date = itab_layout-eeind.

    APPEND itab_doc_sched.

    itab_schd_update-po_item = vl_posnr_c.
    itab_schd_update-sched_line = vl_posnr_c.
    itab_schd_update-del_datcat_ext = c_x.
    itab_schd_update-delivery_date = c_x.

    APPEND itab_schd_update.

    * Condiciones
    itab_doc_cond-itm_number = c_itm_number.
    itab_doc_cond-cond_count = c_cond_count.
    itab_doc_cond-cond_type = c_cond_type.
    itab_doc_cond-cond_value = itab_layout-netpr.
    itab_doc_cond-currency = itab_layout-waers.
    itab_doc_cond-change_id = c_change_id.

    APPEND itab_doc_cond.

    itab_cond_update-itm_number = c_x.
    itab_cond_update-cond_count = c_x.
    itab_cond_update-cond_type = c_x.
    itab_cond_update-cond_value = c_x.
    itab_cond_update-currency = c_x.
    itab_cond_update-change_id = c_x.

    APPEND itab_cond_update.

    * vl_posnr = vl_posnr + 10.

    ENDLOOP.

    IF sy-subrc EQ 0.
    PERFORM f_ejecuta_bapi.
    ENDIF.

    ENDFORM. " f_genera_documentos


    *&---------------------------------------------------------------------*
    *& Form f_ejecuta_bapi
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    FORM f_ejecuta_bapi.

    * Se limpia la tabla interna para recibir los mensajes del proceso del BAPI
    FREE itab_return.
    CLEAR itab_return.

    * Se ejecuta el BAPI para la creación de la orden de compra
    CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
    poheader = wa_doc_header
    poheaderx = wa_head_update
    no_price_from_po = c_x
    TABLES
    return = itab_return
    poitem = itab_doc_item
    poitemx = itab_item_update
    pocond = itab_doc_cond
    pocondx = itab_cond_update
    poschedule = itab_doc_sched
    poschedulex = itab_schd_update
    posrvaccessvalues = itab_doc_srvacc.

    * Se ejecuta el Commit par que la transacción quede en firme
    PERFORM f_bapi_commit.

    * Se presentan los mensajes que se generaron en la ejecución del BAPI
    LOOP AT itab_return. "where type eq c_error.

    WRITE:/ itab_return-type,
    itab_return-id,
    itab_return-number,
    itab_return-message,
    itab_return-log_no,
    itab_return-log_msg_no,
    itab_return-message_v1,
    itab_return-message_v2,
    itab_return-message_v3,
    itab_return-message_v4,
    itab_return-parameter,
    itab_return-row,
    itab_return-field,
    itab_return-system.

    ENDLOOP.

    ENDFORM. " f_ejecuta_bapi


    *&---------------------------------------------------------------------*
    *& Form f_bapi_commit
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    FORM f_bapi_commit.

    * Se ejecuta el Commit par que la transacción quede en firme
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    wait = 'X'
    IMPORTING
    return = itab_return1.

    ENDFORM. " f_bapi_commit

    Comentario

    Trabajando...