‎2007 Oct 30 11:31 AM
hi frnds
we can handle error in call transaction method by using bdcmsgcoll,
error is handled by system using session method and these errors can be analysed by going to tr sm35 . <b>is there is any way by which i will use session method in my program and all the errors will be written in the o/p of the list.
is this is possible , if so pls give me some sample code</b>
thanks
pankaj
‎2007 Oct 30 11:33 AM
Hey i have never worked on that. so no sample code..
But you can read the session method log into your internal table using some Function modules as well as by hitting Log tables.
The details you have to provide are session name, username, date, time..etc
‎2007 Oct 30 11:37 AM
Hi,
check the belwo sample code.
Declaration of local constants
CONSTANTS : lc_tcode TYPE tstc-tcode VALUE 'ME31K',
lc_n TYPE ctu_mode VALUE 'N'.
Declaration of local variables
DATA: lv_msg TYPE string,
lv_subrc LIKE sy-subrc,
lv_opt TYPE ctu_params.
lv_opt-defsize = c_x.
lv_opt-dismode = lc_n.
lv_opt-updmode = c_l.
REFRESH i_messtab.
Call the transaction to create the Purchasing Contracts
CALL TRANSACTION lc_tcode USING i_bdcdata
OPTIONS FROM lv_opt
MESSAGES INTO i_messtab.
MOVE sy-subrc TO lv_subrc.
IF lv_subrc NE 0.
v_err_cnt = v_err_cnt + 1.
IF NOT i_messtab[] IS INITIAL.
READ TABLE i_messtab WITH KEY msgtyp = 'E'.
IF sy-subrc EQ 0.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = i_messtab-msgid
lang = sy-langu
no = i_messtab-msgnr
v1 = i_messtab-msgv1
v2 = i_messtab-msgv2
v3 = i_messtab-msgv3
v4 = i_messtab-msgv4
IMPORTING
msg = lv_msg.
MOVE: p_wa_header-lifnr TO wa_error-lifnr,
p_wa_header-evart TO wa_error-evart,
p_wa_header-vedat TO wa_error-vedat,
p_wa_header-ekorg TO wa_error-ekorg,
p_wa_header-ekgrp TO wa_error-ekgrp,
p_wa_header-epstp TO wa_error-epstp,
p_wa_header-knttp TO wa_error-knttp,
p_wa_header-bukrs TO wa_error-bukrs,
p_wa_header-kdatb TO wa_error-kdatb,
p_wa_header-kdate TO wa_error-kdate,
p_wa_header-ktwrt TO wa_error-ktwrt,
p_wa_header-waers TO wa_error-waers,
p_wa_header-wkurs TO wa_error-wkurs,
p_wa_header-inco1 TO wa_error-inco1,
p_wa_header-inco2 TO wa_error-inco2,
p_wa_header-ihran TO wa_error-ihran,
p_wa_header-angnr TO wa_error-angnr,
lv_msg TO wa_error-msg.
APPEND wa_error TO i_error.
CLEAR wa_error.
ELSE.
READ TABLE i_messtab WITH KEY msgtyp = 'S'.
IF sy-subrc EQ 0.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = i_messtab-msgid
lang = sy-langu
no = i_messtab-msgnr
v1 = i_messtab-msgv1
v2 = i_messtab-msgv2
v3 = i_messtab-msgv3
v4 = i_messtab-msgv4
IMPORTING
msg = lv_msg.
ENDIF.
ENDIF.
ENDIF.
ELSE.
v_cnt = v_cnt + 1.
ENDIF.
REFRESH i_bdcdata.
&----
*& Form prepare_field_catalog
&----
Prepare Field catalog
----
<--P_I_FIELDCAT[] Internal table for Field Catalog
----
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE t_fieldcat.
Declaration of local workarea
DATA: lwa_fieldcat TYPE slis_fieldcat_alv.
Declaration of local constants
CONSTANTS : lc_long_text(1) TYPE c VALUE 'L'.
*--Call the functino module to get the field catalog.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'I_SUCCESS'
i_inclname = sy-repid
CHANGING
ct_fieldcat = pt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_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.
ELSE.
LOOP AT pt_fieldcat INTO lwa_fieldcat.
CASE lwa_fieldcat-fieldname.
WHEN 'VEDAT'.
lwa_fieldcat-ddictxt = lc_long_text.
lwa_fieldcat-seltext_l = text-004.
MODIFY i_fieldcat FROM lwa_fieldcat
INDEX sy-tabix TRANSPORTING ddictxt seltext_l .
CLEAR lwa_fieldcat.
WHEN 'KDATB'.
lwa_fieldcat-ddictxt = lc_long_text.
lwa_fieldcat-seltext_l = text-005.
MODIFY i_fieldcat FROM lwa_fieldcat
INDEX sy-tabix TRANSPORTING ddictxt seltext_l .
CLEAR lwa_fieldcat.
WHEN 'KDATE'.
lwa_fieldcat-ddictxt = lc_long_text.
lwa_fieldcat-seltext_l = text-006.
MODIFY i_fieldcat FROM lwa_fieldcat
INDEX sy-tabix TRANSPORTING ddictxt seltext_l .
CLEAR lwa_fieldcat.
WHEN 'IHRAN'.
lwa_fieldcat-ddictxt = lc_long_text.
lwa_fieldcat-seltext_l = text-007.
MODIFY i_fieldcat FROM lwa_fieldcat
INDEX sy-tabix TRANSPORTING ddictxt seltext_l .
CLEAR lwa_fieldcat.
ENDCASE.
ENDLOOP. "LOOP AT pt_fieldcat INTO lwa_fieldcat.
ENDIF. "IF sy-subrc <> 0
ENDFORM. " prepare_field_catalog
&----
*& Form display_output
&----
To display the success contracts output in ALV
----
FORM display_output .
Declaration of local workarea
DATA : lwa_layout TYPE slis_layout_alv.
Declaration of local constants
CONSTANTS : lc_chk(1) TYPE c VALUE 'X',
lc_page TYPE slis_formname VALUE 'SUB_TOP_OF_PAGE'.
Subroutine to prepare the Field Catalog
PERFORM prepare_field_catalog CHANGING i_fieldcat[].
Subroutine to build layout
lwa_layout-box_tabname = 'I_SUCCESS'.
lwa_layout-no_input = lc_chk.
lwa_layout-colwidth_optimize = lc_chk.
lwa_layout-zebra = lc_chk.
lwa_layout-cell_merge = lc_chk.
FM to call the ALV Grid
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_bypassing_buffer = c_x
i_callback_top_of_page = lc_page
is_layout = lwa_layout
it_fieldcat = i_fieldcat[]
TABLES
t_outtab = i_success
EXCEPTIONS
program_error = 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. " display_output
Rewrad if helpful.
Regards,
Nagaraj
‎2007 Oct 30 11:42 AM
hi nagaraj sir,
the process u defined is for call tr method i want session method to be used in which all the errors are written by system
thanks
pankaj
‎2007 Oct 30 11:57 AM
Hi,
try like this
define a parameter in selection screen for session
SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_sesn RADIOBUTTON GROUP ctu, "Create session
p_group(12) TYPE c, "Session Name.
' ' = delete session if finished
'X' = keep session if finished
p_keep AS CHECKBOX.
PARAMETERS: p_trans RADIOBUTTON GROUP ctu, "Call Transaction
p_mode LIKE ctu_params-dismode DEFAULT 'N',
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
p_egroup(12) TYPE c, "Session Name for Error.
' ' = delete session if finished
'X' = keep session if finished
p_ekeep AS CHECKBOX.
SELECTION-SCREEN : END OF BLOCK b2.
Declaration of local constants
CONSTANTS : lc_tcode TYPE tstc-tcode VALUE 'ME31K'.
Declaration of local variables
DATA: lv_msg TYPE string,
lv_subrc LIKE sy-subrc,
lv_opt TYPE ctu_params.
DATA:lv_ebeln TYPE ebeln.
IF p_sesn EQ c_x.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = lc_tcode
TABLES
dynprotab = i_bdcdata.
ELSE.
lv_opt-defsize = c_x.
lv_opt-dismode = p_mode.
lv_opt-updmode = c_l.
REFRESH i_messtab.
CALL TRANSACTION lc_tcode USING i_bdcdata
OPTIONS FROM lv_opt
MESSAGES INTO i_messtab.
MOVE sy-subrc TO lv_subrc.
IF lv_subrc NE 0.
v_err_cnt = v_err_cnt + 1.
IF NOT i_messtab[] IS INITIAL.
READ TABLE i_messtab WITH KEY msgtyp = 'E'.
IF sy-subrc EQ 0.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = i_messtab-msgid
lang = sy-langu
no = i_messtab-msgnr
v1 = i_messtab-msgv1
v2 = i_messtab-msgv2
v3 = i_messtab-msgv3
v4 = i_messtab-msgv4
IMPORTING
msg = lv_msg.
MOVE: p_wa_header-lifnr TO wa_error-lifnr,
p_wa_header-evart TO wa_error-evart,
p_wa_header-vedat TO wa_error-vedat,
p_wa_header-ekorg TO wa_error-ekorg,
p_wa_header-ekgrp TO wa_error-ekgrp,
p_wa_header-epstp TO wa_error-epstp,
p_wa_header-knttp TO wa_error-knttp,
p_wa_header-bukrs TO wa_error-bukrs,
p_wa_header-kdatb TO wa_error-kdatb,
p_wa_header-kdate TO wa_error-kdate,
p_wa_header-ktwrt TO wa_error-ktwrt,
p_wa_header-waers TO wa_error-waers,
p_wa_header-wkurs TO wa_error-wkurs,
p_wa_header-inco1 TO wa_error-inco1,
p_wa_header-inco2 TO wa_error-inco2,
p_wa_header-ihran TO wa_error-ihran,
p_wa_header-angnr TO wa_error-angnr,
lv_msg TO wa_error-msg.
APPEND wa_error TO i_error.
CLEAR wa_error.
IF lv_subrc NE 0.
IF v_e_group_opened IS INITIAL.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = p_egroup
user = sy-uname
keep = p_ekeep.
v_e_group_opened = c_x.
ENDIF.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = lc_tcode
TABLES
dynprotab = i_bdcdata.
ENDIF.
ENDIF.
ENDIF.
ELSE.
v_cnt = v_cnt + 1.
ENDIF.
ENDIF.
REFRESH i_bdcdata.
Now u will get the error session.
regards,
Nagaraj
‎2007 Oct 30 11:41 AM
CALL TRANSACTION 'PA30' USING it_bdcdata
MODE 'N'
UPDATE 'S'
MESSAGES INTO it_bdcmsgcoll.
IF sy-subrc = 0.
*--- Successful records
ELSE.
**--- Rejected records
IF gv_open IS INITIAL.
**--- Open the session to process error records
PERFORM bdc_open_group.
gv_open = 'X'.
ENDIF.
**--- Insert the records
PERFORM bdc_insert.
**--- Collect Error records
PERFORM error_records.
ENDIF.
ENDLOOP.
IF gv_open = 'X'.
**--- Close the session
PERFORM bdc_close_group.
ENDIF.
&----
*& Form bdc_open_group
&----
text
----
--> p1 text
<-- p2 text
----
*FORM bdc_open_group.
**--- Open the session
*CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
GROUP =
HOLDDATE = sy-datum
keep = 'X'
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.
IF sy-batch <> 'X'.
MESSAGE i000(zz) WITH 'Unable to open the Session'(005).
ELSE.
WRITE:/ 'Unable to open the Session'(005).
ENDIF.
ENDIF.
*ENDFORM. " bdc_open_group
&----
*& Form bdc_close_group
&----
text
----
--> p1 text
<-- p2 text
----
*FORM bdc_close_group.
**-- To close the session
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
IF sy-batch <> 'X'.
MESSAGE i000(zz) WITH 'Unable to close the session'(012).
ELSE.
WRITE:/ 'Unable to close the session'(012).
ENDIF.
ENDIF.
*ENDFORM. " bdc_close_group
&----
*& Form error_records
&----
text
----
--> p1 text
<-- p2 text
----
FORM error_records.
CLEAR gv_message.
CLEAR sy-tfill.
DESCRIBE TABLE it_bdcmsgcoll LINES sy-tfill.
READ TABLE it_bdcmsgcoll INDEX sy-tfill.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = it_bdcmsgcoll-msgid
lang = sy-langu
no = it_bdcmsgcoll-msgnr
v1 = it_bdcmsgcoll-msgv1
v2 = it_bdcmsgcoll-msgv2
v3 = it_bdcmsgcoll-msgv3
v4 = it_bdcmsgcoll-msgv4
IMPORTING
msg = gv_message
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
write 😕 gv_message.
CLEAR gv_message.
ENDIF.
ENDFORM. " error_records
&----
*& Form bdc_insert
&----
text
----
--> p1 text
<-- p2 text
----
*FORM bdc_insert.
**--- Insert the records into session
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'PA30'
TABLES
dynprotab = it_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.
IF sy-batch <> 'X'.
MESSAGE i000(zz) WITH 'Unable to insert data into BDC session'(019)
*.
ELSE.
WRITE:/ 'Unable to insert data into BDC session'(019).
ENDIF.
ENDIF.
*ENDFORM. " bdc_insert
Regards
vasu
‎2007 Oct 30 11:57 AM
hi sir,
i dont want to use call tr method i want to use session method.
thanks
pankaj