Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

call transaction

Former Member
0 Likes
1,019

how we can handle errors in call transaction? could u plzz tell me?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
981

Hi Sumit,

Check this info.

When Session Method updates the records in database table, error records are stored in the log file. In Call transaction there is no such log file available and error record is lost unless handled. Usually you need to give report of all the error records i.e., records which are not inserted or updated in the database table. This can be done by the following method:

Steps for the error handling in CALL TRANSACTION

1. Internal table for the data (structure similar to your local file)

2. BDCTAB like BDCDATA

3. Internal table BDCMSG like BDCMSGCOLL

4. Internal table similar to Ist internal table

(Third and fourth steps are for error handling)

5. UPLOAD or WS_UPLOAD function to upload the data from the local file to itab. (Considering file is local file)

6. Loop at itab.

Populate BDCTAB table.

Call transaction <tr.code> using <Bdctab>

Mode <A/N/E>

Update <S/A>

Messages <BDCMSG>.

Perform check.

Refresh BDCTAB.

Endloop.

7 Form check.

IF sy-subrc <> 0. (Call transaction returns the sy-subrc if updating is not successful).

Call function Format_message.

(This function is called to store the message given by system and to display it along with record)

Append itab2.

Display the record and message.

Hope this resolves your query.

Reward all the helpful answers.

Regards

7 REPLIES 7
Read only

Former Member
0 Likes
981

Hi

Use structure BDCMSGCOLL

DATA: BEGIN OF messtab OCCURS 0.

INCLUDE STRUCTURE bdcmsgcoll.

DATA: END OF messtab.

CALL TRANSACTION 'ME22' USING bdc_tab MODE 'N' UPDATE 'S'

MESSAGES INTO messtab.

IF sy-subrc EQ 0.

Some code.

ELSE.

LOOP AT messtab WHERE msgtyp = 'E'.

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING

msgid = messtab-msgid

msgnr = messtab-msgnr

msgv1 = messtab-msgv1

msgv2 = messtab-msgv2

msgv3 = messtab-msgv3

msgv4 = messtab-msgv4

IMPORTING

message_text_output = w_textout.

ENDLOOP.

Hope this helps

Regds

Seema

Read only

Former Member
0 Likes
981

Hi,

THe CALL transaction has an addition MESSAGE INTO itab..

In the internal table itab you will get the messages along with the type..

If the type is 'E' or 'A' then the call transaction is not successful.

ALso if the SY-SUBRC is not equal to zero..after the call transaction..Then the transaction is not successful.

Thanks,

Naren

Read only

Former Member
0 Likes
981

Hi Sumit,

Check the following Code. Hope it will help u.

Regards,

Shafi

INCLUDE <icon>.

DATA: it_bdc LIKE bdcdata

OCCURS 0 WITH HEADER LINE.

DATA: w_flname LIKE ibipparms-path.

DATA: t_excel LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE .

data : begin of it_upload occurs 0,

condtyp(4),

salg(4),

prtyp(2),

matnr(18),

rate(11),

date(10),

end of it_upload.

DATA date2(10).

DATA v_count TYPE i.

DATA v_count1 TYPE i.

data matnr type matnr.

DATA: t_msgtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.

DATA: BEGIN OF t_messages OCCURS 0,

index TYPE i,

matnr(18),

  • account(18),

msgtyp(1),

message(120),

END OF t_messages.

DATA: w_index TYPE i VALUE 1.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME title text-a01 .

PARAMETERS : p_flname LIKE rlgrap-filename OBLIGATORY .

SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_flname.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

  • FIELD_NAME = ' '

IMPORTING

file_name = w_flname.

p_flname = w_flname.

START-OF-SELECTION.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_flname

i_begin_col = '1'

i_begin_row = '2'

i_end_col = '7'

i_end_row = '9999'

TABLES

intern = t_excel

  • EXCEPTIONS

  • INCONSISTENT_PARAMETERS = 1

  • UPLOAD_OLE = 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.

CLEAR it_upload.

LOOP AT t_excel.

IF t_excel-col = 2 .

it_upload-salg = t_excel-value.

ELSEIF t_excel-col = 3 .

it_upload-prtyp = t_excel-value.

ELSEIF t_excel-col = 5 .

it_upload-matnr = t_excel-value.

ELSEIF t_excel-col = 6 .

it_upload-rate = t_excel-value.

ELSEIF t_excel-col = 7 .

it_upload-date = t_excel-value.

ENDIF .

AT END OF row.

CONDENSE: it_upload-salg , it_upload-prtyp,

it_upload-matnr , it_upload-rate,

it_upload-date .

APPEND it_upload.

CLEAR it_upload.

endat.

ENDLOOP.

LOOP AT it_upload.

CLEAR : v_count,v_count1.

  • matnr = it_upload-matnr.

  • v_count = strlen( it_upload-matnr ).

  • v_count1 = 10 - v_count.

*

  • DO v_count1 TIMES.

  • CONCATENATE '0' matnr INTO matnr.

  • ENDDO.

CONCATENATE it_upload-date0(2) '.' it_upload-date3(2) '.'

it_upload-date+6(4)

INTO date2.

REFRESH it_bdc.

PERFORM fill_bdcdata USING :

'SAPMV13A' '0100' 'X',

'BDC_OKCODE' '/00' ' ',

'RV13A-KSCHL' 'ZHST' ' ',

'SAPLV14A' '0100' 'X',

'BDC_OKCODE' '=WEIT' ' ',

'VIQMUR-URCOD' 'Z' ' ',

'RV130-SELKZ(02)' 'X' ' ',

'SAPMV13A' '1986' 'X',

'BDC_OKCODE' '=SICH' ' ',

'KOMG-VKORG' it_upload-salg ' ',

'KOMG-PLTYP' it_upload-prtyp ' ',

'KOMG-WAERK' 'INR' ' ',

'KOMG-MATNR(01)' it_upload-matnr ' ',

'KONP-KBETR(01)' it_upload-rate ' ',

'RV13A-DATAB(01)' date2 ' '.

CALL TRANSACTION 'VK11' USING it_bdc MODE 'A' UPDATE 'S'

MESSAGES INTO t_msgtab.

PERFORM collect_messages.

clear it_upload.

endloop.

PERFORM write_messages.

&----


*& Form fill_bdcdata

&----


  • text

----


  • -->P_0222 text

  • -->P_0223 text

  • -->P_0224 text

----


FORM fill_bdcdata USING val1

val2

val3.

CLEAR it_bdc.

IF val3 = 'X'.

MOVE val1 TO it_bdc-program.

MOVE val2 TO it_bdc-dynpro.

MOVE val3 TO it_bdc-dynbegin.

ELSE.

MOVE val1 TO it_bdc-fnam.

MOVE val2 TO it_bdc-fval.

ENDIF.

APPEND it_bdc.

ENDFORM. " fill_bdcdata

&----


*& Form collect_messages

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form collect_messages.

DATA: w_msg(100).

  • IF w_tabix <> 0 AND p_val = '2'.

LOOP AT t_msgtab.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = t_msgtab-msgid

lang = t_msgtab-msgspra

no = t_msgtab-msgnr

v1 = t_msgtab-msgv1

v2 = t_msgtab-msgv2

IMPORTING

msg = w_msg

EXCEPTIONS

OTHERS = 0.

CONDENSE w_msg.

CLEAR t_messages.

t_messages-matnr = it_upload-matnr.

  • t_messages-account = t_itab-newko2.

t_messages-index = w_index.

t_messages-msgtyp = t_msgtab-msgtyp.

t_messages-message = w_msg.

APPEND t_messages.

ENDLOOP.

w_index = w_index + 1.

REFRESH t_msgtab.

endform. " collect_messages

&----


*& Form write_messages

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form write_messages.

DATA: wa_msg LIKE t_messages.

LOOP AT t_messages.

wa_msg = t_messages.

WRITE:/1 sy-vline.

AT NEW matnr.

CONDENSE: wa_msg-matnr.

WRITE: 2 wa_msg-matnr .

ENDAT.

WRITE : 29 sy-vline.

IF wa_msg-msgtyp = 'S'.

WRITE: 30 icon_green_light.

ELSEIF wa_msg-msgtyp = 'E'.

WRITE: 30 icon_red_light.

ELSEIF wa_msg-msgtyp = 'W'.

WRITE: 30 icon_yellow_light.

ENDIF.

WRITE: 39 sy-vline,

40 wa_msg-message , 240 sy-vline.

AT END OF matnr.

WRITE:/1 sy-vline.

ULINE 1(240).

ENDAT.

ENDLOOP.

endform. " write_messages

Read only

Former Member
0 Likes
981

Yes. You can handle errors in call transaction as below.

itab_error like standard table of message.
CALL TRANSACTION PA30 USING BDCDATA.
If sy-subrc <> 0.
*append the error message to an internal table
itab_error-msg1 = sy-msgv1.
itab_error-msg2 = sy-msgv2.
itab_error-msg3 = sy-msgv3.
*call function WRITE_MESSAGE to get the error description and store it in the itab_error itself
append itab_error.
endif.

Reward points if useful...

Cheers,

Sam

Read only

Former Member
0 Likes
982

Hi Sumit,

Check this info.

When Session Method updates the records in database table, error records are stored in the log file. In Call transaction there is no such log file available and error record is lost unless handled. Usually you need to give report of all the error records i.e., records which are not inserted or updated in the database table. This can be done by the following method:

Steps for the error handling in CALL TRANSACTION

1. Internal table for the data (structure similar to your local file)

2. BDCTAB like BDCDATA

3. Internal table BDCMSG like BDCMSGCOLL

4. Internal table similar to Ist internal table

(Third and fourth steps are for error handling)

5. UPLOAD or WS_UPLOAD function to upload the data from the local file to itab. (Considering file is local file)

6. Loop at itab.

Populate BDCTAB table.

Call transaction <tr.code> using <Bdctab>

Mode <A/N/E>

Update <S/A>

Messages <BDCMSG>.

Perform check.

Refresh BDCTAB.

Endloop.

7 Form check.

IF sy-subrc <> 0. (Call transaction returns the sy-subrc if updating is not successful).

Call function Format_message.

(This function is called to store the message given by system and to display it along with record)

Append itab2.

Display the record and message.

Hope this resolves your query.

Reward all the helpful answers.

Regards

Read only

Former Member
0 Likes
981
CALL TRANSACTION pv_tcode USING it_bdcdata

MODE ctumode "c_n
UPDATE ctupdate "c_s
MESSAGES INTO it_msgtab.

IF sy-subrc NE 0.
* Format the error message and update the Error log table.
perform z_error_format.
endif.
*&---------------------------------------------------------------------*
*& Form z_error_format
*&---------------------------------------------------------------------*
* Format the error message and update the error-log table
*----------------------------------------------------------------------*
Form z_error_format.

READ TABLE it_msgtab INTO st_msgtab WITH KEY msgtyp = c_e.
IF sy-subrc <> 0.
READ TABLE it_msgtab INTO st_msgtab WITH KEY msgtyp = c_a.
ENDIF.

CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = st_msgtab-msgid
lang = SY-LANGU
no = st_msgtab-msgnr
v1 = st_msgtab-msgv1
v2 = st_msgtab-msgv2
v3 = st_msgtab-msgv3
v4 = st_msgtab-msgv4
IMPORTING
msg = w_errmsg
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
CLEAR w_errmsg.
ENDIF.


st_err_log-message = w_errmsg.
st_err_log-matnr = st_eord-matnr.
st_err_log-werks = st_eord-werks.
st_err_log-zeord = st_eord-zeord.
st_err_log-lifnr = st_eord-lifnr.
APPEND st_err_log TO it_err_log.
clear st_err_log.

endform. " z_error_format
Read only

Former Member
0 Likes
981

hi,

we can handle errors using BDCMSGCOll OR FORMAT_MESSAGES.and even we can open session for error records we just we have to provide Session logic if sy-subrc <> 0 after call transaction syntax.

check the below coding

REPORT ZSR_CALL_SESSION .

TABLES : LFA1, RF02K.

DATA : BEGIN OF ITAB OCCURS 0 ,

LIFNR LIKE RF02K-LIFNR,

KTOKK LIKE RF02K-KTOKK,

NAME1 LIKE LFA1-NAME1,

SORTL LIKE LFA1-SORTL,

LAND1 LIKE LFA1-LAND1,

SPRAS LIKE LFA1-SPRAS,

END OF ITAB.

DATA : BDCTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

BDCMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'c:\call.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = ITAB

  • 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.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

  • DEST = FILLER8

GROUP = 'hmgroup'

HOLDDATE = SY-DATUM

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.

LOOP AT ITAB.

REFRESH BDCTAB.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '100'.

PERFORM BDC_FIELD USING 'bdc_cursor' 'RF02K-ktokk'.

PERFORM BDC_FIELD USING 'bdc_okcode' '/00'.

PERFORM BDC_FIELD USING 'RF02K-LIFNR' ITAB-LIFNR.

PERFORM BDC_FIELD USING 'RF02K-ktokk' ITAB-KTOKK.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '110'.

PERFORM BDC_FIELD USING 'bdc_cursor' 'lfa1-spras'.

PERFORM BDC_FIELD USING 'bdc_okcode' '/00'.

PERFORM BDC_FIELD USING 'lfa1-name1' ITAB-NAME1.

PERFORM BDC_FIELD USING 'lfa1-sortl' ITAB-SORTL.

PERFORM BDC_FIELD USING 'lfa1-land1' ITAB-LAND1.

PERFORM BDC_FIELD USING 'lfa1-spras' ITAB-SPRAS.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '120'.

PERFORM BDC_FIELD USING 'bdc_cursor' 'lfa1-kunnr'.

PERFORM BDC_FIELD USING 'bdc_okcode' '/00'.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '130'.

PERFORM BDC_FIELD USING 'bdc_cursor' 'lfbk-banks(01)'.

PERFORM BDC_FIELD USING 'bdc_okcode' '/00'.

PERFORM BDC_DYNPRO USING 'SAPLSP01' '300'.

PERFORM BDC_FIELD USING 'bdc_okcode' '/=yes'.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'XK01'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

TABLES

DYNPROTAB = BDCTAB

  • 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.

*call transaction 'XK01' using bdctab mode 'a' update 'a' messages into bdcmsg.

*read table bdcmsg with KEY MSGTYP = 'E'.

*CALL FUNCTION 'FORMAT_MESSAGE'

  • EXPORTING

  • ID = bdcmsg-MSGID

  • LANG = 'EN'

  • NO = bdcmsg-MSGNR

  • V1 = bdcmsg-MSGV1

  • V2 = bdcmsg-MSGV2

  • V3 = bdcmsg-MSGV3

  • V4 = bdcmsg-MSGV4

  • IMPORTING

  • MSG = bdcmsg-MSGV1

    • 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 😕 bdcmsg-MSGV1.

ENDLOOP.

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.

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_P1 text

  • -->P_P2 text

----


FORM BDC_DYNPRO USING P_P1

P_P2.

CLEAR BDCTAB.

BDCTAB-PROGRAM = P_P1.

BDCTAB-DYNPRO = P_P2.

BDCTAB-DYNBEGIN = 'X'.

APPEND BDCTAB.

ENDFORM. " bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->P_P3 text

  • -->P_P4 text

----


FORM BDC_FIELD USING P_P3

P_P4.

CLEAR BDCTAB.

BDCTAB-FNAM = P_P3.

BDCTAB-FVAL = P_P4.

APPEND BDCTAB.

ENDFORM. " bdc_field

if helpful reward points