http://www.sapdev.co.uk/dictionary/lock_enqueue.htm
Example Program
Material and batch are primaly keys in table ZL009 , just use this two fields to lock a particular record in table.
FUNCTION z_insert_zl009.
*"----------------------------------------------------------------------
*"*"Update function module:
*"
*"*"Local interface:
*" IMPORTING
*" VALUE(I_ZL009) LIKE ZL009 STRUCTURE ZL009
*"----------------------------------------------------------------------
* TABLES: *ZL009.
*
* DATA: OBJECTID TYPE CDHDR-OBJECTID,
* TCODE TYPE CDHDR-TCODE,
* PLANNED_CHANGE_NUMBER TYPE CDHDR-PLANCHNGNR,
* UTIME TYPE CDHDR-UTIME,
* UDATE TYPE CDHDR-UDATE,
* USERNAME TYPE CDHDR-USERNAME,
* CDOC_PLANNED_OR_REAL TYPE CDHDR-CHANGE_IND,
* CDOC_UPD_OBJECT TYPE CDHDR-CHANGE_IND VALUE 'U',
* CDOC_NO_CHANGE_POINTERS TYPE CDHDR-CHANGE_IND.
************************************************************************
* Change History *
* Date : 23-SEP-2009 *
* Modified By : PARAKKAD *
* Transport # : D47K9A04G2 *
* Marked By : @001 *
* ADT # : UNITY00004226 *
* Description : 6Fields added after SET command to update *
* table zl009 *
************************************************************************
* Change History *
* Date : 2-DEC-2010 *
* Modified By : CARRM5 *
* Transport # : D47K9A0HKP *
* Marked By : D47K9A0HKP *
* SCR # : 162999 *
* Description : Track changes to ZL009-RevLv on ZREC_ZC21 *
* table *
************************************************************************
************************************************************************
* Change History *
* Date : 06-Dec-2012 *
* Modified By : GUPTAA8 *
* Transport # : D47K9A0RM6 *
* Marked By : D47K9A0RM6 *
* SCR # : 458943 *
* Description : Revision Level Update for table ZL009 for *
* all the Movement type for Tcode(MIGO & MB01)*
* & Mat.Grp.-010(Capital Equipment–BSC Mfg) *
************************************************************************
* Begin Insert - D47K9A0HKP
TABLES: ZREC_ZC21.
DATA: lc_matkl TYPE MATKL.
CONSTANTS: c_981(3) TYPE C VALUE '981',
c_011(3) TYPE C VALUE '011',
c_MIGO TYPE TCODE VALUE 'MIGO',
c_MB01 TYPE TCODE VALUE 'MB01',
C_010(3) TYPE C VALUE '010'. "D47K9A0RM6+
* End Insert - D47K9A0HKP
DATA : BEGIN OF lock_arg,
mandt LIKE zl009-mandt,
matnr LIKE zl009-matnr,
charg LIKE zl009-charg,
END OF lock_arg.
DATA : lock_arg-val LIKE rstable-varkey.
CLEAR lock_arg-val.
CLEAR lock_arg.
CLEAR zl009.
MOVE-CORRESPONDING i_zl009 TO zl009.
lock_arg-mandt = sy-mandt.
lock_arg-matnr = zl009-matnr.
lock_arg-charg = zl009-charg.
lock_arg-val = lock_arg.
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'S'
tabname = 'ZL009'
varkey = lock_arg-val
** X_TABNAME = ' '
** X_VARKEY = ' '
_scope = '2'
** _WAIT = ' '
EXCEPTIONS
foreign_lock = 4
system_failure = 8
OTHERS = 3.
CASE sy-subrc.
WHEN 0.
WHEN 4.
MESSAGE a041 WITH lock_arg.
WHEN OTHERS.
MESSAGE a042 WITH 'ZL009'.
ENDCASE.
INSERT zl009.
IF sy-subrc NE 0 AND sy-subrc NE 4.
MESSAGE a089 WITH 'ZL009' zl009-matnr zl009-charg.
* System error : Error when inserting table &, Material no &, Batch no
ENDIF.
IF sy-subrc = 4.
UPDATE zl009
SET
ebeln = zl009-ebeln
mjahr = zl009-mjahr
ersda = zl009-ersda
ernam = zl009-ernam
revlv = zl009-revlv
werks = zl009-werks
bwart = zl009-bwart
vfdat = zl009-vfdat
lifnr = zl009-lifnr
licha = zl009-licha
aufnr = zl009-aufnr
zovwrit = zl009-zovwrit
*********************** Begin Ins @001*****************
zorigwerks = zl009-zorigwerks
zzsterlot = zl009-zzsterlot
zzstldat = zl009-zzstldat
zzstlloc = zl009-zzstlloc
zzstlmthd = zl009-zzstlmthd
zzproduct = zl009-zzproduct
********************* End Ins @001***********************
WHERE
matnr = zl009-matnr AND
charg = zl009-charg .
IF sy-subrc NE 0.
MESSAGE a089 WITH 'ZL009' zl009-matnr zl009-charg.
* System error : Error when inserting table &, Material no &, Batch no
ENDIF.
* Begin Insert - D47K9A0HKP
* The following code was lifted from MZC09F01 in transaction ZC21.
* We are inserting an entry in table ZREC_ZC21 to track RevLv history.
* We can only store the current value of ZL009-RevLv because at this
* point we have no access to previous value. We will store the current
* value in ZREC_ZC21-XVALUE. This table update occurs only when the
* transaction is MIGO or MB01, the movement is 981, and the material
* group is 011.
* IF ZL009-BWART = c_981 "D47K9A0RM6-
* AND ( SY-TCODE = c_MIGO OR SY-TCODE = c_MB01 ). "D47K9A0RM6-
IF ( SY-TCODE = c_MIGO OR SY-TCODE = c_MB01 ). "D47K9A0RM6+
CLEAR lc_matkl.
SELECT SINGLE MATKL INTO lc_matkl FROM MARA
WHERE MATNR = ZL009-MATNR.
* IF lc_matkl = c_011. "D47K9A0RM6-
IF ( lc_matkl = c_011 OR LC_MATKL EQ C_010 ). "D47K9A0RM6+
CLEAR ZREC_ZC21.
ZREC_ZC21-MANDT = SY-MANDT .
ZREC_ZC21-SYSID = SY-UNAME .
ZREC_ZC21-PLANT = ZL009-WERKS.
ZREC_ZC21-MATNR = ZL009-MATNR.
ZREC_ZC21-CHARG = ZL009-CHARG.
ZREC_ZC21-RECDATE = SY-DATUM.
ZREC_ZC21-RECTIME = SY-UZEIT.
ZREC_ZC21-ACTION = 'MOD'.
ZREC_ZC21-XTABLE = 'ZL009'.
ZREC_ZC21-XFIELD = 'Revision'.
ZREC_ZC21-XVALUE = ZL009-REVLV.
ZREC_ZC21-TCODE = SY-TCODE.
INSERT ZREC_ZC21.
ENDIF.
ENDIF.
* End Insert - D47K9A0HKP
ENDIF.
******
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'S'
tabname = 'ZL009'
varkey = lock_arg-val
* X_TABNAME = ' '
* X_VARKEY = ' '
_scope = '2'
_synchron = 'X'.
*********************************************************
* OBJECTID = 'CHARGE'.
* UDATE = SY-DATUM.
* UTIME = SY-UZEIT.
* TCODE = SY-TCODE.
* USERNAME = SY-UNAME.
* *ZL009 = ZL009.
*
* CALL FUNCTION 'CHANGEDOCUMENT_OPEN'
* EXPORTING
* OBJECTCLASS = 'CHARGE '
* OBJECTID = OBJECTID
* EXCEPTIONS
* SEQUENCE_INVALID = 1
* OTHERS = 2.
*
* CASE SY-SUBRC.
* WHEN 1. MESSAGE A004 WITH 'Sequence invalid'.
* WHEN 2. MESSAGE A004 WITH 'OPEN-Failure'.
* ENDCASE.
*
* CALL FUNCTION 'CHANGEDOCUMENT_SINGLE_CASE'
* EXPORTING
* TABLENAME = 'ZL009 '
* WORKAREA_OLD = *ZL009
* WORKAREA_NEW = ZL009
* CHANGE_INDICATOR = 'U'
* DOCU_DELETE = ' '
* EXCEPTIONS
* NAMETAB_ERROR = 1
* OPEN_MISSING = 2
* POSITION_INSERT_FAILED = 3
* OTHERS = 4.
*
* CASE SY-SUBRC.
* WHEN 1. MESSAGE A004 WITH 'Name table failure'.
* WHEN 2. MESSAGE A004 WITH 'Open missing'.
* WHEN 3. MESSAGE A004 WITH 'INSERT failure'.
* WHEN 4. MESSAGE A004 WITH 'SINGLE Failure'.
* ENDCASE.
*
* CALL FUNCTION 'CHANGEDOCUMENT_CLOSE'
* EXPORTING
* OBJECTCLASS = 'CHARGE '
* OBJECTID = OBJECTID
* DATE_OF_CHANGE = UDATE
* TIME_OF_CHANGE = UTIME
* TCODE = TCODE
* USERNAME = USERNAME
* EXCEPTIONS
* HEADER_INSERT_FAILED = 1
* OBJECT_INVALID = 2
* OPEN_MISSING = 3
* NO_POSITION_INSERTED = 4
* OTHERS = 5.
*
* CASE SY-SUBRC.
* WHEN 1. MESSAGE A004 WITH 'Insert Header failed'.
* WHEN 2. MESSAGE A004 WITH 'Object invalid'.
* WHEN 3. MESSAGE A004 WITH 'Open missing'.
* WHEN 5. MESSAGE A004 WITH 'CLOSE Failure'.
* ENDCASE.
ENDFUNCTION.
Thursday, 5 September 2013
Saturday, 17 August 2013
Move Data from Select-Options to Internal Table
TABLES : mara.
TYPES : BEGIN OF ty_mat,
matnr TYPE matnr,
END OF ty_mat.
data : gw_mat type ty_mat.
SELECT-OPTIONS : mat FOR mara-matnr.
DATA : itab TYPE STANDARD TABLE OF mara.
DATA : it TYPE STANDARD TABLE OF matnr.
*MOVE mat[] TO it[] .
LOOP AT mat INTO gw_mat.
APPEND gw_mat+2 to it.
* Here we have added +2(offset) because every time IE or IEQ gets added. To remove this character we need to keep +2 or +3. if hte value is getting truncation in internal table IT, then increase the lenght of field in internaltable IT
CLEAR gw_mat.
ENDLOOP.
SELECT * FROM mara INTO TABLE itab WHERE matnr IN mat.
CLEAR : mat[].
mat[] = it[] .
WRITE : 'bharat' .
TYPES : BEGIN OF ty_mat,
matnr TYPE matnr,
END OF ty_mat.
data : gw_mat type ty_mat.
SELECT-OPTIONS : mat FOR mara-matnr.
DATA : itab TYPE STANDARD TABLE OF mara.
DATA : it TYPE STANDARD TABLE OF matnr.
*MOVE mat[] TO it[] .
LOOP AT mat INTO gw_mat.
APPEND gw_mat+2 to it.
* Here we have added +2(offset) because every time IE or IEQ gets added. To remove this character we need to keep +2 or +3. if hte value is getting truncation in internal table IT, then increase the lenght of field in internaltable IT
CLEAR gw_mat.
ENDLOOP.
SELECT * FROM mara INTO TABLE itab WHERE matnr IN mat.
CLEAR : mat[].
mat[] = it[] .
WRITE : 'bharat' .
Sunday, 28 July 2013
Finding Funtion Group
We can find all FunctionGroup as below.
Goto Se11
Enter Table TADIR
In table selection screen enter OBJECT = FUGR, then you will get all the function groups.
If you want function groups created by a person , enter author name in addition to OBJECT = FUGR
Goto Se11
Enter Table TADIR
In table selection screen enter OBJECT = FUGR, then you will get all the function groups.
If you want function groups created by a person , enter author name in addition to OBJECT = FUGR
Standard Program to Delete Scheduled Jobs is RSBTCDEL
Standard Program to Delete Scheduled Jobs is RSBTCDEL.
Run this program in SE38, here you can delete all the jobs
Run this program in SE38, here you can delete all the jobs
Saturday, 22 June 2013
Using Perform of one program in Another program
Example :
PERFORM f_add_ser_cond IN PROGRAM znm_sc_r_qn_erro_disp IF FOUND
TABLES i_cond2
t_serialno
lt_sernr
USING matnr
vwerk
aufart
repos
CHANGING lv_flag.
PERFORM f_add_ser_cond IN PROGRAM znm_sc_r_qn_erro_disp IF FOUND
TABLES i_cond2
t_serialno
lt_sernr
USING matnr
vwerk
aufart
repos
CHANGING lv_flag.
Tuesday, 18 June 2013
User Exit Table MODSAP
1. MODSAP is the table which has Exit name .
2. When you have a include of an exit, use the where used list and find the EXIT name.
3. Pass the Exit name to the MODSAP , then you can find the Enhancement name.
2. When you have a include of an exit, use the where used list and find the EXIT name.
3. Pass the Exit name to the MODSAP , then you can find the Enhancement name.
Wednesday, 12 June 2013
Disable Fields in Selection Screen of Report Program based on Authority Check.
1. First check for Required condition ( Checking authorization in current example) in INITIALIZATION . Based on condition use LOOP AT SCREEN to disable or make the field invisible.
Example
INITIALIZATION.
gv_readonly_flag = 'X' .
LOOP AT SCREEN.
IF screen-name EQ 'P_R1'.
break mavb.
screen-invisible = '1'.
screen-active = '0' .
MODIFY SCREEN.
ENDIF.
ENDLOOP.
2. Keep a flag when you run the above code and copy the same code in AT SELECTION-SCREEN OUTPUT. as initially the field will be invisible in the selection screen but when the user press ENTER, the field will become visible as INITIALIZATION will be executed only once in the life of program, so when the user press enter the field will become visible. So we have to write the same code in AT SELECTION-SCREEN OUTPUT.
Example
AT SELECTION-SCREEN OUTPUT.
IF gv_readonly_flag = 'X' .
LOOP AT SCREEN.
IF screen-name EQ 'P_R1'.
break mavb.
screen-invisible = '1'.
screen-active = '0' .
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
Example with a scenario for Authorisation check :
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS : p_r1 RADIOBUTTON GROUP g1 ,
p_r2 RADIOBUTTON GROUP g1 .
SELECTION-SCREEN END OF BLOCK b2.
INITIALIZATION.
CALL FUNCTION 'AUTHORITY_CHECK'
EXPORTING
user = sy-uname
object = 'ZQMCERTMGR'
field1 = 'ZQMCRTACVT'
value1 = '01'
EXCEPTIONS
user_dont_exist = 1
user_is_authorized = 2
user_not_authorized = 3
user_is_locked = 4
OTHERS = 5.
IF sy-subrc NE 2.
CALL FUNCTION 'AUTHORITY_CHECK'
EXPORTING
user = sy-uname
object = 'ZQMCERTMGR'
field1 = 'ZQMCRTACVT'
value1 = '03'
EXCEPTIONS
user_dont_exist = 1
user_is_authorized = 2
user_not_authorized = 3
user_is_locked = 4
OTHERS = 5.
IF sy-subrc EQ 2 .
gv_readonly_flag = 'X' .
ELSEIF sy-subrc NE 0 .
MESSAGE 'User is not Authorised'(019) TYPE 'E' .
LEAVE TO LIST-PROCESSING.
EXIT.
ENDIF.
ENDIF.
IF gv_readonly_flag = 'X' .
LOOP AT SCREEN.
IF screen-name EQ 'P_R1'.
break mavb.
screen-invisible = '1'.
screen-active = '0' .
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
AT SELECTION-SCREEN OUTPUT.
IF gv_readonly_flag = 'X' .
LOOP AT SCREEN.
IF screen-name EQ 'P_R1'.
break mavb.
screen-invisible = '1'.
screen-active = '0' .
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
Explanation : P_R1 and P_R2 are radion buttons. P_R1 is for write access and P_R2 is for read only report. So when we check for authorisation using the Authority_check function module, if user has authorisation for write access, authority FM with field value '01' will pass, if the user doesn't have write access , then we check for read access.If user has read access then we make the radio button P_R1 invisible as per above code.
Example
INITIALIZATION.
gv_readonly_flag = 'X' .
LOOP AT SCREEN.
IF screen-name EQ 'P_R1'.
break mavb.
screen-invisible = '1'.
screen-active = '0' .
MODIFY SCREEN.
ENDIF.
ENDLOOP.
2. Keep a flag when you run the above code and copy the same code in AT SELECTION-SCREEN OUTPUT. as initially the field will be invisible in the selection screen but when the user press ENTER, the field will become visible as INITIALIZATION will be executed only once in the life of program, so when the user press enter the field will become visible. So we have to write the same code in AT SELECTION-SCREEN OUTPUT.
Example
AT SELECTION-SCREEN OUTPUT.
IF gv_readonly_flag = 'X' .
LOOP AT SCREEN.
IF screen-name EQ 'P_R1'.
break mavb.
screen-invisible = '1'.
screen-active = '0' .
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
Example with a scenario for Authorisation check :
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS : p_r1 RADIOBUTTON GROUP g1 ,
p_r2 RADIOBUTTON GROUP g1 .
SELECTION-SCREEN END OF BLOCK b2.
INITIALIZATION.
CALL FUNCTION 'AUTHORITY_CHECK'
EXPORTING
user = sy-uname
object = 'ZQMCERTMGR'
field1 = 'ZQMCRTACVT'
value1 = '01'
EXCEPTIONS
user_dont_exist = 1
user_is_authorized = 2
user_not_authorized = 3
user_is_locked = 4
OTHERS = 5.
IF sy-subrc NE 2.
CALL FUNCTION 'AUTHORITY_CHECK'
EXPORTING
user = sy-uname
object = 'ZQMCERTMGR'
field1 = 'ZQMCRTACVT'
value1 = '03'
EXCEPTIONS
user_dont_exist = 1
user_is_authorized = 2
user_not_authorized = 3
user_is_locked = 4
OTHERS = 5.
IF sy-subrc EQ 2 .
gv_readonly_flag = 'X' .
ELSEIF sy-subrc NE 0 .
MESSAGE 'User is not Authorised'(019) TYPE 'E' .
LEAVE TO LIST-PROCESSING.
EXIT.
ENDIF.
ENDIF.
IF gv_readonly_flag = 'X' .
LOOP AT SCREEN.
IF screen-name EQ 'P_R1'.
break mavb.
screen-invisible = '1'.
screen-active = '0' .
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
AT SELECTION-SCREEN OUTPUT.
IF gv_readonly_flag = 'X' .
LOOP AT SCREEN.
IF screen-name EQ 'P_R1'.
break mavb.
screen-invisible = '1'.
screen-active = '0' .
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
Explanation : P_R1 and P_R2 are radion buttons. P_R1 is for write access and P_R2 is for read only report. So when we check for authorisation using the Authority_check function module, if user has authorisation for write access, authority FM with field value '01' will pass, if the user doesn't have write access , then we check for read access.If user has read access then we make the radio button P_R1 invisible as per above code.
Subscribe to:
Posts (Atom)