Application Development 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: 

BAPI_SALESDOCU_CREATEFROMDATA1 runtime error

Former Member
0 Kudos

I am having a problem with the length of the header structure when I am calling FM BAPI_SALESDOCU_CREATEFROMDATA1. The error that I get is as follows:

Error analysis

An exception occurred. This exception is dealt with in more detail below

. The exception, which is assigned to the class 'CX_SY_DYN_CALL_ILLEGAL_TYPE',

was neither

caught nor passed along using a RAISING clause, in the procedure

"CREATESALESORDER" "(FORM)"

.

Since the caller of the procedure could not have expected this exception

to occur, the running program was terminated.

The reason for the exception is:

The call to the function module "BAPI_SALESORDER_CREATEFROMDAT1" is incorrect:

<b> 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

"HEADER" is the correct type, its length is incorrect. </b>

Here is the code that effects the header:

DATA: header LIKE bapisdhead1,

...

FORM fillheader .

  IF t_invoice = '1'.
    header-doc_type = 'OR'.
  ELSE.
    header-doc_type = 'FD'.
  ENDIF.

  header-purch_date = t_erdat.
  header-purch_no_c = t_bstnk.

  CASE t_site.
    WHEN 'SY' OR 'sy' OR 'Sy' OR 'sy'.
      header-sales_org = '0010'.
      headerx-sales_org = 'X'.
      header-distr_chan = '10'.
      headerx-distr_chan = 'X'.
      header-division = '00'.
      headerx-division = 'X'.
*      header-SALES_GRP
*      headerx-sales_grp = 'X'.
*      header-SALES_OFF
*      header - sales_off = 'X'.
    WHEN 've' OR 've' OR 've' OR 've'.
      header-sales_org = '0010'.
      headerx-sales_org = 'X'.
      header-distr_chan = '10'.
      headerx-distr_chan = 'X'.
      header-division = '00'.
      headerx-division = 'X'.
*      header-SALES_GRP
*      headerx-sales_grp = 'X'.
*      header-SALES_OFF
*      header - sales_off = 'X'.
  ENDCASE.


ENDFORM.                    " fillheader

...

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
  EXPORTING
    order_header_in           = header
*   WITHOUT_COMMIT            = ' '
*   CONVERT_PARVW_AUART       = ' '
* IMPORTING
*   SALESDOCUMENT             =
*   SOLD_TO_PARTY             =
*   SHIP_TO_PARTY             =
*   BILLING_PARTY             =
*   RETURN                    =
  tables
    order_items_in            = item
    order_partners            = partner
*   ORDER_ITEMS_OUT           =
*   ORDER_CFGS_REF            =
*   ORDER_CFGS_INST           =
*   ORDER_CFGS_PART_OF        =
*   ORDER_CFGS_VALUE          =
*   ORDER_CCARD               =
*   ORDER_CFGS_BLOB           =
*   ORDER_SCHEDULE_EX         =
 .

However, I have a test program, for the FM call, and it executes just fine. The test program is below:

                     *&---------------------------------------------------------------------*
*& Report  Z_PERFECT_TEN
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  z_perfect_ten.

*SALES ORDER INPUT CREATION.

PARAMETERS: p_auart TYPE auart OBLIGATORY.
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
PARAMETERS: p_spart TYPE vtweg OBLIGATORY.

PARAMETERS: p_sold TYPE kunnr OBLIGATORY.
PARAMETERS: p_ship TYPE kunnr OBLIGATORY.

*ITEM
PARAMETERS: p_matnr TYPE matnr OBLIGATORY.
PARAMETERS: p_menge TYPE kwmeng OBLIGATORY.
PARAMETERS: p_plant TYPE werks_d OBLIGATORY.
PARAMETERS: p_itcat TYPE pstyv OBLIGATORY.

* DATA DECLARATIONS.
DATA: v_vbeln LIKE vbak-vbeln.
DATA: header LIKE bapisdhead1.
DATA: headerx LIKE bapisdhead1x.
DATA: item LIKE bapisditem OCCURS 0 WITH HEADER LINE.
DATA: itemx LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
DATA: partner LIKE bapipartnr OCCURS 0 WITH HEADER LINE.
DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_inx TYPE STANDARD TABLE OF bapischdlx
WITH HEADER LINE.
DATA: lt_schedules_in TYPE STANDARD TABLE OF bapischdl
WITH HEADER LINE.

* HEADER DATA
header-doc_type = p_auart.
headerx-doc_type = 'X'.

header-sales_org = p_vkorg.
headerx-sales_org = 'X'.

header-distr_chan = p_vtweg.
headerx-distr_chan = 'X'.

header-division = p_spart.
headerx-division = 'X'.

headerx-updateflag = 'I'.

* PARTNER DATA
partner-partn_role = 'AG'.
partner-partn_numb = p_sold.
APPEND partner.

partner-partn_role = 'WE'.
partner-partn_numb = p_ship.
partner-name = 'Aaron Shover'.
partner-street = '1285 Ritner Highway'.
partner-City = 'Carlisle'.
partner-Region = 'PA'.
partner-country = 'US'.
partner-postl_code = '17013'.
partner-taxjurcode = '123456'.
partner-district = 'Cumberland'.
*clear partner-TAXJURCODE.
*clear partner-DISTRICT.
partner-TRANSPZONE = partner-Region.

APPEND partner.

* ITEM DATA
itemx-updateflag = 'I'.

item-itm_number = '000010'.
itemx-itm_number = 'X'.


item-material = p_matnr.
itemx-material = 'X'.

item-plant = p_plant.
itemx-plant = 'X'.

item-target_qty = p_menge.
itemx-target_qty = 'X'.

item-target_qu = 'FT2'.
itemx-target_qu = 'X'.

item-item_categ = p_itcat.
itemx-item_categ = 'X'.

APPEND item.
APPEND itemx.

* Fill schedule lines
lt_schedules_in-itm_number = '000010'.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = p_menge.
APPEND lt_schedules_in.

* Fill schedule line flags
lt_schedules_inx-itm_number = '000010'.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-updateflag = 'X'.
lt_schedules_inx-req_qty = 'X'.
APPEND lt_schedules_inx.

* Call the BAPI
CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
EXPORTING
sales_header_in = header
sales_header_inx = headerx
IMPORTING
salesdocument_ex = v_vbeln
TABLES
return = return
sales_items_in = item
sales_items_inx = itemx
sales_schedules_in = lt_schedules_in
sales_schedules_inx = lt_schedules_inx
sales_partners = partner.

* Check the return table.
LOOP AT return WHERE type = 'E' OR type = 'A'.
EXIT.
ENDLOOP.

IF sy-subrc = 0.

WRITE: / 'Error in creating document'.

ELSE.

COMMIT WORK AND WAIT.

WRITE: / 'Document ', v_vbeln, ' created'.

ENDIF.

Do you have any idea what I need to do to the length?

Thanks,

Davis

4 REPLIES 4

Former Member
0 Kudos

Try:

DATA: header LIKE bapisdhead,   "<====

Rob

0 Kudos

Rob,

That did it, thanks. Do you know why, or what the difference is?

Davis

0 Kudos

They're different structures. I always try to use the structure defined in the interface.

Rob

0 Kudos

Yeah, I just realized that it wasn't defined. I was looking at BAPI_SALESDOCU_CREATEFROMDATA2 on my other monitor and didn't realize it.

Thanks.