Call with tables and structures (BAPI_SALESORDER_SIMULATE)

We want to call up a BAPI function, passing and returning values in structures and tables.


The user enters a customer number and several material numbers and quantities. We determine the prices and the availablities via BAPI_SALESORDER_SIMULATE.

GuiXT Script

// create structures and tables if not yet done

not V[orderitems.rowcount]

  // item table for UI
  // use any field names you like
   CreateTable V[orderitems] matnr quantity unit shorttext price _
                           currency avail_date avail_quantity status

  // BAPI stuctures and tables for BAPI_SALESORDER_SIMULATE
  // we only list the columns needed in GuiXT
  // use the SAP names of the function interface (transaction SE37)
  CreateStructure V[header_in] doc_type sales_org distr_chan division
  CreateStructure V[sold_to] name city
  CreateStructure V[bapireturn] message type
  CreateTable V[partners] partn_role partn_numb
  CreateTable V[items_in] material req_qty
  CreateTable V[items_out] itm_number material _
                           sales_unit short_text net_value1 currency
  CreateTable V[schedule_ex] itm_number req_qty req_date confir_qty


// display UI
Offset (2,2)

InputField (0,0) "Customer" (0,20) size=10 name="kunnr" techname="VBAK-KUNNR"

// custmer name returned by BAPI
Text (0,34) "&V[sold_to.name] &V[sold_to.city]"

// Item table
Table (2,0) (12,112) name="orderitems" fixedColumns=9
Column "St" size=3 name="status" -readonly
Column "Material" size=18 name="matnr" techname="VBAP-MATNR"
Column "Quantity" size=10 name="quantity"
Column "Unit" size=6 name="unit" -readonly
Column "Text" size=30 name="shorttext" -readonly
Column "Price" size=10 name="price" -readonly
Column "Curr" size=5 name="currency" -readonly
Column "Deliv.Date" size=12 name="avail_date" -readonly
Column "Quantity" size=10 name="avail_quantity" -readonly

// Button to determine prices and availablity
Pushbutton (12,0) "Determine price and availability" size=(2,35) _


// clear BAPI structures and tables
Clear V[header_in]
Clear V[sold_to]
Clear V[partners]
Clear V[items_in]
Clear V[items_out]
Clear V[schedule_ex]
Clear V[bapireturn]

// fill order header (fixed data)
Set V[header_in.doc_type]   "TA"
Set V[header_in.sales_org]  "1000"
Set V[header_in.distr_chan] "10"
Set V[header_in.division]   "00"

// fill partner table
Set V[partners.partn_role.1] "AG"
Set V[partners.partn_numb.1] "&V[kunnr]"

// fill items table
Set V[k] 1

label next_item
if V[orderitems.matnr.&V[k]]
  Set V[items_in.material.&V[k]] "&V[orderitems.matnr.&V[k]]"

  // the quantity requires 3 decimals in the BAPI interface
  Set V[items_in.req_qty.&V[k]] "&V[orderitems.quantity.&V[k]]" * 1000

Set V[k] &V[k] + 1
goto next_item

// call up the order simulation
export.order_header_in="header_in" _
export.order_partners="partners" _
 export.order_items_in="items_in" _
import.sold_to_party="sold_to" _
import.order_items_out="items_out" _
import.order_schedule_ex="schedule_ex" _

// any error message?
if V[bapireturn.type=E]
  Return "E: &V[bapireturn.message]" -statusline

// copy results into order item table
Set V[k] 1
label next_item_out
if V[items_in.material.&V[k]]
  Set V[orderitems.price.&V[k]] "&V[items_out.net_value1.&V[k]]" / 10000 decimals=2
Set V[orderitems.unit.&V[k]] "&V[items_out.sales_unit.&V[k]]"
Set V[orderitems.shorttext.&V[k]] "&V[items_out.short_text.&V[k]]"
Set V[orderitems.currency.&V[k]] "&V[items_out.currency.&V[k]]"

  // determine availability from schedule table
  Clear V[orderitems.avail_date.&V[k]]
Clear V[orderitems.avail_quantity.&V[k]]
Set V[n] 1
label next_delivery
if V[schedule_ex.itm_number.&V[n]]
     if V[schedule_ex.itm_number.&V[n]=&V[items_out.itm_number.&V[k]]] _
and V[schedule_ex.req_qty.&V[n]>0]
        Set V[orderitems.avail_date.&V[k]] "&V[schedule_ex.req_date.&V[n]]"
        Set V[orderitems.avail_quantity.&V[k]] "&V[schedule_ex.req_qty.&V[n]]" / 1000 decimals=0
    goto set_status_icon

  Set V[n] &V[n] + 1
 goto next_delivery


 // set red status icon if no price could be determined
 // or if a product is not available
 label set_status_icon
  Set V[orderitems.status.&V[k]] "@5B@"   // green OK icon
  if V[orderitems.price.&V[k]=0.00]
    Set V[orderitems.status.&V[k]] "@5D\QNo price available@"   // yellow

  if not V[orderitems.avail_quantity.&V[k]=&V[orderitems.quantity.&V[k]]]
   Set V[orderitems.status.&V[k]] "@5C\QProduct not available@"  // red

  Set V[k] &V[k] + 1
  goto next_item_out

// done