Skip to Content
author's profile photo Former Member
Former Member

BDC messages

how to retrieve all the messages of a bdc which will be displayed in the status bar while running the bdc. after we run the program we should display all those messages on the screen in a report program.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 09:56 AM

    <b>THIS IS CALL TRANSACTION METHOD.

    TCODE 'MK01' WITH DISPLAY ERROR MESSAGE .</b>

    no standard page heading line-size 255.

    data: begin of itab occurs 0,

    lifnr like lfa1-lifnr,

    ekorg like lfm1-ekorg,

    ktokk like lfa1-ktokk,

    name1 like lfa1-name1,

    sortl like lfa1-sortl,

    end of itab.

    data: bdcdata like bdcdata occurs 0 with header line,

    i_msg like bdcmsgcoll occurs 0 with header line.

    *include bdcrecx1.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = 'C:/ITAB.TXT'

    • FILETYPE = 'ASC'

    HAS_FIELD_SEPARATOR = 'X'

    • HEADER_LENGTH = 0

    • READ_BY_LINE = 'X'

    • DAT_MODE = ' '

    • CODEPAGE = ' '

    • IGNORE_CERR = ABAP_TRUE

    • REPLACEMENT = '#'

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

    start-of-selection.

    *perform open_group.

    LOOP AT ITAB.

    perform bdc_dynpro using 'SAPMF02K' '0107'.

    perform bdc_field using 'BDC_CURSOR'

    'RF02K-KTOKK'.

    perform bdc_field using 'BDC_OKCODE'

    '/00'.

    perform bdc_field using 'RF02K-LIFNR'

    • 'Di001'.

    ITAB-LIFNR.

    perform bdc_field using 'RF02K-EKORG'

    • '1000'.

    ITAB-EKORG.

    perform bdc_field using 'RF02K-KTOKK'

    • '0001'.

    ITAB-KTOKK.

    perform bdc_dynpro using 'SAPMF02K' '0110'.

    perform bdc_field using 'BDC_CURSOR'

    'LFA1-LAND1'.

    perform bdc_field using 'BDC_OKCODE'

    '/00'.

    perform bdc_field using 'LFA1-NAME1'

    • 'nehru'.

    ITAB-NAME1.

    perform bdc_field using 'LFA1-SORTL'

    • 'NE'.

    ITAB-SORTL.

    perform bdc_field using 'LFA1-LAND1'

    'in'.

    perform bdc_dynpro using 'SAPMF02K' '0120'.

    perform bdc_field using 'BDC_CURSOR'

    'LFA1-KUNNR'.

    perform bdc_field using 'BDC_OKCODE'

    '/00'.

    perform bdc_dynpro using 'SAPMF02K' '0310'.

    perform bdc_field using 'BDC_CURSOR'

    'LFM1-WAERS'.

    perform bdc_field using 'BDC_OKCODE'

    '/00'.

    perform bdc_field using 'LFM1-WAERS'

    'inr'.

    perform bdc_dynpro using 'SAPMF02K' '0320'.

    perform bdc_field using 'BDC_CURSOR'

    'RF02K-LIFNR'.

    perform bdc_field using 'BDC_OKCODE'

    '=ENTR'.

    perform bdc_dynpro using 'SAPLSPO1' '0300'.

    perform bdc_field using 'BDC_OKCODE'

    '=YES'.

    *perform bdc_transaction using 'MK01'.

    *perform close_group.

    CALL TRANSACTION 'MK01' USING BDCDATA

    UPDATE 'A'

    MODE 'A'

    MESSAGES INTO I_MSG.

    IF SY-SUBRC <> 0 .

    PERFORM ERROR.

    ENDIF.

    CLEAR BDCDATA.

    REFRESH BDCDATA.

    ENDLOOP.

    ----


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

    <b>form ERR .

    DATA V_MSG(255) TYPE C.

    READ TABLE I_MSG WITH KEY MSGTYP = 'E'.

    IF SY-SUBRC = 0.

    CALL FUNCTION 'FORMAT_MESSAGE'

    EXPORTING

    ID = I_MSG-MSGID

    LANG = 'E'

    NO = I_MSG-MSGNR

    V1 = I_MSG-MSGV1

    V2 = I_MSG-MSGV2

    V3 = I_MSG-MSGV3

    V4 = I_MSG-MSGV4

    IMPORTING

    MSG = V_MSG

    • 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 V_MSG. " Error Message Displayed Here.

    CLEAR V_MSG.

    ENDIF.

    endform. " ERR</b>

    The above Blocked Part for Handling Message Using <b>BDCMSGCOLL</b> Structure.

    Regards,

    Vijay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 09:46 AM

    Where as in call transaction method errors will store in BDCMSGCALL then u can clear that using the FM ---FORMAT_MESSEGE

    Batch Input and CALL TRANSACTION are both data transfer methods. Batch Input usually are used to transfer large amount of data. For example you are implementing a new SAP project, and of course you will need some data transfer from legacy system to SAP system. If there is no standard batch input program, direct input program, you would need to write your own data transfer program and it is going to be batch input program. CALL TRANSACTION methods is real-time method, whenever you run the program CALL TRANSACTION can be triggered. CALL TRANSACTION is used especially for integration actions between two SAP systems or between different modules. Users sometimes wish to do something like that click a button or an item then SAP would inserts or changes data automatically. Here CALL TRANSACTION should be considered. You use CALL TRANSACTION and you do everything automatically, collect necessary data, call transaction and so do database update. If any error occurs, show the user them.

    Batch Input

    With the Batch Input method, an ABAP program reads the external data that is to be entered in the R/3 System and stores the data in a “batch input session”. The session records the actions that are required to transfer data into the system using normal SAP transactions.

    When the program has generated the session, you can run the session to execute the SAP transactions in it. You can explicitly start and monitor a session with the batch input management function (by choosing System - Services - Batch Input), or have the session run in the background processing session.

    It offers management of sessions, support for playing back and correcting sessions that contain errors, and detailed logging. Your program prepares the data and stores it in a batch input session. A session is a collection of transaction data for one or more transactions. Batch input sessions are maintained by the system in the batch input queue. You can process batch input sessions in the background processing system.

    Your program must open a session in the queue before transferring data to it, and must close it again afterwards. All of these operations are performed by making function modules calls from the ABAP program.

    The most important aspects of the session interface are:

    Asynchronous processing

    Transfer data for multiple transactions

    Synchronous database update. During processing, no transaction is started until the previous transaction has been written to the database.

    A batch input processing log is generated for each session

    Sessions cannot be generated in parallel. The batch input program must not open a session until it has closed the preceding session.

    CALL TRANSACTION

    In the second method, your program uses the ABAP statement CALL TRANSACTION USING to run an SAP transaction. External data doesn’t have to be deposited in a session for later processing. Instead, the entire batch input process takes place inline in your program. With CALL TRANSACTION USING, the system process the data more quickly than with batch input sessions. Unlike batch input sessions, CALL TRANSACTION USING does not automatically support interactive correction or logging functions.

    Your program prepares the data and then calls the corresponding transaction that is then processed immediately.

    The most important features of CALL TRANSACTION USING are:

    Synchronous processing

    Transfer of data from an individual transaction each time the statement CALL TRANSACTION USING is called

    You can update the database both synchronously and asynchronously. The program specifies the update type.

    Separate LUW (Logical Units of Work) for the transaction. The system executes a database commit immediately before and after the CALL TRANSACTION USING statement.

    No batch input processing log

    Code used to create BDC

    &----


    *& Report ZBDC_EXAMPLE *

    *& *

    &----


    *& Example BDC program, which updates net price of item 00010 of a *

    *& particular Purchase order(EBELN). *

    *& *

    &----


    REPORT ZBDC_EXAMPLE NO STANDARD PAGE HEADING

    LINE-SIZE 132.

    *----


    • Data declaration

    TABLES: ekko, ekpo.

    TYPES: BEGIN OF t_ekko,

    ebeln TYPE ekko-ebeln,

    waers TYPE ekko-waers,

    netpr TYPE ekpo-netpr,

    err_msg(73) TYPE c,

    END OF t_ekko.

    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

    wa_ekko TYPE t_ekko,

    it_error TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

    wa_error TYPE t_ekko,

    it_success TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

    wa_success TYPE t_ekko.

    DATA: w_textout LIKE t100-text.

    DATA: gd_update TYPE i,

    gd_lines TYPE i.

    *Used to store BDC data

    DATA: BEGIN OF bdc_tab OCCURS 0.

    INCLUDE STRUCTURE bdcdata.

    DATA: END OF bdc_tab.

    *Used to stores error information from CALL TRANSACTION Function Module

    DATA: BEGIN OF messtab OCCURS 0.

    INCLUDE STRUCTURE bdcmsgcoll.

    DATA: END OF messtab.

    *----


    *Screen declaration

    SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME

    TITLE text-001. "Purchase order Num

    SELECT-OPTIONS: so_ebeln FOR ekko-ebeln OBLIGATORY.

    SELECTION-SCREEN END OF BLOCK block1.

    SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME

    TITLE text-002. "New NETPR value

    PARAMETERS: p_newpr(14) TYPE c obligatory. "LIKE ekpo-netpr.

    SELECTION-SCREEN END OF BLOCK block2.

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

    *START-OF-SELECTION

    START-OF-SELECTION.

    • Retrieve data from Purchase order table(EKKO)

    SELECT ekkoebeln ekkowaers ekpo~netpr

    INTO TABLE it_ekko

    FROM ekko AS ekko INNER JOIN ekpo AS ekpo

    ON ekpoebeln EQ ekkoebeln

    WHERE ekko~ebeln IN so_ebeln AND

    ekpo~ebelp EQ '10'.

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

    *END-OF-SELECTION

    END-OF-SELECTION.

    • Check data has been retrieved ready for processing

    DESCRIBE TABLE it_ekko LINES gd_lines.

    IF gd_lines LE 0.

    • Display message if no data has been retrieved

    MESSAGE i003(zp) WITH 'No Records Found'(001).

    LEAVE TO SCREEN 0.

    ELSE.

    • Update Customer master data (instalment text)

    LOOP AT it_ekko INTO wa_ekko.

    PERFORM bdc_update.

    ENDLOOP.

    • Display message confirming number of records updated

    IF gd_update GT 1.

    MESSAGE i003(zp) WITH gd_update 'Records updated'(002).

    ELSE.

    MESSAGE i003(zp) WITH gd_update 'Record updated'(003).

    ENDIF.

    • Display Success Report

    • **********************

    • Check Success table

    DESCRIBE TABLE it_success LINES gd_lines.

    IF gd_lines GT 0.

    • Display result report column headings

    PERFORM display_column_headings.

    • Display result report

    PERFORM display_report.

    ENDIF.

    • Display Error Report

    • ********************

    • Check errors table

    DESCRIBE TABLE it_error LINES gd_lines.

    • If errors exist then display errors report

    IF gd_lines GT 0.

    • Display errors report

    PERFORM display_error_headings.

    PERFORM display_error_report.

    ENDIF.

    ENDIF.

    &----


    *& Form DISPLAY_COLUMN_HEADINGS

    &----


    • Display column headings

    ----


    FORM display_column_headings.

    WRITE:2 ' Success Report '(014) COLOR COL_POSITIVE.

    SKIP.

    WRITE:2 'The following records updated successfully:'(013).

    WRITE:/ sy-uline(42).

    FORMAT COLOR COL_HEADING.

    WRITE:/ sy-vline,

    (10) 'Purchase Order'(004), sy-vline,

    (11) 'Old Netpr'(005), sy-vline,

    (11) 'New Netpr'(006), sy-vline.

    WRITE:/ sy-uline(42).

    ENDFORM. " DISPLAY_COLUMN_HEADINGS

    &----


    *& Form BDC_UPDATE

    &----


    • Populate BDC table and call transaction ME22

    ----


    FORM bdc_update.

    PERFORM dynpro USING:

    'X' 'SAPMM06E' '0105',

    ' ' 'BDC_CURSOR' 'RM06E-BSTNR',

    ' ' 'RM06E-BSTNR' wa_ekko-ebeln,

    ' ' 'BDC_OKCODE' '/00', "OK code

    'X' 'SAPMM06E' '0120',

    ' ' 'BDC_CURSOR' 'EKPO-NETPR(01)',

    ' ' 'EKPO-NETPR(01)' p_newpr,

    ' ' 'BDC_OKCODE' '=BU'. "OK code

    • Call transaction to update customer instalment text

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

    MESSAGES INTO messtab.

    • Check if update was succesful

    IF sy-subrc EQ 0.

    ADD 1 TO gd_update.

    APPEND wa_ekko TO it_success.

    ELSE.

    • Retrieve error messages displayed during BDC update

    LOOP AT messtab WHERE msgtyp = 'E'.

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

    ENDLOOP.

    • Build error table ready for output

    wa_error = wa_ekko.

    wa_error-err_msg = w_textout.

    APPEND wa_error TO it_error.

    CLEAR: wa_error.

    ENDIF.

    • Clear bdc date table

    CLEAR: bdc_tab.

    REFRESH: bdc_tab.

    ENDFORM. " BDC_UPDATE

    ----


    • FORM DYNPRO *

    ----


    • stores values to bdc table *

    ----


    • --> DYNBEGIN *

    • --> NAME *

    • --> VALUE *

    ----


    FORM dynpro USING dynbegin name value.

    IF dynbegin = 'X'.

    CLEAR bdc_tab.

    MOVE: name TO bdc_tab-program,

    value TO bdc_tab-dynpro,

    'X' TO bdc_tab-dynbegin.

    APPEND bdc_tab.

    ELSE.

    CLEAR bdc_tab.

    MOVE: name TO bdc_tab-fnam,

    value TO bdc_tab-fval.

    APPEND bdc_tab.

    ENDIF.

    ENDFORM. " DYNPRO

    &----


    *& Form DISPLAY_REPORT

    &----


    • Display Report

    ----


    FORM display_report.

    FORMAT COLOR COL_NORMAL.

    • Loop at data table

    LOOP AT it_success INTO wa_success.

    WRITE:/ sy-vline,

    (10) wa_success-ebeln, sy-vline,

    (11) wa_success-netpr CURRENCY wa_success-waers, sy-vline,

    (11) p_newpr, sy-vline.

    CLEAR: wa_success.

    ENDLOOP.

    WRITE:/ sy-uline(42).

    REFRESH: it_success.

    FORMAT COLOR COL_BACKGROUND.

    ENDFORM. " DISPLAY_REPORT

    &----


    *& Form DISPLAY_ERROR_REPORT

    &----


    • Display error report data

    ----


    FORM display_error_report.

    LOOP AT it_error INTO wa_error.

    WRITE:/ sy-vline,

    (10) wa_error-ebeln, sy-vline,

    (11) wa_error-netpr CURRENCY wa_error-waers, sy-vline,

    (73) wa_error-err_msg, sy-vline.

    ENDLOOP.

    WRITE:/ sy-uline(104).

    REFRESH: it_error.

    ENDFORM. " DISPLAY_ERROR_REPORT

    &----


    *& Form DISPLAY_ERROR_HEADINGS

    &----


    • Display error report headings

    ----


    FORM display_error_headings.

    SKIP.

    WRITE:2 ' Error Report '(007) COLOR COL_NEGATIVE.

    SKIP.

    WRITE:2 'The following records failed during update:'(008).

    WRITE:/ sy-uline(104).

    FORMAT COLOR COL_HEADING.

    WRITE:/ sy-vline,

    (10) 'Purchase Order'(009), sy-vline,

    (11) 'Netpr'(010), sy-vline,

    (73) 'Error Message'(012), sy-vline.

    WRITE:/ sy-uline(104).

    FORMAT COLOR COL_NORMAL.

    ENDFORM. " DISPLAY_ERROR_HEADINGS

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 22, 2007 at 09:47 AM

    Hi,

    define an internal table with structure BDCMSGCOLL and then u can use it to display messages..

    Reward if helpful.

    Regards,

    nagaraj

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 22, 2007 at 09:55 AM

    Hi Try out this... This will solve ur question...

    CALL TRANSACTION c_tcode USING gt_bdcdata

    MODE g_mode

    UPDATE c_update

    MESSAGES INTO gt_bdcmsgs.

    IF sy-subrc = 0.

    LOOP AT gt_bdcmsgs INTO wa_bdcmsgs.

    • Capturing the success message.

    PERFORM fill_success.

    ENDLOOP.

    ELSE.

    LOOP AT gt_bdcmsgs INTO wa_bdcmsgs.

    • Capturing the error message.

    PERFORM fill_error.

    ENDLOOP.

    FORM fill_success.

    DATA : l_message TYPE string. "Success or error message

    CALL FUNCTION 'FORMAT_MESSAGE'

    EXPORTING

    id = wa_bdcmsgs-msgid

    lang = sy-langu

    no = wa_bdcmsgs-msgnr

    v1 = wa_bdcmsgs-msgv1

    v2 = wa_bdcmsgs-msgv2

    v3 = wa_bdcmsgs-msgv3

    v4 = wa_bdcmsgs-msgv4

    IMPORTING

    msg = l_message

    EXCEPTIONS

    not_found = 1

    OTHERS = 2.

    IF sy-subrc = 0.

    • store the success messages and append into the internal table.

    wa_success-mesg = l_message.

    ENDIF.

    • Populate the table which you want

    APPEND wa_success TO gt_success.

    CLEAR: wa_success,

    wa_bdcmsgs.

    ENDFORM.

    Similarly u can do for error messages also..

    reward if found useful..

    thanks & regards,

    Prakash ghantasala

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.