SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Create Outgoing Delivery from Delivery Due List



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sun Apr 13, 2008 12:39 pm    Post subject: Create Outgoing Delivery from Delivery Due List Reply with quote

Code:
REPORT z.
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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.