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

Former Member
0 Likes
1,823

Hi,

I am creating credit memo foe co-op and I used the function SD_SALESDOCUMENT_CREATE to create it. I tested the function with the same data and also created the CM with VA01 using same data. But when I implement it in the program it is giving me error saying 'Sales document type CR is not defined', it is in the table VBAK-AUART = 'CR'. Please help me what I am doing wrong here.

I will have only one item here. Do I have to fill Schedule lines?

Thanks,

Veni.

LOOP AT gt2_zcoop INTO gs_zcoop1.

PERFORM headerdata.

  • PERFORM texts.

PERFORM itemdata.

APPEND gs_zcoop1 TO gt3_zcoop.

CLEAR gs_zcoop1.

PERFORM call_function.

PERFORM update_gt_zcoop.

PERFORM errorcheckandcommit.

CLEAR chbox.

REFRESH partner.

REFRESH item.

REFRESH itemx.

REFRESH lt_schedules_in.

REFRESH lt_schedules_inx.

REFRESH conditions1.

  • REFRESH order_text.

lv_itemno = 10.

ENDLOOP.

PERFORM update_zsdcoop.

WRITE: /01(179) sy-uline.

PERFORM headings.

WRITE: /01(179) sy-uline.

PERFORM displaydata.

ENDCASE.

*&----


*

*& Form headerdata

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM headerdata.

  • header data

  • Sales document type

header-doc_type = 'CR'.

headerx-doc_type = 'X'.

  • Sales organization

header-sales_org = '300'.

headerx-sales_org = 'X'.

  • Distribution channel

header-distr_chan = '10'.

headerx-distr_chan = 'X'.

  • Division

header-division = '01'.

headerx-division = 'X'.

  • Customer PO Number

header-purch_no_c = gs_zcoop1-cyear.

headerx-purch_no_c = 'X'.

  • Order Reason

header-ord_reason = '008'.

headerx-ord_reason = 'X'.

  • Ref Doc Number

header-ref_doc_l = gs_zcoop1-cyear.

headerx-ref_doc_l = 'X'.

headerx-updateflag = 'I'.

ENDFORM. " headerdata

*&----


*

*& Form itemdata

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM itemdata.

  • Partner data

  • Sold to

partner-partn_role = 'AG'.

partner-partn_numb = gs_zcoop1-kunnr.

APPEND partner.

  • ITEM DATA

itemx-updateflag = 'I'.

  • Line item number.

item-itm_number = lv_itemno.

itemx-itm_number = 'X'.

  • Material

item-material = 'CO-OP'.

itemx-material = 'X'.

  • Quantity

item-target_qty = '1'.

itemx-target_qty = 'X'.

APPEND item.

APPEND itemx.

*Fill schedule lines

lt_schedules_in-itm_number = lv_itemno.

lt_schedules_in-sched_line = '0001'.

lt_schedules_in-req_qty = '1'.

APPEND lt_schedules_in.

*Fill schedule line flags

lt_schedules_inx-itm_number = lv_itemno.

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 = lv_itemno.

conditions1-cond_type = 'ZCCO'.

conditions1-cond_value = gs_zcoop1-coopamt.

conditions1-currency = 'USD'.

conditions1-cond_unit = 'EA'.

conditions1-cond_p_unt = 1.

APPEND conditions1.

ENDFORM. " itemdata

*&----


*

*& Form call_function

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM call_function.

CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'

EXPORTING

sales_header_in = header

sales_header_inx = headerx

IMPORTING

salesdocument_ex = salesdocument

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_text = order_text.

ENDFORM. " call_function

*&----


*

*& Form errorcheck

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM errorcheckandcommit.

  • 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'.

ENDIF.

ENDFORM. " errorcheckandcommit

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,245

Hi All,

I am stuck with this problem. When I single test the FM it is creating CM and with VA01 also I was able to create CM, but with the same fields in the program it is giving me error.

Can some one please help me.

Thanks,

veni.

7 REPLIES 7
Read only

Former Member
0 Likes
1,246

Hi All,

I am stuck with this problem. When I single test the FM it is creating CM and with VA01 also I was able to create CM, but with the same fields in the program it is giving me error.

Can some one please help me.

Thanks,

veni.

Read only

0 Likes
1,245

Any help Please.......

Can we use Sales docu type VBAK-AUART = 'CR'?

What is the problem with my code?

I will really appriciate your help.

Thanks,

Veni.

Read only

0 Likes
1,245

Do I have to use the BUSINESS_OBJECT 'BUS2094'?

Any help is appriciated?

Thanks,

Veni.

Read only

0 Likes
1,245

Is AUART contains internal value for CR (credit memo)? I see there is a conversion routine for this field. I dont have any CR's created in my system. In the table contents check whether auart field has CR in it or any other internal value.

Good luck.

Read only

0 Likes
1,245

Hi Naren,

Yes, there AUART has value 'CR' in the table. I did not get any error while creating with VA01 or single testing the Function. Error is comming only in the Program.

Any one please help.

Thanks,

Veni.

Read only

0 Likes
1,245

hi veni..

pass CR through CONVERSION_EXIT_AUART_INPUT then get the ouput of this FM and pass that

may be G2

try this and let me know:)

Read only

0 Likes
1,245

Thank you Naren and Madan.

I really appriciate your help.

It is stored in the system as 'G2'.

Thanks,

Veni.