01-22-2008 9:04 AM
Hi Guurus,
Can you please help? I finally finished with function creation (I just adopted the function, which I found in the system and it works ok, YEAH!!!)
BUT!!! It is working just for the sales order creation with one item.
Is it a big deal if you adopt my code that the function will have possibility to add more then one item?
Thanks in advance
Sao
Here is the code:
*FUNCTION Z_RFC_SD_SIMO_SALES_ORDER2.
**"----
*-
*""Local interface:
**" IMPORTING
**" VALUE(P_AUART) TYPE AUART DEFAULT 'zhp'
**" VALUE(P_VKORG) TYPE VKORG DEFAULT 0001
**" VALUE(P_VTWEG) TYPE VTWEG DEFAULT 07
**" VALUE(P_SPART) TYPE SPART DEFAULT 01
**" VALUE(P_AUGRU) TYPE AUGRU DEFAULT 001
**" VALUE(P_BSTKD) TYPE BSTKD DEFAULT 'test si order avtom'
**" VALUE(P_SOLD) TYPE KUNNR DEFAULT 21000069
**" VALUE(P_SHIP) TYPE KUNNR DEFAULT 21000069
**" VALUE(P_MATNR) TYPE MATNR DEFAULT 'SIOBRACUN'
**" VALUE(P_MENGE) TYPE KWMENG DEFAULT 1
**" VALUE(P_PLANT) TYPE WERKS_D DEFAULT 0001
**" VALUE(P_ITCAT) TYPE PSTYV DEFAULT 'ZG2W'
**" VALUE(P_LGORT) TYPE LGORT_D DEFAULT 0001
**" EXPORTING
**" VALUE(V_VBELN) TYPE VBELN
**" VALUE(RESULT) TYPE CHAR01
**"----
*-
*
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'.
**order reason
*header-ord_reason = p_augru.
*headerx-ord_reason = 'X'.
**PO number from MAX
*header-PURCH_NO_C = p_BSTKD.
*headerx-PURCH_NO_C = '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.
*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 = ' '.
*itemx-target_qu = 'X'.
*
*item-item_categ = p_itcat.
*itemx-item_categ = 'X'.
*
**item-STORE_LOC = p_LGORT.
**itemx-STORE_LOC = '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.
*
*result = 'E'.
*
*ELSE.
*
*COMMIT WORK AND WAIT.
*
*result = 'S'.
*ENDIF.
*
*
*
*
*
*ENDFUNCTION.
Edited by: Saso Poljansek on Jan 22, 2008 10:23 AM
01-22-2008 10:29 AM
Hi,,
----
Include YCL_CREATE_SALES_DOCU *
----
----
Form salesdocu
----
This Subroutine is used to create Sales Order
----
-->P_HEADER Document Header Data
-->P_HEADERX Checkbox for Header Data
-->P_ITEM Item Data
-->P_ITEMX Item Data Checkboxes
-->P_LT_SCHEDULES_IN Schedule Line Data
-->P_LT_SCHEDULES_INX Checkbox Schedule Line Data
-->P_PARTNER text Document Partner
<--P_w_vbeln text Sales Document Number
----
DATA:
lfs_return like line of t_return.
FORM create_sales_document changing P_HEADER like fs_header
P_HEADERX like fs_headerx
Pt_ITEM like t_item[]
Pt_ITEMX like t_itemx[]
P_LT_SCHEDULES_IN like t_schedules_in[]
P_LT_SCHEDULES_INX like t_schedules_inx[]
Pt_PARTNER like t_partner[]
P_w_vbeln like w_vbeln.
This Perform is used to fill required data for Sales order creation
perform sales_fill_data changing p_header
p_headerx
pt_item
pt_itemx
p_lt_schedules_in
p_lt_schedules_inx
pt_partner.
Function Module to Create Sales and Distribution Document
perform sales_order_creation using p_header
p_headerx
pt_item
pt_itemx
p_lt_schedules_in
p_lt_schedules_inx
pt_partner.
perform return_check using p_w_vbeln .
ENDFORM. " salesdocu
----
Form commit_work
----
To execute external commit *
----
FORM commit_work .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = c_x
.
ENDFORM. " Commit_work
Include ycl_sales_order_header " To Fill Header data and Item data
Include ycl_sales_order_header.
----
Form return_check
----
To validate the sales order creation
----
FORM return_check using pr_vbeln type vbeln.
if pr_vbeln is initial.
LOOP AT t_return into lfs_return .
WRITE / lfs_return-message.
clear lfs_return.
ENDLOOP. " Loop at return
else.
perform commit_work. " External Commit
Refresh t_return.
fs_disp-text = text-003.
fs_disp-number = pr_vbeln.
append fs_disp to it_disp.
if p_del eq c_x or p_torder eq c_x or
p_pgi eq c_x or p_bill eq c_x.
perform delivery_creation. " Delivery order creation
endif. " If p_del eq 'X'......
endif. " If p_w_vbeln is initial
ENDFORM. " Return_check
&----
*& Form sales_order_creation
&----
text
----
-->P_P_HEADER text
-->P_P_HEADERX text
-->P_PT_ITEM text
-->P_PT_ITEMX text
-->P_P_LT_SCHEDULES_IN text
-->P_P_LT_SCHEDULES_INX text
-->P_PT_PARTNER text
----
FORM sales_order_creation USING P_P_HEADER like fs_header
P_P_HEADERX like fs_headerx
P_PT_ITEM like t_item[]
P_PT_ITEMX like t_itemx[]
P_P_LT_SCHEDULES_IN like t_schedules_in[]
P_P_LT_SCHEDULES_INX like t_schedules_inx[]
P_PT_PARTNER like t_partner[].
CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
EXPORTING
sales_header_in = p_p_header
sales_header_inx = p_p_headerx
IMPORTING
salesdocument_ex = w_vbeln
TABLES
return = t_return
sales_items_in = p_pt_item
sales_items_inx = p_pt_itemx
sales_schedules_in = p_p_lt_schedules_in
sales_schedules_inx = p_p_lt_schedules_inx
sales_partners = p_pt_partner.
ENDFORM. " sales_order_creation
this is code to create sales document
plzz reward if it is usefull...
plzz dont forget to reward......
01-22-2008 9:29 AM
Store all the item fields in an internal table and pass it to your function module via the tables interface, not via importing.
Is there a need to pass the item numbers?
Think they will be assigned automatically, same for scheduling line fields.
01-22-2008 10:01 AM
Hi,
Thanks for the answer.
I understand, but I don't know how to do it
You said that I need to create a Z-table and import data to the Z-table first. And then from FM call this table and create sales order, right?
It is not need to pass item numbers, they can be created automatically.
What do you mean with "pass it to your function module via the tables interface,"?
Is there an SAP demo FM in the system with this?
Thanks for your help
Saso
01-22-2008 10:25 AM
Hi,
no not a Z-table but internal table.
Example of a function module interface:
CALL FUNCTION 'Z_FIND_CUSTOMERS' EXPORTING
findpar = w_searchcriteria
TABLES
customers = t_customers.
In the example above, t_customers is an internal table.
01-22-2008 10:29 AM
Hi,,
----
Include YCL_CREATE_SALES_DOCU *
----
----
Form salesdocu
----
This Subroutine is used to create Sales Order
----
-->P_HEADER Document Header Data
-->P_HEADERX Checkbox for Header Data
-->P_ITEM Item Data
-->P_ITEMX Item Data Checkboxes
-->P_LT_SCHEDULES_IN Schedule Line Data
-->P_LT_SCHEDULES_INX Checkbox Schedule Line Data
-->P_PARTNER text Document Partner
<--P_w_vbeln text Sales Document Number
----
DATA:
lfs_return like line of t_return.
FORM create_sales_document changing P_HEADER like fs_header
P_HEADERX like fs_headerx
Pt_ITEM like t_item[]
Pt_ITEMX like t_itemx[]
P_LT_SCHEDULES_IN like t_schedules_in[]
P_LT_SCHEDULES_INX like t_schedules_inx[]
Pt_PARTNER like t_partner[]
P_w_vbeln like w_vbeln.
This Perform is used to fill required data for Sales order creation
perform sales_fill_data changing p_header
p_headerx
pt_item
pt_itemx
p_lt_schedules_in
p_lt_schedules_inx
pt_partner.
Function Module to Create Sales and Distribution Document
perform sales_order_creation using p_header
p_headerx
pt_item
pt_itemx
p_lt_schedules_in
p_lt_schedules_inx
pt_partner.
perform return_check using p_w_vbeln .
ENDFORM. " salesdocu
----
Form commit_work
----
To execute external commit *
----
FORM commit_work .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = c_x
.
ENDFORM. " Commit_work
Include ycl_sales_order_header " To Fill Header data and Item data
Include ycl_sales_order_header.
----
Form return_check
----
To validate the sales order creation
----
FORM return_check using pr_vbeln type vbeln.
if pr_vbeln is initial.
LOOP AT t_return into lfs_return .
WRITE / lfs_return-message.
clear lfs_return.
ENDLOOP. " Loop at return
else.
perform commit_work. " External Commit
Refresh t_return.
fs_disp-text = text-003.
fs_disp-number = pr_vbeln.
append fs_disp to it_disp.
if p_del eq c_x or p_torder eq c_x or
p_pgi eq c_x or p_bill eq c_x.
perform delivery_creation. " Delivery order creation
endif. " If p_del eq 'X'......
endif. " If p_w_vbeln is initial
ENDFORM. " Return_check
&----
*& Form sales_order_creation
&----
text
----
-->P_P_HEADER text
-->P_P_HEADERX text
-->P_PT_ITEM text
-->P_PT_ITEMX text
-->P_P_LT_SCHEDULES_IN text
-->P_P_LT_SCHEDULES_INX text
-->P_PT_PARTNER text
----
FORM sales_order_creation USING P_P_HEADER like fs_header
P_P_HEADERX like fs_headerx
P_PT_ITEM like t_item[]
P_PT_ITEMX like t_itemx[]
P_P_LT_SCHEDULES_IN like t_schedules_in[]
P_P_LT_SCHEDULES_INX like t_schedules_inx[]
P_PT_PARTNER like t_partner[].
CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
EXPORTING
sales_header_in = p_p_header
sales_header_inx = p_p_headerx
IMPORTING
salesdocument_ex = w_vbeln
TABLES
return = t_return
sales_items_in = p_pt_item
sales_items_inx = p_pt_itemx
sales_schedules_in = p_p_lt_schedules_in
sales_schedules_inx = p_p_lt_schedules_inx
sales_partners = p_pt_partner.
ENDFORM. " sales_order_creation
this is code to create sales document
plzz reward if it is usefull...
plzz dont forget to reward......