BAPI_SALESORDER_CHANGE throws type exception

1.1k views Asked by At

I'm having trouble using the FM BAPI_SALESORDER_CHANGE.

As soon as I execute my report, an exception is thrown by the FM. Following is the dump of the exception.

An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was
 not caught and
therefore caused a runtime error.
The reason for the exception is:
The call to the function module "BAPI_SALESORDER_CHANGE" is incorrect:

In the function module interface, you can specify only
fields of a specific type and length under "ORDER_HEADER_IN".
Although the currently specified field
"LS_ORDER_HEADER_IN" is the correct type, its length is incorrect.

Now, I got that LS_ORDER_HEADER_IN's length is incorrect. But what I don't understand is why it is incorrect.

Following is my report's code:

REPORT ztesting.

DATA:
      lv_sales_document   TYPE bapivbeln-vbeln,

      ls_order_header_in  TYPE bapisdhd1,
      lt_order_header_in  TYPE TABLE OF bapisdhd1,

      ls_order_header_inx TYPE bapisdhd1x,
      lt_order_header_inx TYPE TABLE OF bapisdh1x,

      lt_return           TYPE TABLE OF bapiret2,

      ls_order_item_in    TYPE bapisditm,
      lt_order_item_in    TYPE bapisditm OCCURS 0 WITH HEADER LINE,

      ls_order_item_inx   TYPE bapisditmx,
      lt_order_item_inx   TYPE bapisditmx OCCURS 0 WITH HEADER LINE,

      ls_schedule_lines   TYPE bapischdl,
      lt_schedule_lines   TYPE STANDARD TABLE OF bapischdl WITH HEADER LINE,

      ls_schedule_linesx  TYPE bapischdlx,
      lt_schedule_linesx  TYPE STANDARD TABLE OF bapischdlx WITH HEADER LINE,

      ls_return           TYPE bapiret2.

lv_sales_document               = '5999999'.

ls_order_header_inx-updateflag  = 'U'.

ls_order_item_in-itm_number     = '10'.
ls_order_item_inx-itm_number    = 'X'.

ls_order_item_in-material       = '16'.
ls_order_item_inx-material      = 'X'.

ls_order_item_inx-updateflag    = 'U'.

ls_schedule_lines-itm_number    = '10'.
ls_schedule_linesx-itm_number   = 'X'.

ls_schedule_lines-req_qty       = '1000'.
ls_schedule_linesx-req_qty       = 'X'.


ls_schedule_linesx-req_qty    = 'X'.

APPEND:
  ls_order_header_inx TO lt_order_header_inx,
  ls_order_header_in TO lt_order_header_in,
  ls_order_item_in TO lt_order_item_in,
  ls_order_item_inx TO lt_order_item_inx,
  ls_schedule_lines TO lt_schedule_lines,
  ls_schedule_linesx TO lt_schedule_linesx.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
  EXPORTING
    salesdocument    = lv_sales_document
    order_header_in  = ls_order_header_in
    order_header_inx = ls_order_header_inx
  TABLES
    return           = lt_return
    order_item_in    = lt_order_item_in
    order_item_inx   = lt_order_item_inx
    schedule_lines   = lt_schedule_lines
    schedule_linesx  = lt_schedule_linesx.

DATA: lt_return2 TYPE TABLE OF bapiret2.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    wait = 'X'.

LOOP AT lt_return INTO ls_return.
  WRITE: / sy-subrc, ls_return-type, ls_return-number, ls_return-id, ls_return-message.
ENDLOOP.

Also, can you spot any other mistakes I've made? It's the first time I'm using this function. Note: I copied the code from the SAP Forum. I just modified values and variable names.

Thanks in advance.

Regards, Diego.

1

There are 1 answers

0
Suncatcher On BEST ANSWER

Your types for header are wrong, you need:

  ls_order_header_in TYPE bapisdh1

instead of bapisdhd1, and

  ls_order_header_inx TYPE bapisdh1x

instead of bapisdhd1x. The table types must also match this.

They looks almost similar, but they are not the same, the ones you used are structures for generic SD document, not SO.