Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Error BAPI_SALESORDER_CREATEFROMDAT2 - quantity of position at zero

Former Member
0 Likes
807

Google Translator

Hi,

I have implemented a program with the BAPI_SALESORDER_CREATEFROMDAT2, and although properly filled all the required fields, including the field of quantity with the value 1, the document is created correctly but the position appears 0 and therefore the document does not calculate the value field overall.

He sought any notes or other OSS thread describing the problem and nothing found.

Sending the code of the test program.

Regards,

Jhonny


REPORT  zpruebajm08.

DATA:
* Order partners
      li_order_partners    TYPE STANDARD TABLE OF bapiparnr,
      l_order_partners     LIKE bapiparnr,

* Structures for order header
      l_order_header_in    LIKE bapisdhd1,
      l_order_header_inx   LIKE bapisdhd1x,

* Tables for order items
      li_order_items_in    TYPE STANDARD TABLE OF bapisditm,
      l_order_items_in     LIKE bapisditm,

      li_order_items_inx   TYPE STANDARD TABLE OF bapisditmx,
      l_order_items_inx    LIKE bapisditmx,

* Return table from bapi call
      li_return TYPE STANDARD TABLE OF bapiret2,
      l_return  TYPE bapiret2,

* Sales document number
      l_vbeln LIKE bapivbeln-vbeln,

* Error flag
      l_errflag(1) TYPE c.
*------------------------------------------------------------------
* Build partner information
*------------------------------------------------------------------
  CLEAR l_order_partners.
  l_order_partners-partn_role = 'AG'.
  l_order_partners-partn_numb = '0000001000'.
  APPEND l_order_partners TO li_order_partners.

*------------------------------------------------------------------
* Build order header
*------------------------------------------------------------------

* Update flag
  l_order_header_inx-updateflag = 'I'.

* Sales document type
  l_order_header_in-doc_type    = 'TA'.
  l_order_header_inx-doc_type   = 'X'.

* Sales organization
  l_order_header_in-sales_org  = '1000'.
  l_order_header_inx-sales_org  = 'X'.

* Distribution channel
  l_order_header_in-distr_chan = '10'.
  l_order_header_inx-distr_chan = 'X'.

* Division
  l_order_header_in-division = '00'.
  l_order_header_inx-division = 'X'.

*------------------------------------------------------------------
* Build order item(s) - Only 1 is used in this example
*------------------------------------------------------------------

  l_order_items_in-itm_number = '10'.
  l_order_items_inx-itm_number = '10'.

  l_order_items_in-material = 'GTS-14001'.
  l_order_items_inx-material = 'X'.

  l_order_items_in-target_qty = '1.000'.
  l_order_items_inx-target_qty = 'X'.

  APPEND l_order_items_in TO li_order_items_in.

  l_order_items_inx-updateflag = 'I'.
  APPEND l_order_items_inx TO li_order_items_inx.


*------------------------------------------------------------------
* CALL Bapi
*------------------------------------------------------------------

  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
  EXPORTING
    order_header_in  = l_order_header_in
    order_header_inx = l_order_header_inx
*      testrun          = 'X'
  IMPORTING
    salesdocument    = l_vbeln
  TABLES
    return           = li_return
    order_items_in   = li_order_items_in
    order_items_inx  = li_order_items_inx
    order_partners   = li_order_partners.

*------------------------------------------------------------------
* Check and write Return table
*------------------------------------------------------------------

  CLEAR l_errflag.

  WRITE: / 'Sales document: ', l_vbeln.

  LOOP AT li_return INTO l_return.
    WRITE: / l_return-type, l_return-message.
    IF l_return-type = 'E'.
      l_errflag = 'X'.
    ENDIF.
  ENDLOOP.

*------------------------------------------------------------------
* No errors - Commit
*------------------------------------------------------------------

IF l_errflag  IS INITIAL.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
     wait = 'X'
     .
ENDIF.

Google Translator

Hi,

I have implemented a program with the BAPI_SALESORDER_CREATEFROMDAT2, and although properly filled all the required fields, including the field of quantity with the value 1, the document is created correctly but the position appears 0 and therefore the document does not calculate the value field overall.

He sought any notes or other OSS thread describing the problem and nothing found.

Sending the code of the test program.

Regards,

Jhonny


REPORT  zpruebajm08.

DATA:
* Order partners
      li_order_partners    TYPE STANDARD TABLE OF bapiparnr,
      l_order_partners     LIKE bapiparnr,

* Structures for order header
      l_order_header_in    LIKE bapisdhd1,
      l_order_header_inx   LIKE bapisdhd1x,

* Tables for order items
      li_order_items_in    TYPE STANDARD TABLE OF bapisditm,
      l_order_items_in     LIKE bapisditm,

      li_order_items_inx   TYPE STANDARD TABLE OF bapisditmx,
      l_order_items_inx    LIKE bapisditmx,

* Return table from bapi call
      li_return TYPE STANDARD TABLE OF bapiret2,
      l_return  TYPE bapiret2,

* Sales document number
      l_vbeln LIKE bapivbeln-vbeln,

* Error flag
      l_errflag(1) TYPE c.
*------------------------------------------------------------------
* Build partner information
*------------------------------------------------------------------
  CLEAR l_order_partners.
  l_order_partners-partn_role = 'AG'.
  l_order_partners-partn_numb = '0000001000'.
  APPEND l_order_partners TO li_order_partners.

*------------------------------------------------------------------
* Build order header
*------------------------------------------------------------------

* Update flag
  l_order_header_inx-updateflag = 'I'.

* Sales document type
  l_order_header_in-doc_type    = 'TA'.
  l_order_header_inx-doc_type   = 'X'.

* Sales organization
  l_order_header_in-sales_org  = '1000'.
  l_order_header_inx-sales_org  = 'X'.

* Distribution channel
  l_order_header_in-distr_chan = '10'.
  l_order_header_inx-distr_chan = 'X'.

* Division
  l_order_header_in-division = '00'.
  l_order_header_inx-division = 'X'.

*------------------------------------------------------------------
* Build order item(s) - Only 1 is used in this example
*------------------------------------------------------------------

  l_order_items_in-itm_number = '10'.
  l_order_items_inx-itm_number = '10'.

  l_order_items_in-material = 'GTS-14001'.
  l_order_items_inx-material = 'X'.

  l_order_items_in-target_qty = '1.000'.
  l_order_items_inx-target_qty = 'X'.

  APPEND l_order_items_in TO li_order_items_in.

  l_order_items_inx-updateflag = 'I'.
  APPEND l_order_items_inx TO li_order_items_inx.


*------------------------------------------------------------------
* CALL Bapi
*------------------------------------------------------------------

  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
  EXPORTING
    order_header_in  = l_order_header_in
    order_header_inx = l_order_header_inx
*      testrun          = 'X'
  IMPORTING
    salesdocument    = l_vbeln
  TABLES
    return           = li_return
    order_items_in   = li_order_items_in
    order_items_inx  = li_order_items_inx
    order_partners   = li_order_partners.

*------------------------------------------------------------------
* Check and write Return table
*------------------------------------------------------------------

  CLEAR l_errflag.

  WRITE: / 'Sales document: ', l_vbeln.

  LOOP AT li_return INTO l_return.
    WRITE: / l_return-type, l_return-message.
    IF l_return-type = 'E'.
      l_errflag = 'X'.
    ENDIF.
  ENDLOOP.

*------------------------------------------------------------------
* No errors - Commit
*------------------------------------------------------------------

IF l_errflag  IS INITIAL.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
     wait = 'X'
     .
ENDIF.

1 REPLY 1
Read only

Former Member
0 Likes
486

Google Translator

Hi,

I have implemented other program with the BAPI_SALESORDER_CREATEFROMDAT1, with same data and works perfectly, but tyhis BAPI is obsolete. What is the problem with the BAPI_SALESORDER_CREATEFROMDAT2???...

Sending the code of the test program.

Regards,

Jhonny


REPORT  zpruebajm09.
*-------------------------Data Declaration-----------------------------*
DATA: st_bapisdhead LIKE bapisdhead, " Sales Order Header Data
      ta_bapiitemin LIKE bapiitemin OCCURS 0 WITH HEADER LINE, " Ln item
      ta_bapipartnr LIKE bapipartnr OCCURS 0 WITH HEADER LINE, " Partner
      d_bapireturn1 LIKE bapireturn1, " Bapi return msg
      d_vbeln LIKE bapivbeln-vbeln. " Sales Order Number

* Move the data to create sales order in the repective parameters------*
MOVE: 'TA' TO st_bapisdhead-doc_type,
      '1000' TO st_bapisdhead-sales_org,
      '10' TO st_bapisdhead-distr_chan,
      '00' TO st_bapisdhead-division,

'00010' TO ta_bapiitemin-itm_number,
'GTS-14001' TO ta_bapiitemin-material,
'1000' TO ta_bapiitemin-plant,
'1.000' TO ta_bapiitemin-req_qty,

'AG' TO ta_bapipartnr-partn_role, " Sold to Party
'0000001000' TO ta_bapipartnr-partn_numb.

* Append the internal tables-------------------------------------------*
APPEND ta_bapipartnr.
CLEAR ta_bapipartnr.
APPEND ta_bapiitemin.
CLEAR ta_bapiitemin.

* Move ship to party---------------------------------------------------*
MOVE: 'RG' TO ta_bapipartnr-partn_role, " Ship to party
'0000001000' TO ta_bapipartnr-partn_numb.

* Append the internal tables-------------------------------------------*
APPEND ta_bapipartnr.
CLEAR ta_bapipartnr.


* Call the Bapi to create the sales order
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
EXPORTING
  order_header_in = st_bapisdhead
* WITHOUT_COMMIT = ' '
* CONVERT_PARVW_AUART = ' '
IMPORTING
  salesdocument = d_vbeln
* SOLD_TO_PARTY =
* SHIP_TO_PARTY =
* BILLING_PARTY =
  return = d_bapireturn1
TABLES
  order_items_in = ta_bapiitemin
  order_partners = ta_bapipartnr
* ORDER_ITEMS_OUT =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CCARD =
* ORDER_CFGS_BLOB =
* ORDER_SCHEDULE_EX =
  .

IF d_vbeln <> SPACE.
  WRITE: 'Sales order No. ', d_vbeln.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    WAIT = 'X'.
ELSE.
  WRITE: 'No data'.
  WRITE: / d_bapireturn1-MESSAGE.
ENDIF.