0% found this document useful (0 votes)
6 views

BAPI BAPI_PO_CREATE1

The document outlines the process of creating a purchase order in an SAP system using BAPIs. It includes the definition of data structures for the purchase order header, items, and associated services, along with the logic for populating these structures based on input data. Finally, it calls the BAPI function to create the purchase order and logs the results.

Uploaded by

Eduardo RC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

BAPI BAPI_PO_CREATE1

The document outlines the process of creating a purchase order in an SAP system using BAPIs. It includes the definition of data structures for the purchase order header, items, and associated services, along with the logic for populating these structures based on input data. Finally, it calls the BAPI function to create the purchase order and logs the results.

Uploaded by

Eduardo RC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

DATA(ls_header) = VALUE bapimepoheader( comp_code = is_eban-bukrs

doc_type = 'ZSER'
vendor = is_eban-lifnr
pmnttrms = is_eban-zterm
purch_org = is_eban-ekorg
pur_group = is_eban-ekgrp
vper_start = sy-datum
vper_end = is_eban-kdate
currency = is_eban-waers
collect_no = '1' ).

DATA(ls_headerx) = VALUE bapimepoheaderx( comp_code = abap_true


doc_type = abap_true
vendor = abap_true
pmnttrms = abap_true
purch_org = abap_true
pur_group = abap_true
vper_start = abap_true
vper_end = abap_true
currency = abap_true
collect_no = abap_true ).

DATA(lt_extensionin) = VALUE bapiparex_t( ( structure = 'BAPI_TE_MEPOHEADER'


valuepart1 = VALUE
bapi_te_mepoheader( zzpref = 'ESTR' ) )
( structure = 'BAPI_TE_MEPOHEADERX'
valuepart1 = VALUE
bapi_te_mepoheaderx( zzpref = abap_true ) ) ).

DATA: lt_items_pckg_no LIKE bapiekpoc-pckg_no.

DATA:lv_items_pckg_no TYPE bapiekpoc-pckg_no,


lv_lt_services_line_no TYPE bapiesllc-line_no,
lv_serial_no LIKE bapiekkn-serial_no,
lv_extrow TYPE extrow.

DATA: lv_ccount_serial_no TYPE bapiekkn-serial_no.

DATA: lv_ebelp TYPE ekpo-ebelp,


lv_orden_compra TYPE bapimepoheader-po_number.

DATA: lt_item TYPE bapimepoitem_tp,


lt_itemx TYPE bapimepoitemx_tp.

DATA: lt_poservices TYPE STANDARD TABLE OF bapiesllc,


lt_posrvaccessvalues TYPE STANDARD TABLE OF bapiesklc.

DATA: lt_poschedule TYPE TABLE OF bapimeposchedule,


lt_poschedulex TYPE TABLE OF bapimeposchedulx.

DATA: lt_ccount TYPE TABLE OF bapimepoaccount ,


lt_return TYPE TABLE OF bapiret2,
lt_ccountx TYPE TABLE OF bapimepoaccountx.

DATA: lv_packno TYPE packno,


lv_line_no TYPE srv_line_no.
CLEAR : lv_items_pckg_no, lv_ebelp.
lv_lt_services_line_no = 1.
lv_items_pckg_no = 1.

* Posiciones
CLEAR: lt_item[] , lt_itemx[], lt_ccount[], lt_ccountx[], lt_poschedule[],
lt_poschedulex[], lt_poservices[], lt_posrvaccessvalues[], lv_ebelp,
lv_packno, lv_line_no.
LOOP AT gt_eban ASSIGNING FIELD-SYMBOL(<eban>) FROM iv_tabix.
IF <eban>-banfn = is_eban-banfn.
lv_ebelp = lv_ebelp + 10.
lv_packno = lv_packno + 1.

****** Datos de asignaciones de cuentas ******


lv_ccount_serial_no = 1.

lt_item = VALUE #( BASE lt_item ( po_item = lv_ebelp


quantity = <eban>-menge
acctasscat = <eban>-knttp
item_cat = <eban>-pstyp
plant = <eban>-werks
preq_name = sy-uname
pckg_no = lv_packno "1
plan_del = '7'
agreement = <eban>-konnr
agmt_item = <eban>-ktpnr
preq_no = <eban>-banfn
preq_item = <eban>-bnfpo ) ).

lt_itemx = VALUE #( BASE lt_itemx ( po_item = lv_ebelp


quantity = abap_true
acctasscat = abap_true
item_cat = abap_true
plant = abap_true
preq_name = abap_true
pckg_no = abap_true
plan_del = abap_true
agreement = abap_true
agmt_item = abap_true
preq_no = abap_true
preq_item = abap_true ) ).

READ TABLE gt_ebkn ASSIGNING FIELD-SYMBOL(<ebkn>) WITH KEY banfn = <eban>-


banfn
bnfpo = <eban>-
bnfpo BINARY SEARCH.
IF sy-subrc EQ 0.

lt_ccount = VALUE #( BASE lt_ccount ( po_item = lv_ebelp


serial_no = lv_ccount_serial_no
quantity = <eban>-menge
gl_account = <ebkn>-sakto
orderid = <ebkn>-aufnr ) ).

* ACC: Flags de imputacion


lt_ccountx = VALUE #( BASE lt_ccountx ( po_item = lv_ebelp
serial_no = abap_true
quantity = abap_true
po_itemx = abap_true
serial_nox = abap_true
gl_account = abap_true
orderid = abap_true
net_value = abap_true ) ).
ENDIF.
DATA(lv_delivery_date) = CONV datum( sy-datum + 7 ).
lt_poschedule = VALUE #( BASE lt_poschedule ( po_item = lv_ebelp
delivery_date = |
{ lv_delivery_date+6(2) }.{ lv_delivery_date+4(2) }.{ lv_delivery_date(4) }|
) ).

lt_poschedulex = VALUE #( BASE lt_poschedulex ( po_item = lv_ebelp


delivery_date =
abap_true ) ).

READ TABLE gt_esll TRANSPORTING NO FIELDS WITH KEY packno = <eban>-packno


BINARY SEARCH.
IF sy-subrc EQ 0.
LOOP AT gt_esll ASSIGNING FIELD-SYMBOL(<esll>) FROM sy-tabix.
IF <esll>-packno = <eban>-packno.
lv_lt_services_line_no = 1.
READ TABLE gt_esll_sub TRANSPORTING NO FIELDS WITH KEY packno = <esll>-
sub_packno BINARY SEARCH.
IF sy-subrc EQ 0.
LOOP AT gt_esll_sub ASSIGNING FIELD-SYMBOL(<esll_sub>) FROM sy-tabix.
IF <esll_sub>-packno = <esll>-sub_packno.
****** Datos del Encabezado del servicio ******
ADD 1 TO lv_extrow.

IF lv_lt_services_line_no = 1.
APPEND INITIAL LINE TO lt_poservices ASSIGNING FIELD-
SYMBOL(<fs_poservices>).
<fs_poservices>-pckg_no = lv_packno.
<fs_poservices>-line_no = 1.
<fs_poservices>-outl_level = '0'.
<fs_poservices>-outl_ind = 'X'.
<fs_poservices>-subpckg_no = lv_packno + 1.
ADD 1 TO lv_packno.
ENDIF.
lv_lt_services_line_no = lv_lt_services_line_no + 1.

IF lv_line_no IS INITIAL.
ADD 3 TO lv_line_no.
ELSE.
ADD 1 TO lv_line_no.
ENDIF.

APPEND INITIAL LINE TO lt_poservices ASSIGNING


<fs_poservices> .

<fs_poservices>-pckg_no = lv_packno.
<fs_poservices>-line_no = lv_line_no.
<fs_poservices>-ext_line = <esll_sub>-extrow.
<fs_poservices>-base_uom = <esll_sub>-meins.
<fs_poservices>-quantity = <esll_sub>-menge.
<fs_poservices>-price_unit = <esll_sub>-peinh.
<fs_poservices>-gr_price = <esll_sub>-brtwr.
<fs_poservices>-net_value = <esll_sub>-netwr.
<fs_poservices>-short_text = <esll_sub>-ktext1.
<fs_poservices>-matl_group = <esll_sub>-matkl.
<fs_poservices>-pln_pckg = <esll_sub>-sub_packno.
<fs_poservices>-pln_line = <esll_sub>-introw.
<fs_poservices>-service = <esll_sub>-srvpos.

APPEND INITIAL LINE TO lt_posrvaccessvalues ASSIGNING FIELD-


SYMBOL(<fs_posrvaccessvalues>).
<fs_posrvaccessvalues>-pckg_no = lv_packno.
<fs_posrvaccessvalues>-line_no = lv_line_no.
<fs_posrvaccessvalues>-serial_no = '01'.
<fs_posrvaccessvalues>-serno_line = '01'.
<fs_posrvaccessvalues>-percentage = 100. "'0'.
<fs_posrvaccessvalues>-quantity = <esll_sub>-menge .
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDLOOP.

CALL FUNCTION 'BAPI_PO_CREATE1'


EXPORTING
poheader = ls_header
poheaderx = ls_headerx
IMPORTING
exppurchaseorder = lv_orden_compra
TABLES
return = lt_return
poitem = lt_item
poitemx = lt_itemx
poservices = lt_poservices
posrvaccessvalues = lt_posrvaccessvalues
poaccount = lt_ccount
poaccountx = lt_ccountx
extensionin = lt_extensionin
poschedule = lt_poschedule
poschedulex = lt_poschedulex.

IF lv_orden_compra IS NOT INITIAL.


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.

WAIT UP TO 1 SECONDS.
ENDIF.

LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<return>) WHERE type = 'S' or type =


'E'.
APPEND INITIAL LINE TO gt_log ASSIGNING FIELD-SYMBOL(<log>).
<log>-banfn = is_eban-banfn.
<log>-type = <return>-type.
<log>-id = <return>-id.
<log>-number = <return>-number.
<log>-message = <return>-message.
ENDLOOP.

You might also like