The purchase-to-sales order cycle is the core intercompany procurement workflow in Hechizo SAP Intercompany. When a branch company needs inventory from the central Hechizo warehouse, the operator raises a purchase request in their own SAP B1 company. The sync application then carries that request through a multi-step transformation: it lands in Hechizo as a purchase request, is converted internally into a Hechizo sales order, and finally materializes as a purchase order back in the originating branch. Any subsequent changes to the Hechizo sales order are also propagated back to the branch purchase order, keeping both sides of the transaction in sync. All document relationships are tracked through custom UDF fields so each document can unambiguously trace its origin across company boundaries.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/FCS-Consultores/hechizo-SAP-intercompany/llms.txt
Use this file to discover all available pages before exploring further.
Document flow
Branch creates a purchase request (SolicitudCompra)
An operator in a branch company (e.g.,
hogar) creates a purchase request in SAP B1 with ReqType = 171. The request must have the custom UDF U_Estado = 'N' (unprocessed) and a DocStatus = 'O' (open). The Requester field must link to a valid employee record in OHEM.No application code runs at this step — it is a manual SAP B1 action.Branch purchase requests → Hechizo purchase requests
OPRQ and joining OHEM for the requester code) and posts them to Hechizo’s PurchaseRequests Service Layer endpoint using Conexion.token_hechizo. On success, the branch record is flagged with U_Estado = 'Y' and the assigned Hechizo DocNum/DocEntry are written back into U_DocNumDestino/U_DocEntryDestino. On failure the error message is stored in U_ComentarioError.U_OrigenIntercompany UDF on the created Hechizo purchase request is set to the full HANA database name of the originating branch (e.g., 10071_3_102_956112), establishing the cross-company link.Hechizo purchase requests → Hechizo sales orders (OrdVenta)
OPRQ table for purchase requests that have U_ConvertirOV = 'Y' (flagged for conversion), are open and not cancelled, have a non-null U_OrigenIntercompany, and have U_Estado = 'N'. For each qualifying request, it:- Determines the correct
CardCodefor the destination branch by callingConsultarCardCodewith the origin database name. - Posts the document to Hechizo’s
Ordersendpoint, creating a sales order. - Updates the Hechizo
OPRQrecord withU_Estado = 'Y'and the new sales order’sDocEntry/DocNum. - Closes the originating purchase request via a
PurchaseRequests({DocEntry})/Closecall so it no longer appears in open document queries.
Hechizo sales orders → Branch purchase orders (OrdCompra)
ORDR (sales orders) table for open, unprocessed orders (U_Estado = 'N') whose U_OrigenIntercompany matches the branch’s full database name, or whose CardCode matches the branch’s intercompany partner code. It then:- Resolves the corresponding branch purchase request
DocEntryfrom the Hechizo solicitud chain. - Builds a purchase order JSON object from the Hechizo sales order header and line items.
- Sets
U_DocEntryOrigenandU_DocNumOrigenon the new purchase order to the Hechizo sales order values. - When the sales order originated from a branch solicitud, document lines carry a
BaseType/BaseEntryreference back to the branch purchase request (BaseType = 1470000113). - Posts to the branch’s
PurchaseOrdersService Layer endpoint. - Stamps the Hechizo
ORDRrecord withU_Estado = 'Y'and the branch’s newDocEntry/DocNum.
Replicate Hechizo sales order updates → Branch purchase orders
ActualizarEnOrdCompra picks up those changes and patches the corresponding branch purchase orders using a Service Layer PATCH request, keying on U_DocEntryOrigen to locate the correct destination document.Document tracking UDFs
Cross-company document linking relies on custom User-Defined Fields that must be present in every participating SAP B1 company. The table below lists the key UDFs used throughout the purchase-sales cycle.| UDF | Table | Purpose |
|---|---|---|
U_Estado | OPRQ, ORDR, OPOR | Processing state flag: 'N' = pending, 'Y' = processed |
U_DocEntryOrigen | ORDR, OPOR | DocEntry of the source document in the origin company |
U_DocNumOrigen | ORDR, OPOR | Human-readable DocNum of the source document |
U_DocEntryDestino | OPRQ, ORDR | DocEntry assigned to the created document in the destination |
U_DocNumDestino | OPRQ, ORDR | DocNum assigned in the destination company |
U_OrigenIntercompany | OPRQ, ORDR, OPOR | Full HANA database name of the originating company |
U_ConvertirOV | OPRQ (Hechizo) | Flag set by a user or rule to trigger conversion to a sales order |
U_ComentarioError | OPRQ, ORDR | Service Layer error message stored on failed attempts |
V2 test variant
The source contains aProcesarEnOrdCompraV2 method and a corresponding ActualizarEnOrdCompraV2. These are identical in logic to their V1 counterparts except that ProcesarEnOrdCompraV2 additionally calls ComparePricesAndLog after a successful insert, logging any price discrepancies between the Hechizo sales order and the branch price list. Both variants are currently commented out in Program.cs and are marked as TEST: