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

BDCMSGCOLL

Former Member
0 Likes
812

I want the code for sending message to BDCMSGCOLL while using call transaction

4 REPLIES 4
Read only

uwe_schieferstein
Active Contributor
0 Likes
748

Hello Ayan

The syntax for the CALL TRANSACTION statement is:

CALL TRANSACTION <tcode> USING bdc_tab
... { {[MODE mode] [UPDATE upd]} 
    | [OPTIONS FROM opt] } 
    [MESSAGES INTO itab] ... . 

<b>Effect </b>

Using this addition (-> MESSAGES INTO itab), all the messages sent during batch input processing are stored in an internal table itab of the type BDCMSGCOLL from the ABAP Dictionary.

Regards

Uwe

Read only

0 Likes
748

In addition to Uwe code,

with in the loop and endloop of itab call a perform tht writes the error message

eg:

loop at itab.

call transaction ......

if sy-subrc <> '0'.

perform error_message.

endif.

endloop.

form error_message.

call funtion 'format_message'. * to write the error message in to the screen

endform.

hope this solves ur problem...

reward poins if useful...

Read only

Former Member
0 Likes
748

Hi Ayan

The code for sending message to BDCMSGCOLL while using CALL TRANSACTION is:

CALL TRANSACTION c_tcode USING tbl_bdcdata
                                          MODE  c_mode
                                          UPDATE c_update
                        MESSAGES INTO tbl_bdcmsgcoll.

In the code above:

1. c_tode is the transaction code you have run the BDC for.

2. c_mode is the mode you want to run the BDC for. Modes can be:

a. A(Processing with display of screens) .

b. N(Processing without display of screens. If a breakpoint is reached in one of

the called transactions, processing is terminated with sy-subrc same as

1001. The field sy-msgty contains "S", sy-msgid contains "00", sy-msgno

contains "344", sy-msgv1 contains "SAPMSSY3", and sy-msgv2

contains "0131").

c. P(Processing without display of the screens. If a breakpoint is reached in

one of the called transactions, the system branches to the ABAP Debugger).

d. E(Display of screen if an error

occurs) .

Normally 'N' is the mode we choose in our program.

3. c_update is the processing mode .The values can be :

a. A - asynchronous update

b. S - synchronous update

c. L - Local update

Normally 'S' is the value for this parameter unless you want the other 2 types of processing. If you dont specify the value for this , the default value taken is 'A'.

4. tbl_bdcmsgcll is the internal table of type BDCMSGCOLL.All the messages would be collected into this table and you can process this to display the errors to the users.

Hope this helps.

cheers

shivika

Read only

Former Member
0 Likes
748

See the below example code for BDMSGCOLL Structure ...

REPORT znit_bdc_assign

NO STANDARD PAGE HEADING LINE-SIZE 255.

  • for programs doing a data transfer by creating a batch-input session

  • and

  • for programs doing a data transfer by CALL TRANSACTION USING

*******Here SESSION = ' ' and CTU = 'X'

DATA: ctumode LIKE ctu_params-dismode VALUE 'N' ,

cupdate LIKE ctu_params-updmode VALUE 'L' ,

e_group(12), "group name of error-session

e_user(12) , "user for error-session

e_keep VALUE 'X', "'X' = keep session if finished

e_hdate LIKE sy-datum.

DATA: smalllog VALUE ' ' ,

nodata VALUE '/'.

DATA: flag .

************************************************************************

  • DATA DECLARATION *

************************************************************************

TYPES: begin of t_result,

matnr(18) , "TYPE RMMG1-MATNR

maktx(40) , "TYPE makt-maktx

bismt(18) , "TYPE mara-bismt

brgew(13) , "TYPE mara-brgew

gewei(3) , "TYPE mara-gewei

message(250), "Message

END OF t_result .

DATA : right TYPE STANDARD TABLE OF t_result ,

wrong TYPE STANDARD TABLE OF t_result ,

wa_result TYPE t_result .

----


  • data definition

----


  • Batchinputdata of single transaction

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

  • messages of call transaction

DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

  • error session opened (' ' or 'X')

DATA: e_group_opened.

  • message texts

TABLES: t100.

----


*INITIALIZATION

----


INITIALIZATION.

MOVE sy-uname TO e_user .

----


  • Start new transaction according to parameters *

----


FORM bdc_transaction USING tcode.

DATA: l_mstring(480).

DATA: l_subrc LIKE sy-subrc.

  • batch input session

REFRESH messtab.

CALL TRANSACTION tcode USING bdcdata

MODE ctumode

UPDATE cupdate

MESSAGES INTO messtab.

l_subrc = sy-subrc.

IF smalllog <> 'X'.

  • WRITE: / 'CALL_TRANSACTION', "CH01

  • tcode, "CH01

  • 'returncode:'(i05), "CH01

  • l_subrc, "CH01

  • 'RECORD:', "CH01

  • sy-index. "CH01

LOOP AT messtab.

SELECT SINGLE * FROM t100 WHERE sprsl = messtab-msgspra

AND arbgb = messtab-msgid

AND msgnr = messtab-msgnr.

IF sy-subrc = 0.

l_mstring = t100-text.

IF l_mstring CS '&1'.

REPLACE '&1' WITH messtab-msgv1 INTO l_mstring.

REPLACE '&2' WITH messtab-msgv2 INTO l_mstring.

REPLACE '&3' WITH messtab-msgv3 INTO l_mstring.

REPLACE '&4' WITH messtab-msgv4 INTO l_mstring.

ELSE.

REPLACE '&' WITH messtab-msgv1 INTO l_mstring.

REPLACE '&' WITH messtab-msgv2 INTO l_mstring.

REPLACE '&' WITH messtab-msgv3 INTO l_mstring.

REPLACE '&' WITH messtab-msgv4 INTO l_mstring.

ENDIF.

CONDENSE l_mstring.

  • WRITE: / messtab-msgtyp, l_mstring(250).

************************************************************************

IF messtab-msgtyp = 'S' . "If successfully uploaded CH01

flag = '1' .

ELSE .

flag = '2' . "if not succesfully uploaded CH01

ENDIF.

MOVE l_mstring TO wa_result-message .

************************************************************************

ELSE.

WRITE: / messtab.

ENDIF.

ENDLOOP.

  • SKIP.

    • Erzeugen fehlermappe ************************************************

IF l_subrc <> 0 AND e_group <> space.

IF e_group_opened = ' '.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = e_group

user = e_user

keep = e_keep

holddate = e_hdate.

e_group_opened = 'X'.

ENDIF.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = tcode

TABLES

dynprotab = bdcdata.

ENDIF.

ENDIF.

REFRESH bdcdata.

ENDFORM.

----


  • Start new screen *

----


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM.

----


  • Insert field *

----


FORM bdc_field USING fnam fval.

IF fval <> nodata.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDIF.

ENDFORM.

*Structure of the internal table in which data has to be uploaded

TYPES: BEGIN OF t_final,

matnr(18) , "TYPE RMMG1-MATNR

maktx(40) , "TYPE makt-maktx

bismt(18) , "TYPE mara-bismt

brgew(13) , "TYPE mara-brgew

gewei(3) , "TYPE mara-gewei

END OF t_final .

DATA: answer , "return value in popup_to_comfirm

count1 TYPE i , "no. of records not succusfully uploaded

count2 TYPE i . "no. of records successfully uploaded

DATA: i_final TYPE STANDARD TABLE OF t_final ,

wa_final TYPE t_final .

PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY.

  • stores file name to be uploaded

************************************************************************

  • AT SELECTION SCREEN *

************************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file .

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

  • DEF_FILENAME = ' '

  • DEF_PATH = ' '

mask = ',.,..'

  • MODE = ' '

  • TITLE = ' '

IMPORTING

filename = p_file

  • RC =

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

************************************************************************

  • START OF SELECTION *

************************************************************************

START-OF-SELECTION.

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

titlebar = 'Confirm Pop-UP'

  • DIAGNOSE_OBJECT = ' '

text_question = 'Would you like to proceed?'

text_button_1 = 'Yes'(001)

icon_button_1 = 'ICON_OKAY'

text_button_2 = 'No'(002)

icon_button_2 = 'ICON_CANCEL'

default_button = '1'

display_cancel_button = 'X'

  • USERDEFINED_F1_HELP = ' '

start_column = 25

start_row = 6

  • POPUP_TYPE =

IMPORTING

answer = answer

  • TABLES

  • PARAMETER =

EXCEPTIONS

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

CHECK answer EQ '1'.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

filename = p_file

filetype = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = i_final

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

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT i_final INTO wa_final .

PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RMMG1-MATNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RMMG1-MATNR'

wa_final-matnr.

MOVE wa_final-matnr TO wa_result-matnr .

PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

PERFORM bdc_field USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTR'.

PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'

'X'.

PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

PERFORM bdc_field USING 'MAKT-MAKTX'

wa_final-maktx.

PERFORM bdc_field USING 'BDC_CURSOR'

'MARA-BISMT'.

PERFORM bdc_field USING 'MARA-BISMT'

wa_final-bismt.

PERFORM bdc_field USING 'MARA-BRGEW'

wa_final-brgew.

PERFORM bdc_field USING 'MARA-GEWEI'

wa_final-gewei.

MOVE wa_final-maktx TO wa_result-maktx .

MOVE wa_final-bismt TO wa_result-bismt .

MOVE wa_final-brgew TO wa_result-brgew .

MOVE wa_final-gewei TO wa_result-gewei .

PERFORM bdc_transaction USING 'MM02'.

            • flag = '1' Record updated successfully

            • flag = '2' Record not updated

IF flag = '1' .

APPEND wa_result TO right .

count1 = count1 + 1 .

ELSEIF flag = '2' .

APPEND wa_result TO wrong .

count2 = count2 + 1 .

ENDIF .

ENDLOOP.

    • Report Generation

WRITE : ' Success Item' .

SKIP .

WRITE : / ' Number of Success Items: ', count1 , ' Items.' .

SKIP .

WRITE: / 'Material Number ',

19 'Material Name',

59 'Old Mat. Name',

77 'Gross Wt.',

90 'Weight Unit',

105 'Message' .

WRITE: sy-uline .

LOOP AT right INTO wa_result .

WRITE: / wa_result-matnr ,

19 wa_result-maktx ,

59 wa_result-bismt ,

77 wa_result-brgew ,

90 wa_result-gewei ,

105 wa_result-message .

ENDLOOP .

SKIP 2 .

WRITE : /' Error Item' .

SKIP .

WRITE : / ' Number of Error Items: ', count2 , ' Items.' .

SKIP .

WRITE: / 'Material Number ',

19 'Material Name',

59 'Old Mat. Name',

77 'Gross Wt.',

90 'Weight Unit',

105 'Message' .

WRITE: sy-uline .

LOOP AT wrong INTO wa_result .

WRITE: / wa_result-matnr ,

19 wa_result-maktx ,

59 wa_result-bismt ,

77 wa_result-brgew ,

90 wa_result-gewei ,

105 wa_result-message .

ENDLOOP .

Reward Points if it is helpful

Thanks

Seshu