Application Development 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: 

BDC not displaying errored data

Former Member
0 Kudos

Hi All,

in my BDC i have used CALL FUNCTION 'BAPI_MESSAGE_GETDETAIL'

to handle errored data,

but i am not getting errored data as a message, please help me how could i write

such that i can get error message on wrong data.

1 ACCEPTED SOLUTION

former_member187748
Active Contributor
0 Kudos

Hi Srikant,

in view of previous reply, one thing more .

Create an internal table, for error and success messages, and append it.

12 REPLIES 12

former_member187748
Active Contributor
0 Kudos

Hi Srikant,

declare an internal table of type bapiret2, please write your code as below

then you can populate your error and success messages as shown below

You have to create work area for storing error and success messages.

and the field1, field2, field3 mentioned here are those from where you wants to see your data

having success or errored data.

Please change this code as per as your requirement, and let me know what happens.

DATA: i_messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,

       l_message LIKE bapiret2-message.


DATA : BEGIN OF options.

         INCLUDE STRUCTURE ctu_params.

DATA : END OF options.


then you have to write something like this


CALL TRANSACTION 'your txn. no.' USING bdcdata

                             OPTIONS FROM options

                             MESSAGES INTO i_messtab.

     IF SY-SUBRC NE 0.

       CALL FUNCTION 'BAPI_MESSAGE_GETDETAIL'

         EXPORTING

           id         = sy-msgid

           number     = sy-msgno

           language   = sy-langu

           textformat = 'ASC'

           message_v1 = sy-msgv1

           message_v2 = sy-msgv2

           message_v3 = sy-msgv3

           message_v4 = sy-msgv4

         IMPORTING

           message    = l_message.

       .

       CONCATENATE l_message '-' wa_input-field1 wa_input-field2 wa_input-field3 INTO it_error-text

       SEPARATED BY ' '.

       APPEND it_error.

     ELSE.

       CONCATENATE 'DATA UPLOADED SUCCESSFULLY :' wa_input-field1  wa_input-field2 wa_input-field3

       INTO it_success-text SEPARATED BY ' '.

       APPEND it_success.

     ENDIF.

     REFRESH bdcdata.

     CLEAR: wa_input,l_message.

former_member187748
Active Contributor
0 Kudos

Hi Srikant,

in view of previous reply, one thing more .

Create an internal table, for error and success messages, and append it.

0 Kudos

Hi Sanjeev,

i have used this code, but i think something is still missing,

because i got error messages during debugging but not getting

it as an output, can you elaborate it at some extent,

what else i am missing.

0 Kudos

Hi Srikant,

apart from my above written code snippet, you have to implement two perform statement

like shown below. This will show error and success messages accordingly.

*Report for success

PERFORM  success_text.

*   Report for Error

   PERFORM  error_text.


Before fetching BDC data , declare these perform statements, and after

call transaction method, use both perform statement as .


FORM success_text.

*****write logic for success text***

ENDFORM.


FORM error_text.

****logic for error text****

ENDFORM.


Then you will get your error and success text accordingly.

0 Kudos

Hi Sanjeev,

i have done almost all coding, but if you have any sample code then please rovide the same.

It would be a great appreciate for me.

Thanks a lot once again.

0 Kudos

Hi Srikant,

please see this sample code, and change it accordingly for transaction code, fields, etc.

Please see those who are in bold letters.

Still if you have any issue, then please revert me back.

report ZFB01_POST_DOCUMENT

        no standard page heading line-size 255.

INCLUDE zbdcrec.

TYPE-POOLS : TRUXS.

TYPESBEGIN OF ty_input,

        Your final data.

END OF ty_input.

DATA: it_input TYPE STANDARD TABLE OF ty_input WITH HEADER LINE ,

       wa_input TYPE ty_input.

DATA : BEGIN OF options.

         INCLUDE STRUCTURE ctu_params.

DATA : END OF options.

DATA: i_messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,

       l_message LIKE bapiret2-message.

DATA: p_mode TYPE c.

DATA  BEGIN OF it_error OCCURS 1.

DATA : text(100TYPE c.

DATA  END   OF it_error.

DATA  BEGIN OF it_success OCCURS 1.

DATAtext(100) TYPE c.

DATA  END   OF it_success.

DATA: it_raw TYPE truxs_t_text_data.

*--------------------------------------------------------------------*

* sELECTION sCREEN

*--------------------------------------------------------------------*

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECTION-SCREEN SKIP 1.

PARAMETERS : p_path LIKE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN : END   OF BLOCK b1.

SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

SELECTION-SCREEN SKIP 1.

PARAMETERS : mode_a      RADIOBUTTON    GROUP  r1,

              mode_n      RADIOBUTTON    GROUP  r1.

SELECTION-SCREEN : END   OF BLOCK b2.

*--------------------------------------------------------------------*

* AT SELECTION SCREEN

*--------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.

   CALL FUNCTION 'F4_FILENAME'

     EXPORTING

       field_name = 'P_FILE '

     IMPORTING

       file_name  = p_path.

START-OF-SELECTION.

   CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

     EXPORTING

       i_line_header        = 'X'

       i_tab_raw_data       = it_raw       " WORK TABLE

       i_filename           = p_path

     TABLES

       i_tab_converted_data = it_input[]  "ACTUAL DATA

     EXCEPTIONS

       conversion_failed    = 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.

   LOOP AT it_input.

   IF sy-tabix EQ 1 "for first  row

     CONTINUE.

   ENDIF.

ENDLOOP.

*--------------------------------------------------------------------*\

* start of selection

*--------------------------------------------------------------------*

START-OF-SELECTION.

  PERFORM upload_data.

*   Report for success

  PERFORM  success_text.

*   Report for Error

   PERFORM  error_text.

END-OF-SELECTION.

*

*  PERFORM bdc_transaction USING 'FB01'.

*

*  PERFORM close_group.

*&---------------------------------------------------------------------*

*&      Form  UPLOAD_DATA

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

form UPLOAD_DATA .

    IF mode_a EQ 'X'.

     p_mode = 'A'.

   ELSEIF mode_n EQ 'X'.

     p_mode = 'N'.

   ENDIF.

   options-defsize = 'X'.

   options-updmode = ''.

   options-dismode = p_mode.

   LOOP AT it_input INTO wa_input.

   Your BDC data (code for BDC).

     BDC Recording data.

CALL TRANSACTION 'txn. code' USING bdcdata

                             OPTIONS FROM options

                             MESSAGES INTO i_messtab.

     IF SY-SUBRC NE 0.

       CALL FUNCTION 'BAPI_MESSAGE_GETDETAIL'

         EXPORTING

           id         = sy-msgid

           number     = sy-msgno

           language   = sy-langu

           textformat = 'ASC'

           message_v1 = sy-msgv1

           message_v2 = sy-msgv2

           message_v3 = sy-msgv3

           message_v4 = sy-msgv4

         IMPORTING

           message    = l_message.

       .

       CONCATENATE l_message '-' wa_input-field1 wa_input-field2 wa_input-field3 INTO it_error-text

       SEPARATED BY ' '.

       APPEND it_error.

     ELSE.

       CONCATENATE 'DATA UPLOADED SUCCESSFULLY :' wa_input-field1  wa_input-field2 wa_input-field3

       INTO it_success-text SEPARATED BY ' '.

       APPEND it_success.

     ENDIF.

     REFRESH bdcdata.

     CLEAR: wa_input,l_message.

ENDLOOP.

***ENDLOOP.

endform.

                    " UPLOAD_DATA

FORM success_text .

   LOOP AT it_success.

     AT FIRST.

       WRITE :/10  'Following records successfully uploaded'.

       ULINE.

     ENDAT.

     WRITE :/10  it_success-text.

   ENDLOOP.

ENDFORM.

FORM error_text .

  LOOP AT it_error.

     AT FIRST.

       WRITE :/10  'Following records  are not uploaded'.

       ULINE.

     ENDAT.

     WRITE :/10  it_error-text.

  ENDLOOP.

ENDFORM.

0 Kudos

Hi Sanjeev,

thanks a lot buddy, i have done it.

Thanks a lot again.

Former Member
0 Kudos

Hi Srikant,

I propose this FM MESSAGE_TEXT_BUILD .

Check the BDC Message tab with error or success! both messages can be handled!

call function 'MESSAGE_TEXT_BUILD'
     exporting
       msgid               = sy-msgid
       msgnr               = sy-msgno
       msgv1               = sy-msgv1
       msgv2               = sy-msgv2
     importing
       message_text_output = news-text.

0 Kudos

Hi Kiran,

thanks for your reply, please be specific, i have to show both error and success messages

at a single call, will i achieve through it.

Any other changes that i have to perform, (other code lines for using this FM)

0 Kudos

Hi Srikanth,

Yes you can do it! you can build the two internal tables one for error and one for success and capture it accordingly.

example code for quick reference you can modify the code later!

Read table message_tab with key mstyp = 'E.

if sy-subrc = 0.
*     BUILDS ACTUAL MESSAGE BASED ON INFO RETURNED FROM CALL TRANSACTION
       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.


apepend it_error.


else.

Read table message_tab with key mstyp = 's.

       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.


apeedn it_success.

endif.

if you want you can do it in the loop also.

rg, Kiran

Former Member
0 Kudos

Dear Srikant,

You can add the following code to get the error messages:

loop at i_messtab into wa_messtab.

call function RPY_MESSAGE_COMPOSE

IMPORTING

    LANGUAGE = sy-langu

      MESSAGE_ID = wa_messtab-MSGID

      MESSAGE_NUMBER = wa_messtab-MSGNO

      MESSAGE_VAR1 = wa_messtab-MSGV1

      MESSAGE_VAR2) =  wa_messtab-MSGV2

    VALUE(MESSAGE_VAR3) =  wa_messtab-MSGV3

    VALUE(MESSAGE_VAR4) =  wa_messtab-MSGV4

  EXPORTING

    MESSAGE_TEXT = LV_LISEL

"  TABLES

*"      LONGTEXT STRUCTURE  TLINE OPTIONAL

  EXCEPTIONS

      MESSAGE_NOT_FOUND = 1.

"Use LV_LISEL to either populate ALV or Write message".

endloop.

Alternatively you can also use FM "BAPI_MESSAGE_GETDETAIL".

Best Regards,

Imran

atul_mohanty
Active Contributor
0 Kudos

Hi Srikant -

Here is an example below which might help you.


Types : Begin of t_itab,

        lifnr like lfa1-lifnr,   "10

        bukrs like t001-bukrs,   "4

        ktokk like rf02k-ktokk,  "4

        anred like lfa1-anred,   "15

        name1 like lfa1-name1,   "35

        sortl like lfa1-sortl,   "10

        land1 like lfa1-land1,   "3

        spras(2) ,                "2

        akont like lfb1-akont,   "10

        fdgrv like lfb1-fdgrv,   "10

       end of T_itAB,
         
        begin of t_error,
        message type string,

        end of t_error.


*--- 2


Data : i_itab type standard table of t_itab,

          w_itab type  t_itab,


DATA : I_BDCDATA type standard table of BDCDATA ,

        w_BDCDATA type  BDCDATA,
      
        i_error type standard table of t_error,
         w_error type t_error.


DATA i_messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE,

     v_msgtxt TYPE string,

*-- 3

CALL FUNCTION 'UPLOAD'

EXPORTING

   FILENAME                      = 'C:\WINDOWS\DESKTOP\VEND.TXT'

   FILETYPE                      = 'ASC'

  TABLES

    data_tab                      = I_ITAB.

Loop at I_itab into wa_itab.

perform fill_bdc_Data.

call transaction 'XK01' using i_bdcdata

                 mode 'N'

                 update 'S'.

                  MESSAGES INTO i_messtab.

                 refresh i_bdcdata.

PERFORM FORMAT_MESSAGE.

endloop.


*&---------------------------------------------------------------------*

*&      Form  fill_bdc_Data

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

form fill_bdc_Data.

*--- 0100

w_bdcdata-PROGRAM  = 'SAPMF02K'.

w_bdcdata-DYNPRO  =  '0100' .

w_bdcdata-DYNBEGIN = 'X'.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'RF02K-LIFNR'.

w_bdcdata-fval =  w_itab-lifnr.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'RF02K-BUKRS'.

w_bdcdata-fval =  w_itab-bukrs.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'RF02K-KTOKK'.

w_bdcdata-fval =  w_itab-ktokk.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'RF02K-KTOKK' .

w_bdcdata-fval = w_itab-ktokk.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'BDC_OKCODE' .

w_bdcdata-fval = '/00'.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

*--- 110

i_bdcdata-program = 'SAPMF02K'.

i_bdcdata-dynpro = '0110'.

i_bdcdata-dynbegin = 'X'.

append i_bdcdata.

clear i_bdcdata.

i_bdcdata-fnam = 'LFA1-ANRED' .

i_bdcdata-fval = itab-anred.

append i_bdcdata.

clear i_bdcdata .

w_bdcdata-fnam = 'LFA1-NAME1' .

w_bdcdata-fval = w_itab-name1.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

i_bdcdata-fnam = 'LFA1-SORTL' .

i_bdcdata-fval = itab-sortl.

append i_bdcdata.

clear i_bdcdata .

w_bdcdata-fnam = 'LFA1-LAND1' .

w_bdcdata-fval = w_itab-land1.
append w_bdcdata to i_bdcdata.

clear w_bdcdata.
.

w_bdcdata-fnam = 'LFA1-SPRAS' .

w_bdcdata-fval = itab-spras.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'BDC_OKCODE' .

w_bdcdata-fval = '=VW'.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

*--- 0120

w_bdcdata-program = 'SAPMF02K'.

w_bdcdata-dynpro = '0120'.

w_bdcdata-dynbegin = 'X'.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'BDC_OKCODE' .

w_bdcdata-fval = '=VW'.
append w_bdcdata to i_bdcdata.

clear w_bdcdata.

*--- 130

w_bdcdata-program = 'SAPMF02K'.

w_bdcdata-dynpro = '0130'.

w_bdcdata-dynbegin = 'X'.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'BDC_OKCODE' .

w_bdcdata-fval = '=VW'.
append w_bdcdata to i_bdcdata.

clear w_bdcdata.

*--- 210

w_bdcdata-program = 'SAPMF02K'.

w_bdcdata-dynpro = '0210'.

w_bdcdata-dynbegin = 'X'.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'LFB1-AKONT' .

w_bdcdata-fval = w_itab-akont.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'LFB1-FDGRV' .

w_bdcdata-fval = w_itab-fdgrv.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

w_bdcdata-fnam = 'BDC_OKCODE' .

w_bdcdata-fval = '=UPDA'.

append w_bdcdata to i_bdcdata.

clear w_bdcdata.

endform.                    " fill_bdc_Data

FORM format_message .

  CLEAR lv_msgtxt.

  READ TABLE it_messtab WITH KEY msgtyp = 'E'.

  IF sy-subrc = 0.

CALL FUNCTION 'FORMAT_MESSAGE'

    EXPORTING

      id        = sy-msgid

      lang      = 'EN'

      no        = sy-msgno

      v1        = sy-msgv1

      v2        = sy-msgv2

      v3        = sy-msgv3

      v4        = sy-msgv4

    IMPORTING

      msg       = lv_msgtxt

    EXCEPTIONS

      not_found = 1

      OTHERS    = 2.

  IF sy-subrc = 0.

    
     w_error-message = lv_msgtxt.
     append w_error to i_error.
     clear w_error.
 

  ENDIF.
ENDIF.

ENDFORM.                    " FORMAT_MESSAGE