2007 Jul 10 10:07 PM
Hello,
I am trying to use the BAPI_PO_CREATE to create a PO with reference to another PO/item. So far I have not found a way to make this work. I can see that you can do this in ME21, but not sure if the bapi can do this too. We are in 4.6C, so I have to use this bapi instead of BAPI_PO_CREATE1. Any help would be appreciated!
Thanks!
Kristina
2007 Jul 11 8:20 AM
Hi Kristina,
you can check this bapi information below:
Short Text
Create Purchase Order
Functionality
Function module BAPI_PO_CREATE1 enables you to create purchase orders. The BAPI uses the technology behind the Enjoy purchase order transaction ( ME21N).
Alternatively, the IDoc type PORDCR1 is available. The data from this IDoc automatically populates the interface parameters of the function module BAPI_PO_CREATE1.
Functionality in Detail
Authorization
The following authorization objects are checked when an Enjoy purchase order is created (activity 01):
M_BEST_BSA (document type in PO)
M_BEST_EKG (purchasing group in PO)
M_BEST_EKO (purchasing organization in PO)
M_BEST_WRK (plant in PO)
Controlling adoption of field values via X parameter
For most tables, you can determine via your own parameters in the associated X parameter in each case (e.g. PoItemX) whether fields are to be set initial, values inserted via the interface, or default values adopted (e.g. from Customizing or master records) (for example, it is not mandatory to adopt the material group from an underlying purchase requisition - you can change it with the BAPI).
Transfer
Header data
The header data of the Enjoy purchase order is transferred in the table PoHeader.
Item data
The item data of the Enjoy purchase order is stored in the table PoItem (general item data). The delivery schedule lines are stored in the table PoSchedule.
Use the table PoAccount to specify the account assignment information. If account assignments have been specified for services and limits, you show the relevant account assignment line in PoAccount in the table PoSrvAccessValues via the package number of the service or the limit.
Services and limits
Services, free limits and limits with contract reference can be specified in the tables PoServices, PoLimits, and PoContractLimits.
Conditions
Conditions are transferred in the table PoCond; header conditions in the table PoCondHeader. Price determination is reinitiated via the parameter CALCTYPE in the table PoItem.
Vendor and delivery address
The vendor's address can be specified individually in the table PoAddrVendor; the delivery address in the table PoAddrDelivery. If you do not make any individual specification, the fields will be populated via the central address management facility.
Note
In this method, the following restrictions apply with regard to addresses:
Addresses can only be created with this method - they cannot be changed. You can only change address data with the method BAPI_ADDRESSORG_CHANGE.
When you create addresses, they are not checked by the method. An Enjoy purchase order may therefore contain faulty address data.
Partner roles
The partners can be maintained individually via the table PoPartner (with the exception of the partner role "vendor").
Import/export data
Import/Export data can be specified per item in the table PoExpImpItem. Foreign trade data can only be transferred as default data for new items.
Texts
Header and item texts can be transferred in the tables PoTextHeader and PoTextItem. Texts for services are imported in the table PoServicesText.
Version Management
You can make use of the Version Management facility via the table AllVersions.
Return
The PO number is returned in the parameter ExpPurchaseOrder. In addition, all information except the service and export/import tables is placed in the output structures.
Return messages
Messages are returned in the parameter Return. This also contains information as to whether interface data has been wrongly or probably wrongly (heuristical interface check) populated. When a PO has been created successfully, the PO number is also placed in the return table with the appropriate message.
Restrictions
With this function module, it is not possible to:
Create subcontracting components (you can only use existing ones)
Create configurations (you can only use existing ones)
Change message records (table NAST) and additional message data (this data can only be determined via the message determination facility (Customizing))
Attach documents to the purchase order
See also further information in SAP Note 197958.
Example
Example of population of BAPI interface in the Function Builder
Parameter: POHEADER
COMP_CODE = 1000
DOC_TYPE = NB
ITEM_INTVL = 00001
VENDOR = 0000001000
PMNTTRMS = 0001
PURCH_ORG = 1000
PUR_GROUP = 001
CURRENCY = EUR
Parameter: POHEADERX
COMP_CODE = X
DOC_TYPE = X
ITEM_INTVL = X
VENDOR = X
PMNTTRMS = X
PURCH_ORG = X
PUR_GROUP = X
Parameter: POITEM
PO_ITEM = 00001
MATERIAL = 100-100
PLANT = 1000
STGE_LOC = 0001
QUANTITY = 15.000
TAX_CODE = V0
ITEM_CAT = 0
ACCTASSCAT = K
Parameter: POITEMX
PO_ITEM = 00001
MATERIAL = X
PLANT = X
STGE_LOC = X
QUANTITY = X
TAX_CODE = X
ITEM_CAT = X
ACCTASSCAT = X
Parameter: POSCHEDULE
PO_ITEM = 00001
SCHED_LINE = 0001
DELIVERY_DATE = 02.12.2002
QUANTITY = 6.000
PO_ITEM = 00001
SCHED_LINE = 0002
DELIVERY_DATE = 03.12.2002
QUANTITY = 5.000
PO_ITEM = 00001
SCHED_LINE = 0003
DELIVERY_DATE = 04.12.2002
QUANTITY = 4.000
Parameter: POSCHEDULEX
PO_ITEM = 00001
SCHED_LINE = 0001
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
PO_ITEM = 00001
SCHED_LINE = 0002
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
PO_ITEM = 00001
SCHED_LINE = 0003
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
Parameter: POACCOUNT
PO_ITEM = 00001
SERIAL_NO = 01
QUANTITY = 15.000
GL_ACCOUNT = 0000400000
COSTCENTER = 0000001000
CO_AREA = 1000
Parameter: POACCOUNTX
PO_ITEM = 00001
SERIAL_NO = 01
QUANTITY = X
GL_ACCOUNT = X
COSTCENTER = X
CO_AREA = X
Parameter: POCOND
ITM_NUMBER = 000001
COND_ST_NO = 001
COND_TYPE = PB00
COND_VALUE = 79.900000000
CURRENCY = EUR
CURRENCY_ISO = EUR
COND_UNIT = KG
COND_P_UNT = 1
CHANGE_ID = U
Parameter: POCONDX
ITM_NUMBER = 000001
COND_ST_NO = 000
ITM_NUMBERX = X
COND_TYPE = X
COND_VALUE = X
CURRENCY = X
CHANGE_ID = X
Parameter: POPARTNER
PARTNERDESC = OA
LANGU = EN
BUSPARTNO = 0000001100
PARTNERDESC = GS
LANGU = EN
BUSPARTNO = 0000001200
PARTNERDESC = PI
LANGU = EN
BUSPARTNO = 0000001000
Help in the Case of Problems
SAP Note 197958 lists answers to frequently asked questions (FAQs). (Note 499626 contains answers to FAQs relating specifically to External Services Management.)
If you have detected an error in the function of a BAPI, create a reproducible example in the test data directory in the Function Builder (transaction code SE37). SAP Note 375886 tells you how to do this.
If the problem persists, create a Customer Problem Message for the componente MM-PUR-PO-BAPI, and document the reproducible example where appropriate.
Customer Enhancements
The following customer exits (function modules) are available for the BAPI BAPI_PO_CREATE1:
EXIT_SAPL2012_001 (at start of BAPI)
EXIT_SAPL2012_003 (at end of BAPI)
The following customer exits (function modules) are available for the BAPI BAPI_PO_CHANGE:
EXIT_SAPL2012_002 (at start of BAPI)
EXIT_SAPL2012_004 (at end of BAPI)
These exits belong to the enhancement SAPL2012 (see also transaction codes SMOD and CMOD).
There is also the option of populating customers' own fields for header, item, or account assignment data via the parameter EXTENSIONIN.
Further information
Further information on purchase order BAPIs is available in SAP Note 197958.
If you test the BAPIs BAPI_PO_CREATE1 or BAPI_PO_CHANGE in the Function Builder (transaction code SE37), no database updates will be carried out. If you need this function, take a look at Note 420646.
The BAPI BAPI_PO_GETDETAIL serves to read the details of a purchase order. The BAPI cannot read all details (e.g. conditions). However, you can use the BAPI BAPI_PO_CHANGE for this purpose if just the document number is populated and the invoker has change authorizations for purchase orders.
Frequently used BAPIs for purchase orders are BAPI_PO_CREATE, BAPI_PO_CREATE1, BAPI_PO_CHANGE, BAPI_PO_GETDETAIL, BAPI_PO_GETITEMS, BAPI_PO_GETITEMSREL, and BAPI_PO_GETRELINFO.
For more information on purchase orders, refer to the SAP library (under MM Purchasing -> Purchase Orders) or the Help for the Enjoy Purchase Order, or choose the path Tools -> ABAP Workbench -> Overview -> BAPI Explorer from the SAP Easy Access menu.
Parameters
POHEADER
POHEADERX
POADDRVENDOR
TESTRUN
MEMORY_UNCOMPLETE
MEMORY_COMPLETE
POEXPIMPHEADER
POEXPIMPHEADERX
VERSIONS
NO_MESSAGING
NO_MESSAGE_REQ
NO_AUTHORITY
NO_PRICE_FROM_PO
EXPPURCHASEORDER
EXPHEADER
EXPPOEXPIMPHEADER
RETURN
POITEM
POITEMX
POADDRDELIVERY
POSCHEDULE
POSCHEDULEX
POACCOUNT
POACCOUNTPROFITSEGMENT
POACCOUNTX
POCONDHEADER
POCONDHEADERX
POCOND
POCONDX
POLIMITS
POCONTRACTLIMITS
POSERVICES
POSRVACCESSVALUES
POSERVICESTEXT
EXTENSIONIN
EXTENSIONOUT
POEXPIMPITEM
POEXPIMPITEMX
POTEXTHEADER
POTEXTITEM
ALLVERSIONS
POPARTNER
POCOMPONENTS
POCOMPONENTSX
POSHIPPING
POSHIPPINGX
POSHIPPINGEXP
<b>Reward pts if found usefull:)</b>
Regards
Sathish
2007 Jul 10 11:53 PM
Check with below FM :
ME_CREATE_DOCUMENT ,if you need example code check with where used list
Thanks
Seshu
2007 Jul 11 8:20 AM
Hi Kristina,
you can check this bapi information below:
Short Text
Create Purchase Order
Functionality
Function module BAPI_PO_CREATE1 enables you to create purchase orders. The BAPI uses the technology behind the Enjoy purchase order transaction ( ME21N).
Alternatively, the IDoc type PORDCR1 is available. The data from this IDoc automatically populates the interface parameters of the function module BAPI_PO_CREATE1.
Functionality in Detail
Authorization
The following authorization objects are checked when an Enjoy purchase order is created (activity 01):
M_BEST_BSA (document type in PO)
M_BEST_EKG (purchasing group in PO)
M_BEST_EKO (purchasing organization in PO)
M_BEST_WRK (plant in PO)
Controlling adoption of field values via X parameter
For most tables, you can determine via your own parameters in the associated X parameter in each case (e.g. PoItemX) whether fields are to be set initial, values inserted via the interface, or default values adopted (e.g. from Customizing or master records) (for example, it is not mandatory to adopt the material group from an underlying purchase requisition - you can change it with the BAPI).
Transfer
Header data
The header data of the Enjoy purchase order is transferred in the table PoHeader.
Item data
The item data of the Enjoy purchase order is stored in the table PoItem (general item data). The delivery schedule lines are stored in the table PoSchedule.
Use the table PoAccount to specify the account assignment information. If account assignments have been specified for services and limits, you show the relevant account assignment line in PoAccount in the table PoSrvAccessValues via the package number of the service or the limit.
Services and limits
Services, free limits and limits with contract reference can be specified in the tables PoServices, PoLimits, and PoContractLimits.
Conditions
Conditions are transferred in the table PoCond; header conditions in the table PoCondHeader. Price determination is reinitiated via the parameter CALCTYPE in the table PoItem.
Vendor and delivery address
The vendor's address can be specified individually in the table PoAddrVendor; the delivery address in the table PoAddrDelivery. If you do not make any individual specification, the fields will be populated via the central address management facility.
Note
In this method, the following restrictions apply with regard to addresses:
Addresses can only be created with this method - they cannot be changed. You can only change address data with the method BAPI_ADDRESSORG_CHANGE.
When you create addresses, they are not checked by the method. An Enjoy purchase order may therefore contain faulty address data.
Partner roles
The partners can be maintained individually via the table PoPartner (with the exception of the partner role "vendor").
Import/export data
Import/Export data can be specified per item in the table PoExpImpItem. Foreign trade data can only be transferred as default data for new items.
Texts
Header and item texts can be transferred in the tables PoTextHeader and PoTextItem. Texts for services are imported in the table PoServicesText.
Version Management
You can make use of the Version Management facility via the table AllVersions.
Return
The PO number is returned in the parameter ExpPurchaseOrder. In addition, all information except the service and export/import tables is placed in the output structures.
Return messages
Messages are returned in the parameter Return. This also contains information as to whether interface data has been wrongly or probably wrongly (heuristical interface check) populated. When a PO has been created successfully, the PO number is also placed in the return table with the appropriate message.
Restrictions
With this function module, it is not possible to:
Create subcontracting components (you can only use existing ones)
Create configurations (you can only use existing ones)
Change message records (table NAST) and additional message data (this data can only be determined via the message determination facility (Customizing))
Attach documents to the purchase order
See also further information in SAP Note 197958.
Example
Example of population of BAPI interface in the Function Builder
Parameter: POHEADER
COMP_CODE = 1000
DOC_TYPE = NB
ITEM_INTVL = 00001
VENDOR = 0000001000
PMNTTRMS = 0001
PURCH_ORG = 1000
PUR_GROUP = 001
CURRENCY = EUR
Parameter: POHEADERX
COMP_CODE = X
DOC_TYPE = X
ITEM_INTVL = X
VENDOR = X
PMNTTRMS = X
PURCH_ORG = X
PUR_GROUP = X
Parameter: POITEM
PO_ITEM = 00001
MATERIAL = 100-100
PLANT = 1000
STGE_LOC = 0001
QUANTITY = 15.000
TAX_CODE = V0
ITEM_CAT = 0
ACCTASSCAT = K
Parameter: POITEMX
PO_ITEM = 00001
MATERIAL = X
PLANT = X
STGE_LOC = X
QUANTITY = X
TAX_CODE = X
ITEM_CAT = X
ACCTASSCAT = X
Parameter: POSCHEDULE
PO_ITEM = 00001
SCHED_LINE = 0001
DELIVERY_DATE = 02.12.2002
QUANTITY = 6.000
PO_ITEM = 00001
SCHED_LINE = 0002
DELIVERY_DATE = 03.12.2002
QUANTITY = 5.000
PO_ITEM = 00001
SCHED_LINE = 0003
DELIVERY_DATE = 04.12.2002
QUANTITY = 4.000
Parameter: POSCHEDULEX
PO_ITEM = 00001
SCHED_LINE = 0001
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
PO_ITEM = 00001
SCHED_LINE = 0002
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
PO_ITEM = 00001
SCHED_LINE = 0003
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
Parameter: POACCOUNT
PO_ITEM = 00001
SERIAL_NO = 01
QUANTITY = 15.000
GL_ACCOUNT = 0000400000
COSTCENTER = 0000001000
CO_AREA = 1000
Parameter: POACCOUNTX
PO_ITEM = 00001
SERIAL_NO = 01
QUANTITY = X
GL_ACCOUNT = X
COSTCENTER = X
CO_AREA = X
Parameter: POCOND
ITM_NUMBER = 000001
COND_ST_NO = 001
COND_TYPE = PB00
COND_VALUE = 79.900000000
CURRENCY = EUR
CURRENCY_ISO = EUR
COND_UNIT = KG
COND_P_UNT = 1
CHANGE_ID = U
Parameter: POCONDX
ITM_NUMBER = 000001
COND_ST_NO = 000
ITM_NUMBERX = X
COND_TYPE = X
COND_VALUE = X
CURRENCY = X
CHANGE_ID = X
Parameter: POPARTNER
PARTNERDESC = OA
LANGU = EN
BUSPARTNO = 0000001100
PARTNERDESC = GS
LANGU = EN
BUSPARTNO = 0000001200
PARTNERDESC = PI
LANGU = EN
BUSPARTNO = 0000001000
Help in the Case of Problems
SAP Note 197958 lists answers to frequently asked questions (FAQs). (Note 499626 contains answers to FAQs relating specifically to External Services Management.)
If you have detected an error in the function of a BAPI, create a reproducible example in the test data directory in the Function Builder (transaction code SE37). SAP Note 375886 tells you how to do this.
If the problem persists, create a Customer Problem Message for the componente MM-PUR-PO-BAPI, and document the reproducible example where appropriate.
Customer Enhancements
The following customer exits (function modules) are available for the BAPI BAPI_PO_CREATE1:
EXIT_SAPL2012_001 (at start of BAPI)
EXIT_SAPL2012_003 (at end of BAPI)
The following customer exits (function modules) are available for the BAPI BAPI_PO_CHANGE:
EXIT_SAPL2012_002 (at start of BAPI)
EXIT_SAPL2012_004 (at end of BAPI)
These exits belong to the enhancement SAPL2012 (see also transaction codes SMOD and CMOD).
There is also the option of populating customers' own fields for header, item, or account assignment data via the parameter EXTENSIONIN.
Further information
Further information on purchase order BAPIs is available in SAP Note 197958.
If you test the BAPIs BAPI_PO_CREATE1 or BAPI_PO_CHANGE in the Function Builder (transaction code SE37), no database updates will be carried out. If you need this function, take a look at Note 420646.
The BAPI BAPI_PO_GETDETAIL serves to read the details of a purchase order. The BAPI cannot read all details (e.g. conditions). However, you can use the BAPI BAPI_PO_CHANGE for this purpose if just the document number is populated and the invoker has change authorizations for purchase orders.
Frequently used BAPIs for purchase orders are BAPI_PO_CREATE, BAPI_PO_CREATE1, BAPI_PO_CHANGE, BAPI_PO_GETDETAIL, BAPI_PO_GETITEMS, BAPI_PO_GETITEMSREL, and BAPI_PO_GETRELINFO.
For more information on purchase orders, refer to the SAP library (under MM Purchasing -> Purchase Orders) or the Help for the Enjoy Purchase Order, or choose the path Tools -> ABAP Workbench -> Overview -> BAPI Explorer from the SAP Easy Access menu.
Parameters
POHEADER
POHEADERX
POADDRVENDOR
TESTRUN
MEMORY_UNCOMPLETE
MEMORY_COMPLETE
POEXPIMPHEADER
POEXPIMPHEADERX
VERSIONS
NO_MESSAGING
NO_MESSAGE_REQ
NO_AUTHORITY
NO_PRICE_FROM_PO
EXPPURCHASEORDER
EXPHEADER
EXPPOEXPIMPHEADER
RETURN
POITEM
POITEMX
POADDRDELIVERY
POSCHEDULE
POSCHEDULEX
POACCOUNT
POACCOUNTPROFITSEGMENT
POACCOUNTX
POCONDHEADER
POCONDHEADERX
POCOND
POCONDX
POLIMITS
POCONTRACTLIMITS
POSERVICES
POSRVACCESSVALUES
POSERVICESTEXT
EXTENSIONIN
EXTENSIONOUT
POEXPIMPITEM
POEXPIMPITEMX
POTEXTHEADER
POTEXTITEM
ALLVERSIONS
POPARTNER
POCOMPONENTS
POCOMPONENTSX
POSHIPPING
POSHIPPINGX
POSHIPPINGEXP
<b>Reward pts if found usefull:)</b>
Regards
Sathish
2007 Jul 11 5:12 PM
Thanks for your replies! As for the first option, I can not use ME_CREATE_DOCUMENT because it is not a released function on our system, plus I don't think this function has any copy with reference capability, or if it does, I do not know how to make that work. As for the second option, I can not use BAPI_PO_CREATE1, as this is not a released function on our system. I can only use BAPI_PO_CREATE on our system, and I do not know if this bapi has copy capabilities and if it does I don't know how to invoke it.....any help on this would be appreciated. I have read the function documentation, and it did not help me in this regard. Any additional help you have is very much appreciated. Thanks!
2007 Oct 19 4:29 PM
I give you an example. It works well...
*&----
*
*& Report ZMM_CARGA_PEDIDOS_CS
*&----
*
REPORT zmm_carga_pedidos_cs.
*----
-
L O G D E M O D I F I C A C I O N E S
*----
-
TABLES:
ekko.
*----
*
tipos y variables *
*----
*
DATA: t_items LIKE bapiekpo OCCURS 0 WITH HEADER LINE,
t_items_app LIKE bapiekpo OCCURS 0 WITH HEADER LINE,
t_items_tx LIKE bapiekpotx OCCURS 0 WITH HEADER LINE,
t_header LIKE bapiekkol,
t_header_app LIKE bapiekkol OCCURS 0 WITH HEADER LINE,
t_header_tx LIKE bapiekkotx OCCURS 0 WITH HEADER LINE,
t_linea LIKE tline OCCURS 0 WITH HEADER LINE,
t_extent LIKE bapiparex OCCURS 0 WITH HEADER LINE,
t_extent_app LIKE bapi_te_po_header OCCURS 0 WITH HEADER LINE,
t_history LIKE bapiekbes OCCURS 0 WITH HEADER LINE,
t_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: po_header LIKE bapimepoheader,
po_headerx LIKE bapimepoheaderx,
po_items LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,
po_itemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE,
poschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE,
poschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE,
poaccount LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE,
poaccountx LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE,
po_business_partner LIKE bapiekkop OCCURS 0 WITH HEADER LINE,
t_txt_h LIKE bapimepotextheader OCCURS 0 WITH HEADER LINE,
po_cond LIKE bapimepocond OCCURS 0 WITH HEADER LINE,
po_condx LIKE bapimepocondx OCCURS 0 WITH HEADER LINE,
po_hcond LIKE bapimepocondheader OCCURS 0 WITH HEADER LINE,
po_hcondx LIKE bapimepocondheaderx OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF t_sched_app OCCURS 0.
INCLUDE STRUCTURE bapieket.
DATA: ebeln TYPE ebeln.
DATA: END OF t_sched_app.
DATA: BEGIN OF t_account_app OCCURS 0.
DATA: ebeln TYPE ebeln.
INCLUDE STRUCTURE bapiekkn.
DATA: END OF t_account_app.
DATA: BEGIN OF t_condic OCCURS 0.
DATA: ebeln TYPE ebeln.
INCLUDE STRUCTURE konv.
DATA: END OF t_condic.
TYPE-POOLS: slis.
DATA: BEGIN OF t_log OCCURS 0,
lights,
ebeln LIKE ekko-ebeln,
bsart LIKE ekko-bsart,
bukrs LIKE ekko-bukrs,
werks LIKE ekpo-werks,
mensg LIKE t_return-message,
anter LIKE ekko-ebeln,
END OF t_log.
DATA: BEGIN OF t_aux OCCURS 0,
pos LIKE konv-kposn,
END OF t_aux.
DATA:
gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gs_layout TYPE slis_layout_alv.
DATA c_ebeln LIKE ekko-ebeln.
DATA l_append.
DATA l_anter LIKE ekko-ebeln.
DATA w_borrar.
DATA w_modif.
*&----
*
Parametros de seleccion
*&----
*
SELECTION-SCREEN BEGIN OF BLOCK 0001 WITH FRAME.
PARAMETERS:
fecha LIKE ekko-bedat OBLIGATORY.
SELECTION-SCREEN END OF BLOCK 0001.
SELECTION-SCREEN BEGIN OF BLOCK 0002 WITH FRAME.
PARAMETERS:
file_h(128) OBLIGATORY LOWER CASE,
file_i(128) OBLIGATORY LOWER CASE,
file_e(128) OBLIGATORY LOWER CASE,
file_c(128) OBLIGATORY LOWER CASE,
file_p(128) OBLIGATORY LOWER CASE,
file_k(128) OBLIGATORY LOWER CASE,
file_a(128) OBLIGATORY LOWER CASE,
file_s(128) OBLIGATORY LOWER CASE.
SELECTION-SCREEN END OF BLOCK 0002.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_h.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = file_h
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_i.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = file_i
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_e.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = file_e
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_c.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = file_c
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_p.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = file_p
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_s.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = file_s
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_k.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = file_k
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_a.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = file_a
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
*&----
*
Inicio del Programa
*&----
*
START-OF-SELECTION.
PERFORM upload_files.
LOOP AT t_header_app.
PERFORM clear.
PERFORM condiciones.
PERFORM separar_tablas.
PERFORM extensiones.
l_anter = po_header-po_number.
CLEAR po_header-po_number.
CLEAR c_ebeln.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = po_header
poheaderx = po_headerx
IMPORTING
exppurchaseorder = c_ebeln
TABLES
return = t_return
poitem = po_items
poitemx = po_itemx
poschedule = poschedule
poschedulex = poschedulex
poaccount = poaccount
poaccountx = poaccountx
pocond = po_cond
pocondx = po_condx
extensionin = t_extent
potextheader = t_txt_h
potextitem = t_items_tx
popartner = po_business_partner.
LOOP AT t_return.
CASE t_return-type.
WHEN 'E'.
IF t_return-id NE 'BAPI' AND t_return-id NE 'MEPO'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
MOVE 1 TO t_log-lights.
t_log-ebeln = c_ebeln.
t_log-bsart = t_header_app-doc_type.
t_log-bukrs = t_header_app-co_code.
t_log-werks = po_items-plant.
t_log-mensg = t_return-message.
t_log-anter = l_anter.
APPEND t_log.
CLEAR l_append.
EXIT.
ENDIF.
WHEN 'W'.
IF t_return-message CS 'La ctd.pedido'.
w_modif = 'X'.
MOVE 3 TO t_log-lights.
t_log-ebeln = c_ebeln.
t_log-bsart = t_header_app-doc_type.
t_log-bukrs = t_header_app-co_code.
t_log-werks = po_items-plant.
t_log-mensg = text-000.
t_log-anter = l_anter.
l_append = 'X'.
ELSE.
MOVE 3 TO t_log-lights.
t_log-ebeln = c_ebeln.
t_log-bsart = t_header_app-doc_type.
t_log-bukrs = t_header_app-co_code.
t_log-werks = po_items-plant.
t_log-mensg = text-000.
t_log-anter = l_anter.
l_append = 'X'.
ENDIF.
WHEN OTHERS.
IF t_return-message CS 'El precio neto'.
w_modif = 'X'.
MOVE 3 TO t_log-lights.
t_log-ebeln = c_ebeln.
t_log-bsart = t_header_app-doc_type.
t_log-bukrs = t_header_app-co_code.
t_log-werks = po_items-plant.
t_log-mensg = text-000.
t_log-anter = l_anter.
l_append = 'X'.
ENDIF.
ENDCASE.
ENDLOOP.
IF l_append EQ 'X'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
APPEND t_log.
CLEAR l_append.
ENDIF.
IF w_modif = 'X'. "Cambio aquellos campos que cambian automaticamente
PERFORM separar_tablas.
PERFORM formato_2.
po_header-po_number = c_ebeln.
po_headerx-po_number = 'X'.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = c_ebeln
poheader = po_header
poheaderx = po_headerx
TABLES
return = t_return
poitem = po_items
poitemx = po_itemx.
LOOP AT t_return.
CASE t_return-type.
WHEN 'E'.
CLEAR l_append.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
EXIT.
WHEN OTHERS.
l_append = 'X'.
ENDCASE.
ENDLOOP.
IF l_append EQ 'X'.
CLEAR l_append.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDIF.
ENDLOOP.
PERFORM textos. "Probar que la BAPI lo haga bien
PERFORM imprime_log.
*----
FIN DEL PROGRAMA----
*
*&----
*
*& Form UPLOAD_FILES
*&----
*
FORM upload_files.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = file_h
filetype = 'DAT'
TABLES
data_tab = t_header_app
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = file_a
filetype = 'DAT'
TABLES
data_tab = t_account_app
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = file_i
filetype = 'DAT'
TABLES
data_tab = t_items_app
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = file_e
filetype = 'DAT'
TABLES
data_tab = t_extent_app
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = file_c
filetype = 'DAT'
TABLES
data_tab = t_header_tx
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = file_p
filetype = 'DAT'
TABLES
data_tab = t_items_tx
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = file_s
filetype = 'DAT'
TABLES
data_tab = t_sched_app
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = file_k
filetype = 'DAT'
TABLES
data_tab = t_condic
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " UPLOAD_FILES
*&----
*
*& Form SEPARAR_TABLAS
*&----
*
FORM separar_tablas.
DATA l_itm_number LIKE po_cond-itm_number.
DATA l_cond_type LIKE po_cond-cond_type.
DATA l_change_id LIKE po_cond-change_id.
Datos de Cabecera
po_header-po_number = t_header_app-po_number.
po_header-comp_code = t_header_app-co_code.
po_header-doc_type = t_header_app-doc_type.
po_header-delete_ind = t_header_app-delete_ind.
po_header-status = t_header_app-status.
po_header-creat_date = t_header_app-created_on.
po_header-created_by = t_header_app-created_by.
po_header-item_intvl = t_header_app-item_intvl.
po_header-vendor = t_header_app-vendor.
po_header-langu = t_header_app-language.
po_header-pmnttrms = t_header_app-pmnttrms.
po_header-dscnt1_to = t_header_app-dscnt1_to.
po_header-dscnt2_to = t_header_app-dscnt2_to.
po_header-dscnt3_to = t_header_app-dscnt3_to.
po_header-dsct_pct1 = t_header_app-cash_disc1.
po_header-dsct_pct2 = t_header_app-cash_disc2.
po_header-purch_org = t_header_app-purch_org.
po_header-pur_group = t_header_app-pur_group.
po_header-currency = t_header_app-currency.
po_header-exch_rate = t_header_app-exch_rate.
po_header-ex_rate_fx = t_header_app-ex_rate_fx.
po_header-doc_date = t_header_app-doc_date.
po_header-doc_date = fecha.
po_header-vper_start = t_header_app-vper_start.
po_header-vper_end = t_header_app-vper_end.
po_header-warranty = t_header_app-warranty.
po_header-quotation = t_header_app-quotation.
po_header-quot_date = t_header_app-quot_dead.
po_header-ref_1 = t_header_app-ref_1.
po_header-sales_pers = t_header_app-sales_pers.
po_header-telephone = t_header_app-telephone.
po_header-suppl_vend = t_header_app-suppl_vend.
po_header-customer = t_header_app-customer.
po_header-agreement = t_header_app-agreement.
po_header-gr_message = t_header_app-gr_message.
po_header-suppl_plnt = t_header_app-suppl_plnt.
po_header-incoterms1 = t_header_app-incoterms1.
po_header-incoterms2 = t_header_app-incoterms2.
po_header-collect_no = t_header_app-coll_no.
po_header-diff_inv = t_header_app-diff_inv.
po_header-our_ref = t_header_app-our_ref.
po_header-logsystem = t_header_app-logsystem.
po_header-subitemint = t_header_app-subitemint.
po_header-po_rel_ind = t_header_app-rel_ind.
po_header-rel_status = t_header_app-rel_status.
po_headerx-po_number = 'X'.
po_headerx-comp_code = 'X'.
po_headerx-doc_type = 'X'.
po_headerx-delete_ind = 'X'.
po_headerx-status = 'X'.
po_headerx-creat_date = 'X'.
po_headerx-created_by = 'X'.
po_headerx-item_intvl = 'X'.
po_headerx-vendor = 'X'.
po_headerx-langu = 'X'.
po_headerx-pmnttrms = 'X'.
po_headerx-dscnt1_to = 'X'.
po_headerx-dscnt2_to = 'X'.
po_headerx-dscnt3_to = 'X'.
po_headerx-dsct_pct1 = 'X'.
po_headerx-dsct_pct2 = 'X'.
po_headerx-purch_org = 'X'.
po_headerx-pur_group = 'X'.
po_headerx-currency = 'X'.
po_headerx-exch_rate = 'X'.
po_headerx-ex_rate_fx = 'X'.
po_headerx-doc_date = 'X'.
po_headerx-vper_start = 'X'.
po_headerx-vper_end = 'X'.
po_headerx-warranty = 'X'.
po_headerx-quotation = 'X'.
po_headerx-quot_date = 'X'.
po_headerx-ref_1 = 'X'.
po_headerx-sales_pers = 'X'.
po_headerx-telephone = 'X'.
po_headerx-suppl_vend = 'X'.
po_headerx-customer = 'X'.
po_headerx-agreement = 'X'.
po_headerx-gr_message = 'X'.
po_headerx-suppl_plnt = 'X'.
po_headerx-incoterms1 = 'X'.
po_headerx-incoterms2 = 'X'.
po_headerx-collect_no = 'X'.
po_headerx-diff_inv = 'X'.
po_headerx-our_ref = 'X'.
po_headerx-logsystem = 'X'.
po_headerx-subitemint = 'X'.
po_headerx-po_rel_ind = 'X'.
po_headerx-rel_status = 'X'.
Datos de Posiciones
LOOP AT t_items_app WHERE po_number EQ t_header_app-po_number.
PO_ITEMS-PO_PRICE = ' '.
po_items-po_item = t_items_app-po_item.
po_items-delete_ind = t_items_app-delete_ind.
po_items-short_text = t_items_app-short_text.
po_items-material = t_items_app-material.
po_items-ematerial = t_items_app-pur_mat.
po_items-plant = t_items_app-plant.
po_items-stge_loc = t_items_app-store_loc.
po_items-trackingno = t_items_app-trackingno.
po_items-matl_group = t_items_app-mat_grp.
po_items-info_rec = t_items_app-info_rec.
po_items-vend_mat = t_items_app-vend_mat.
po_items-quantity = t_items_app-quantity.
po_items-po_unit = t_items_app-unit.
po_items-orderpr_un = t_items_app-orderpr_un.
po_items-conv_num1 = t_items_app-conv_num1.
po_items-conv_den1 = t_items_app-conv_den1.
po_items-net_price = t_items_app-net_price.
po_items-price_unit = t_items_app-price_unit.
po_items-gr_pr_time = t_items_app-gr_pr_time.
IF t_items_app-tax_code IS INITIAL.
t_items_app-tax_code = 'U0'.
ENDIF.
po_items-tax_code = t_items_app-tax_code.
po_items-bon_grp1 = t_items_app-sett_grp1.
po_items-qual_insp = t_items_app-qual_insp.
po_items-info_upd = t_items_app-info_upd.
po_items-prnt_price = t_items_app-prnt_price.
po_items-est_price = t_items_app-est_price.
po_items-reminder1 = t_items_app-reminder1.
po_items-reminder2 = t_items_app-reminder2.
po_items-reminder3 = t_items_app-reminder3.
po_items-over_dlv_tol = t_items_app-overdeltol.
po_items-unlimited_dlv = t_items_app-unlimited.
po_items-under_dlv_tol = t_items_app-under_tol.
po_items-val_type = t_items_app-val_type.
po_items-no_more_gr = t_items_app-del_compl.
po_items-final_inv = t_items_app-final_inv.
po_items-item_cat = t_items_app-item_cat.
po_items-acctasscat = t_items_app-acctasscat.
po_items-distrib = t_items_app-distrib.
po_items-part_inv = t_items_app-part_inv.
po_items-gr_ind = t_items_app-gr_ind.
po_items-gr_non_val = t_items_app-gr_non_val.
po_items-ir_ind = t_items_app-ir_ind.
po_items-gr_basediv = t_items_app-gr_basediv.
po_items-ackn_reqd = t_items_app-ackn_reqd.
po_items-acknowl_no = t_items_app-acknowl_no.
po_items-agreement = t_items_app-agreement.
po_items-agmt_item = t_items_app-agmt_item.
po_items-shipping = t_items_app-shipping.
po_items-customer = t_items_app-customer.
po_items-cond_group = t_items_app-cond_group.
po_items-no_disct = t_items_app-no_c_disc.
po_items-plan_del = t_items_app-plan_del.
po_items-net_weight = t_items_app-net_weight.
po_items-weightunit = t_items_app-weightunit.
po_items-weightunit_iso = t_items_app-weightunit_iso.
po_items-taxjurcode = t_items_app-tax_jur_cd.
po_items-ctrl_key = t_items_app-ctr_key_qm.
po_items-conf_ctrl = t_items_app-conf_ctrl.
po_items-rev_lev = t_items_app-rev_lev.
po_items-fund = t_items_app-fund.
po_items-funds_ctr = t_items_app-funds_ctr.
po_items-cmmt_item = t_items_app-cmmt_item.
po_items-pricedate = t_items_app-price_ctr.
po_items-price_date = t_items_app-price_date.
PO_ITEMS-GROSS_WT = T_ITEMS_APP-GROSS_WGHT.
po_items-volume = t_items_app-volume.
po_items-volumeunit = t_items_app-volumeunit.
po_items-volumeunit_iso = t_items_app-volumeunit_iso.
po_items-incoterms1 = t_items_app-incoterms1.
po_items-incoterms2 = t_items_app-incoterms2.
po_items-pre_vendor = t_items_app-prior_vend.
po_items-vend_part = t_items_app-sub_range.
po_items-hl_item = t_items_app-hl_item.
po_items-gr_to_date = t_items_app-gr_to_date.
po_items-supp_vendor = t_items_app-suppl_vend.
po_items-sc_vendor = t_items_app-sc_vendor.
po_items-kanban_ind = t_items_app-kanban_ind.
po_items-ers = t_items_app-ers.
po_items-r_promo = t_items_app-promotion.
po_items-points = t_items_app-points.
po_items-point_unit = t_items_app-points_un.
po_items-point_unit_iso = t_items_app-points_un_iso.
po_items-season = t_items_app-season_ty.
po_items-season_yr = t_items_app-season_yr.
po_items-bon_grp2 = t_items_app-sett_grp_2.
po_items-bon_grp3 = t_items_app-sett_grp_3.
po_items-sett_item = t_items_app-sett_item.
po_items-minremlife = t_items_app-remshlife.
po_items-rfq_no = t_items_app-rfq.
po_items-rfq_item = t_items_app-rfq_item.
po_items-preq_no = t_items_app-config_org.
po_items-preq_item = t_items_app-preq_item.
po_items-si_cat = t_items_app-si_cat.
po_items-ret_item = t_items_app-ret_item.
po_items-at_relev = t_items_app-at_relev.
po_items-order_reason = t_items_app-ord_reas.
po_items-int_obj_no = t_items_app-del_typ_rt.
po_items-pckg_no = t_items_app-pckg_no.
po_items-grant_nbr = t_items_app-grant_nbr.
po_items-cmmt_item_long = t_items_app-cmmt_item_long.
po_items-func_area_long = t_items_app-func_area_long.
APPEND po_items.
PO_ITEMX-PO_PRICE = 'X'.
po_itemx-po_item = t_items_app-po_item.
po_itemx-delete_ind = 'X'.
po_itemx-short_text = 'X'.
po_itemx-material = 'X'.
po_itemx-ematerial = 'X'.
po_itemx-plant = 'X'.
po_itemx-stge_loc = 'X'.
po_itemx-trackingno = 'X'.
po_itemx-matl_group = 'X'.
po_itemx-info_rec = 'X'.
po_itemx-vend_mat = 'X'.
po_itemx-quantity = 'X'.
po_itemx-po_unit = 'X'.
po_itemx-orderpr_un = 'X'.
po_itemx-conv_num1 = 'X'.
po_itemx-conv_den1 = 'X'.
po_itemx-net_price = 'X'.
po_itemx-price_unit = 'X'.
po_itemx-gr_pr_time = 'X'.
po_itemx-tax_code = 'X'.
po_itemx-bon_grp1 = 'X'.
po_itemx-qual_insp = 'X'.
po_itemx-info_upd = 'X'.
po_itemx-prnt_price = 'X'.
po_itemx-est_price = 'X'.
po_itemx-reminder1 = 'X'.
po_itemx-reminder2 = 'X'.
po_itemx-reminder3 = 'X'.
po_itemx-over_dlv_tol = 'X'.
po_itemx-unlimited_dlv = 'X'.
po_itemx-under_dlv_tol = 'X'.
po_itemx-val_type = 'X'.
po_itemx-no_more_gr = 'X'.
po_itemx-final_inv = 'X'.
po_itemx-item_cat = 'X'.
po_itemx-acctasscat = 'X'.
po_itemx-distrib = 'X'.
po_itemx-part_inv = 'X'.
po_itemx-gr_ind = 'X'.
po_itemx-gr_non_val = 'X'.
po_itemx-ir_ind = 'X'.
po_itemx-gr_basediv = 'X'.
po_itemx-ackn_reqd = 'X'.
po_itemx-acknowl_no = 'X'.
po_itemx-agreement = 'X'.
po_itemx-agmt_item = 'X'.
po_itemx-shipping = 'X'.
po_itemx-customer = 'X'.
po_itemx-cond_group = 'X'.
po_itemx-no_disct = 'X'.
po_itemx-plan_del = 'X'.
po_itemx-net_weight = 'X'.
po_itemx-weightunit = 'X'.
po_itemx-weightunit_iso = 'X'.
po_itemx-taxjurcode = 'X'.
po_itemx-ctrl_key = 'X'.
po_itemx-conf_ctrl = 'X'.
po_itemx-rev_lev = 'X'.
po_itemx-fund = 'X'.
po_itemx-funds_ctr = 'X'.
po_itemx-cmmt_item = 'X'.
po_itemx-pricedate = 'X'.
po_itemx-price_date = 'X'.
PO_ITEMX-GROSS_WT = 'X'.
po_itemx-volume = 'X'.
po_itemx-volumeunit = 'X'.
po_itemx-volumeunit_iso = 'X'.
po_itemx-incoterms1 = 'X'.
po_itemx-incoterms2 = 'X'.
po_itemx-pre_vendor = 'X'.
po_itemx-vend_part = 'X'.
po_itemx-hl_item = 'X'.
po_itemx-gr_to_date = 'X'.
po_itemx-supp_vendor = 'X'.
po_itemx-sc_vendor = 'X'.
po_itemx-kanban_ind = 'X'.
po_itemx-ers = 'X'.
po_itemx-r_promo = 'X'.
po_itemx-points = 'X'.
po_itemx-point_unit = 'X'.
po_itemx-point_unit_iso = 'X'.
po_itemx-season = 'X'.
po_itemx-season_yr = 'X'.
po_itemx-bon_grp2 = 'X'.
po_itemx-bon_grp3 = 'X'.
po_itemx-sett_item = 'X'.
po_itemx-minremlife = 'X'.
po_itemx-rfq_no = 'X'.
po_itemx-rfq_item = 'X'.
po_itemx-preq_no = 'X'.
po_itemx-preq_item = 'X'.
po_itemx-si_cat = 'X'.
po_itemx-ret_item = 'X'.
po_itemx-at_relev = 'X'.
po_itemx-order_reason = 'X'.
po_itemx-int_obj_no = 'X'.
po_itemx-pckg_no = 'X'.
po_itemx-grant_nbr = 'X'.
po_itemx-cmmt_item = 'X'.
po_itemx-func_area_long = 'X'.
APPEND po_itemx.
ENDLOOP.
LOOP AT t_sched_app WHERE ebeln EQ t_header_app-po_number.
poschedule-po_item = t_sched_app-po_item.
poschedule-sched_line = t_sched_app-serial_no.
poschedule-delivery_date = t_sched_app-deliv_date.
poschedule-quantity = t_sched_app-quantity.
poschedule-deliv_time = t_sched_app-deliv_time.
poschedule-preq_no = t_sched_app-preq_no.
poschedule-preq_item = t_sched_app-preq_item.
poschedule-del_datcat_ext = t_sched_app-del_datcat_ext.
APPEND poschedule.
poschedulex-po_item = t_sched_app-po_item.
poschedulex-sched_line = t_sched_app-serial_no.
poschedulex-delivery_date = 'X'.
poschedulex-quantity = 'X'.
poschedulex-deliv_time = 'X'.
poschedulex-preq_no = 'X'.
poschedulex-preq_item = 'X'.
poschedulex-del_datcat_ext = 'X'.
APPEND poschedulex.
ENDLOOP.
LOOP AT t_account_app WHERE ebeln EQ t_header_app-po_number.
poaccount-po_item = t_account_app-po_item.
poaccount-serial_no = t_account_app-serial_no.
poaccount-quantity = t_account_app-quantity.
poaccount-distr_perc = t_account_app-distr_perc.
poaccount-gl_account = t_account_app-g_l_acct.
poaccount-bus_area = t_account_app-bus_area.
poaccount-costcenter = t_account_app-cost_ctr.
poaccount-sd_doc = t_account_app-sd_doc.
poaccount-itm_number = t_account_app-sdoc_item.
poaccount-sched_line = t_account_app-sched_line.
poaccount-asset_no = t_account_app-asset_no.
poaccount-sub_number = t_account_app-sub_number.
poaccount-orderid = t_account_app-order_no.
poaccount-gr_rcpt = t_account_app-gr_rcpt.
poaccount-unload_pt = t_account_app-unload_pt.
poaccount-co_area = t_account_app-co_area.
poaccount-costobject = t_account_app-cost_obj.
poaccount-profit_ctr = t_account_app-profit_ctr.
poaccount-wbs_element = t_account_app-wbs_elem_e.
poaccount-network = t_account_app-network.
poaccount-rl_est_key = t_account_app-rl_est_key.
poaccount-part_acct = t_account_app-part_acct.
poaccount-cmmt_item = t_account_app-cmmt_item.
poaccount-rec_ind = t_account_app-rec_ind.
poaccount-funds_ctr = t_account_app-funds_ctr.
poaccount-fund = t_account_app-fund.
poaccount-func_area = t_account_app-func_area.
poaccount-ref_date = t_account_app-ref_date.
poaccount-cmmt_item_long = t_account_app-cmmt_item_long.
poaccount-func_area_long = t_account_app-func_area_long.
poaccount-res_item = t_account_app-res_item.
READ TABLE t_items_app WITH KEY po_number = t_account_app-ebeln
po_item = t_account_app-po_item.
IF t_items_app-tax_code IS INITIAL.
t_items_app-tax_code = 'U0'.
ENDIF.
poaccount-tax_code = t_items_app-tax_code.
APPEND poaccount.
poaccountx-po_item = t_account_app-po_item.
poaccountx-serial_no = t_account_app-serial_no.
poaccountx-quantity = 'X'.
poaccountx-distr_perc = 'X'.
poaccountx-gl_account = 'X'.
poaccountx-bus_area = 'X'.
poaccountx-costcenter = 'X'.
poaccountx-sd_doc = 'X'.
poaccountx-itm_number = 'X'.
poaccountx-sched_line = 'X'.
poaccountx-asset_no = 'X'.
poaccountx-sub_number = 'X'.
poaccountx-orderid = 'X'.
poaccountx-gr_rcpt = 'X'.
poaccountx-unload_pt = 'X'.
poaccountx-co_area = 'X'.
poaccountx-costobject = 'X'.
poaccountx-profit_ctr = 'X'.
poaccountx-wbs_element = 'X'.
poaccountx-network = 'X'.
poaccountx-rl_est_key = 'X'.
poaccountx-part_acct = 'X'.
poaccountx-cmmt_item = 'X'.
poaccountx-rec_ind = 'X'.
poaccountx-funds_ctr = 'X'.
poaccountx-fund = 'X'.
poaccountx-func_area = 'X'.
poaccountx-ref_date = 'X'.
poaccountx-cmmt_item = 'X'.
poaccountx-func_area = 'X'.
poaccountx-res_item = 'X'.
poaccountx-tax_code = 'X'.
APPEND poaccountx.
ENDLOOP.
IF NOT t_header_app-suppl_vend IS INITIAL.
po_business_partner-buspartno = t_header_app-suppl_vend.
po_business_partner-partnerdesc = 'PM'.
po_business_partner-langu = t_header_app-language.
APPEND po_business_partner.
ENDIF.
IF NOT t_header_app-diff_inv IS INITIAL.
po_business_partner-buspartno = t_header_app-diff_inv.
po_business_partner-partnerdesc = 'EF'.
po_business_partner-langu = t_header_app-language.
APPEND po_business_partner.
ENDIF.
Textos de Cabecera
LOOP AT t_header_tx.
MOVE-CORRESPONDING t_header_tx TO t_txt_h.
APPEND t_txt_h.
ENDLOOP.
CLEAR w_borrar.
Condiciones
LOOP AT t_condic WHERE ebeln EQ t_header_app-po_number.
IF t_condic-kschl EQ 'ZPB0'.
w_borrar = 'X'.
ENDIF.
t_aux-pos = t_condic-kposn.
APPEND t_aux.
po_cond-itm_number = t_condic-kposn.
po_cond-cond_type = t_condic-kschl.
po_cond-cond_value = t_condic-kbetr.
po_cond-currency = t_condic-waers.
po_cond-change_id = 'I'.
PO_COND-COND_ST_NO = '007'.
PO_COND-COND_COUNT = '07'.
PO_COND-CONDISACTI = 'Y'.
po_cond-condition_no = t_condic-knumv.
po_cond-cond_count = t_condic-zaehk.
po_cond-cond_unit = t_condic-kmein.
po_cond-cond_p_unt = t_condic-kpein.
po_cond-applicatio = t_condic-kappl.
po_cond-conpricdat = t_condic-kdatu.
po_cond-calctypcon = t_condic-krech.
po_cond-conbaseval = t_condic-kawrt.
po_cond-conexchrat = t_condic-kkurs.
po_cond-numconvert = t_condic-kumza.
po_cond-denominato = t_condic-kumne.
po_cond-condtype = t_condic-kntyp.
po_cond-stat_con = t_condic-kstat.
po_cond-scaletype = t_condic-knprs.
po_cond-accruals = t_condic-kruek.
po_cond-coninvolst = t_condic-kreli.
po_cond-condorigin = t_condic-kherk.
po_cond-groupcond = t_condic-kgrpe.
po_cond-cond_updat = t_condic-koupd.
po_cond-access_seq = t_condic-kolnr.
po_cond-condcount = t_condic-kopos.
po_cond-condcntrl = t_condic-ksteu.
po_cond-condisacti = t_condic-kinak.
po_cond-condclass = t_condic-koaid.
po_cond-factbasval = t_condic-kfaktor.
po_cond-scalebasin = t_condic-kzbzg.
po_cond-scalbasval = t_condic-kstbs.
po_cond-unitmeasur = t_condic-konms.
po_cond-currenckey = t_condic-konws.
po_cond-condincomp = t_condic-kfkiv.
po_cond-condconfig = t_condic-kvarc.
po_cond-condchaman = t_condic-kmprs.
po_cond-cond_no = t_condic-knumh.
po_cond-vendor_no = t_condic-lifnr.
APPEND po_cond.
po_condx-itm_number = t_condic-kposn.
po_condx-cond_type = 'X'.
po_condx-cond_value = 'X'.
po_condx-change_id = 'X'.
APPEND po_condx.
po_condx-itm_number = t_condic-kposn.
po_condx-itm_numberx = 'X'.
po_condx-cond_type = 'X'.
po_condx-cond_value = 'X'.
po_condx-currency = 'X'.
po_condx-change_id = 'X'.
PO_CONDX-COND_ST_NO = '007'.
PO_CONDX-COND_ST_NOX = 'X'.
PO_CONDX-COND_COUNT = 'X'.
PO_CONDX-CONDISACTI = 'X'.
po_condx-condition_no = t_condic-knumv.
po_condx-condition_nox = 'X'.
po_condx-cond_count = 'X'.
po_condx-cond_unit = 'X'.
po_condx-cond_p_unt = 'X'.
po_condx-applicatio = 'X'.
po_condx-conpricdat = 'X'.
po_condx-calctypcon = 'X'.
po_condx-conbaseval = 'X'.
po_condx-conexchrat = 'X'.
po_condx-numconvert = 'X'.
po_condx-denominato = 'X'.
po_condx-condtype = 'X'.
po_condx-stat_con = 'X'.
po_condx-scaletype = 'X'.
po_condx-accruals = 'X'.
po_condx-coninvolst = 'X'.
po_condx-condorigin = 'X'.
po_condx-groupcond = 'X'.
po_condx-cond_updat = 'X'.
po_condx-access_seq = 'X'.
po_condx-condcount = 'X'.
po_condx-condcntrl = 'X'.
po_condx-condisacti = 'X'.
po_condx-condclass = 'X'.
po_condx-factbasval = 'X'.
po_condx-scalebasin = 'X'.
po_condx-scalbasval = 'X'.
po_condx-unitmeasur = 'X'.
po_condx-currenckey = 'X'.
po_condx-condincomp = 'X'.
po_condx-condconfig = 'X'.
po_condx-condchaman = 'X'.
po_condx-cond_no = 'X'.
po_condx-vendor_no = 'X'.
APPEND po_condx.
ENDLOOP.
IF w_borrar EQ 'X'.
DELETE ADJACENT DUPLICATES FROM t_aux.
CLEAR po_cond.
LOOP AT t_aux.
po_cond-itm_number = t_aux-pos.
po_cond-cond_type = 'PBXX'.
po_cond-change_id = 'D'.
APPEND po_cond.
ENDLOOP.
CLEAR po_condx.
LOOP AT t_aux.
po_condx-itm_number = t_aux-pos.
po_condx-cond_type = 'X'.
po_condx-change_id = 'X'.
APPEND po_condx.
ENDLOOP.
ENDIF.
ENDFORM. " SEPARAR_TABLAS
*&----
*
*& Form CLEAR
*&----
*
FORM clear.
CLEAR po_header.
CLEAR po_headerx.
CLEAR po_items. REFRESH po_items.
CLEAR po_itemx. REFRESH po_itemx.
CLEAR poschedule. REFRESH poschedule.
CLEAR poschedulex. REFRESH poschedulex.
CLEAR poaccount. REFRESH poaccount.
CLEAR poaccountx. REFRESH poaccountx.
CLEAR po_business_partner. REFRESH po_business_partner.
CLEAR t_return. REFRESH t_return.
CLEAR t_txt_h. REFRESH t_txt_h.
CLEAR t_items_tx. REFRESH t_items_tx.
CLEAR po_cond. REFRESH po_cond.
CLEAR po_condx. REFRESH po_condx.
CLEAR po_hcond. REFRESH po_hcond.
CLEAR po_hcondx. REFRESH po_hcondx.
CLEAR t_aux. REFRESH t_aux.
CLEAR w_modif.
CLEAR l_append.
ENDFORM. " CLEAR
*&----
*
*& Form IMPRIME_LOG
*&----
*
FORM imprime_log.
PERFORM init_fieldcat.
PERFORM init_layout.
SORT t_log BY lights.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
i_save = 'A'
TABLES
t_outtab = t_log
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " IMPRIME_LOG
*&----
*
*& Form INIT_FIELDCAT
*&----
*
FORM init_fieldcat.
gt_fieldcat-seltext_l = 'Pedido Anterior'.
gt_fieldcat-fieldname = 'ANTER'.
gt_fieldcat-ref_tabname = 'T_LOG'.
APPEND gt_fieldcat.
gt_fieldcat-seltext_l = 'Nuevo Pedido'.
gt_fieldcat-fieldname = 'EBELN'.
gt_fieldcat-ref_tabname = 'T_LOG'.
APPEND gt_fieldcat.
gt_fieldcat-seltext_l = 'Clase Doc. Compras'.
gt_fieldcat-fieldname = 'BSART'.
gt_fieldcat-ref_tabname = 'T_LOG'.
APPEND gt_fieldcat.
gt_fieldcat-seltext_l = 'Sociedad'.
gt_fieldcat-fieldname = 'BUKRS'.
gt_fieldcat-ref_tabname = 'T_LOG'.
APPEND gt_fieldcat.
gt_fieldcat-seltext_l = 'Centro'.
gt_fieldcat-fieldname = 'WERKS'.
gt_fieldcat-ref_tabname = 'T_LOG'.
APPEND gt_fieldcat.
gt_fieldcat-seltext_l = 'Descripción del error'.
gt_fieldcat-fieldname = 'MENSG'.
gt_fieldcat-ref_tabname = 'T_LOG'.
APPEND gt_fieldcat.
ENDFORM. " INIT_FIELDCAT
*&----
*
*& Form INIT_LAYOUT
*&----
*
FORM init_layout.
Mediante esta estructura podemos definir el formato de salida
gs_layout-zebra = 'X'.
gs_layout-f2code = '&ETA'.
gs_layout-detail_popup = 'X'.
gs_layout-max_linesize = 80.
gs_layout-window_titlebar = text-001.
campos para el uso de Semaforos
gs_layout-lights_fieldname = 'LIGHTS'.
gs_layout-lights_condense = 'X'.
gs_layout-lights_rollname = 'ZECEP'.
ENDFORM. " INIT_LAYOUT
*&----
*
*& Form EXTENSIONES
*&----
*
FORM extensiones.
MOVE 'BAPI_TE_PO_HEADER' TO t_extent-structure.
LOOP AT t_extent_app WHERE po_number EQ t_header_app-po_number.
CONCATENATE
t_extent_app-zterm t_extent_app-zbd1t
t_extent_app-zbd1p t_extent_app-zbd2t
t_extent_app-zbd2p t_extent_app-zbd3t
INTO t_extent-valuepart1.
APPEND t_extent.
ENDLOOP.
ENDFORM. " EXTENSIONES
*&----
*
*& Form TEXTOS
*&----
*
FORM textos.
DATA e_head LIKE thead.
LOOP AT t_header_app.
CLEAR e_head.
CLEAR t_linea. REFRESH t_linea.
LOOP AT t_header_tx WHERE po_number EQ t_header_app-po_number.
AT FIRST.
e_head-tdobject = 'EKKO'.
e_head-tdname = c_ebeln.
e_head-tdspras = 'EN'.
e_head-tdid = t_header_tx-text_id.
e_head-tdversion = '00001'.
ENDAT.
MOVE t_header_tx-text_form TO t_linea-tdformat.
MOVE t_header_tx-text_line TO t_linea-tdline.
APPEND t_linea.
ENDLOOP.
IF NOT t_header_tx[] IS INITIAL.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = e_head
insert = 'X'
savemode_direct = 'X'
owner_specified = 'X'
TABLES
lines = t_linea.
ENDIF.
ENDLOOP.
ENDFORM. " TEXTOS
*&----
*
*& Form condiciones
*&----
*
FORM condiciones.
DATA: BEGIN OF t_datos OCCURS 0,
matnr LIKE eina-matnr,
lifnr LIKE eina-lifnr,
ekorg LIKE eine-ekorg,
werks LIKE eine-werks,
infnr LIKE eine-infnr,
END OF t_datos.
DATA: BEGIN OF t_konp OCCURS 0,
kschl LIKE konp-kschl,
END OF t_konp.
DATA: BEGIN OF t_a017 OCCURS 0,
knumh LIKE konp-knumh,
END OF t_a017.
READ TABLE t_items_app WITH KEY po_number = t_header_app-po_number.
IF NOT t_items_app-info_rec IS INITIAL.
SELECT matnr lifnr infnr
FROM eina
INTO CORRESPONDING FIELDS OF TABLE t_datos
WHERE matnr EQ t_items_app-material
AND lifnr EQ t_header_app-vendor
AND loekz NE 'X'.
LOOP AT t_datos.
SELECT SINGLE werks ekorg
FROM eine
INTO CORRESPONDING FIELDS OF t_datos
WHERE infnr EQ t_datos-infnr.
MODIFY t_datos.
ENDLOOP.
SELECT knumh
FROM a017
INTO TABLE t_a017
FOR ALL ENTRIES IN t_datos
WHERE lifnr = t_datos-lifnr
AND matnr = t_datos-matnr
AND werks = t_datos-werks
AND ekorg = t_datos-ekorg
AND datbi >= po_header-doc_date.
SELECT kschl
FROM konp
INTO TABLE t_konp
FOR ALL ENTRIES IN t_a017
WHERE knumh = t_a017-knumh.
LOOP AT t_konp.
LOOP AT t_condic WHERE kschl EQ t_konp-kschl
AND ebeln EQ t_header_app-po_number.
DELETE t_condic INDEX sy-tabix.
ENDLOOP.
ENDLOOP.
ELSE.
LOOP AT t_condic WHERE ebeln EQ t_header_app-po_number.
DELETE t_condic INDEX sy-tabix.
ENDLOOP.
ENDIF.
CLEAR t_condic.
ENDFORM. " condiciones