07-28-2007 6:13 AM
anyone have lockobject sample code for any transaction, i just want to see how to use.
07-28-2007 6:36 AM
Check the below program and i am using planned order transaction lock
Tables
tables : mara,
aufk,
afpo,
afko,
jest.
Constants
constants : c_werks(4) type c value '1000',
c_mode(1) type c value 'N',
c_update(1) type c value 'S',
c_auart(4) type c value 'PP01'.
Variables
data : w_cm61w LIKE cm61w,
w_msg_log_imp LIKE msg_log,
w_msg_text_exp LIKE msg_text.
Internal Table
data : begin of i_porders occurs 0,
aufnr like aufk-aufnr,
objnr like aufk-objnr,
matnr like afpo-matnr,
end of i_porders.
Internal table for Planned order
data i_plaf like plaf occurs 0 with header line.
Internal Table for Error Handling
DATA: BEGIN OF i_error OCCURS 0,
order(20) type c,
messg(100) TYPE c,
val(1) type c,
END OF i_error.
Internal table for bdcdata and bdcmsgcoll.
data : i_bdcdata like bdcdata occurs 0 with header line,
i_msg like bdcmsgcoll occurs 0 with header line.
INTERNAL TABLE FOR MATERIAL #
DATA : BEGIN OF I_MATNR OCCURS 0,
MATNR LIKE MARA-MATNR,
END OF I_MATNR.
Internal table for Planned Order Number
data : begin of i_plnum occurs 0,
plnum like plaf-plnum,
end of i_plnum.
DATA V1(255) TYPE C.
Internal Table for JEST ( Production Order Status )
DATA: t_jstat LIKE jstat OCCURS 0 WITH HEADER LINE.
************************************************************************
S E L E C T I O N S C R E E N ***********************
************************************************************************
selection-screen: begin of block blk with frame title text-001.
selection-screen: skip 1.
select-options : s_matnr for mara-matnr obligatory no intervals.
parameters : p_date like sy-datum obligatory.
selection-screen: skip 1.
selection-screen : end of block blk.
************************************************************************
S T A R T - O F - S E L E C T I O N *******************
***********************************************************************
start-of-selection.
Initiliaze the data .
perform initilize_data.
Keep the Material # into Internal Table
PERFORM prepare_material_internal_tabl.
Do the Validation against on Prod Order tables and
Planned Order Table and Create the Production Order.
perform Validation_Create.
end-of-selection.
Displays the error Log.
*
loop at i_error.
if i_error-val = 'S'.
format color 4 on.
*
write:/20 i_error-order,65 i_error-messg.
format color 4 off.
else.
format color 6 on.
*
write:/20 i_error-order,65 i_error-messg.
format color 6 off.
endif.
*
endloop.
submit zfd_check_production_orders
WITH p_werks EQ c_werks
WITH p_vdatu EQ p_date.
***********************************************************************
T O P - O F - P A G E ************************
***********************************************************************
top-of-page.
format color 5 on.
Write:/45 'FreshDirect Production Validation Error Handling Tool'.
Skip 1 .
Write:/20 'Material Number' ,65 'Log Message'.
skip 1.
format color 5 off.
&----
*& Form initilize_data
&----
Clear the all fields and Internal Tables
----
FORM initilize_data.
clear : i_matnr,
i_bdcdata,
i_plaf,
i_porders,
i_error,
w_cm61w,
w_msg_log_imp,
w_msg_text_exp,
i_plnum,
i_msg.
refresh : i_matnr,
i_bdcdata,
i_plaf,
i_porders,
i_error,
i_plnum,
i_msg.
ENDFORM. " initilize_data
&----
*& Form PREPARE_MATERIAL_INTERNAL_TABL
&----
text
----
--> p1 text
<-- p2 text
----
FORM PREPARE_MATERIAL_INTERNAL_TABL.
LOOP AT S_MATNR.
MOVE S_MATNR-LOW TO I_MATNR-MATNR.
APPEND I_MATNR.
clear i_matnr.
ENDLOOP.
ENDFORM. " PREPARE_MATERIAL_INTERNAL_TABL
&----
*& Form Validation_Create
&----
Creation of Production Order
----
FORM Validation_Create.
sort i_matnr by matnr.
loop at i_matnr.
First Check the Production order is available for Given Material and
Delivery date
refresh : i_porders.
clear : i_porders.
Get the Prod Orders data as per given condition
select a~aufnr a~objnr c~matnr into table i_porders
from aufk as a inner join afko as b on a~aufnr = b~aufnr
inner join afpo as c on c~aufnr = a~aufnr
and c~matnr = b~plnbez
where c~matnr = i_matnr-matnr
and b~gstrp = p_date
and b~plnbez = i_matnr-matnr.
if sy-subrc eq 0.
perform change_status.
endif.
Check the Planned Order Number available for Given Materil and
Deleivery date
refresh : i_plaf.
clear : i_plaf.
select * from plaf into table i_plaf
where matnr = i_matnr-matnr
and psttr = p_date
and plwrk = c_werks.
if sy-subrc eq 0.
Delete the Planned Order
perform delete_planned_order.
endif.
Run MRP Transaction MD02
perform run_mrp_bdc.
No data at Plaf and then no need to go Production order
if i_plnum[] is initial.
continue.
endif.
Convert New Planned Orders to Production Order
perform convert_planned_orders.
cleaR : I_MATNR.
endloop.
ENDFORM. " Validation_Create
&----
*& Form change_status
&----
Change the Production Order Status
----
FORM change_status.
loop at i_porders.
Get status of production order
CLEAR : t_jstat.
REFRESH: t_jstat.
CALL FUNCTION 'STATUS_READ'
EXPORTING
client = sy-mandt
objnr = i_porders-objnr
only_active = 'X'
TABLES
status = t_jstat
EXCEPTIONS
object_not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
Ignore orders flagged for deletion
Statuses "Deletion indicator" and "Deleted" are not relevant here and
so need not be checked!
READ TABLE t_jstat WITH KEY stat = 'I0076'.
IF sy-subrc <> 0.
Check if production order has CNF (confirmed) status. If so, ignore
the order
READ TABLE t_jstat WITH KEY stat = 'I0009'.
IF sy-subrc <> 0.
Check if order has PCNF (partially confirmed) status
READ TABLE t_jstat WITH KEY stat = 'I0010'.
IF sy-subrc <> 0.
If it is not in CNF or PCNF status, as per the spec, it must be in
REL status. Change status of the order from REL to TECO
READ TABLE t_jstat WITH KEY stat = 'I0002'.
IF sy-subrc = 0.
Status change that we effect using this function does not cancel the
requirement (MD04) even though the status is changed. Revert to BDC!
PERFORM change_order_teco.
endif.
endif.
endif.
endif.
endif.
endloop.
ENDFORM. " change_status
&----
*& Form change_order_teco
&----
Change the Order Status into 'TECO'
----
FORM change_order_teco.
CLEAR : i_bdcdata, i_msg.
REFRESH: i_bdcdata, i_msg.
perform bdc_dynpro using 'SAPLCOKO1' '0110'.
perform bdc_field using 'BDC_CURSOR'
'CAUFVD-AUFNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'CAUFVD-AUFNR'
i_porders-aufnr.
perform bdc_field using 'R62CLORD-FLG_OVIEW'
'X'.
perform bdc_dynpro using 'SAPLCOKO1' '0115'.
perform bdc_field using 'BDC_OKCODE'
'=TABS'.
perform bdc_field using 'BDC_CURSOR'
'CAUFVD-GAMNG'.
perform bdc_dynpro using 'SAPLCOKO1' '0115'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BDC_CURSOR'
'CAUFVD-GAMNG'.
**
CALL TRANSACTION 'CO02' USING i_bdcdata
mode c_mode
update c_update
MESSAGES INTO i_msg.
SAP BDC Message
CLEAR : V1.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = V1
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
if sy-msgty = 'W' OR sy-msgty = 'S'.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'S'.
append i_error.
else.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'E'.
append i_error.
endif.
ENDFORM. " change_order_teco
&----
*& Form get_bdcdata
&----
Fill the BDCDATA Structure
----
-->P_1640 text
-->P_1641 text
-->P_1642 text
----
FORM get_bdcdata USING p_fnam
p_fval
p_dynb.
CLEAR i_bdcdata.
IF p_dynb IS INITIAL.
i_bdcdata-fnam = p_fnam.
i_bdcdata-fval = p_fval.
ELSE.
i_bdcdata-program = p_fnam.
i_bdcdata-dynpro = p_fval.
i_bdcdata-dynbegin = p_dynb.
ENDIF.
APPEND i_bdcdata.
ENDFORM. " get_bdcdata
&----
*& Form delete_planned_order
&----
Delete The Planned Order
----
FORM delete_planned_order.
loop at i_plaf.
Partially confirmed planned order cannot be deleted
IF i_plaf-wemng > 0.
MOVE: i_plaf-plnum TO i_error-order,
text-010 TO i_error-messg.
i_error-val = 'E'.
APPEND i_error.
CLEAR i_error.
CONTINUE.
ENDIF.
Lock planned order
CALL FUNCTION 'ENQUEUE_EMPLAFE'
EXPORTING
plnum = i_plaf-plnum
_scope = '3'
EXCEPTIONS
foreign_lock = 2
system_failure = 3.
IF sy-subrc > 0.
MOVE: i_plaf-plnum TO i_error-order,
text-011 TO i_error-messg.
i_error-val = 'E'.
APPEND i_error.
CLEAR i_error.
CONTINUE.
ENDIF.
clear : w_cm61w.
Get MRP control indicator at plant level
CALL FUNCTION 'MD_READ_PLANT'
EXPORTING
ewerks = i_plaf-plwrk
IMPORTING
icm61w = w_cm61w.
Delete planned order
CALL FUNCTION 'LOESCHEN_PLANAUFTRAG'
EXPORTING
ecm61w = w_cm61w
eplaf = i_plaf
EXCEPTIONS
undefined_interface = 1
OTHERS = 2.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
MOVE: i_plaf-plnum TO i_error-order,
text-012 TO i_error-messg.
i_error-val = 'E'.
APPEND i_error.
CLEAR i_error.
continue.
ENDIF.
Unlock planned order
CALL FUNCTION 'DEQUEUE_EMPLAFE'
EXPORTING
plnum = i_plaf-plnum.
endloop.
ENDFORM. " delete_planned_order
&----
*& Form run_mrp_bdc
&----
BDC for MRP Transaction
----
FORM run_mrp_bdc.
Clear : i_bdcdata,
i_msg.
refresh : i_bdcdata,
i_msg.
perform bdc_dynpro using 'SAPMM61X' '0150'.
perform bdc_field using 'BDC_CURSOR'
'RM61X-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RM61X-MATNR'
i_matnr-matnr.
perform bdc_field using 'RM61X-WERKS'
c_werks.
perform bdc_field using 'RM61X-VERSL'
'NETCH'.
perform bdc_field using 'RM61X-BANER'
'2'.
perform bdc_field using 'RM61X-LIFKZ'
'3'.
perform bdc_field using 'RM61X-DISER'
'1'.
perform bdc_field using 'RM61X-PLMOD'
'1'.
perform bdc_field using 'RM61X-TRMPL'
'1'.
perform bdc_dynpro using 'SAPMSSY0' '0120'.
perform bdc_field using 'BDC_OKCODE'
'=XBAC'.
call transaction 'MD02' using i_bdcdata
mode c_mode
update c_update
messages into i_msg.
SAP BDC Message
CLEAR : V1.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = V1
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
if sy-msgty = 'W' OR sy-msgty = 'S'.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'S'.
append i_error.
else.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'E'.
append i_error.
endif.
refresh : i_plnum.
clear : i_plnum.
select plnum from plaf into table i_plnum
where matnr = i_matnr-matnr
and psttr = p_date.
ENDFORM. " run_mrp_bdc
&----
*& Form bdc_dynpro
&----
BDCDATA for Program and Screen Number
----
FORM bdc_dynpro USING p_prog
p_scrn.
clear i_bdcdata .
i_bdcdata-program = p_prog.
i_bdcdata-dynpro = p_scrn.
i_bdcdata-dynbegin = 'X'.
append i_bdcdata.
ENDFORM. " bdc_dynpro
&----
*& Form bdc_field
&----
BDCDATA For Fieldvalue and Field name
----
FORM bdc_field USING p_fnam
p_fval.
clear i_bdcdata.
i_bdcdata-fnam = p_fnam.
i_bdcdata-fval = p_fval.
append i_bdcdata.
ENDFORM. " bdc_field
&----
*& Form convert_planned_orders
&----
Convering the Planned order to Production Order
----
FORM convert_planned_orders.
DATA: lv_orders LIKE pla_tab OCCURS 0 WITH HEADER LINE.
*
refresh : lv_orders.
clear : lv_orders.
loop at i_plnum.
*lv_orders-plnum = i_plnum-plnum.
*append lv_orders.
Clear : i_bdcdata,
i_msg.
refresh : i_bdcdata,
i_msg.
CO40 First Screen
perform bdc_dynpro using 'SAPLCOKO1' '0150'.
perform bdc_field using 'BDC_CURSOR'
'AFPOD-PLNUM'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'AFPOD-PLNUM'
i_plnum-plnum.
perform bdc_field using 'AUFPAR-PP_AUFART'
c_auart.
perform bdc_dynpro using 'SAPLCOKO1' '0115'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BDC_CURSOR'
'CAUFVD-GAMNG'.
CALL TRANSACTION 'CO40' USING i_BDCDATA
MODE c_mode
UPDATE c_update
MESSAGES INTO i_msg.
SAP BDC Message
CLEAR : V1.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = V1
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Error Handling
if sy-msgty = 'W' OR sy-msgty = 'S'.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'S'.
append i_error.
else.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'E'.
append i_error.
endif.
endloop.
ENDFORM. " convert_planned_orders
Thanks
Seshu
07-28-2007 6:36 AM
Check the below program and i am using planned order transaction lock
Tables
tables : mara,
aufk,
afpo,
afko,
jest.
Constants
constants : c_werks(4) type c value '1000',
c_mode(1) type c value 'N',
c_update(1) type c value 'S',
c_auart(4) type c value 'PP01'.
Variables
data : w_cm61w LIKE cm61w,
w_msg_log_imp LIKE msg_log,
w_msg_text_exp LIKE msg_text.
Internal Table
data : begin of i_porders occurs 0,
aufnr like aufk-aufnr,
objnr like aufk-objnr,
matnr like afpo-matnr,
end of i_porders.
Internal table for Planned order
data i_plaf like plaf occurs 0 with header line.
Internal Table for Error Handling
DATA: BEGIN OF i_error OCCURS 0,
order(20) type c,
messg(100) TYPE c,
val(1) type c,
END OF i_error.
Internal table for bdcdata and bdcmsgcoll.
data : i_bdcdata like bdcdata occurs 0 with header line,
i_msg like bdcmsgcoll occurs 0 with header line.
INTERNAL TABLE FOR MATERIAL #
DATA : BEGIN OF I_MATNR OCCURS 0,
MATNR LIKE MARA-MATNR,
END OF I_MATNR.
Internal table for Planned Order Number
data : begin of i_plnum occurs 0,
plnum like plaf-plnum,
end of i_plnum.
DATA V1(255) TYPE C.
Internal Table for JEST ( Production Order Status )
DATA: t_jstat LIKE jstat OCCURS 0 WITH HEADER LINE.
************************************************************************
S E L E C T I O N S C R E E N ***********************
************************************************************************
selection-screen: begin of block blk with frame title text-001.
selection-screen: skip 1.
select-options : s_matnr for mara-matnr obligatory no intervals.
parameters : p_date like sy-datum obligatory.
selection-screen: skip 1.
selection-screen : end of block blk.
************************************************************************
S T A R T - O F - S E L E C T I O N *******************
***********************************************************************
start-of-selection.
Initiliaze the data .
perform initilize_data.
Keep the Material # into Internal Table
PERFORM prepare_material_internal_tabl.
Do the Validation against on Prod Order tables and
Planned Order Table and Create the Production Order.
perform Validation_Create.
end-of-selection.
Displays the error Log.
*
loop at i_error.
if i_error-val = 'S'.
format color 4 on.
*
write:/20 i_error-order,65 i_error-messg.
format color 4 off.
else.
format color 6 on.
*
write:/20 i_error-order,65 i_error-messg.
format color 6 off.
endif.
*
endloop.
submit zfd_check_production_orders
WITH p_werks EQ c_werks
WITH p_vdatu EQ p_date.
***********************************************************************
T O P - O F - P A G E ************************
***********************************************************************
top-of-page.
format color 5 on.
Write:/45 'FreshDirect Production Validation Error Handling Tool'.
Skip 1 .
Write:/20 'Material Number' ,65 'Log Message'.
skip 1.
format color 5 off.
&----
*& Form initilize_data
&----
Clear the all fields and Internal Tables
----
FORM initilize_data.
clear : i_matnr,
i_bdcdata,
i_plaf,
i_porders,
i_error,
w_cm61w,
w_msg_log_imp,
w_msg_text_exp,
i_plnum,
i_msg.
refresh : i_matnr,
i_bdcdata,
i_plaf,
i_porders,
i_error,
i_plnum,
i_msg.
ENDFORM. " initilize_data
&----
*& Form PREPARE_MATERIAL_INTERNAL_TABL
&----
text
----
--> p1 text
<-- p2 text
----
FORM PREPARE_MATERIAL_INTERNAL_TABL.
LOOP AT S_MATNR.
MOVE S_MATNR-LOW TO I_MATNR-MATNR.
APPEND I_MATNR.
clear i_matnr.
ENDLOOP.
ENDFORM. " PREPARE_MATERIAL_INTERNAL_TABL
&----
*& Form Validation_Create
&----
Creation of Production Order
----
FORM Validation_Create.
sort i_matnr by matnr.
loop at i_matnr.
First Check the Production order is available for Given Material and
Delivery date
refresh : i_porders.
clear : i_porders.
Get the Prod Orders data as per given condition
select a~aufnr a~objnr c~matnr into table i_porders
from aufk as a inner join afko as b on a~aufnr = b~aufnr
inner join afpo as c on c~aufnr = a~aufnr
and c~matnr = b~plnbez
where c~matnr = i_matnr-matnr
and b~gstrp = p_date
and b~plnbez = i_matnr-matnr.
if sy-subrc eq 0.
perform change_status.
endif.
Check the Planned Order Number available for Given Materil and
Deleivery date
refresh : i_plaf.
clear : i_plaf.
select * from plaf into table i_plaf
where matnr = i_matnr-matnr
and psttr = p_date
and plwrk = c_werks.
if sy-subrc eq 0.
Delete the Planned Order
perform delete_planned_order.
endif.
Run MRP Transaction MD02
perform run_mrp_bdc.
No data at Plaf and then no need to go Production order
if i_plnum[] is initial.
continue.
endif.
Convert New Planned Orders to Production Order
perform convert_planned_orders.
cleaR : I_MATNR.
endloop.
ENDFORM. " Validation_Create
&----
*& Form change_status
&----
Change the Production Order Status
----
FORM change_status.
loop at i_porders.
Get status of production order
CLEAR : t_jstat.
REFRESH: t_jstat.
CALL FUNCTION 'STATUS_READ'
EXPORTING
client = sy-mandt
objnr = i_porders-objnr
only_active = 'X'
TABLES
status = t_jstat
EXCEPTIONS
object_not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
Ignore orders flagged for deletion
Statuses "Deletion indicator" and "Deleted" are not relevant here and
so need not be checked!
READ TABLE t_jstat WITH KEY stat = 'I0076'.
IF sy-subrc <> 0.
Check if production order has CNF (confirmed) status. If so, ignore
the order
READ TABLE t_jstat WITH KEY stat = 'I0009'.
IF sy-subrc <> 0.
Check if order has PCNF (partially confirmed) status
READ TABLE t_jstat WITH KEY stat = 'I0010'.
IF sy-subrc <> 0.
If it is not in CNF or PCNF status, as per the spec, it must be in
REL status. Change status of the order from REL to TECO
READ TABLE t_jstat WITH KEY stat = 'I0002'.
IF sy-subrc = 0.
Status change that we effect using this function does not cancel the
requirement (MD04) even though the status is changed. Revert to BDC!
PERFORM change_order_teco.
endif.
endif.
endif.
endif.
endif.
endloop.
ENDFORM. " change_status
&----
*& Form change_order_teco
&----
Change the Order Status into 'TECO'
----
FORM change_order_teco.
CLEAR : i_bdcdata, i_msg.
REFRESH: i_bdcdata, i_msg.
perform bdc_dynpro using 'SAPLCOKO1' '0110'.
perform bdc_field using 'BDC_CURSOR'
'CAUFVD-AUFNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'CAUFVD-AUFNR'
i_porders-aufnr.
perform bdc_field using 'R62CLORD-FLG_OVIEW'
'X'.
perform bdc_dynpro using 'SAPLCOKO1' '0115'.
perform bdc_field using 'BDC_OKCODE'
'=TABS'.
perform bdc_field using 'BDC_CURSOR'
'CAUFVD-GAMNG'.
perform bdc_dynpro using 'SAPLCOKO1' '0115'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BDC_CURSOR'
'CAUFVD-GAMNG'.
**
CALL TRANSACTION 'CO02' USING i_bdcdata
mode c_mode
update c_update
MESSAGES INTO i_msg.
SAP BDC Message
CLEAR : V1.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = V1
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
if sy-msgty = 'W' OR sy-msgty = 'S'.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'S'.
append i_error.
else.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'E'.
append i_error.
endif.
ENDFORM. " change_order_teco
&----
*& Form get_bdcdata
&----
Fill the BDCDATA Structure
----
-->P_1640 text
-->P_1641 text
-->P_1642 text
----
FORM get_bdcdata USING p_fnam
p_fval
p_dynb.
CLEAR i_bdcdata.
IF p_dynb IS INITIAL.
i_bdcdata-fnam = p_fnam.
i_bdcdata-fval = p_fval.
ELSE.
i_bdcdata-program = p_fnam.
i_bdcdata-dynpro = p_fval.
i_bdcdata-dynbegin = p_dynb.
ENDIF.
APPEND i_bdcdata.
ENDFORM. " get_bdcdata
&----
*& Form delete_planned_order
&----
Delete The Planned Order
----
FORM delete_planned_order.
loop at i_plaf.
Partially confirmed planned order cannot be deleted
IF i_plaf-wemng > 0.
MOVE: i_plaf-plnum TO i_error-order,
text-010 TO i_error-messg.
i_error-val = 'E'.
APPEND i_error.
CLEAR i_error.
CONTINUE.
ENDIF.
Lock planned order
CALL FUNCTION 'ENQUEUE_EMPLAFE'
EXPORTING
plnum = i_plaf-plnum
_scope = '3'
EXCEPTIONS
foreign_lock = 2
system_failure = 3.
IF sy-subrc > 0.
MOVE: i_plaf-plnum TO i_error-order,
text-011 TO i_error-messg.
i_error-val = 'E'.
APPEND i_error.
CLEAR i_error.
CONTINUE.
ENDIF.
clear : w_cm61w.
Get MRP control indicator at plant level
CALL FUNCTION 'MD_READ_PLANT'
EXPORTING
ewerks = i_plaf-plwrk
IMPORTING
icm61w = w_cm61w.
Delete planned order
CALL FUNCTION 'LOESCHEN_PLANAUFTRAG'
EXPORTING
ecm61w = w_cm61w
eplaf = i_plaf
EXCEPTIONS
undefined_interface = 1
OTHERS = 2.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
MOVE: i_plaf-plnum TO i_error-order,
text-012 TO i_error-messg.
i_error-val = 'E'.
APPEND i_error.
CLEAR i_error.
continue.
ENDIF.
Unlock planned order
CALL FUNCTION 'DEQUEUE_EMPLAFE'
EXPORTING
plnum = i_plaf-plnum.
endloop.
ENDFORM. " delete_planned_order
&----
*& Form run_mrp_bdc
&----
BDC for MRP Transaction
----
FORM run_mrp_bdc.
Clear : i_bdcdata,
i_msg.
refresh : i_bdcdata,
i_msg.
perform bdc_dynpro using 'SAPMM61X' '0150'.
perform bdc_field using 'BDC_CURSOR'
'RM61X-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RM61X-MATNR'
i_matnr-matnr.
perform bdc_field using 'RM61X-WERKS'
c_werks.
perform bdc_field using 'RM61X-VERSL'
'NETCH'.
perform bdc_field using 'RM61X-BANER'
'2'.
perform bdc_field using 'RM61X-LIFKZ'
'3'.
perform bdc_field using 'RM61X-DISER'
'1'.
perform bdc_field using 'RM61X-PLMOD'
'1'.
perform bdc_field using 'RM61X-TRMPL'
'1'.
perform bdc_dynpro using 'SAPMSSY0' '0120'.
perform bdc_field using 'BDC_OKCODE'
'=XBAC'.
call transaction 'MD02' using i_bdcdata
mode c_mode
update c_update
messages into i_msg.
SAP BDC Message
CLEAR : V1.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = V1
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
if sy-msgty = 'W' OR sy-msgty = 'S'.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'S'.
append i_error.
else.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'E'.
append i_error.
endif.
refresh : i_plnum.
clear : i_plnum.
select plnum from plaf into table i_plnum
where matnr = i_matnr-matnr
and psttr = p_date.
ENDFORM. " run_mrp_bdc
&----
*& Form bdc_dynpro
&----
BDCDATA for Program and Screen Number
----
FORM bdc_dynpro USING p_prog
p_scrn.
clear i_bdcdata .
i_bdcdata-program = p_prog.
i_bdcdata-dynpro = p_scrn.
i_bdcdata-dynbegin = 'X'.
append i_bdcdata.
ENDFORM. " bdc_dynpro
&----
*& Form bdc_field
&----
BDCDATA For Fieldvalue and Field name
----
FORM bdc_field USING p_fnam
p_fval.
clear i_bdcdata.
i_bdcdata-fnam = p_fnam.
i_bdcdata-fval = p_fval.
append i_bdcdata.
ENDFORM. " bdc_field
&----
*& Form convert_planned_orders
&----
Convering the Planned order to Production Order
----
FORM convert_planned_orders.
DATA: lv_orders LIKE pla_tab OCCURS 0 WITH HEADER LINE.
*
refresh : lv_orders.
clear : lv_orders.
loop at i_plnum.
*lv_orders-plnum = i_plnum-plnum.
*append lv_orders.
Clear : i_bdcdata,
i_msg.
refresh : i_bdcdata,
i_msg.
CO40 First Screen
perform bdc_dynpro using 'SAPLCOKO1' '0150'.
perform bdc_field using 'BDC_CURSOR'
'AFPOD-PLNUM'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'AFPOD-PLNUM'
i_plnum-plnum.
perform bdc_field using 'AUFPAR-PP_AUFART'
c_auart.
perform bdc_dynpro using 'SAPLCOKO1' '0115'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BDC_CURSOR'
'CAUFVD-GAMNG'.
CALL TRANSACTION 'CO40' USING i_BDCDATA
MODE c_mode
UPDATE c_update
MESSAGES INTO i_msg.
SAP BDC Message
CLEAR : V1.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = V1
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Error Handling
if sy-msgty = 'W' OR sy-msgty = 'S'.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'S'.
append i_error.
else.
i_error-order = i_matnr-matnr.
i_error-messg = V1.
i_error-val = 'E'.
append i_error.
endif.
endloop.
ENDFORM. " convert_planned_orders
Thanks
Seshu
07-28-2007 7:24 AM
Hi
Lock objects are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.
SAP Provide three type of Lock objects.
- Read Lock(Shared Locked)
protects read access to an object. The read lock allows other transactions read access but not write access to
the locked area of the table
- Write Lock(exclusive lock)
protects write access to an object. The write lock allows other transactions neither read nor write access to
the locked area of the table.
- Enhanced write lock (exclusive lock without cumulating)
works like a write lock except that the enhanced write lock also protects from further accesses from the
same transaction.
You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.
Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.
Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.
Technicaly:
When you create a lock object System automatically creat two function module.
1. ENQUEUE_<Lockobject name>. to insert the object in a queue.
2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.
You have to use these function module in your program.
check this link for example.
http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
tables:vbak.
call function 'ENQUEUE_EZLOCK3'
exporting
mode_vbak = 'E'
mandt = sy-mandt
vbeln = vbak-vbeln
X_VBELN = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Normally ABAPers will create the Lock objects, because we know when to lock and how to lock and where to lock the Object then after completing our updations we unlock the Objects in the Tables
http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
purpose: If multiple user try to access a database object, inconsistency may occer. To avoid that inconsistency and to let multiple user give the accessibility of the database objects the locking mechanism is used.
Steps: first we create a loc object in se11 . Suppose for a table mara. It will create two functional module.:
1. enque_lockobject
1. deque_lockobject
before updating any table first we lock the table by calling enque_lockobject fm and then after updating we release the lock by deque_lockobject.
http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
GO TO SE11
Select the radio button "Lock object"..
Give the name starts with EZ or EY..
Example: EYTEST
Press Create button..
Give the short description..
Example: Lock object for table ZTABLE..
In the tables tab..Give the table name..
Example: ZTABLE
Save and generate..
Your lock object is now created..You can see the LOCK MODULES..
In the menu ..GOTO -> LOCK MODULES..There you can see the ENQUEUE and DEQUEUE function
Lock objects:
http://www.sap-img.com/abap/type-and-uses-of-lock-objects-in-sap.htm
http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
Match Code Objects:
http://help.sap.com/saphelp_nw2004s/helpdata/en/41/f6b237fec48c67e10000009b38f8cf/content.htm
http://searchsap.techtarget.com/tip/0,289483,sid21_gci553386,00.html
See this link:
http://www.sap-img.com/abap/type-and-uses-of-lock-objects-in-sap.htm
Check these links -
<b>Reward points for useful Answers</b>
Regards
Anji
07-28-2007 7:29 AM
Hi,
purpose: If multiple user try to access a database object, inconsistency may occer. To avoid that inconsistency and to let multiple user give the accessibility of the database objects the locking mechanism is used.
Steps: first we create a loc object in se11 . Suppose for a table mara. It will create two functional module.:
1. enque_lockobject
1. deque_lockobject
before updating any table first we lock the table by calling enque_lockobject fm and then after updating we release the lock by deque_lockobject.
For your requirement of Employee,
use the FM.
HR_EMPLOYEE_ENQUEUE
HR_EMPLOYEE_DEQUEUE
2.
DATA : ret LIKE bapireturn1.
DATA : locking_user LIKE sy-uname.
*----
For Enque
IF react = 'E'.
CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'
EXPORTING
number = ptab-pernr
IMPORTING
return = ret
locking_user = locking_user.
3. In case of VIEW,
do not enque.
In case of edit, Yes, enqueue.
4. This FM is standard SAP.
Hence, it will take care of other sap
trnascations like pa30 etc.
regards,