SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

BAPI_PO_CREATE1



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
Lord
Профессионал
Профессионал



Joined: 10 Sep 2007
Posts: 168

PostPosted: Wed Sep 19, 2007 5:48 pm    Post subject: BAPI_PO_CREATE1 Reply with quote

Code:
*&---------------------------------------------------------------------*
*& Report ZCHARLI *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

*& *
*&---------------------------------------------------------------------*
*& Program demonstrates the BAPI call to create Purchase Order *
*& Minimum required parameters are used are as per the current *
*& system configuration *
*&---------------------------------------------------------------------*
REPORT ZBAPI_CREATE_PO .
*&---------------------------------------------------------------------*
*DATA DECLARATION
CONSTANTS : C_X VALUE 'X'.

*Structures to hold PO header data
DATA : HEADER LIKE BAPIMEPOHEADER ,
HEADERX LIKE BAPIMEPOHEADERX .

*Structures to hold PO account data
DATA : ACCOUNT LIKE BAPIMEPOACCOUNT OCCURS 0 WITH HEADER LINE ,
ACCOUNTX LIKE BAPIMEPOACCOUNTX OCCURS 0 WITH HEADER LINE .

*Structures to hold PO schedule data
DATA : ITEMSCHEDULE LIKE BAPIMEPOSCHEDULE OCCURS 0 WITH HEADER LINE ,
ITEMSCHEDULEX LIKE BAPIMEPOSCHEDULX OCCURS 0 WITH HEADER LINE .

*Structures to hold PO (distrib.imputac.lín.servicios) data
DATA : POSRVACCESSVALUES LIKE BAPIESKLC OCCURS 0 WITH HEADER LINE .

*Structures to hold PO services data
DATA : SERVICES LIKE BAPIESLLC OCCURS 0 WITH HEADER LINE .


*Internal Tables to hold PO ITEM DATA
DATA : ITEM LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE,
ITEMX LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE,

*Internal table to hold messages from BAPI call
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,

*Internal table to hold messages from BAPI call
POCONTRACTLIMITS LIKE BAPIESUCC OCCURS 0 WITH HEADER LINE.

data : w_header(40) value 'PO Header',
PURCHASEORDER LIKE BAPIMEPOHEADER-PO_NUMBER,
DELIVERY_DATE LIKE BAPIMEPOSCHEDULE-DELIVERY_DATE.

data : ws_langu like sy-langu.

*text-001 = 'PO Header' - define as text element
selection-screen begin of block b1 with frame title text-001.
parameters : company like header-comp_code default '1000' ,
doctyp like HEADER-DOC_TYPE default 'PM' ,
cdate like HEADER-CREAT_DATE default sy-datum ,
vendor like HEADER-VENDOR default '100006' ,
pur_org like HEADER-PURCH_ORG default '1000' ,
pur_grp like HEADER-PUR_GROUP default '850' ,
sociedad like HEADER-COMP_CODE default '1000' ,
vendedor like HEADER-SALES_PERS default 'Wilda Messina'.


selection-screen end of block b1.

selection-screen begin of block b2 with frame title text-002.
parameters : item_num like ITEM-PO_ITEM default '00010',
material like ITEM-MATERIAL default 'CRANE' ,
tipo_imp like ITEM-ACCTASSCAT default 'K' ,
pos_doc like ITEM-ITEM_CAT default 'F' ,
shorttxt like ITEM-SHORT_TEXT default 'PRUEBA BAPI' ,
grup_art like ITEM-MATL_GROUP default '350001' ,
plant like ITEM-PLANT default '1000' ,
mpe like ITEM-TRACKINGNO default '9999' ,
contrato like ITEM-AGREEMENT default '4904000003' ,
quantity like ITEM-QUANTITY default 1 .
* po_unit like ITEM-PO_UNIT default 'UP'.

selection-screen end of block b2.

* Parámnetros para los servicios
selection-screen begin of block b3 with frame title text-003.
parameters : paquete like SERVICES-PCKG_NO default '956',
numlinin like SERVICES-LINE_NO default '9' ,
numlinea like SERVICES-EXT_LINE default '80',
service like SERVICES-SERVICE default '8010',
srv_cant like SERVICES-quantity default '5' ,
precio like SERVICES-GR_PRICE default '300' ,
impuesto like SERVICES-TAX_CODE default 'I2' .

selection-screen end of block b3.

* Parámnetros de imputación
selection-screen begin of block b4 with frame title text-004.
parameters : centro like ACCOUNT-COSTCENTER default '120100',
cuenta like ACCOUNT-GL_ACCOUNT default '6501002000' ,
num_pos like ACCOUNT-PO_ITEM default '10' ,
serial like ACCOUNT-SERIAL_NO default '01' ,
ind_imp like ACCOUNT-TAX_CODE default 'I2' .

selection-screen end of block b4.


*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*DATA POPULATION
*&---------------------------------------------------------------------*
ws_langu = sy-langu. "Language variable

*POPULATE HEADER DATA FOR PO
HEADER-COMP_CODE = sociedad .
HEADER-DOC_TYPE = doctyp .
HEADER-VENDOR = vendor .
HEADER-CREAT_DATE = cdate .
HEADER-CREATED_BY = 'TD17191' .
HEADER-PURCH_ORG = pur_org .
HEADER-PUR_GROUP = pur_grp .
HEADER-COMP_CODE = company .
HEADER-LANGU = ws_langu .
HEADER-SALES_PERS = vendedor .
HEADER-CURRENCY = 'DOP' .
*HEADER-ITEM_INTVL = 10 .
*HEADER-PMNTTRMS = 'N30' .
*HEADER-EXCH_RATE = 1 .


*&---------------------------------------------------------------------*
*POPULATE HEADER FLAG.
*&---------------------------------------------------------------------*
HEADERX-comp_code = c_x.
HEADERX-doc_type = c_x.
HEADERX-vendor = c_x.
HEADERX-creat_date = c_x.
HEADERX-created_by = c_x.
HEADERX-purch_org = c_x.
HEADERX-pur_group = c_x.
HEADERX-langu = c_x.
HEADERX-sales_pers = c_x.
HEADERX-CURRENCY = c_x.
*HEADER-ITEM_INTVL = c_x.
*HEADER-PMNTTRMS = c_x.
*HEADER-EXCH_RATE = c_x.
*HEADER-EXCH_RATE = c_x.

*&---------------------------------------------------------------------*
*POPULATE ITEM DATA.
*&---------------------------------------------------------------------*
ITEM-PO_ITEM = '10'.
ITEM-QUANTITY = '1'.
*ITEM-MATERIAL = material .
ITEM-SHORT_TEXT = 'prueba bapi_po_create1'.
ITEM-TAX_CODE = 'I2'.
ITEM-ACCTASSCAT = 'K' .
ITEM-ITEM_CAT = 'F' .
ITEM-MATL_GROUP = '350001' .
ITEM-PLANT = '1000' .
ITEM-TRACKINGNO = '99999'.
ITEM-AGREEMENT = '4904000004' .
ITEM-AGMT_ITEM = '0010'.
ITEM-QUANTITY = '1' .
ITEM-PO_UNIT = 'UP'.
*ITEM-ORDERPR_UN = 'UP'.
ITEM-CONV_NUM1 = '1'.
ITEM-CONV_DEN1 = '1'.
ITEM-NET_PRICE = '1000000' .
ITEM-PRICE_UNIT = '1'.
ITEM-GR_PR_TIME = '0'.
ITEM-PRNT_PRICE = 'X'.
ITEM-UNLIMITED_DLV = 'X'.
ITEM-GR_IND = 'X' .
ITEM-IR_IND = 'X' .
ITEM-GR_BASEDIV = 'X'.
ITEM-PCKG_NO = '2748' .


APPEND ITEM. CLEAR ITEM.

*&---------------------------------------------------------------------*
*POPULATE ITEM FLAG TABLE
*&---------------------------------------------------------------------*
ITEMX-PO_ITEM = item_num.
ITEMX-PO_ITEMX = c_x.
*ITEMX-MATERIAL = C_X.
ITEMX-SHORT_TEXT = C_X.
ITEMX-QUANTITY = C_X.
ITEMX-TAX_CODE = C_X.
ITEMX-ACCTASSCAT = C_X.
ITEMX-ITEM_CAT = c_x.
ITEMX-MATL_GROUP = C_X.
ITEMX-PLANT = C_X.
ITEMX-TRACKINGNO = C_X.
ITEMX-AGREEMENT = C_X.
ITEMX-AGMT_ITEM = c_x.
ITEMX-STGE_LOC = C_X.
ITEMX-QUANTITY = C_X.
ITEMX-PO_UNIT = C_X.
*ITEMX-ORDERPR_UN = C_X.
ITEMX-CONV_NUM1 = C_X.
ITEMX-CONV_DEN1 = C_X.
ITEMX-NET_PRICE = C_X.
ITEMX-PRICE_UNIT = C_X.
ITEMX-GR_PR_TIME = C_X.
ITEMX-PRNT_PRICE = C_X.
ITEMX-UNLIMITED_DLV = C_X.
ITEMX-GR_IND = C_X .
ITEMX-IR_IND = C_X .
ITEMX-GR_BASEDIV = C_X .
ITEMX-PCKG_NO = C_X.

APPEND ITEMX. CLEAR ITEMX.

*&---------------------------------------------------------------------*
*POPULATE ITEM SCHEDULE DATA.
*&---------------------------------------------------------------------*
ITEMSCHEDULE-PO_ITEM = '00010'.
ITEMSCHEDULE-DEL_DATCAT_EXT = 'T'.
ITEMSCHEDULE-DELIVERY_DATE = '21.04.2005'. "sy-datum + 2 dias.
*ITEM_SCHEDULE-QUANTITY = '1'. "ITDETALLE-CANTIDAD.
APPEND ITEMSCHEDULE.
CLEAR ITEMSCHEDULE.

*&---------------------------------------------------------------------*
*POPULATE ITEM FLAG FOR SCHEDULE TABLE.
*&---------------------------------------------------------------------*
ITEMSCHEDULEX-PO_ITEM = '10'.
ITEMSCHEDULEX-PO_ITEMX = c_x .
ITEMSCHEDULEX-DEL_DATCAT_EXT = c_x.
ITEMSCHEDULEX-DELIVERY_DATE = c_x .
*ITEMSCHEDULEX-QUANTITY = '1' . "ITDETALLE-CANTIDAD.
APPEND ITEMSCHEDULEX.
CLEAR ITEMSCHEDULEX.


*&---------------------------------------------------------------------*
*POPULATE ACCOUNT DATA.
*&---------------------------------------------------------------------*
ACCOUNT-PO_ITEM = '10' .
ACCOUNT-SERIAL_NO = serial .
ACCOUNT-CREAT_DATE = sy-datum .
ACCOUNT-COSTCENTER = centro .
ACCOUNT-GL_ACCOUNT = cuenta .
ACCOUNT-CO_AREA = 'CD01' .
ACCOUNT-TAX_CODE = 'I2' .
APPEND ACCOUNT. CLEAR ACCOUNT.

*&---------------------------------------------------------------------*
*POPULATE ACCOUNT FLAG TABLE.
*&---------------------------------------------------------------------*
ACCOUNTX-PO_ITEM = '10' .
ACCOUNTX-PO_ITEMX = c_x .
ACCOUNTX-SERIAL_NO = serial .
ACCOUNTX-SERIAL_NOX = c_x .
ACCOUNTX-CREAT_DATE = c_x .
ACCOUNTX-COSTCENTER = c_x .
ACCOUNTX-GL_ACCOUNT = c_x .
ACCOUNTX-CO_AREA = c_x .
ACCOUNTX-TAX_CODE = c_x .
APPEND ACCOUNTX. CLEAR ACCOUNTX.


*&---------------------------------------------------------------------*
*POPULATE POSRVACCESSVALUES TABLE DATA.
*&---------------------------------------------------------------------*

* FIRST ENTRY
POSRVACCESSVALUES-PCKG_NO = '0000002749' .
POSRVACCESSVALUES-LINE_NO = '0000000002' .
POSRVACCESSVALUES-SERNO_LINE = '01'.
POSRVACCESSVALUES-PERCENTAGE = '100'.
POSRVACCESSVALUES-SERIAL_NO = '01'.
*POSRVACCESSVALUES-QUANTITY = '1'.
POSRVACCESSVALUES-NET_VALUE = '850'.
APPEND POSRVACCESSVALUES . CLEAR POSRVACCESSVALUES.

* SECOND ENTRY
POSRVACCESSVALUES-PCKG_NO = '0000002749' .
POSRVACCESSVALUES-LINE_NO = '0000000003' .
POSRVACCESSVALUES-SERNO_LINE = '01'.
POSRVACCESSVALUES-PERCENTAGE = '100'.
POSRVACCESSVALUES-SERIAL_NO = '01'.
*POSRVACCESSVALUES-QUANTITY =
POSRVACCESSVALUES-NET_VALUE = '150'.
APPEND POSRVACCESSVALUES . CLEAR POSRVACCESSVALUES.



*&---------------------------------------------------------------------*
*POPULATE SERVICES DATA.
*&---------------------------------------------------------------------*

* servicio JERARQUIA SUPERIOR

SERVICES-PCKG_NO = '2748'.
SERVICES-LINE_NO = '0000000001' .
SERVICES-EXT_LINE = '0000000000' .
SERVICES-OUTL_LEVEL = '0'.
SERVICES-OUTL_NO = ' '.
SERVICES-OUTL_IND = 'X'.
SERVICES-SUBPCKG_NO = '2749'.
*SERVICES-SERVICE = ' ' .
SERVICES-EDITION = '0000' .
*SERVICES-BASE_UOM = '
SERVICES-QUANTITY = '0' .
SERVICES-OVF_TOL = '0' .
SERVICES-GR_PRICE = '0' .
SERVICES-FROM_LINE = '1' .
SERVICES-PERS_NO = '00000000' .
SERVICES-PLN_PCKG = '0000000000' .
SERVICES-PLN_LINE = '0000000000' .
SERVICES-CON_PCKG = '0000000000' .
SERVICES-CON_LINE = '0000000000' .
SERVICES-TMP_PCKG = '0000000000' .
SERVICES-TMP_LINE = '0000000000' .
SERVICES-LIMIT_LINE = '0000000000' .
SERVICES-TAX_CODE = impuesto .
*SERVICES-SHORT_TEXT = 'prueba creacion BAPI'.
*SERVICES-MATL_GROUP = '350001'.

APPEND SERVICES. CLEAR SERVICES .


* servicio 1

SERVICES-PCKG_NO = '2749'.
SERVICES-LINE_NO = '2' .
SERVICES-EXT_LINE = '10' .
SERVICES-OUTL_LEVEL = '0'.
*SERVICES-OUTL_NO = ' '.
*SERVICES-OUTL_IND = 'X'.
SERVICES-SUBPCKG_NO = '0000000000'.
SERVICES-SERVICE = '000000000000008010'.
SERVICES-EDITION = '0000' .
SERVICES-BASE_UOM = 'UNO' .
SERVICES-UOM_ISO = 'C62' .
SERVICES-QUANTITY = '1' .
SERVICES-PRICE_UNIT = '1' .
SERVICES-OVF_TOL = '0' .
*SERVICES-FROM_LINE = '1' .
SERVICES-SHORT_TEXT = 'prueba creacion BAPI'.
SERVICES-PERS_NO = '00000000' .
SERVICES-PLN_PCKG = '0000001980' .
SERVICES-PLN_LINE = '0000000002' .
SERVICES-CON_PCKG = '0000001980' .
SERVICES-CON_LINE = '0000000002' .
SERVICES-TMP_PCKG = '0000000000' .
SERVICES-TMP_LINE = '0000000000' .
SERVICES-LIMIT_LINE = '0000000000' .
SERVICES-TAX_CODE = 'I2' .
SERVICES-GR_PRICE = '850' .
SERVICES-MATL_GROUP = '350001'.

APPEND SERVICES. CLEAR SERVICES .


*&---------------------------------------------------------------------*
*POPULATE CONTRACT LIMITS DATA.
*&---------------------------------------------------------------------*
POCONTRACTLIMITS-PCKG_NO = '956'.
POCONTRACTLIMITS-CON_NUMBER = '4903000004'.
POCONTRACTLIMITS-CON_ITEM = '10'.
POCONTRACTLIMITS-NO_LIMIT = c_x.
POCONTRACTLIMITS-PRICE_CHG = c_x.
APPEND POCONTRACTLIMITS. CLEAR POCONTRACTLIMITS .


*&---------------------------------------------------------------------*
*BAPI CALL
*&---------------------------------------------------------------------*
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = HEADER
POHEADERX = HEADERX
* POADDRVENDOR =
* TESTRUN =
IMPORTING
EXPPURCHASEORDER = PURCHASEORDER
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
RETURN = RETURN
POITEM = ITEM
POITEMX = ITEMX
POSCHEDULE = ITEMSCHEDULE
POSCHEDULEX = ITEMSCHEDULEX
POACCOUNT = ACCOUNT
POACCOUNTX = ACCOUNTX
POSERVICES = SERVICES.

*&---------------------------------------------------------------------*
*Confirm the document creation by calling database COMMIT
*&---------------------------------------------------------------------*
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
..

end-of-selection.
*&---------------------------------------------------------------------*
*Output the messages returned from BAPI call
*&---------------------------------------------------------------------*
LOOP AT RETURN.
WRITE / RETURN-MESSAGE.
ENDLOOP.



Code:

REPORT ZTEST26 . " ME_PO_CREATE


DATA : L_PO_HEADER LIKE BAPIMEPOHEADER.
DATA : L_PO_HEADERX LIKE BAPIMEPOHEADERX.


DATA : L_PURCHASEORDER LIKE BAPIMEPOHEADER-PO_NUMBER.
*DATA : L_HEADER LIKE BAPIMEPOHEADER STRUCTURE BAPIMEPOHEADER.



DATA : BEGIN OF T_PO_ITEMS OCCURS 0.
INCLUDE STRUCTURE BAPIMEPOITEM.
DATA : END OF T_PO_ITEMS.


DATA : BEGIN OF T_PO_ITEMSX OCCURS 0.
INCLUDE STRUCTURE BAPIMEPOITEMX.
DATA : END OF T_PO_ITEMSX.


DATA : BEGIN OF T_RETURN OCCURS 0.
INCLUDE STRUCTURE BAPIRET2.
DATA : END OF T_RETURN.

CLEAR : L_PO_HEADER.

L_PO_HEADER-COMP_CODE = '0010'." Company Code
L_PO_HEADER-DOC_TYPE = 'NB'. " Order Typr BSART
L_PO_HEADER-CREAT_DATE = SY-DATUM. " P.O Dt - BEDAT
L_PO_HEADER-VENDOR = '0000210012'. "Vendor - EKKO-LIFNR
L_PO_HEADER-PURCH_ORG = '0001'. " Purch. Org - EKKO-EKORG
L_PO_HEADER-PUR_GROUP = '001'. " Purch Group - EKKO-EKGRP
L_PO_HEADER-CURRENCY_ISO = 'USD'. " Currency Default field for Enjoy


*L_PO_HEADER-DOC_CAT = 'F'. " Account Assign Cat EKPO-KNTTP

*_PO_HEADER-CREATED_BY = SY-UNAME.

CLEAR : L_PO_HEADERX.

L_PO_HEADERX-PO_NUMBER = 'X'.
L_PO_HEADERX-COMP_CODE = 'X'." Company Code
L_PO_HEADERX-DOC_TYPE = 'X'. " Order Typr BSART

L_PO_HEADERX-VENDOR = 'X'. "Vendor - EKKO-LIFNR
L_PO_HEADERX-PURCH_ORG = 'X'. " Purch. Org - EKKO-EKORG
L_PO_HEADERX-PUR_GROUP = 'X'. " Purch Group - EKKO-EKGRP
L_PO_HEADERX-CURRENCY_ISO = 'X'. " Currency Default field for Enjoy



* PO Line Items


T_PO_ITEMS-PO_ITEM = '00001'." Line Item No - EKPO-EBELP
*T_PO_ITEMS-SHORT_TEXT = 'KSR TEXT'." Line Item TEXT

T_PO_ITEMS-MATERIAL = '000000000000000111'. " Material No - EKPO-EMATN
T_PO_ITEMS-PLANT = '01'. " Plant - EKPO-WERKS
T_PO_ITEMS-QUANTITY = '1.000'.
T_PO_ITEMS-NET_PRICE = '10.000000000'. " EKPO-NETPR

T_PO_ITEMS-PRICE_UNIT = '10'.
T_PO_ITEMS-TAX_CODE = 'A2'.

APPEND T_PO_ITEMS.
CLEAR T_PO_ITEMS.


T_PO_ITEMSX-PO_ITEM = '00001'.
T_PO_ITEMSX-PO_ITEMX = 'X'.


T_PO_ITEMSX-EMATERIAL = 'X'.

T_PO_ITEMSX-PLANT = 'X'.
T_PO_ITEMSX-QUANTITY = 'X'.
T_PO_ITEMSX-NET_PRICE = 'X'.

T_PO_ITEMSX-PRICE_UNIT = 'X'.
T_PO_ITEMSX-TAX_CODE = 'X'.

APPEND T_PO_ITEMSX.
CLEAR T_PO_ITEMSX.

*** Second Line Item


CLEAR : L_PURCHASEORDER.



CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = L_PO_HEADER

POHEADERX = L_PO_HEADERX

* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
IMPORTING
EXPPURCHASEORDER = L_PURCHASEORDER
* EXPHEADER = L_HEADER
TABLES

POITEM = T_PO_ITEMS
POITEMX = T_PO_ITEMSX

* POADDRDELIVERY =
* POSCHEDULE =
RETURN = T_RETURN
* POPARTNER =

* POSCHEDULEX =
* POACCOUNT =
* POACCOUNTX =
* POACCOUNTPROFITSEGMENT =
* POCONDHEADER =
* POCONDHEADERX =
* POCOND =
* POCONDX =
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* POTEXTHEADER =
* POTEXTITEM =
POPARTNER =
.

IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.
ENDIF.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.