http://scn.sap.com/community/abap/testing-and-troubleshooting/blog/2010/11/10/new-abap-debugger-tips-and-tricks
Friday, 20 September 2013
Wednesday, 18 September 2013
How to Avoid Internal Commit or Implicit Commit in Standard BAPI
Below is the reply from SAP to avoid internal/implicit commit in standard Bapis : BAPIs BAPI_BATCH_CREATE, BAPI_BATCH_CHANGE, and
BAPI_BATCH_SAVE_REPLICA
Not sure whether this works for other standard Bapi's or not . We can try the below method given by SAP
BAPIs BAPI_BATCH_CREATE, BAPI_BATCH_CHANGE, and
BAPI_BATCH_SAVE_REPLICA can be used for maintaining batch data.
The three BAPIs mentioned above implicitly carry out a separate COMMIT
WORK.
If a COMMIT WORK AND WAIT is required, or if batch maintenance is to
be included om a transaction, the implicit COMMIT of the BAPIs has to
be suppressed.
This is done by calling function module 'TRANSACTION_BEGIN' before
calling the individual BAPI. Thus the calling program takes over
transaction control. The transaction is terminated by calling function
18.09.2013 Page 3 of 4
SAP Note 619913 - FAQ: Basic functions of batch
management
module 'TRANSACTION_END' or 'BAPI_TRANSACTION_COMMIT'.
BAPI_BATCH_CREATE
This BAPI exclusively serves for creating new batches or expanding
existing batches by plant or storage location segments.
BAPI_BATCH_CHANGE
This BAPI exclusively serves for changing existing batches.
BAPI_BATCH_SAVE_REPLICA
This BAPI creates batches or changes existing batches. It combines the
functions of the above-mentioned BAPIs.
BAPI_BATCH_SAVE_REPLICA
Not sure whether this works for other standard Bapi's or not . We can try the below method given by SAP
BAPIs BAPI_BATCH_CREATE, BAPI_BATCH_CHANGE, and
BAPI_BATCH_SAVE_REPLICA can be used for maintaining batch data.
The three BAPIs mentioned above implicitly carry out a separate COMMIT
WORK.
If a COMMIT WORK AND WAIT is required, or if batch maintenance is to
be included om a transaction, the implicit COMMIT of the BAPIs has to
be suppressed.
This is done by calling function module 'TRANSACTION_BEGIN' before
calling the individual BAPI. Thus the calling program takes over
transaction control. The transaction is terminated by calling function
18.09.2013 Page 3 of 4
SAP Note 619913 - FAQ: Basic functions of batch
management
module 'TRANSACTION_END' or 'BAPI_TRANSACTION_COMMIT'.
BAPI_BATCH_CREATE
This BAPI exclusively serves for creating new batches or expanding
existing batches by plant or storage location segments.
BAPI_BATCH_CHANGE
This BAPI exclusively serves for changing existing batches.
BAPI_BATCH_SAVE_REPLICA
This BAPI creates batches or changes existing batches. It combines the
functions of the above-mentioned BAPIs.
Friday, 13 September 2013
Changing the import parameter of User Exit
DM07M is the input parameter of a user exit. Check the image for your information .
Declare a constant with main program in bracket followed by the field you want to change.
Example :
Constant : gc_temp type char30 value '(Main program name) Table-field' .
Field symbol : <FS> type table-field .
assign (gc_temp) to <FS> .
move the value required to field symbol.
Move 'Bharat' to <FS> .
Below is the example
CONSTANTS: gc_ref_fld TYPE char25 VALUE '(SAPMM07M)DM07M-KZCLA' .
FIELD-SYMBOLS: <fs_wa> TYPE dm07m-kzcla.
ASSIGN (gc_ref_fld) TO <fs_wa>.
IF <fs_wa> IS ASSIGNED.
*Do not show the characteristic screen...change to background mode
MOVE '1' TO <fs_wa>.
ENDIF.
Wednesday, 11 September 2013
Wild Card Search in Select Statements
for suppose you need wild card search parameter like
data:patient(10) type c.
search : a*
TRANSLATE patient TO UPPER CASE.
replace all occurrences of '*' in patient with '%'.
select a
b
c
into table itab
where A like patient.
With queries, I think its possible to use just the wild card '%'.
Say N%, then it retrieves data starting with N
%N% retrieves data which has N anywhere in between
%N retrieves data ending with N.
replace all occurrences of '*' in patient with '%'.
b
c
into table itab
where A like patient.
With queries, I think its possible to use just the wild card '%'.
Say N%, then it retrieves data starting with N
%N% retrieves data which has N anywhere in between
%N retrieves data ending with N.
Thursday, 5 September 2013
Function module to find Differnce between two timestamps in Hours and minutes
SD_CALC_DURATION_FROM_DATETIME
This function module gives the time difference between two dates and time mentioned for each date.
This function module gives the time difference between two dates and time mentioned for each date.
Lock Object ENQUEUE_E_TABLE
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.
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.
Subscribe to:
Posts (Atom)