Application Development 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: 

GN_DELIVERY_CREATE for outbound using PO

Former Member
0 Kudos

I need to create an outbound delivery by PO using FM GN_DELIVERY_CREATE. Has anyone used this FM before and does anyone have some sample code for it. Thank you

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

good

go through this link

http://translate.google.com/translate?hl=en&sl=es&u=http://www.abap.es/centro_IDOCS_practica_curso.h...

check this code too

&----


*& Report ZSAN_BAPI_GOODSMVT_CREATE *

*& *

&----


*& *

*& *

&----


REPORT ZSAN_BAPI_GOODSMVT_CREATE .

DATA: GOODSMVT_HEADER LIKE BAPI2017_GM_HEAD_01,

" Material Document Header Data

GOODSMVT_CODE LIKE BAPI2017_GM_CODE,

" Assign code to transaction for BAPI goods movement

MATERIALDOCUMENT LIKE BAPI2017_GM_HEAD_RET-MAT_DOC,

" Number of Material Document

GOODSMVT_ITEM LIKE BAPI2017_GM_ITEM_CREATE OCCURS 0 WITH HEADER LINE,

" Create Material Document Item

RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE

" Return table for messages

.

*Fill values in header

GOODSMVT_HEADER-PSTNG_DATE = '20030825'.

GOODSMVT_HEADER-DOC_DATE = '20030802'.

*Fill GOODSMVT_CODE

GOODSMVT_CODE-GM_CODE = '05' .

*Fill Item Table

GOODSMVT_ITEM-MATERIAL = '100-100'.

GOODSMVT_ITEM-PLANT = '1000'.

GOODSMVT_ITEM-STGE_LOC = '0001'.

GOODSMVT_ITEM-MOVE_TYPE = '501'.

GOODSMVT_ITEM-ENTRY_QNT = '50'.

GOODSMVT_ITEM-ITEM_TEXT = 'Test Sanket'.

*GOODSMVT_ITEM-COSTCENTER = '1000'.

APPEND GOODSMVT_ITEM.

*Create Good's movement

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

GOODSMVT_HEADER = GOODSMVT_HEADER

GOODSMVT_CODE = GOODSMVT_CODE

IMPORTING

MATERIALDOCUMENT = MATERIALDOCUMENT

TABLES

GOODSMVT_ITEM = GOODSMVT_ITEM

RETURN = RETURN.

*Commit BAPI

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'.

*Display Goods movement number

FORMAT COLOR 6 INVERSE ON.

READ TABLE RETURN WITH KEY TYPE = 'E'.

IF SY-SUBRC = 0.

WRITE: /,'ERROR! Goods movement not created'.

ELSE.

WRITE: /,'Goods movent number',MATERIALDOCUMENT COLOR 5,

'posted for material',GOODSMVT_ITEM-MATERIAL.

ENDIF.

FORMAT COLOR OFF INVERSE OFF.

reward point if helpful.

thanks

mrutyun^

3 REPLIES 3

Former Member
0 Kudos

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

Murali Poli

Former Member
0 Kudos

hi

good

go through this link

http://translate.google.com/translate?hl=en&sl=es&u=http://www.abap.es/centro_IDOCS_practica_curso.h...

check this code too

&----


*& Report ZSAN_BAPI_GOODSMVT_CREATE *

*& *

&----


*& *

*& *

&----


REPORT ZSAN_BAPI_GOODSMVT_CREATE .

DATA: GOODSMVT_HEADER LIKE BAPI2017_GM_HEAD_01,

" Material Document Header Data

GOODSMVT_CODE LIKE BAPI2017_GM_CODE,

" Assign code to transaction for BAPI goods movement

MATERIALDOCUMENT LIKE BAPI2017_GM_HEAD_RET-MAT_DOC,

" Number of Material Document

GOODSMVT_ITEM LIKE BAPI2017_GM_ITEM_CREATE OCCURS 0 WITH HEADER LINE,

" Create Material Document Item

RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE

" Return table for messages

.

*Fill values in header

GOODSMVT_HEADER-PSTNG_DATE = '20030825'.

GOODSMVT_HEADER-DOC_DATE = '20030802'.

*Fill GOODSMVT_CODE

GOODSMVT_CODE-GM_CODE = '05' .

*Fill Item Table

GOODSMVT_ITEM-MATERIAL = '100-100'.

GOODSMVT_ITEM-PLANT = '1000'.

GOODSMVT_ITEM-STGE_LOC = '0001'.

GOODSMVT_ITEM-MOVE_TYPE = '501'.

GOODSMVT_ITEM-ENTRY_QNT = '50'.

GOODSMVT_ITEM-ITEM_TEXT = 'Test Sanket'.

*GOODSMVT_ITEM-COSTCENTER = '1000'.

APPEND GOODSMVT_ITEM.

*Create Good's movement

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

GOODSMVT_HEADER = GOODSMVT_HEADER

GOODSMVT_CODE = GOODSMVT_CODE

IMPORTING

MATERIALDOCUMENT = MATERIALDOCUMENT

TABLES

GOODSMVT_ITEM = GOODSMVT_ITEM

RETURN = RETURN.

*Commit BAPI

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'.

*Display Goods movement number

FORMAT COLOR 6 INVERSE ON.

READ TABLE RETURN WITH KEY TYPE = 'E'.

IF SY-SUBRC = 0.

WRITE: /,'ERROR! Goods movement not created'.

ELSE.

WRITE: /,'Goods movent number',MATERIALDOCUMENT COLOR 5,

'posted for material',GOODSMVT_ITEM-MATERIAL.

ENDIF.

FORMAT COLOR OFF INVERSE OFF.

reward point if helpful.

thanks

mrutyun^

Former Member
0 Kudos

I am looking for GN_DELIVERY_CREATE as I have been told its the best FM to create outbound delivery from PO.