2007 Feb 26 3:37 PM
can any one give, how to catch the error records using call transaction method without using BDCMSGCOL.
can any one give, how to catch the error records using call transaction method without using BDCMSGCOL.
2007 Feb 26 3:39 PM
hi,
following is an example program use this
REPORT zmmme029_rbc_enhancement
NO STANDARD PAGE HEADING
MESSAGE-ID zmm.
----
T Y P E D E C L A R A T I O N S *
----
Final output structure
TYPES: BEGIN OF ty_s_cbht,
matnr TYPE zkt_cbht-matnr, "Material Number
werks TYPE zkt_cbht-werks, "Plant
stprs TYPE mbew-stprs , "Material Standard price
trcom TYPE zkt_cbht-trcom, "Transaction Complete Ind
END OF ty_s_cbht,
ty_t_cbht TYPE STANDARD TABLE OF ty_s_cbht.
Error Table Structure
TYPES: BEGIN OF ty_s_matnr,
matnr TYPE matnr, "Material number
werks TYPE werks, "Plant
msg(500) TYPE c, "Messages
END OF ty_s_matnr,
ty_t_matnr TYPE STANDARD TABLE OF ty_s_matnr.
Plant n amd material pertaing to to single company code.
TYPES: BEGIN OF ty_s_plant,
matnr TYPE matnr, "Material number
werks TYPE marc-werks, "Plant
END OF ty_s_plant,
ty_t_plant TYPE STANDARD TABLE OF ty_s_plant.
Success table Structure
TYPES: BEGIN OF ty_s_success,
matnr TYPE matnr, "Material number
END OF ty_s_success,
ty_t_success TYPE STANDARD TABLE OF ty_s_success.
BDC Structure Table
TYPES:ty_t_bdc_tab TYPE STANDARD TABLE OF bdcdata.
BDC Messages Structure
TYPES: ty_s_bdcmsg TYPE bdcmsgcoll.
BDC messages Table
TYPES:ty_t_bdcmsg TYPE STANDARD TABLE OF bdcmsgcoll.
Capturing error messages
TYPES: BEGIN OF ty_s_msgs,
msg(200), "Error messages
END OF ty_s_msgs,
ty_t_msgs TYPE STANDARD TABLE OF ty_s_msgs.
----
I N T E R N A L T A B L E S *
----
DATA: gt_objhead TYPE TABLE OF solisti1, "Object Header Table
gt_objtxt TYPE TABLE OF solisti1, "Body
gt_reclist TYPE TABLE OF somlreci1, "Recipient list
gt_cbht TYPE ty_t_cbht, "internal table
gt_cbht_tmp TYPE ty_t_cbht, "Temp internal table
gt_error TYPE ty_t_matnr, "Error table
gt_marc TYPE ty_t_plant, "Plant table
gt_success TYPE ty_t_success, "Success table
gt_bdc_tab TYPE ty_t_bdc_tab, "BDC table
gt_bdc_msg TYPE STANDARD TABLE OF bdcmsgcoll. "Message table
----
V A R I A B L E S *
----
DATA: gv_tab_lines TYPE i,
gv_bdc_open_flag TYPE c.
----
G L O B A L D A T A D E C L A R A T I O N S *
----
DATA: gs_objtxt TYPE solisti1, "Body
gs_reclist TYPE somlreci1, "Recipient List
gs_doc_chng TYPE sodocchgi1, "Mail Header details
gs_error TYPE ty_s_matnr, "Error table structure
gs_marc TYPE ty_s_plant, "Plant data Structure
gs_success TYPE ty_s_matnr, "Success table Structure
gs_bdc_tab TYPE bdcdata, "BDC table data
gt_msgs TYPE ty_t_msgs. "Capturing the messages
----
G L O B A L C O N S T A N T S *
----
CONSTANTS: gc_x(1) TYPE c VALUE 'X', "For checking field
gc_c(1) TYPE c VALUE 'C', "Constant value C
gc_u(1) TYPE c VALUE 'U', "Contant value U
gc_p(4) TYPE c VALUE '1000', "Constant value 1000
gc_f TYPE c VALUE 'F', "Footer indicator
gc_h TYPE c VALUE 'H', "Header indicator
gc_at(2) TYPE c VALUE '@', "@ symbol
gc_grpid TYPE apqi-groupid VALUE 'RBC_ERRORS',
gc_cbht TYPE rstable-tabname VALUE 'ZKT_CBHT',
gc_s VALUE 'S', "constant S
gc_2 VALUE '2', "constant value 2
gc_3 VALUE '3', "constant value 3
gc_y VALUE 'Y'. "constant Y
----
S E L E C T I O N S C R E E N *
----
Selection Screen data for block b.
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-001.
PARAMETERS: p_gjahr TYPE zkt_cbht-gjahr OBLIGATORY, "Fiscal Year
p_monat TYPE zkt_cbht-monat OBLIGATORY, "FiscalPeriod
p_fweek TYPE zkt_cbht-fweek OBLIGATORY, "Fiscal week
p_budat TYPE budat OBLIGATORY DEFAULT sy-datum,
p_bukrs TYPE t001-bukrs OBLIGATORY DEFAULT gc_p.
SELECTION-SCREEN END OF BLOCK b.
*Selection Screen data for block b1.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-006.
PARAMETERS: p_dlist TYPE p10_email OBLIGATORY."Email ID/Distr List
SELECTION-SCREEN END OF BLOCK b1.
----
A T S E L E C T I O N S C R E E N *
----
Validation check for Comapny code
AT SELECTION-SCREEN ON p_bukrs.
PERFORM validate_bukrs.
----
S T A R T O F S E L E C T I O N *
----
INITIALIZATION.
Defaulting the Fiscal Year/Period/Week on the Selection-screen
PERFORM default_fiscal_data.
----
S T A R T O F S E L E C T I O N *
----
START-OF-SELECTION.
Retrieve costing data from the custom table.
PERFORM get_cbht_data.
Retrieve all the plants data for which the material is extended
PERFORM get_data_from_marc.
Run the MR21 transaction to update Std Price retrieved from ZKT_CBHT
PERFORM update_std_price.
Display materials which are not updated.
PERFORM display_materials.
Check for materials that failed to update
IF gt_error IS NOT INITIAL.
Send a mail with error information
PERFORM send_log_mail.
ENDIF.
----
E N D O F S E L E C T I O N *
----
END-OF-SELECTION.
Footer for the report display using FM 'Z_SL_HEADER_FOOTER'
PERFORM header_footer USING gc_f.
----
T O P O F P A G E *
----
TOP-OF-PAGE.
Header for the report display using FM 'Z_SL_HEADER_FOOTER'
PERFORM header_footer USING gc_h .
----
Form get_cbht_data *
----
Retrieving data from the CBHT custom table *
----
FORM get_cbht_data .
Populate the internal table.
SELECT matnr "Material
werks "Plant
stprs "Standard material Price
trcom "Costing version
FROM zkt_cbht
INTO TABLE gt_cbht
WHERE gjahr EQ p_gjahr AND
monat EQ p_monat AND
fweek EQ p_fweek.
Delete the records for which the MR21 is completed
DELETE gt_cbht WHERE trcom EQ gc_y.
If the table is empty
IF gt_cbht IS INITIAL .
MESSAGE s004. "No data found status message
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " get_cbht_data
----
Form get_data_from_marc *
----
Retrieving All the Plant data from MARC table *
----
FORM get_data_from_marc.
local declaration
TYPES : BEGIN OF ty_s_t001k,
bwkey TYPE t001k-bwkey,
END OF ty_s_t001k,
ty_t_t001k TYPE STANDARD TABLE OF ty_s_t001k.
DATA : lr_bwkey TYPE RANGE OF t001k-bwkey,
ls_bwkey LIKE LINE OF lr_bwkey,
lt_t001k TYPE ty_t_t001k,
ls_t001k TYPE ty_s_t001k.
CONSTANTS: lc_i VALUE 'I',
lc_eq(2) VALUE 'EQ'.
REFRESH : lt_t001k,
gt_marc.
Get the Unique Materials from ZKT_CBHT
IF NOT gt_cbht IS INITIAL.
gt_cbht_tmp = gt_cbht.
SORT gt_cbht_tmp BY matnr.
DELETE ADJACENT DUPLICATES FROM gt_cbht_tmp COMPARING matnr.
ENDIF.
select all the plants and company codes
SELECT bwkey "Valuation area
FROM t001k
INTO TABLE lt_t001k
WHERE bukrs EQ p_bukrs.
Populating the range table for the Plants that are retrieved
ls_bwkey-sign = lc_i.
ls_bwkey-option = lc_eq.
LOOP AT lt_t001k INTO ls_t001k.
ls_bwkey-low = ls_t001k-bwkey.
APPEND ls_bwkey TO lr_bwkey.
CLEAR: ls_bwkey-low.
ENDLOOP.
Select all the plant values
SELECT matnr "Material number
werks "Plant
FROM marc
INTO TABLE gt_marc
FOR ALL ENTRIES IN gt_cbht_tmp
WHERE matnr EQ gt_cbht_tmp-matnr AND
werks IN lr_bwkey.
SORT gt_marc BY matnr werks.
If the table is empty
IF gt_marc IS INITIAL .
MESSAGE s004. "No data found status message
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " get_data_from_marc
----
Form UPDATE_STD_PRICE *
----
Run the BDC recording for MR21 for updating the Std Price *
----
FORM update_std_price.
clear the flag value and loop the cost blending table
CLEAR: gv_bdc_open_flag.
Filling the BDCDATA
PERFORM prepare_bdc_tab.
Close the SESSION
IF gv_bdc_open_flag = gc_x.
PERFORM bdc_close_group.
ENDIF.
ENDFORM. "UPDATE_STD_PRICE
----
Form prepare_bdc_tab *
----
Prepare BDC Table for updating Copack Purchase Prices *
----
FORM prepare_bdc_tab .
Local variable.
DATA: lv_date(10) TYPE c,
ls_stprs TYPE ty_s_cbht,
ls_plant TYPE ty_s_plant,
lv_fnmatnr TYPE bdcdata-fnam,
lv_fnbwkey TYPE bdcdata-fnam,
lv_fnnewvalpr TYPE bdcdata-fnam,
lv_counter(2) TYPE n,
lv_num TYPE i.
CONSTANTS: lc_8 VALUE '8'.
CLEAR: lv_date.
SORT gt_cbht BY matnr.
LOOP AT gt_marc INTO gs_marc.
ls_plant = gs_marc.
AT NEW matnr.
CLEAR lv_counter.
Capture the date as per the user setting
WRITE p_budat TO lv_date.
Initial Screen of MR21 transaction
PERFORM bdc_dynpro USING 'SAPRCKM_MR21' '0201'.
PERFORM bdc_field USING: 'BDC_OKCODE' '=ENTR',
'MR21HEAD-BUDAT' lv_date,
'MR21HEAD-BUKRS' p_bukrs,
'MR21HEAD-WERKS' space.
READ TABLE gt_cbht INTO ls_stprs
WITH KEY matnr = ls_plant-matnr BINARY SEARCH.
ENDAT.
CLEAR : lv_fnmatnr,
lv_fnbwkey,
lv_fnnewvalpr.
lv_counter = lv_counter + 1.
lv_num = lv_num + 1.
CONCATENATE:
'CKI_MR21_0250-MATNR(' lv_counter ')' INTO lv_fnmatnr,
'CKI_MR21_0250-BWKEY(' lv_counter ')' INTO lv_fnbwkey,
'CKI_MR21_0250-NEWVALPR(' lv_counter ')' INTO lv_fnnewvalpr.
Second screen of MR21 transaction
PERFORM bdc_dynpro USING 'SAPRCKM_MR21' '0201'.
PERFORM bdc_field USING: 'BDC_OKCODE' '=ENTR',
lv_fnmatnr ls_plant-matnr,
lv_fnbwkey ls_plant-werks,
lv_fnnewvalpr ls_stprs-stprs.
IF lv_num EQ lc_8.
PERFORM bdc_dynpro USING 'SAPRCKM_MR21' '0201'.
PERFORM bdc_field USING: 'BDC_OKCODE' '=DOWN'.
CLEAR lv_num.
CLEAR lv_counter.
ENDIF.
AT END OF matnr.
PERFORM bdc_field USING: 'BDC_OKCODE' '=SAVE'.
Run MR21 using CALL TRANSACTION, if errors found create a SESSION
PERFORM call_transaction_mr21 USING ls_plant.
CLEAR : ls_stprs.
REFRESH gt_bdc_tab.
ENDAT.
CLEAR : gs_marc,
ls_plant.
ENDLOOP.
ENDFORM. " prepare_bdc_tab
----
Form call_transaction_mr21 *
----
Call Transaction for updating CoPack Price entries *
----
FORM call_transaction_mr21 USING p_ls_plant TYPE ty_s_plant.
Local Data Declaration
CONSTANTS:lc_e TYPE c VALUE 'E',
lc_mr21(4) TYPE c VALUE 'MR21',
lc_mode(1) TYPE c VALUE 'N',
lc_update(1) TYPE c VALUE 'U'.
DATA: ls_msgs TYPE ty_s_msgs.
REFRESH: gt_bdc_msg.
Call MR21 Transaction
CALL TRANSACTION lc_mr21
USING gt_bdc_tab
MODE lc_mode
UPDATE lc_update
MESSAGES INTO gt_bdc_msg.
If the Call Transaction Fails
IF sy-subrc NE 0.
IF gv_bdc_open_flag IS INITIAL.
PERFORM bdc_open_group.
gv_bdc_open_flag = gc_x.
ENDIF.
PERFORM bdc_insert_group.
DELETE gt_bdc_msg WHERE msgtyp NE lc_e.
get the error message
PERFORM read_error_message USING gt_bdc_msg
CHANGING gt_msgs.
If the message table is having error mesasges
IF gt_bdc_msg IS NOT INITIAL.
LOOP AT gt_msgs INTO ls_msgs.
gs_error-matnr = p_ls_plant-matnr.
gs_error-msg = ls_msgs-msg.
APPEND gs_error TO gt_error.
CLEAR gs_error.
ENDLOOP.
ENDIF.
REFRESH:gt_bdc_msg,
gt_bdc_tab,
gt_msgs.
ELSE.
Update the status as 'Y' for ZKT_CBHT-TRCOM for success records
PERFORM update_transaction_complete USING p_ls_plant.
Record all materials that updated Successfully with Standard Price
gs_success-matnr = p_ls_plant-matnr.
APPEND gs_success TO gt_success.
CLEAR: gs_success.
ENDIF.
CLEAR p_ls_plant.
ENDFORM. " call_transaction_mr21
----
Form UPDATE_TRANSACTION_COMPLETE *
----
-->LS_CBHT text *
----
FORM update_transaction_complete USING p_ls_plant TYPE ty_s_plant.
DATA lv_varkey TYPE rstable-varkey.
generate the KEY for locking the record in ZKT_CBHT
CONCATENATE sy-mandt
p_gjahr
p_monat
p_fweek
p_fweek
p_ls_plant-matnr
INTO lv_varkey.
Lock the ZKT_CBHT table before update
PERFORM lock_cbht_table USING lv_varkey.
Update the Table ZKT_CBHT using the field TRCOM.
UPDATE zkt_cbht
SET trcom = gc_y
WHERE gjahr EQ p_gjahr AND
monat EQ p_monat AND
fweek EQ p_fweek AND
tvers EQ p_fweek AND
matnr EQ p_ls_plant-matnr .
Unlock the ZKT_CBHT table after update
PERFORM unlock_cbht_table USING lv_varkey.
ENDFORM. "UPDATE_TRANSACTION_COMPLETE
----
Form READ_ERROR_MESSAGE *
----
-->GT_BDC_MSG text *
-->LT_MSGS text *
----
FORM read_error_message USING lt_bdc_msg TYPE ty_t_bdcmsg
CHANGING lt_msgs TYPE ty_t_msgs.
DATA: lv_msg(500).
DATA: ls_bdcmsg TYPE ty_s_bdcmsg.
DATA: ls_errormsg TYPE ty_s_msgs.
LOOP AT lt_bdc_msg INTO ls_bdcmsg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = ls_bdcmsg-msgid
lang = 'E'
no = ls_bdcmsg-msgnr
v1 = ls_bdcmsg-msgv1
v2 = ls_bdcmsg-msgv2
v3 = ls_bdcmsg-msgv3
v4 = ls_bdcmsg-msgv4
IMPORTING
msg = lv_msg
EXCEPTIONS
not_found = 0
OTHERS = 0.
ls_errormsg-msg = lv_msg.
APPEND ls_errormsg TO lt_msgs.
CLEAR ls_errormsg-msg.
ENDLOOP.
ENDFORM. "READ_ERROR_MESSAGE
----
Form default_fiscal_data *
----
Fetch Fiscal Year, Fiscal Period, Fiscal Week. *
----
FORM default_fiscal_data .
CALL FUNCTION 'Z_GET_FISCAL_WEEK_FROM_DATE'
EXPORTING
i_datum = sy-datum
i_bukrs = p_bukrs
IMPORTING
e_fisc_period = p_monat
e_fisc_year = p_gjahr
e_week_num = p_fweek
EXCEPTIONS
error_period = 1
error_period_version = 2
error_special_period = 3
error_version = 4
error_fiscal_year = 5
error_posting_period = 6
error_posting_date = 7
invalid_company = 8
OTHERS = 9.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "Default_fiscal_data
----
Form send_log_mail *
----
Sending the Error log as mail *
----
FORM send_log_mail .
Local Constants
CONSTANTS: lc_raw(3) TYPE c VALUE 'RAW'. "Docuement Type
Creating the document to be sent with error message.
IF gt_error IS NOT INITIAL.
gs_doc_chng-obj_name = 'Error Price'(002).
gs_doc_chng-obj_descr =
'Material Standard Price Updation Errors'(003).
Mail Content
gs_objtxt = text-009.
APPEND gs_objtxt TO gt_objtxt.
gs_objtxt = text-020.
APPEND gs_objtxt TO gt_objtxt.
CLEAR gs_objtxt.
APPEND gs_objtxt TO gt_objtxt.
Error message Heading
CONCATENATE text-022 "Material
text-024 "Error Message
INTO gs_objtxt.
APPEND gs_objtxt TO gt_objtxt.
gs_objtxt = text-021. "under line in mail
APPEND gs_objtxt TO gt_objtxt.
LOOP AT gt_error INTO gs_error.
Remove leading zero's for Material
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = gs_error-matnr
IMPORTING
output = gs_error-matnr.
Genearte the error text
gs_objtxt = gs_error-matnr.
gs_objtxt+27 = gs_error-msg.
APPEND gs_objtxt TO gt_objtxt.
ENDLOOP.
ENDIF.
Add the Content to the E-mail
DESCRIBE TABLE gt_objtxt LINES gv_tab_lines.
READ TABLE gt_objtxt INTO gs_objtxt INDEX gv_tab_lines.
gs_doc_chng-doc_size =
( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objtxt ).
Check for Internet Address or Distribution List
IF p_dlist IS NOT INITIAL.
SEARCH p_dlist FOR gc_at.
IF sy-subrc EQ 0.
gs_reclist-rec_type = gc_u.
ELSE.
gs_reclist-rec_type = gc_c.
ENDIF.
gs_reclist-receiver = p_dlist.
APPEND gs_reclist TO gt_reclist.
ENDIF.
Call the function module to send the mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_type = lc_raw
document_data = gs_doc_chng
put_in_outbox = gc_x
commit_work = gc_x
TABLES
object_header = gt_objhead
object_content = gt_objtxt
receivers = gt_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
CASE sy-subrc.
WHEN 0.
SKIP.
FORMAT COLOR 3 ON.
WRITE:/ 'Mail has been sent successfully to below mentioned IDs:->'(005)
.
FORMAT COLOR 3 OFF.
WRITE:/ p_dlist.
WRITE:/ sy-uname.
WHEN 1.
WRITE: / 'Too many receivers specified !'(017).
WHEN 2.
WRITE: / 'No receiver got the document !'(018).
WHEN 4.
WRITE: / 'Missing send authority !'(016).
WHEN OTHERS.
WRITE: / 'Unexpected error occurred !'(019).
ENDCASE.
ENDFORM. " send_log_mail
----
Form display_materials *
----
Display all the Materials which failed to update the Standard Price *
----
FORM display_materials .
IF NOT gt_error IS INITIAL.
Update Failure message.
SKIP 2.
FORMAT COLOR 3 ON.
WRITE:/ text-009,
/ text-020. "Material Std.Price update failure message
FORMAT COLOR 3 OFF.
FORMAT COLOR COL_NEGATIVE ON.
Read all the materials that failed to update
LOOP AT gt_error INTO gs_error.
WRITE:/ gs_error-matnr,
28 gs_error-msg.
ENDLOOP.
FORMAT COLOR COL_NEGATIVE OFF.
SKIP 2.
ENDIF.
IF NOT gt_success IS INITIAL.
Mesage to define the updation is Successful.
FORMAT COLOR 3 ON.
WRITE:/ text-011, 97 p_bukrs."Material Std.Price update Success msg
FORMAT COLOR 3 OFF.
FORMAT COLOR COL_POSITIVE ON.
Read all the materials which updated Successfully
LOOP AT gt_success INTO gs_success.
WRITE:/ gs_success-matnr.
ENDLOOP.
FORMAT COLOR COL_POSITIVE OFF.
ENDIF.
ENDFORM. " display_materials
----
Form header_footer *
----
To write a header and a footer to the report layout *
----
-->P_GC_HF Header and Footer Indicator 'H' or 'F' *
----
FORM header_footer USING p_gc_hf TYPE sywtitl.
Custom Function module for the Header/Footer display for report
CALL FUNCTION 'Z_SL_HEADER_FOOTER'
EXPORTING
rpt_id = sy-cprog
rpt_txt_typ = p_gc_hf
rpt_width = sy-linsz
EXCEPTIONS
err_invalid_parameters = 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.
ENDFORM. " header_footer
----
FORM bdc_dynpro *
----
Generate BDCDATA *
----
FORM bdc_dynpro USING program TYPE bdcdata-program
dynpro TYPE bdcdata-dynpro .
CLEAR: gs_bdc_tab.
gs_bdc_tab-program = program.
gs_bdc_tab-dynpro = dynpro.
gs_bdc_tab-dynbegin = gc_x.
APPEND gs_bdc_tab TO gt_bdc_tab.
ENDFORM. "bdc_dynpro
----
FORM bdc_field *
----
Populate data to the Screen fields *
----
FORM bdc_field USING fnam TYPE bdcdata-fnam
fval TYPE any.
Clear the local structure.
CLEAR: gs_bdc_tab.
WRITE fval TO gs_bdc_tab-fval LEFT-JUSTIFIED.
gs_bdc_tab-fnam = fnam.
APPEND gs_bdc_tab TO gt_bdc_tab.
ENDFORM. "bdc_field
----
Form bdc_open_group *
----
Subroutine for Open BDC Group *
----
FORM bdc_open_group .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = gc_grpid
user = sy-uname
EXCEPTIONS
client_invalid = 1
destination_invalid = 2
group_invalid = 3
group_is_locked = 4
holddate_invalid = 5
internal_error = 6
queue_error = 7
running = 8
system_lock_error = 9
user_invalid = 10
OTHERS = 11.
IF sy-subrc <> 0.
WRITE 😕 text-013. "Error in BDC_OPEN_GROUP
EXIT.
ENDIF.
ENDFORM. " bdc_open_group
----
Form BDC_INSERT_GROUP *
----
Subroutine for calling BDC_INSERT for inserting BDC Table *
----
FORM bdc_insert_group .
DATA lc_mr21 TYPE tstc-tcode VALUE 'MR21'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = lc_mr21
TABLES
dynprotab = gt_bdc_tab
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
OTHERS = 7.
IF sy-subrc <> 0.
WRITE 😕 text-014. "Error in BDC_INSERT
EXIT.
ENDIF.
ENDFORM. " BDC_INSERT_GROUP
----
Form BDC_CLOSE_GROUP *
----
Subroutine for Closeing of BDC group *
----
FORM bdc_close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE 😕 text-015. "Error in BDC_CLOSE_GROUP.
EXIT.
ENDIF.
ENDFORM. " BDC_CLOSE_GROUP
----
Form validate_bukrs *
----
Validation for Company code *
----
FORM validate_bukrs .
Local declarations
DATA: lv_bukrs TYPE bukrs.
CLEAR lv_bukrs.
Check if the specified Company code exists or not
IF p_bukrs IS NOT INITIAL.
SELECT SINGLE bukrs "Comapny code
FROM t001
INTO lv_bukrs
WHERE bukrs EQ p_bukrs.
IF lv_bukrs IS INITIAL.
Enter a valid Company code
MESSAGE e117(zmm). "Invalid Company code
ENDIF.
ENDIF.
ENDFORM. " validate_bukrs
----
Form lock_cbht_table *
----
Lock the table 'ZKT_CBHT' while updating *
----
FORM lock_cbht_table USING p_varkey TYPE rstable-varkey.
CALL FUNCTION 'ENQUEUE_E_TABLES'
EXPORTING
mode_rstable = gc_s
tabname = gc_cbht
varkey = p_varkey
scope = gc2.
ENDFORM. "lock_cbht_table
----
Form unlock_cbht_table *
----
Unlock the table 'ZKT_CBHT' after updating *
----
FORM unlock_cbht_table USING p_varkey TYPE rstable-varkey.
CALL FUNCTION 'DEQUEUE_E_TABLES'
EXPORTING
mode_rstable = gc_s
tabname = gc_cbht
varkey = p_varkey
scope = gc3.
ENDFORM. "unlock_history_table
2007 Feb 27 1:23 PM
Hi,
Go through the following Example Code
Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of it_lfa1 occurs 0,
KTOKK like lfa1-ktokk,
NAME1 like lfa1-name1,
SORTL like lfa1-sortl,
LAND1 like lfa1-land1,
end of it_lfa1.
End generated data section ***
data : it_bdc like bdcdata occurs 0 with header line.
*DATA: IT_MESSAGES TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE.
*DATA: LV_MESSAGE(255).
data : it_messages like bdcmsgcoll occurs 0 with header line.
data : V_message(255).
data : V_flag.
data : V_datum1 type sy-datum.
data : begin of it_mesg occurs 0,
message(100),
end of it_mesg.
*V_datum1 = sy-datum-1.
parameters : P_Sess like APQI-GROUPID.
start-of-selection.
perform Get_data.
*perform open_group.
loop at it_lfa1.
perform bdc_dynpro using 'SAPMF02K' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-KTOKK'
it_lfa1-KTOKK.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'LFA1-NAME1'
it_lfa1-name1.
perform bdc_field using 'LFA1-SORTL'
it_lfa1-sortl.
perform bdc_field using 'LFA1-LAND1'
it_lfa1-land1.
call transaction 'XK01' using it_bdc
mode 'N'
update 'S'
messages into it_messages.
if sy-subrc <> 0.
if V_flag <> 'X'.
perform open_group.
V_flag = 'X'.
endif.
perform bdc_transaction. "using 'XK01'.
endif.
perform format_messages.
refresh : it_bdc,it_messages.
.
endloop.
if V_flag = 'X'.
perform close_group.
endif.
&----
*& Form Get_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM Get_data .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\srinu_vendor.txt'
FILETYPE = 'DAT'
TABLES
DATA_TAB = it_lfa1
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " Get_data
&----
*& Form bdc_dynpro
&----
text
----
-->P_0061 text
-->P_0062 text
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR it_BDC.
it_BDC-PROGRAM = PROGRAM.
it_BDC-DYNPRO = DYNPRO.
it_BDC-DYNBEGIN = 'X'.
APPEND it_BDC.
ENDFORM.
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
CLEAR it_BDC.
it_BDC-FNAM = FNAM.
it_BDC-FVAL = FVAL.
APPEND it_BDC.
ENDFORM.
&----
*& Form format_messages
&----
text
----
--> p1 text
<-- p2 text
----
FORM format_messages .
loop at it_messages.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = it_messages-MSGID
LANG = 'EN'
NO = it_messages-MSGNR
V1 = it_messages-MSGV1
V2 = it_messages-MSGV2
V3 = it_messages-MSGV3
V4 = it_messages-MSGV4
IMPORTING
MSG = V_message
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.
write : / V_message.
clear : V_message.
endloop.
ENDFORM. " format_messages
&----
*& Form open_group
&----
text
----
--> p1 text
<-- p2 text
----
FORM open_group .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = P_Sess
HOLDDATE = V_datum1
KEEP = 'X'
USER = SY-UNAME
.
IF SY-SUBRC = 0.
write : / 'Session Creating wit Name : ',P_Sess.
ENDIF.
ENDFORM. " open_group
&----
*& Form close_group
&----
text
----
--> p1 text
<-- p2 text
----
FORM close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'.
ENDFORM. " close_group
&----
*& Form bdc_transaction
&----
text
----
-->P_0132 text
----
FORM bdc_transaction. "USING VALUE(P_0132).
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'XK01'
POST_LOCAL = NOVBLOCAL
PRINTING = NOPRINT
SIMUBATCH = ' '
CTUPARAMS = ' '
TABLES
DYNPROTAB = it_bdc
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " bdc_transaction
Regards
Sreeni
2007 Feb 27 1:30 PM
YOu have to check the sy-subrc after the call transaction statement.
But it only tells you if the record is succesfully uploaded or not. It will not tell you why was it failed.
call transaction <Tcode> using bdcdata ......
if sy-subrc = 0.
write:/ itab-field1, 'is succesfully uploaded'.
else.
write:/ itab-field1, 'upload failed'.
endif.
2007 Feb 28 4:46 AM
hi,
if u don't want to use BDCMSGCOLL ,u can catch errors using session method.
if sy-subrc <> 0.
write the session logic.
u can check it in sm35.
see the below coding.In this pg i cought errors using session method.i opened session and we can check errors in sm35.
report zsr_bdc .
*report zsk_bdc
no standard page heading line-size 255.
data:begin of w_input1,
g_data(200) type c,
end of w_input1,
t_input1 like standard table of w_input1 initial size 0,
begin of w_input,
ekorg(4) type c,
ktokk(4) type c,
anred(15) type c,
name1(30) type c,
sortl(10) type c,
land1(3) type c,
spras(2) type c,
waers(5) type c,
end of w_input,
t_input like standard table of w_input initial size 0,
g_string type string,
g_flag,
t_bdcdata type standard table of bdcdata initial size 0,
t_bdcmsgcoll type standard table of bdcmsgcoll,
w_bdcdata type bdcdata,
w_bdcmsgcoll type bdcmsgcoll.
parameters: p_file type ibipparms-path.
at selection-screen on value-request for p_file.
call function 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
importing
file_name = p_file
.
g_string = p_file.
*include bdcrecx1.
start-of-selection.
call function 'GUI_UPLOAD'
exporting
filename = g_string
filetype = 'ASC'
tables
data_tab = t_input1
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
loop at t_input1 into w_input1.
split w_input1-g_data at ',' into w_input-ekorg
w_input-ktokk
w_input-anred
w_input-name1
w_input-sortl
w_input-land1
w_input-spras
w_input-waers.
append w_input to t_input.
endloop.
*perform open_group.
loop at t_input into w_input.
refresh t_bdcdata.
perform bdc_dynpro using 'SAPMF02K' '0107'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-EKORG'
w_input-ekorg.
perform bdc_field using 'RF02K-KTOKK'
w_input-ktokk.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-ANRED'
w_input-anred.
perform bdc_field using 'LFA1-NAME1'
w_input-name1.
perform bdc_field using 'LFA1-SORTL'
w_input-sortl.
perform bdc_field using 'LFA1-LAND1'
w_input-land1.
perform bdc_field using 'LFA1-SPRAS'
w_input-spras.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPMF02K' '0310'.
perform bdc_field using 'BDC_CURSOR'
'LFM1-WAERS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFM1-WAERS'
w_input-waers.
perform bdc_dynpro using 'SAPMF02K' '0320'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
call transaction 'MK01' using t_bdcdata
mode 'N'
update 'S'.
messages into t_bdcmsgcoll.
if sy-subrc <> 0.
if g_flag is initial.
call function 'BDC_OPEN_GROUP'
exporting
client = sy-mandt
DEST = FILLER8
group = 'ZSKCL'
HOLDDATE = FILLER8
keep = 'X'
user = sy-uname
RECORD = FILLER1
PROG = SY-CPROG
IMPORTING
QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
g_flag = 'X'.
endif.
call function 'BDC_INSERT'
exporting
tcode = 'XK01'
POST_LOCAL = NOVBLOCAL
PRINTING = NOPRINT
SIMUBATCH = ' '
CTUPARAMS = ' '
tables
dynprotab = t_bdcdata
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endif.
endloop.
if g_flag = 'X'.
call function 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 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.
endif.
*perform close_group.
&----
*& Form bdc_dynpro
&----
text
----
-->P_0156 text
-->P_0157 text
----
form bdc_dynpro using value(p_0156)
value(p_0157).
clear w_bdcdata.
w_bdcdata-program = p_0156.
w_bdcdata-dynpro = p_0157.
w_bdcdata-dynbegin = 'X'.
append w_bdcdata to t_bdcdata.
endform. " bdc_dynpro
&----
*& Form bdc_field
&----
text
----
-->P_0175 text
-->P_0176 text
----
form bdc_field using value(p_0175)
value(p_0176).
clear w_bdcdata.
w_bdcdata-fnam = p_0175.
w_bdcdata-fval = p_0176.
append w_bdcdata to t_bdcdata.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |