‎2006 Mar 08 3:00 PM
Hi all,
In my program I am trying to handle errors in call transaction method using bdcmsgcoll and format_message.To check this I have given some false data like trying to create materials which are already in mara tables. The data is not updated in the mara tables but No error messages are populated into the bdcmsgcoll structure. The status of all messges is success. How do messages get populated into bdcmsgcoll ?
I am forwardimng my code too. Can anyone please explain me what's happening ? For what type of errors, Error messages get poplated into bdcmsgcoll ?
*********************************************************
report Z_MAT_CALL
no standard page heading line-size 255.
data : begin of material occurs 0,
matnr like mara-matnr, " Material Number
mbrsh like mara-mbrsh, " Industry sector
mtart like mara-mtart, " material Type
maktx like makt-maktx, " Material Description
meins like mara-meins, " Base Unit of Measure
end of material.
data fnam type string value 'C:\BW\MAT.TXT'.
*---- BDCDATA
data : bdcdata like bdcdata occurs 0 with header line,
itab like bdcmsgcoll occurs 0 with header line,
mesg(100).
*---- Uploading data into internal table from flat File.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = fnam "'C:\BW\MAT.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
tables
data_tab = material.
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 material.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MATNR'
material-matnr.
perform bdc_field using 'RMMG1-MBRSH'
material-mbrsh.
perform bdc_field using 'RMMG1-MTART'
material-mtart.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(02)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'.
perform bdc_field using 'MSICHTAUSW-KZSEL(02)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
material-maktx.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
material-meins.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
perform bdc_transaction using 'MM01'.
refresh bdcdata.
endloop.
*LOOP AT iTAB.
*WRITE: / iTAB-TCODE,
*iTAB-DYNAME,
*iTAB-DYNUMB,
*iTAB-MSGTYP,
*iTAB-MSGSPRA,
*iTAB-MSGID,
*iTAB-MSGNR.
*ENDLOOP.
*
----
Start new screen *
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
CLEAR BDCDATA.
ENDFORM.
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
CLEAR BDCDATA.
ENDFORM.
----
Form bdc_transaction
----
form bdc_transaction using value(tcode).
call transaction tcode using bdcdata
mode 'N'
update 'S' messages into itab.
if sy-subrc Ne 0.
read table itab with key msgtyp = 'E'.
if sy-subrc = 0.
perform check.
endif.
endif.
endform. " bdc_transaction
----
Form check
----
form check .
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = itab-msgid
lang = sy-langu
no = itab-msgnr
v1 = itab-msgv1
v2 = itab-msgv2
v3 = itab-msgv3
v4 = itab-msgv4
IMPORTING
msg = mesg
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.
endform. " check
*********************************************************
Regards,
Varun.
‎2006 Mar 08 3:09 PM
The message that you are expecting is not actually an error message. Message class M3, number 307. Modify your program like this, you will see the messages.
form bdc_transaction using value(tcode).
call transaction tcode using bdcdata
mode 'N'
update 'S' messages into itab.
if sy-subrc ne 0.
<b> loop at itab.
perform check.
write:/ itab-msgid, itab-msgnr, mesg.
endloop.</b>
endif.
endform. " bdc_transaction
Regards,
Rich Heilman
‎2006 Mar 08 3:04 PM
Hi Varun,
The BDCMSGCOLL gets updated with the last message in your call transaction,whether it is error or success.So, once you get error message then the call transaction stops & the itab gets updated with the error message.
‎2006 Mar 08 3:12 PM
Hi Phani,
As you said bdcmsgcoll gets updated with the last message of the transaction. So if the update fails it should be because of an error right ? In my case the update fails because the flat file data is duplicate.
sy-subrc returns 0 but bdcmsgcoll gets populated with success message. What could be the reason ?
Regards,
Varun.
‎2006 Mar 08 3:15 PM
Hi Varun,
Even if the messages in the itab(If you can see them in debug mode), are type success, their nature is that of an error message. For example if you do not have a field in a screen and you try to populate it with a vakue in the bdc, it will give a success message only, but the sy-subrc will not be 0.
Ravi
‎2006 Mar 08 3:16 PM
Again it really depends on the transaction, in this case in MM01 the message is a sucess message. Run MM01 in dialog mode and you can see for yourself. Not sure why its coded that way, but it is. So for you purposes, you must check for the specific message class/number M3 307 in order to know if it is a duplicate material or not.
Regards,
Rich Heilman
‎2006 Mar 08 3:19 PM
Hi Varun,
I suggest you run the program in the All screen mode & see what message you are getting.
Some times the messages are updated with "Success",even if it is error...
& also you messgae might be of type 'E',when there is problem in the flow of the transaction you defined.
Message was edited by: Phani Kiran Nudurupati
‎2006 Mar 08 3:05 PM
Hi Varun,
After you get the message from the format_message fm, where are you writing it??
YOu write e write statement after the Call to the Format_message FM.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = itab-msgid
lang = sy-langu
no = itab-msgnr
v1 = itab-msgv1
v2 = itab-msgv2
v3 = itab-msgv3
v4 = itab-msgv4
IMPORTING
msg = mesg
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
<b>write:/ mesg.</b>
Regards,
Ravi
P.S: Sometimes the messages will be of type Success only, but actually they are error messages, so , it is better if you loop around itab, instead of reading it.
‎2006 Mar 08 3:09 PM
Try
CALL TRANSACTION
MODE = 'E'this will stop if there is an error!
If none everything is ok!
But it is possible that some tests are not done by SAP when it is in Batch Input.
Regards
Stephan
thx for reward!
‎2006 Mar 08 3:07 PM
Hi
DATA : T_BDCMSGCOLL TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE.
DATA : WA_BDCMSGCOLL TYPE BDCMSGCOLL.
DATA : ERR_LOG TYPE MESSAGE.
Call Transaction MM01
IF W_FLAG NE 'X'.
CALL TRANSACTION 'MM01' USING T_BDCDATA OPTIONS FROM WA_CTU_PARAMS
MESSAGES INTO T_BDCMSGCOLL.
COMMIT WORK AND WAIT.
DESCRIBE TABLE T_BDCMSGCOLL LINES N.
IF N <> 0.
LOOP AT T_BDCMSGCOLL INTO WA_BDCMSGCOLL.
CLEAR ERR_LOG.
W_MSGNO = WA_BDCMSGCOLL-MSGNR.
CALL FUNCTION 'WRITE_MESSAGE'
EXPORTING
MSGID = WA_BDCMSGCOLL-MSGID
MSGNO = W_MSGNO
MSGTY = WA_BDCMSGCOLL-MSGTYP
IMPORTING
MESSG = ERR_LOG.
Error that occurs during transactoon
IF ERR_LOG-MSGTY = 'E'.
MOVE-CORRESPONDING T_UPLOAD TO T_DOWNLOAD.
MOVE ERR_LOG-MSGTX TO T_DOWNLOAD-MSG.
APPEND T_DOWNLOAD.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
check structure declaration and code it may be useful
regards
vinod
‎2006 Mar 08 3:08 PM
In form bdc_transaction, after the call transaction, take out 'if sy-subrc NE 0.' You can never be sure what the return code will be. So the code should be:
FORM bdc_transaction USING value(tcode).
CALL TRANSACTION tcode USING bdcdata
MODE 'N'
UPDATE 'S' MESSAGES INTO itab.
READ TABLE itab WITH KEY msgtyp = 'E'.
IF sy-subrc = 0.
PERFORM check.
ENDIF.
ENDFORM. " bdc_transaction
‎2006 Mar 08 3:09 PM
The message that you are expecting is not actually an error message. Message class M3, number 307. Modify your program like this, you will see the messages.
form bdc_transaction using value(tcode).
call transaction tcode using bdcdata
mode 'N'
update 'S' messages into itab.
if sy-subrc ne 0.
<b> loop at itab.
perform check.
write:/ itab-msgid, itab-msgnr, mesg.
endloop.</b>
endif.
endform. " bdc_transaction
Regards,
Rich Heilman
‎2006 Mar 08 3:18 PM
Hi Rich,
My problem is solved. I got the message I am expecting.
But when can I expect error message? I mean to say when bdcmsgcoll gets populated with error message ? In what scenarios ?
Regards,
Varun.
‎2006 Mar 08 3:22 PM
Hi Varun,
Now now..your question is more functional than technical..:)
For whatever reasons a manual creation fails with an error message , for all such cases you would get an error message in bdcmsgcoll.
And what do you mean, "My problem is solved", what did you do to get that code of yours working??
‎2006 Mar 08 3:25 PM
It will have error messages if a true error message is issued. Meaning that any Error message that happens in the transaction in dialog mode, that appears in RED at the bottom of the screen, will come thru as a message type E.
Please remember to award points for helpful answers and mark you post as solved when solved completely. Thanks.
Regards,
Rich Heilman