‎2007 Jun 15 4:46 AM
hello,
i want to know how to add rollback and commit strategy in BDC programming,
the scnerio is that there're lots of items need to be processed in BDC, and i want the program do nothing when any one of the items can't be processed, that is, all the items should be successed together.
though the BDC is processed through a loop, i wander if it is possible to add such a similar rollback/commit strategy ? Welcome if you have another solution.
thank you !
‎2007 Jun 15 4:54 AM
it is not possible in bdc but you can have one more option in indirectly
keep one check box in selection-screen,like test mode
when you click test mode then do not use save ok_code ( It works like Roll back )
if you use call transaction ,then if you use update mode is Synchronous ,it works like committ work.
Thanks
Seshu
‎2007 Jun 15 4:54 AM
it is not possible in bdc but you can have one more option in indirectly
keep one check box in selection-screen,like test mode
when you click test mode then do not use save ok_code ( It works like Roll back )
if you use call transaction ,then if you use update mode is Synchronous ,it works like committ work.
Thanks
Seshu
‎2007 Jun 15 5:36 AM
hi Seshu,
thanks again!
but would you please show me a code structure ? i can understand you but it's a little nonobjective to me
and more, i met these code in a reference program
PARAMETERS: test LIKE rkec1-test DEFAULT 'X'.
....
CALL FUNCTION 'Z_ALV_REV_DATA_LIST'
EXPORTING
i_flg_show_post = test
i_bukrs = p_bukrs
i_budat = p_budat
TABLES
it_output = it_output.
i really don't know how my predecessor fill the similar task with this. thanks for a little explaination
‎2007 Jun 15 5:47 AM
Sorry,
i should read the code in 'Z_ALV_REV_DATA_LIST' first.
sir may you just show me your code structure.
thanks
‎2007 Jun 15 6:27 AM
See the code and important things marked as bold
************************************************************************
Report : ZMPPC018
Type : Data upload
Author : Seshu Maramreddy
Date : 07/05/2005
Transport : DV3K921247
Transaction: ??
Description: This ABAP/4 Program to Update Rate Routing Material PRT's
for SMI plants using CA22 Transaction.It accepts
tab-delimited spreadsheet input and Run the Call
Transaction Method.
*
************************************************************************
report zmppc018 no standard page heading
line-size 120
line-count 55
message-id zz.
Constants
constants : c_x type c value 'X'," Dynbegin
c_tcode type tstc-tcode value 'CA22'," Transaction Code
c_r(1) type c value 'R'," Task List type
c_O(1) type c value 'O',
c_fh(2) type c value 'FH'.
Variables
data : v_lines_in_xcel like sy-tabix,
v_matnr(18) type c, " Material Number
v_PLNNR like mapl-plnnr," Group
V_DATE(8) type c," System date
v_date1(4) type c,
v_date2(2) type c,
v_date3(2) type c,
V_COUNT TYPE I." Count
Internal table for BDCDATA Structure
data : begin of itab_bdc_tab occurs 0.
include structure bdcdata.
data : end of itab_bdc_tab.
Internal table for File
data : begin of t_file occurs 0,
matnr(18) type c, " Material #
werks(4) type c, " Plant
plnal(2) type n, " Group Counter
vornr(4) type n, " Op #
equnr(18) type c, " PRT Material #
steuf(4) type c, " Control Key
mgvgw(6) type n, " Qty
mgeinh(3) type c, " Qty Unit
end of t_file.
Internal table for Error Log
data : begin of i_error occurs 0,
matnr like mara-matnr,
werks like marc-werks,
vornr like plpo-vornr,
plnnr like plpo-plnnr,
text(90) type c,
end of i_error.
Selection-screen
selection-screen : begin of block blk with frame.
selection-screen: skip 1.
parameters : p_file like rlgrap-filename obligatory,
P_mode type c obligatory Default 'N',
<b> p_test as checkbox ." Roll Back</b>selection-screen : skip 1.
selection-screen : end of block blk.
at selection-screen on value-request for p_file.
F4 value for Input file
perform filename_get.
main processing
start-of-selection.
To get the data from file to Internal table
perform getdata_fromfile.
loop at t_file.
fill in bdc-data for Routing maintenance screens
perform bdc_build_script.
insert the bdc script as a BDC transaction
perform bdc_submit_transaction.
endloop.
top-of-page.
call function 'Z_HEADER'
EXPORTING
FLEX_TEXT1 =
FLEX_TEXT2 =
FLEX_TEXT3 =
.
skip 1.
write:/2 'Material #',24 'Plant',32 'Group',44 'Op #',
53 'Status Message'.
skip 1.
&----
*& Form filename_get
&----
F4 Value for Input File parameter
----
FORM filename_get.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_PATH = 'C:\Temp\ '
MASK = ',.,..'
MODE = 'O'
TITLE = 'Select File '(007)
IMPORTING
FILENAME = p_file
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
ENDFORM. " filename_get
&----
*& Form getdata_fromfile
&----
text
----
FORM getdata_fromfile.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = p_file
FILETYPE = 'DAT'
TABLES
DATA_TAB = t_file
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.
if sy-subrc eq 0.
sort t_file by matnr werks plnal vornr .
clear v_lines_in_xcel.
describe table t_file lines v_lines_in_xcel.
if v_lines_in_xcel is initial.
write: / 'No data in input file'.
stop.
endif.
else.
write:/ 'Error reading input file'.
stop.
endif.
ENDFORM. " getdata_fromfile
&----
*& Form bdc_build_script
&----
BDC Script
----
FORM bdc_build_script.
Get the material number from tables ZMSMI_FERR_RAW,
ZMSMI_SNAP_RAW and ZMSMI_SIMP_RAW
perform get_matnr.
Screen 1010.
perform bdc_screen using 'SAPLCPDI' '1010'.
perform bdc_field using 'BDC_OKCODE' '=VOUE'.
perform bdc_field using 'RC27M-MATNR' SPACE .
perform bdc_field using 'RC27M-WERKS' SPACE.
perform bdc_field using 'RC271-VBELN' SPACE.
perform bdc_field using 'RC271-POSNR' SPACE.
perform bdc_field using 'RC271-PSPNR' SPACE.
Clear v_plnnr.
Get the Group from MAPL Table
select single plnnr from mapl
into v_plnnr
where matnr = t_file-matnr
and werks = t_file-werks
and loekz = space
and plnty = c_r
and plnal = t_file-plnal.
perform bdc_field using 'RC271-PLNNR' v_plnnr.
Current date
MOVE SY-DATUM TO V_DATE.
perform get_date.
perform bdc_field using 'RC271-STTAG' V_DATE.
perform bdc_field using 'RC271-PLNAL' t_file-plnal.
Screen 5400
perform bdc_screen using 'SAPLCPDI' '5400'.
perform bdc_field using 'BDC_OKCODE' '=OSEA'.
Screen 1010
perform bdc_screen using 'SAPLCP02' '1010'.
perform bdc_field using 'BDC_OKCODE' '=ENT1'.
perform bdc_field using 'RC27H-VORNR' T_FILE-VORNR.
Screen 5400
perform bdc_screen using 'SAPLCPDI' '5400'.
perform bdc_field using 'BDC_OKCODE' '=FHUE'.
perform bdc_field using 'RC27X-FLG_SEL(01)' C_X.
Get the no of records from PLAS,PLPO and PLFH Tables
perform get_count.
Screen 0200
IF V_COUNT = 0.
perform bdc_screen using 'SAPLCFDI' '0200'.
perform bdc_field using 'BDC_OKCODE' '/EFIM'.
ELSEif v_count > 0.
Screen 0100
perform bdc_screen using 'SAPLCFDI' '0100'.
perform bdc_field using 'BDC_OKCODE' '/EFIM'.
ENDIF.
Screen 0230
perform bdc_screen using 'SAPLCFDI' '0200'.
perform bdc_field using 'BDC_OKCODE' '=BACK'.
perform bdc_field using 'PLFHD-MATNR' T_FILE-EQUNR.
perform bdc_field using 'PLFHD-STEUF' T_FILE-STEUF.
perform bdc_field using 'PLFHD-MGVGW' T_FILE-mgvgw.
perform bdc_field using 'PLFHD-MGEINH' T_FILE-MGEINH.
Screen 0100
perform bdc_screen using 'SAPLCFDI' '0100'.
<b>if p_test ne 'X'. " Save Button
perform bdc_field using 'BDC_OKCODE' '=BU'.
endif.</b>
ENDFORM. " bdc_build_script
&----
*& Form get_matnr
&----
Get the material number from tables ZMSMI_FERR_RAW,
ZMSMI_SNAP_RAW and ZMSMI_SIMP_RAW
----
FORM get_matnr.
clear v_matnr.
case t_file-werks.
when '0101'.
select single cmatnr from zmsmi_simp_raw
into v_matnr where matnr = t_file-matnr.
if not v_matnr is initial.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.
when '0103'.
select single cmatnr from zmsmi_ferr_raw
into v_matnr where matnr = t_file-matnr.
if not v_matnr is initial.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.
when '0102' or '0110' or '0111' or '0112' or '0113'
or '0114' or '0115' or '0116' or '0117'.
select single cmatnr from zmsmi_snap_raw
into v_matnr where matnr = t_file-matnr.
if not v_matnr is initial.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.
endcase.
ENDFORM. " get_matnr
&----
*& Form bdc_screen
&----
BDC Script for Screen fields
----
-->P_PROG Program name
-->P_SCRN Screen Number
----
FORM bdc_screen USING p_prog
p_scrn.
clear itab_bdc_tab.
itab_bdc_tab-program = p_prog.
itab_bdc_tab-dynpro = p_scrn.
itab_bdc_tab-dynbegin = c_x.
append itab_bdc_tab.
ENDFORM. " bdc_screen
&----
*& Form bdc_field
&----
BDC Script for Screen fileds
----
-->P_NAM Field name
-->P_VAL Field value
----
FORM bdc_field USING p_nam
p_val.
clear itab_bdc_tab.
itab_bdc_tab-fnam = p_nam.
itab_bdc_tab-fval = p_val.
append itab_bdc_tab.
ENDFORM. " bdc_field
&----
*& Form bdc_submit_transaction
&----
BDC_INSERT Function Module
----
FORM bdc_submit_transaction.
call transaction c_tcode using itab_bdc_tab
mode p_mode <b>update 'S'.</b> " This works like comitt work
refresh itab_bdc_tab.
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 = i_error-text
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
i_error-matnr = t_file-matnr.
i_error-werks = t_file-werks.
i_error-plnnr = v_plnnr.
i_error-vornr = t_file-vornr.
append i_error.
clear i_error.
clear t_file.
ENDFORM. " bdc_submit_transaction
&----
*& Form get_date
&----
Converted date as per CA22 Transaction
----
FORM get_date.
clear : v_date,
v_date1,
v_date2,
v_date3.
v_date1 = sy-datum+0(4).
v_date2 = sy-datum+4(2).
v_date3 = sy-datum+6(2).
concatenate v_date2 v_date3 v_date1 into v_date.
ENDFORM. " get_date
&----
*& Form get_count
&----
text
----
FORM get_count.
clear v_count.
select count(*) into v_count
from plas as a inner join plpo as b on aplnty = bplnty
and aplnnr = bplnnr
and aplnkn = bplnkn
inner join plfh as c on cplnty = aplnty
and cplnnr = aplnnr
and cplnal = aplnal
and cplnfl = aplnfl
and cplnkn = bplnkn
where a~plnty = c_r
and a~plnnr = v_plnnr
and a~plnal = t_file-plnal
and c~objct = c_O
and a~loekz = space
and b~vornr = t_file-vornr
and c~objty = c_fh
and c~loekz = space.
ENDFORM. " get_count
end-of-selection.
Displaying Error Log
loop at i_error.
write:/2 i_error-matnr,24 i_error-werks,32 i_error-plnnr,
44 i_error-vornr,50 '-', 53 i_error-text.
endloop.
Reward Points if it is helpful
Thanks
Seshu
‎2007 Jun 15 5:03 AM
Hi,
Why don't you use Error mode
data: begin of i_options occurs 0.
include structure ctu_params.
data: end of i_options.
refresh : i_bdc, i_message, i_options.
move : 'E' to i_options-dismode,
'S' to i_options-updmode,
append i_options.
call transaction v_tcode using i_bdc options from i_options
messages into i_message.
or
instead of using BDC check for Bapi's. using bapi you canrollback .
aRs