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

problem while creating sales order using BAPI

former_member190312
Active Participant
0 Likes
2,815

Hi all,

i am creating a sales order from the purchase order data.

when my client will send a PO in EDI format, my 3rd party edi tool will convert that edi formatted PO to text format. then i will upload that text formatted PO to my program then i will create a SO from those uploaded PO data using BAPI BAPI_SALESORDER_CREATEFROMDAT2.

but,no sales order is being created.& also i am not getting any return message.by debugging also, i am not getting the error.plz suggest where i am doing mistake.below is the coding.

DATA:

gfilename LIKE rlgrap-filename.

*--Internal tables

DATA: BEGIN OF i_item OCCURS 50. "Create Material Document Item

INCLUDE STRUCTURE BAPISDITM .

DATA: END OF i_item .

DATA: BEGIN OF i_partner OCCURS 20. "Return parameter

INCLUDE STRUCTURE BAPIPARNR.

DATA: END OF i_partner.

DATA: BEGIN OF i_schedule OCCURS 20. "Return parameter

INCLUDE STRUCTURE BAPISCHDL .

DATA: END OF i_schedule.

DATA: BEGIN OF i_cond OCCURS 20. "Return parameter

INCLUDE STRUCTURE BAPICOND .

DATA: END OF i_cond.

DATA: BEGIN OF i_part OCCURS 0, " Internal table for split data

part(20),

END OF i_part.

DATA: BEGIN OF i_return OCCURS 20. "Return parameter

INCLUDE STRUCTURE bapiret2.

DATA: END OF i_return.

*-- Work areas

DATA: BEGIN OF wa_header . "sales Document Header Data

INCLUDE STRUCTURE BAPISDHD1.

DATA: END OF wa_header .

*DATA: BEGIN OF wa_return . "Output Structure

  • INCLUDE STRUCTURE BAPIRET2.

*DATA: END OF wa_return .

DATA: begin of sorder.

INCLUDE STRUCTURE BAPIVBELN.

DATA: end of sorder.

data:begin of t_upload,

ebeln(10), "PO no(seagate)

aedat like sy-datum , "PO date

bsart(4) , "PO type

vdatu like sy-datum , "requested delivery date

kunnr(10) , "customer no-sold-to-party

  • kunak like vbak-kunnr, "bill-to-party

name1_s(20), "name1 of sold-to-party

name2_s(15), "name2 of sold-to-party

land1_s(3), "country

ort01_s(10), "city

regio_s(3), "region(state/province)

pstlz_s(10), "postal code

adrnr_s(10), "address

bstkd_e(10), "end customer purchase order

posex(6), "end customer PO line no(item no)

kdmat(18), "end customer material no(part no)

kunag(10), "ship-to-party

name1_c(20), "name1 of ship-to-party

name2_c(15), "name2 of ship-to-party

land1_c(3), "country

ort01_c(10), "city

regio_c(3), "region(state/province)

pstlz_c(10), "postal code

adrnr_c(10), "address

posnr(6), "item no(seagate PO line no)

pstyv(4), "item category

matnr(18), "material no(seagate 9 digit part no)

zmeng(13), "Target quantity in sales unit

  • vrkme like vbap-vrkme, "sales unit

meins(3), "UOM

  • posnr_tot like vbap-posnr,"Total no. of line items

werks(4), "plant

  • vstel like vbap-vstel, "shipping point

empst(10), "receiving point

shtyp(4), "shipment type

route(6), "route

vsbed(2), "shipping conds

  • rkfkf like vbap-rkfkf, "method of billing for co/ppc orders

zterm(4), "terms of payment key

inco1(3), "F.O.B inco term1

inco2(3), "F.O.B inco term2

end of t_upload.

Data: wa_upload like t_upload,

i_upload like standard table of t_upload.

Data:v_kunnr like kna1-kunnr,

v_posnr like vbap-posnr,

v_matnr like vbap-matnr,

v_zmeng like vbap-zmeng,

v_kunag like kna1-kunnr.

*---Constants

CONSTANTS: c_comma TYPE c VALUE ',', " For splitting data at commas

c_01(2) TYPE c VALUE '01', " For movement code in Bapi

c_b TYPE c VALUE 'B', " For mvt. Indicator in Bapi

c_creat(5) TYPE c VALUE 'CREAT', " For button text

c_clear(5) TYPE c VALUE 'CLEAR', " For clear button

c_mvmt(4) TYPE c VALUE 'MVMT',

c_ok(2) TYPE c VALUE 'OK',

c_error(5) TYPE c VALUE 'Error'.

*--


SELECTION SCREEN DESIGN--


SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.

PARAMETERS:

p_auart LIKE vbak-auart, " order type

p_vkorg LIKE vbak-vkorg, " sales org

p_vtweg LIKE vbak-vtweg, " dist channel

p_spart LIKE vbak-spart, " division

p_vkgrp LIKE vbak-vkgrp, " sales group

p_vkbur LIKE vbak-vkbur, "sales office

p_file(256) default 'c:/saleorder.txt'. "File name

SELECTION-SCREEN END OF BLOCK blk1.

SELECTION-SCREEN PUSHBUTTON 15(10) v_create USER-COMMAND creat.

SELECTION-SCREEN PUSHBUTTON 40(10) v_clear USER-COMMAND clear.

*----


INITIALIZATION -


INITIALIZATION.

v_create = c_creat .

v_clear = c_clear.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM selectfile USING p_file.

*--


AT SELECTION_SCREEN--


AT SELECTION-SCREEN .

IF sy-ucomm = c_clear.

PERFORM f_clear.

  • ELSE.

  • IF sy-ucomm <> c_mvmt.

**--- Validating the input data.

  • PERFORM f_check_inputs.

ELSEif sy-ucomm = c_creat.

*--- Validating the input data.

PERFORM f_check_inputs.

*-- Uploading the PO data.

PERFORM f_PO_upload.

*---checking the PO data

  • PERFORM f_check_upload_data.

*---create sales order from PO data

PERFORM f_Sales_order_create.

ENDIF.

FORM f_PO_upload.

gfilename = p_file.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = gfilename

filetype = 'DAT'

TABLES

data_tab = i_upload

EXCEPTIONS

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10.

IF sy-subrc <> 0.

MESSAGE i398(00) WITH '(WS_UPLOAD)'

' Errors occured with exception '

sy-subrc.

ENDIF.

ENDFORM. " f_PO_upload

&----


*& Form selectfile

&----


  • text

----


  • -->P_P_FILE text

----


FORM selectfile CHANGING value(filename) TYPE c.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = gfilename

def_path = 'C:\'

mask = ',*.txt.'

mode = 'O'

title = 'Select File Name'

IMPORTING

filename = filename

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

ENDFORM. " selectfile

FORM f_Sales_order_create.

PERFORM f_fill_header.

PERFORM f_fill_partner.

PERFORM f_fill_item.

PERFORM f_call_BAPI.

ENDFORM. " f_Sales_order_create

&----


*& Form f_fill_header

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_fill_header.

move p_auart to wa_header-doc_type.

move p_vkorg to wa_header-sales_org.

move p_vtweg to wa_header-distr_chan.

move p_spart to wa_header-division.

move p_vkgrp to wa_header-sales_grp.

move p_vkbur to wa_header-sales_off.

Read table i_upload into wa_upload index 1.

move wa_upload-ebeln to wa_header-purch_no_c.

move wa_upload-aedat to wa_header-purch_date.

move wa_upload-bsart to wa_header-po_method.

move wa_upload-vdatu to wa_header-req_date_h.

move wa_upload-bstkd_e to wa_header-purch_no_s.

*move wa_upload-route to wa_header-route.

move wa_upload-vsbed to wa_header-ship_cond.

move wa_upload-empst to wa_header-rec_point.

move wa_upload-shtyp to wa_header-ship_type.

move wa_upload-zterm to wa_header-pmnttrms.

move wa_upload-inco1 to wa_header-incoterms1.

move wa_upload-inco2 to wa_header-incoterms2.

ENDFORM. " f_fill_header

&----


*& Form f_fill_partner

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_fill_partner.

if not wa_upload-kunnr is initial.

select single kunnr from kna1 into v_kunnr

where kunnr = wa_upload-kunnr.

if sy-subrc <> 0.

Message E014 with 'customer does not exist'.

else.

move 'AG' to i_partner-partn_role.

move wa_upload-kunnr to i_partner-partn_numb.

move wa_upload-land1_s to i_partner-country.

move wa_upload-name1_s to i_partner-name.

move wa_upload-name2_s to i_partner-name_2.

move wa_upload-ort01_s to i_partner-city.

move wa_upload-regio_s to i_partner-region.

move wa_upload-pstlz_s to i_partner-postl_code.

move wa_upload-adrnr_s to i_partner-address.

append i_partner.

endif.

endif.

if not wa_upload-kunag is initial.

select single kunnr from kna1 into v_kunag

where kunnr = wa_upload-kunag.

if sy-subrc <> 0.

Message E015 with 'end customer does not exist'.

else.

move 'WE' to i_partner-partn_role.

move wa_upload-kunag to i_partner-partn_numb.

move wa_upload-land1_c to i_partner-country.

move wa_upload-name1_c to i_partner-name.

move wa_upload-name2_c to i_partner-name_2.

move wa_upload-ort01_c to i_partner-city.

move wa_upload-regio_c to i_partner-region.

move wa_upload-pstlz_c to i_partner-postl_code.

move wa_upload-adrnr_c to i_partner-address.

append i_partner.

endif.

endif.

ENDFORM. " f_fill_partner

&----


*& Form f_fill_item

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_fill_item.

loop at i_upload into wa_upload.

if not wa_upload-matnr is initial.

select single maramatnr msegmenge into (v_matnr, v_zmeng) from

mara inner join mseg on maramatnr = msegmatnr

where mara~matnr = wa_upload-matnr.

if sy-subrc <> 0.

Message E016 with 'material no does not exist'.

elseif v_zmeng LT wa_upload-zmeng.

Message E017 with 'order quantity is greater than the quantity present'.

endif.

endif.

move wa_upload-posnr to i_item-itm_number.

move wa_upload-pstyv to i_item-item_categ.

move wa_upload-matnr to i_item-material.

move wa_upload-zmeng to i_item-target_qty.

move wa_upload-meins to i_item-target_qu.

move wa_upload-werks to i_item-plant.

*move wa_upload-meins to wa_vbap-meins.

*move wa_upload-posnr_tot to wa_vbap-posnr_tot.

move wa_upload-posex to i_item-po_itm_no.

move wa_upload-kdmat to i_item-cust_mat22.

move wa_upload-inco1 to i_item-incoterms1.

move wa_upload-inco2 to i_item-incoterms2.

move wa_upload-zterm to i_item-pmnttrms.

move wa_upload-empst to i_item-rec_point.

move wa_upload-shtyp to i_item-ship_type.

move wa_upload-route to i_item-route.

append i_item.

PERFORM f_fill_schedule_line.

PERFORM f_fill_conditions.

ENDLOOP.

ENDFORM. " f_fill_item

&----


*& Form f_fill_schedule_line

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_fill_schedule_line.

move wa_upload-matnr to i_schedule-itm_number.

move sy-datum to i_schedule-req_date.

move wa_upload-zmeng to i_schedule-req_qty.

append i_schedule.

ENDFORM. " f_fill_schedule_line

&----


*& Form f_fill_conditions

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_fill_conditions.

move wa_upload-matnr to i_cond-itm_number.

move sy-datum to i_cond-conpricdat.

append i_cond.

ENDFORM. " f_fill_conditions

&----


*& Form f_clear

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_clear.

clear:p_auart,

p_vkorg,

p_vtweg,

p_spart,

p_vkgrp,

p_vkbur.

ENDFORM. " f_clear

&----


*& Form f_call_BAPI

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_call_BAPI.

clear:i_item,i_partner,i_schedule.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

  • SALESDOCUMENTIN =

ORDER_HEADER_IN = wa_header

  • ORDER_HEADER_INX =

  • SENDER =

  • BINARY_RELATIONSHIPTYPE =

  • INT_NUMBER_ASSIGNMENT =

  • BEHAVE_WHEN_ERROR =

  • LOGIC_SWITCH =

  • TESTRUN =

  • CONVERT = ' '

IMPORTING

SALESDOCUMENT = sorder

TABLES

  • RETURN =

ORDER_ITEMS_IN = i_item

  • ORDER_ITEMS_INX =

ORDER_PARTNERS = i_partner

ORDER_SCHEDULES_IN = i_schedule

  • ORDER_SCHEDULES_INX =

  • ORDER_CONDITIONS_IN = i_cond.

  • ORDER_CFGS_REF =

  • ORDER_CFGS_INST =

  • ORDER_CFGS_PART_OF =

  • ORDER_CFGS_VALUE =

  • ORDER_CFGS_BLOB =

  • ORDER_CFGS_VK =

  • ORDER_CFGS_REFINST =

  • ORDER_CCARD =

  • ORDER_TEXT =

  • ORDER_KEYS =

  • EXTENSIONIN =

  • PARTNERADDRESSES =

.

if not ( sorder-vbeln is initial ).

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

write: /'Order number:', sorder.

else.

loop at i_return.

write: / i_return-id, i_return-number, i_return-message(80).

endloop.

*write: /'Error'.

endif.

*loop at i_return.

*write: / i_return-id, i_return-number, i_return-message(80).

*endloop.

ENDFORM. " f_call_BAPI

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,338

Please verify that you are using correct OrderType in

"move p_auart to wa_header-doc_type."

Also the itm_number is not the Material Partnumber in following two.

"move wa_upload-matnr to i_schedule-itm_number" wrong

"move wa_upload-matnr to i_cond-itm_number" wrong

For i_schedule amd i_cond the itm_number should be equal to wa_upload-posnr as below:

"move wa_upload-posnr to i_item-itm_number"

Regards,

Vishal

*Reqward if helpful*

4 REPLIES 4
Read only

Former Member
0 Likes
1,339

Please verify that you are using correct OrderType in

"move p_auart to wa_header-doc_type."

Also the itm_number is not the Material Partnumber in following two.

"move wa_upload-matnr to i_schedule-itm_number" wrong

"move wa_upload-matnr to i_cond-itm_number" wrong

For i_schedule amd i_cond the itm_number should be equal to wa_upload-posnr as below:

"move wa_upload-posnr to i_item-itm_number"

Regards,

Vishal

*Reqward if helpful*

Read only

0 Likes
1,338

Hi vishal,

now i have created SO successfully by using bapi.but after SO cretion,price calculation for materials & total price in not comming in that SO in VA03.

in bapicond structure, i have passed cond_type also.

1)wheather i have to put logic in my report for price calculation or bapi will do the same.

2)if bapi will do this thing, then which other fields i need to pass to bapi. plz suggest.

Thanks & Regards

Read only

0 Likes
1,338
HI 

  Pricing will be carried basing on the pricing 
procedure. 

Case1: Prices will be carried out automatically if 
necessary condition records are maintained for the 
condition type. 
  For this you can go to Sales Order-> Item Conditions
 In the screen you can click on command button Analysis, 
which gives you the list of condition types associated 
to the pricing procedure. By clicking on the condition 
type you can know the action that has taken place.

Case2: Manually forcing prices for Items.
  To do this, you have to populate ORDER_CONDITIONS_IN & 
ORDER_CONDITIONS_INX. Also note to identify the item 
numbers, you manually pass the item number for each item 
in the sales order, use the same item number for 
populating conditions.

  Parameters required:
ORDER_CONDITIONS_IN:
  ITM_NUMBER, COND_TYPE, COND_VALUE, CURRENCY
ORDER_CONDITIONS_INX:
  ITM_NUMBER, COND_TYPE, UPDATEFLAG, COND_VALUE,CURRENCY.

 

   Hope the above info helps you. Do revert back if you
 need more info.

Kind Regards
Eswar
 
Read only

0 Likes
1,338

Hi vishal,

after creating the sales order, i have seen the created SO in VA03.in va03,net price(vbap-netpr),net value of SO in doc currency(vbap-netwr),SD document currency(vbak-waerk)are absent.

now for these fields to fill up, what procedure i have to follow?

1)wheather i have to put logic in my program to calculate net price & net value or BAPI will take care of these things?

if BAPI will do these things, then what other fields, i have to pass to bapi so that bapi can calculate these prices.plz suggest.

Thanks & Regards