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 with SD_SALESDOCUMENT_CREATE

Former Member
0 Likes
5,811

Hi All,

I was trying to execute the fuction SD_SALESDOCUMENT_CREATE in my report and got short dump saying "

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

In the function module interface, you can specify only

fields of a specific type and length under "SALES_HEADER_IN".

Although the currently specified field

"HEADER" is the correct type, its length is incorrect. "

Please help me. Am I missing any mandatory data.

Thanks,

Neelu.


 LOOP AT gt2_zprice INTO gs_zprice.

* header data
* Sales document type
        header-doc_type = 'ZMKD'.
        headerx-doc_type = 'X'.

* Sales organization
        header-sales_org = '0300'.
        headerx-sales_org = 'X'.

* Distribution channel
        header-distr_chan  = '10'.
        headerx-distr_chan = 'X'.

* Division
        header-division = '01'.
        headerx-division = 'X'.

        headerx-updateflag = 'I'.
*        append header.
*        append headerx.

* Partner data
* Sold to
        partner-partn_role = 'AG'.
        partner-partn_numb = gs_zprice-kunnr. "'0000001012'.
        APPEND partner.

* ITEM DATA
        itemx-updateflag = 'I'.

* Line item number.
        item-itm_number = '000010'.
        itemx-itm_number = 'X'.

* Material
        item-material = gs_zprice-matnr. "'000000000000063006'.
        itemx-material = 'X'.

* Plant
        item-plant    = 'INDY'.
        itemx-plant   = 'X'.

* Quantity
        item-target_qty = '0000000000090'.
        itemx-target_qty = '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    = '0000000000090'.
        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.

*      ENDLOOP.

        CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
           EXPORTING
*         SALESDOCUMENT                 =
             sales_header_in               = header
             sales_header_inx              = headerx
*         SENDER                        =
*         BINARY_RELATIONSHIPTYPE       = ' '
**         INT_NUMBER_ASSIGNMENT         = ' '
*         BEHAVE_WHEN_ERROR             = ' '
*         LOGIC_SWITCH                  = ' '
*         BUSINESS_OBJECT               = ' '
*         TESTRUN                       =
*         CONVERT_PARVW_AUART           = ' '
*         STATUS_BUFFER_REFRESH         = 'X'
          IMPORTING
            salesdocument_ex              = salesdocument
*         SALES_HEADER_OUT              =
          TABLES
            return                        = return
            sales_items_in                = item
            sales_items_inx               = itemx
            sales_partners                = partner
            sales_schedules_in            = lt_schedules_in
            sales_schedules_inx           = lt_schedules_inx

  "         sales_conditions_in           = order_conditions_in

*         SALES_CFGS_REF                =
*         SALES_CFGS_INST               =
*         SALES_CFGS_PART_OF            =
*         SALES_CFGS_VALUE              =
*         SALES_CFGS_BLOB               =
*         SALES_CFGS_VK                 =
*         SALES_CFGS_REFINST            =
*         SALES_CCARD                   =

  "          sales_text                    = order_text

*         SALES_KEYS                    =
*         SALES_CONTRACT_IN             =
*         SALES_CONTRACT_INX            =
*         EXTENSIONIN                   =
*         PARTNERADDRESSES              =
*         SALES_SCHED_CONF_IN           =
*         ITEMS_EX                      =
*         SCHEDULE_EX                   =
*         BUSINESS_EX                   =
*         INCOMPLETE_LOG                =
*         EXTENSIONEX                   =
*         CONDITIONS_EX                 =
*         BATCH_CHARC                   =
                .

* 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 the work.

          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
     wait          = 'X'
* IMPORTING
*   RETURN        =
                    .




*    COMMIT WORK AND WAIT.
*
*   WRITE: / 'Document ', salesdocument, ' created'.
*
        ENDIF.
  ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,227

Neelu,

Make sure that your HEADER data definition matches the SALES_HEADER_IN from the BAPI.

20 REPLIES 20
Read only

Former Member
0 Likes
4,228

Neelu,

Make sure that your HEADER data definition matches the SALES_HEADER_IN from the BAPI.

Read only

0 Likes
4,227

Hi John,

It is matching and I tested the Function Module the Credit Memo has been saved and used the same values in my program and getting the error again.

Please guide me.

Thanks,

Neelu.

Read only

0 Likes
4,227

Neelu,

Please copy in your data defs for the BAPI structs so that I can test here.

Especially HEADER data def...

Read only

0 Likes
4,227

Hi John,

Here is the code.

Thanks,

Neelu.


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.

Loop

* header data
* Sales document type
        header-doc_type = 'ZMKD'.
        headerx-doc_type = 'X'.

* Sales organization
        header-sales_org = '300'.
        headerx-sales_org = 'X'.

* Distribution channel
        header-distr_chan  = '20'.
        headerx-distr_chan = 'X'.

* Division
        header-division = '01'.
        headerx-division = 'X'.

        headerx-updateflag = 'I'.
*        append header.
*        append headerx.

* Partner data
* Sold to
        partner-partn_role = 'AG'.
        partner-partn_numb = '1012'.
        APPEND partner.

* ITEM DATA
        itemx-updateflag = 'I'.

* Line item number.
        item-itm_number = '000010'.
        itemx-itm_number = 'X'.

* Material
        item-material = '61012'.
        itemx-material = 'X'.

* Plant
        item-plant    = 'ATLA'.
        itemx-plant   = 'X'.

* Quantity
        item-target_qty = '90.000'.
        itemx-target_qty = 'X'.

        APPEND item.
        APPEND itemx.


CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
           EXPORTING
*         SALESDOCUMENT                 =
             sales_header_in               = header
             sales_header_inx              = headerx
*         SENDER                        =
*         BINARY_RELATIONSHIPTYPE       = ' '
**         INT_NUMBER_ASSIGNMENT         = ' '
*         BEHAVE_WHEN_ERROR             = ' '
*         LOGIC_SWITCH                  = ' '
*         BUSINESS_OBJECT               = ' '
*         TESTRUN                       =
*         CONVERT_PARVW_AUART           = ' '
*         STATUS_BUFFER_REFRESH         = 'X'
          IMPORTING
            salesdocument_ex              = salesdocument
*         SALES_HEADER_OUT              =
          TABLES
            return                        = return
            sales_items_in                = item
            sales_items_inx               = itemx
            sales_partners                = partner
*            sales_schedules_in            = lt_schedules_in
*            sales_schedules_inx           = lt_schedules_inx

*            sales_conditions_in           = order_conditions_in
                .

Endloop.

Read only

0 Likes
4,227

Neelu,

Your data defs are both incorrect for SALES_HEADER_IN and SALES_HEADER_INX.

Should be BAPISDHD1 and BAPISDHD1X

NOT

LIKE bapisdhead1.

LIKE bapisdhead1x.

Read only

0 Likes
4,227

Use:

data: header like BAPISDHD1,

headerx like BAPISDHD1X.

Read only

0 Likes
4,227

Hi John And Mukul,

Thank you.

Now I am not getting short dump, but it is giving me error saying 'No customer master record exists for customer 1012'. I went to XD03 and checked, it is there.

Please help me figuring out the problem.

Thanks,

Neelu.

Read only

0 Likes
4,227

Neelu,

Looks like some other data defs are incorrect as well.

Item table should BAPISDITM

Item update table should BAPISDITMX

Partner table s/b BAPIPARNR

And schedule lines (which I do not see in your clipboard) s/b

BAPISCHDL

and

BAPISCHDLX

Read only

0 Likes
4,227

Use this:

partner-partn_numb = '0000001012'.

Read only

0 Likes
4,227

Or even better

Data: l_lunnr like kna1-kunnr.

move '1012' to l_kunnr.

move l_kunnr to partner-partn_numb.

And make sure that you change the PARTNER int table def to match what I noted above.

And don't forget thsoe points.

Read only

0 Likes
4,227

Hi John,

Use function module CONVERSION_EXIT_ALPHA_INPUT i.e

<b>Instead of </b>

partner-partn_numb = '0000001012'.

<b>Use</b>

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = '1012'

IMPORTING

output = partner-partn_numb.

Reward points if the answer is helpful.

Regards,

Mukul

Read only

0 Likes
4,227

Mukul,

Use -

Data: l_lunnr like kna1-kunnr.

move '1012' to l_kunnr.

move l_kunnr to partner-partn_numb.

It is a faster way then a FM call... FM calls are expensive b/c SAP run-time needs to start another program and then call out to it.

Read only

0 Likes
4,227

Hi John,

I tried again. Still says No customer master record exists for 1012.

Here is the updated code.

Please help me.

Thanks,

Neelu.


DATA: salesdocument      LIKE vbak-vbeln.
DATA: header             LIKE BAPISDHD1.
DATA: headerx            LIKE BAPISDHD1X.
DATA: item               LIKE BAPISDITM  OCCURS 0 WITH HEADER LINE.
DATA: itemx              LIKE BAPISDITMX OCCURS 0 WITH HEADER LINE.
DATA: partner            LIKE BAPIPARNR  OCCURS 0 WITH HEADER LINE.
DATA: return1             LIKE BAPIRET2    OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_in    TYPE STANDARD TABLE OF BAPISCHDL
                         WITH HEADER LINE.
DATA: lt_schedules_inx   TYPE STANDARD TABLE OF BAPISCHDLX
                         WITH HEADER LINE.
DATA: sales_text         LIKE BAPISDTEXT  OCCURS 0 WITH HEADER LINE.



LOOP.

      Data: l_kunnr like kna1-kunnr,
      l_matnr like mara-matnr.

move '1012' to l_kunnr.
move '61012' to l_matnr.
*move l_kunnr to partner-partn_numb.


* header data
* Sales document type
        header-doc_type = 'ZMKD'.
        headerx-doc_type = 'X'.

* Sales organization
        header-sales_org = '300'.
        headerx-sales_org = 'X'.

* Distribution channel
        header-distr_chan  = '20'.
        headerx-distr_chan = 'X'.

* Division
        header-division = '01'.
        headerx-division = 'X'.

        headerx-updateflag = 'I'.
*        append header.
*        append headerx.

* Partner data
* Sold to
        partner-partn_role = 'AG'.
        partner-partn_numb = l_kunnr. "'1012'.
        APPEND partner.

* ITEM DATA
        itemx-updateflag = 'I'.

* Line item number.
        item-itm_number = '000010'.
        itemx-itm_number = 'X'.

* Material
        item-material = l_matnr. "'61012'.
        itemx-material = 'X'.

* Plant
        item-plant    = 'ATLA'.
        itemx-plant   = 'X'.

* Quantity
        item-target_qty = '90.000'.
        itemx-target_qty = '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    = '90.000'.
        APPEND lt_schedules_in.

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

*      ENDLOOP.

        CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
           EXPORTING
*         SALESDOCUMENT                 =
             sales_header_in               = header
             sales_header_inx              = headerx
*         SENDER                        =
*         BINARY_RELATIONSHIPTYPE       = ' '
**         INT_NUMBER_ASSIGNMENT         = ' '
*         BEHAVE_WHEN_ERROR             = ' '
*         LOGIC_SWITCH                  = ' '
*         BUSINESS_OBJECT               = ' '
*         TESTRUN                       =
*         CONVERT_PARVW_AUART           = ' '
*         STATUS_BUFFER_REFRESH         = 'X'
          IMPORTING
            salesdocument_ex              = salesdocument
*         SALES_HEADER_OUT              =
          TABLES
            return                        = return1
            sales_items_in                = item
            sales_items_inx               = itemx
            sales_partners                = partner
            sales_schedules_in            = lt_schedules_in
            sales_schedules_inx           = lt_schedules_inx

  "         sales_conditions_in           = order_conditions_in

*         SALES_CFGS_REF                =
*         SALES_CFGS_INST               =
*         SALES_CFGS_PART_OF            =
*         SALES_CFGS_VALUE              =
*         SALES_CFGS_BLOB               =
*         SALES_CFGS_VK                 =
*         SALES_CFGS_REFINST            =
*         SALES_CCARD                   =

  "          sales_text                    = order_text

*         SALES_KEYS                    =
*         SALES_CONTRACT_IN             =
*         SALES_CONTRACT_INX            =
*         EXTENSIONIN                   =
*         PARTNERADDRESSES              =
*         SALES_SCHED_CONF_IN           =
*         ITEMS_EX                      =
*         SCHEDULE_EX                   =
*         BUSINESS_EX                   =
*         INCOMPLETE_LOG                =
*         EXTENSIONEX                   =
*         CONDITIONS_EX                 =
*         BATCH_CHARC                   =
                .

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

        IF sy-subrc = 0.

          WRITE: / 'Error in creating document'.

        ELSE.

* Commit the work.

          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait          = 'X'
* IMPORTING
*   RETURN        =
 .


*    COMMIT WORK AND WAIT.
*
*   WRITE: / 'Document ', salesdocument, ' created'.
*
                 endif.
        ENDLOOP.

Read only

0 Likes
4,227

Neelu,

Based on your needs, use:

Data: l_kunnr(10) type n,

l_matnr(18) type n.

Read only

0 Likes
4,227

Hi John,

I tried,

Data: l_kunnr(10) type n,

l_matnr(18) type n.

Now the error is 'Material 000000000000061012 is not defined for sales org.300, distr.chan. 20' .

I eventually have to get the data from the file, but for now I am giving values directly. Once the Credit Memo has been created then I thought I can fill the values from my internal table.

Thank you for all your help. Please guide me to solve this problem.

Thanks,

Neelu.

Read only

0 Likes
4,227

Your MM Team can extend the material for you.

Read only

0 Likes
4,227

Hi John,

I gave the material num directly now The CR Req is saved. Thank you John. I really appriciate your help.

Hi Clemens,

I did change it and now the CR req is created. Thank you.

I tried to enter the the following info,

Cust-po-num and able to do it and is also showing in the CR Req.

Sales - order reason - VBAK-AUGRU - No idea where to add this

Header - texts - tried it but not comming in CR Req

Header - conditions - 'ZCPP' - Price - 8.00 KOMV-KBETR - tried it but not comming in CR Req

please help me to include these values.

Thanks,

Neelu.

DATA: salesdocument      LIKE vbak-vbeln.
DATA: header             LIKE bapisdhd1.
DATA: headerx            LIKE bapisdhd1x.
DATA: item               LIKE bapisditm  OCCURS 0 WITH HEADER LINE.
DATA: itemx              LIKE bapisditmx OCCURS 0 WITH HEADER LINE.
DATA: partner            LIKE bapiparnr  OCCURS 0 WITH HEADER LINE.
DATA: return1             LIKE bapiret2    OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_in    TYPE STANDARD TABLE OF bapischdl
                         WITH HEADER LINE.
DATA: lt_schedules_inx   TYPE STANDARD TABLE OF bapischdlx
                         WITH HEADER LINE.
DATA: conditions1         LIKE bapicond OCCURS 0 WITH HEADER LINE.
DATA: order_text         LIKE BAPISDTEXT OCCURS 0 WITH HEADER LINE.



LOOP AT gt2_zprice INTO gs_zprice.

        DATA: l_kunnr(10) TYPE n, "like kna1-kunnr,
        l_matnr(18) TYPE n. " like mara-matnr.

        MOVE '1012' TO l_kunnr.
*move '61012' to l_matnr.

*move l_kunnr to partner-partn_numb.


* header data
* Sales document type
        header-doc_type = 'ZMKD'.
        headerx-doc_type = 'X'.

* Sales organization
        header-sales_org = '300'.
        headerx-sales_org = 'X'.

* Distribution channel
        header-distr_chan  = '20'.
        headerx-distr_chan = 'X'.

* Division
        header-division = '01'.
        headerx-division = 'X'.

        header-purch_no_c = 'SA-07-003'.
        headerx-purch_no_c = 'X'.

        headerx-updateflag = 'I'.
*        append header.
*        append headerx.

* Partner data
* Sold to
        partner-partn_role = 'AG'.
        partner-partn_numb = l_kunnr.                       "'1012'.
        APPEND partner.

* ITEM DATA
        itemx-updateflag = 'I'.

* Line item number.
        item-itm_number = '000010'.
        itemx-itm_number = 'X'.

* Material
        item-material = '61012'.
        itemx-material = 'X'.

* Plant
        item-plant    = 'ATLA'.
        itemx-plant   = 'X'.

* Quantity
        item-target_qty = '90.000'.
        itemx-target_qty = '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    = '90.000'.
        APPEND lt_schedules_in.

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

*Conditions
        conditions1-itm_number  = '000010'.
        conditions1-cond_type   = 'ZCPP'.
        conditions1-cond_value  = '8.000000000'.

*Texts
       order_text-itm_number  = '000010'.
       order_text-text_line = 'Price Protection'.


*      ENDLOOP.

        CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
           EXPORTING
*         SALESDOCUMENT                 =
             sales_header_in               = header
             sales_header_inx              = headerx
*         SENDER                        =
*         BINARY_RELATIONSHIPTYPE       = ' '
**         INT_NUMBER_ASSIGNMENT         = ' '
*         BEHAVE_WHEN_ERROR             = ' '
*         LOGIC_SWITCH                  = ' '
*         BUSINESS_OBJECT               = ' '
*         TESTRUN                       =
*         CONVERT_PARVW_AUART           = ' '
*         STATUS_BUFFER_REFRESH         = 'X'
          IMPORTING
            salesdocument_ex              = salesdocument
*         SALES_HEADER_OUT              =
          TABLES
            return                        = return1
            sales_items_in                = item
            sales_items_inx               = itemx
            sales_partners                = partner
            sales_schedules_in            = lt_schedules_in
            sales_schedules_inx           = lt_schedules_inx

            sales_conditions_in           = conditions1

*         SALES_CFGS_REF                =
*         SALES_CFGS_INST               =
*         SALES_CFGS_PART_OF            =
*         SALES_CFGS_VALUE              =
*         SALES_CFGS_BLOB               =
*         SALES_CFGS_VK                 =
*         SALES_CFGS_REFINST            =
*         SALES_CCARD                   =

          sales_text                    = order_text

*         SALES_KEYS                    =
*         SALES_CONTRACT_IN             =
*         SALES_CONTRACT_INX            =
*         EXTENSIONIN                   =
*         PARTNERADDRESSES              =
*         SALES_SCHED_CONF_IN           =
*         ITEMS_EX                      =
*         SCHEDULE_EX                   =
*         BUSINESS_EX                   =
*         INCOMPLETE_LOG                =
*         EXTENSIONEX                   =
*         CONDITIONS_EX                 =
*         BATCH_CHARC                   =
                .

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

        IF sy-subrc = 0.

          WRITE: / 'Error in creating document'.

        ELSE.

* Commit the work.

          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait          = 'X'
* IMPORTING
*   RETURN        =
 .


*    COMMIT WORK AND WAIT.
*
*   WRITE: / 'Document ', salesdocument, ' created'.
*
        ENDIF.
      ENDLOOP.

Read only

0 Likes
4,227

Glad to help... and feel free to award even more points.

Read only

Former Member
0 Likes
4,227

Hi,

1. Definition of header and sales_header_in should match.

<b>DATA: header LIKE BAPISDHD1.

DATA: headerx LIKE BAPISDHD1X.</b>

2. Pass <b>I</b> instead of <b>X</b> to lt_schedules_inx-updateflag. i.e.

<b>lt_schedules_inx-updateflag = 'I'.</b>

Reward points if the answer is helpful.

Regards,

Mukul

Message was edited by:

Mukul R. Kulkarni

Read only

Clemenss
Active Contributor
0 Likes
4,227

Hi neelu,

header must be declare as type bapisdhd1.

Regards,

Clemens