2007 May 19 3:08 AM
Hi All,
Can we create an outbound delivery for a sales order using GN_DELIVERY_CREATE.Please send me sample code if anyone has done the same.
Cheers
Nishanth
<b>Thanks Guys,That solves my problem.But i am still curious to know whether we can create an outbound delivery using the FM GN_DELIVERY_CREATE.</b>
null
2007 May 19 4:21 AM
Hi,
Check this sample program for creating delivery from a sales order.
Give the sales order as input..
PARAMETERS: p_vbeln LIKE vbak-vbeln.
DATA: BEGIN OF t_vbap OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
matnr LIKE vbap-matnr,
werks LIKE vbap-werks,
END OF t_vbap.
DATA: t_request TYPE STANDARD TABLE OF bapideliciousrequest
WITH HEADER LINE.
DATA: t_created TYPE STANDARD TABLE OF bapideliciouscreateditems
WITH HEADER LINE.
DATA: t_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
SELECT vbeln posnr kwmeng matnr werks
INTO TABLE t_vbap
FROM vbap
WHERE vbeln = p_vbeln.
LOOP AT t_vbap.
t_request-document_numb = t_vbap-vbeln.
t_request-document_item = t_vbap-posnr.
t_request-quantity_sales_uom = t_vbap-kwmeng.
t_request-id = 1.
t_request-document_type = 'A'.
t_request-delivery_date = sy-datum.
t_request-material = t_vbap-matnr.
t_request-plant = t_vbap-werks.
t_request-date = sy-datum.
t_request-goods_issue_date = sy-datum.
t_request-goods_issue_time = sy-uzeit.
APPEND t_request.
ENDLOOP.
CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
TABLES
request = t_request
createditems = t_created
return = t_return
.
READ TABLE t_return WITH KEY type = 'E'.
IF sy-subrc = 0.
MESSAGE e208(00) WITH 'Delivery creation error'.
ENDIF.
COMMIT WORK.
READ TABLE t_created INDEX 1.
WRITE: / 'Delivery - ', t_created-document_numb.
Thanks,
Naren
2007 May 19 4:18 AM
We did not use GN_DELIVERY_CREATE Function module but we used other function module SHP_VL10_DELIVERY_CREATE_PARA
See Below code :
tables: vbfa,
zwvbak_curr.
----
Selection Screen *
----
selection-screen begin of block b01 with frame title text-b01.
parameters: p_dwerk like zfdwstatus-werks default '1000' obligatory,
p_vdatu like zfdwstatus-vdatu obligatory.
selection-screen end of block b01.
selection-screen begin of block b02 with frame title text-b02.
select-options: s_vbeln for zwvbak_curr-vbeln.
selection-screen end of block b02.
----
Data definition *
----
data: d_task(5) type n.
data: d_vbeln like vbak-vbeln,
d_loop type i,
d_zzrun like zfdwstatus-zzrun.
data: t_vbak like vbak occurs 0 with header line.
data: t_vbap like vbapvb occurs 0 with header line.
data: t_vbep like vbepvb occurs 0 with header line.
data: t_vbkd like vbkdvb occurs 0 with header line.
data: t_vbpa like vbpavb occurs 0 with header line.
data: t_vbuk like vbukvb occurs 0 with header line.
data: t_vbup like vbupvb occurs 0 with header line.
data: begin of t_orders occurs 0,
vbeln like vbak-vbeln.
data: end of t_orders.
----
initialization
----
initialization.
set date as default in dependence of the time.
if sy-uzeit >= '000000' and sy-uzeit <= '190000'.
p_vdatu = sy-datum.
else.
p_vdatu = sy-datum + 1.
endif.
----
Validate Selection Screen
----
at selection-screen.
if sy-batch eq space.
if sy-ucomm = 'ONLI'.
message e000(zwave) with
'Delivery Create Program can'
'ONLY be run in Background mode!!'.
stop.
endif.
endif.
----
START OF MAIN PROGRAM *
----
start-of-selection.
perform get_data.
*-- lock the plant and delivery date to prevent simulatenous delivery
*-- creations
perform lock_zfdwstatus_record using p_dwerk
p_vdatu.
perform create_deliveries.
*--- Unlock Status Record
perform unlock_zfdwstatus_record using p_dwerk
p_vdatu.
end-of-selection.
&----
*& Form create_deliveries
&----
form create_deliveries.
loop at t_orders.
clear d_vbeln.
refresh: t_vbak, t_vbap,
t_vbep, t_vbkd,
t_vbpa, t_vbuk,
t_vbup.
d_vbeln = t_orders-vbeln.
add 1 to d_task.
select * from vbak into table t_vbak
where vbeln = d_vbeln.
select * from vbap into table t_vbap
where vbeln = d_vbeln.
select * from vbep into table t_vbep
where vbeln = d_vbeln.
select * from vbkd into table t_vbkd
where vbeln = d_vbeln.
select * from vbpa into table t_vbpa
where vbeln = d_vbeln.
select * from vbuk into table t_vbuk
where vbeln = d_vbeln.
select * from vbup into table t_vbup
where vbeln = d_vbeln.
clear d_loop.
do.
select single * from vbfa where
vbelv = d_vbeln and
vbtyp_n = 'J'.
if sy-subrc eq 0.
exit.
else.
add 1 to d_loop.
call function 'SHP_VL10_DELIVERY_CREATE_PARA'
starting new task d_task
destination in group 'RFCGROUP'
exporting
if_ledat = p_vdatu
if_nur_vorgabe_pos = ' '
tables
it_vbak = t_vbak
it_vbap = t_vbap
it_vbep = t_vbep
it_vbuk = t_vbuk
it_vbup = t_vbup
it_vbkd = t_vbkd
it_vbpa = t_vbpa
exceptions
system_failure = 1
communication_failure = 2
resource_failure = 3
others = 4.
case sy-subrc.
when '0'.
exit.
when '3'.
if d_loop = 1.
wait up to '0.01' seconds.
elseif d_loop = 2.
wait up to '0.1' seconds.
else.
wait up to 1 seconds.
endif.
when others.
exit.
endcase.
endif.
enddo.
endloop.
if sy-subrc ne 0.
message i000(zwave) with 'No records for the given Selection!'.
else.
message s000(zwave) with 'Deliveries successfully processed!'.
endif.
endform. " create_deliveries
&----
*& Form get_data
&----
form get_data.
select distinct vbeln into table t_orders
from zwvbak_curr
where vbeln in s_vbeln and
vdatu = p_vdatu and
werks = p_dwerk.
*-- Ignore Orders for which Deliveries already created
loop at t_orders.
select single * from vbfa where
vbelv = t_orders-vbeln and
vbtyp_n = 'J'.
if sy-subrc eq 0.
delete t_orders.
endif.
endloop.
endform. " get_data
----
FORM lock_zfdwstatus_record *
----
........ *
----
--> P_WERKS *
--> P_VDATU *
--> P_ZZRUN *
----
form lock_zfdwstatus_record using p_dwerk
p_vdatu.
clear sy-subrc.
concatenate 'L' '00' into d_zzrun.
call function 'ENQUEUE_EZFDWSTATUS'
exporting
mode_zfdwstatus = 'E'
mandt = sy-mandt
werks = p_dwerk
vdatu = p_vdatu
zzrun = d_zzrun
exceptions
foreign_lock = 1
system_failure = 2
others = 3.
case sy-subrc.
when 0.
when 1.
message e000(zwave) with 'Wave Status Record Locked '
'by another process'
'Please try again later.'.
when others.
message e000(zwave) with 'Error Locking Status Record !'.
endcase.
endform. " lock_zfdwstatus_record
----
FORM unlock_zfdwstatus_record *
----
........ *
----
--> P_WERKS *
--> P_VDATU *
--> P_ZZRUN *
----
form unlock_zfdwstatus_record using p_dwerk
p_vdatu.
clear sy-subrc.
call function 'DEQUEUE_EZFDWSTATUS'
exporting
mode_zfdwstatus = 'E'
mandt = sy-mandt
werks = p_dwerk
vdatu = p_vdatu
zzrun = d_zzrun
_scope = '3'
_synchron = ' '.
if sy-subrc ne 0.
message e000(zwave) with 'Error Releasing Lock on Status Record!'.
endif.
endform. " unlock_zfdwstatus_record
Reward Points if it is useful
Thanks
Seshu
2007 May 19 4:21 AM
Hi,
Check this sample program for creating delivery from a sales order.
Give the sales order as input..
PARAMETERS: p_vbeln LIKE vbak-vbeln.
DATA: BEGIN OF t_vbap OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
matnr LIKE vbap-matnr,
werks LIKE vbap-werks,
END OF t_vbap.
DATA: t_request TYPE STANDARD TABLE OF bapideliciousrequest
WITH HEADER LINE.
DATA: t_created TYPE STANDARD TABLE OF bapideliciouscreateditems
WITH HEADER LINE.
DATA: t_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
SELECT vbeln posnr kwmeng matnr werks
INTO TABLE t_vbap
FROM vbap
WHERE vbeln = p_vbeln.
LOOP AT t_vbap.
t_request-document_numb = t_vbap-vbeln.
t_request-document_item = t_vbap-posnr.
t_request-quantity_sales_uom = t_vbap-kwmeng.
t_request-id = 1.
t_request-document_type = 'A'.
t_request-delivery_date = sy-datum.
t_request-material = t_vbap-matnr.
t_request-plant = t_vbap-werks.
t_request-date = sy-datum.
t_request-goods_issue_date = sy-datum.
t_request-goods_issue_time = sy-uzeit.
APPEND t_request.
ENDLOOP.
CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
TABLES
request = t_request
createditems = t_created
return = t_return
.
READ TABLE t_return WITH KEY type = 'E'.
IF sy-subrc = 0.
MESSAGE e208(00) WITH 'Delivery creation error'.
ENDIF.
COMMIT WORK.
READ TABLE t_created INDEX 1.
WRITE: / 'Delivery - ', t_created-document_numb.
Thanks,
Naren