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

Sample BDC pgm

Hi all,

Can u please provide a sample BDC program where the selection screen is not used and is used for call transaction. Thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 12:33 PM

    hi,

    here both the method

    REPORT zbdc_prds

    NO STANDARD PAGE HEADING LINE-SIZE 255.

    *INCLUDE bdcrecx1.

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

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

    --


    Call Transaction Method--

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

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

    PARAMETERS: p_file TYPE rlgrap-filename.

    DATA : BEGIN OF record OCCURS 0,

    matnr_001(018),

    maktx_003(040),

    END OF record.

    DATA : bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

    CALL FUNCTION 'F4_FILENAME'

    IMPORTING

    file_name = p_file.

    START-OF-SELECTION.

    PERFORM data_upload.

    PERFORM bdcdata.

    CALL TRANSACTION 'MM02' USING bdcdata MODE 'A' UPDATE 'A'.

    &----


    *& Form data_upload

    &----


    • text

    ----


    FORM data_upload.

    DATA : flnam TYPE string.

    flnam = p_file.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = flnam

    filetype = 'ASC'

    has_field_separator = 'X'

    TABLES

    data_tab = record

    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.

    ENDFORM. "data_upload

    &----


    *& Form bdcdata

    &----


    • text

    ----


    FORM bdcdata.

    LOOP AT record.

    PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'RMMG1-MATNR'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '=AUSW'.

    PERFORM bdc_field USING 'RMMG1-MATNR'

    record-matnr_001.

    PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'MSICHTAUSW-DYTXT(01)'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '=ENTR'.

    PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '=BU'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'MAKT-MAKTX'.

    PERFORM bdc_field USING 'MAKT-MAKTX'

    record-maktx_003.

    ENDLOOP.

    ENDFORM. "bdcdata

    ----


    • Start new screen *

    ----


    FORM bdc_dynpro USING program dynpro.

    CLEAR bdcdata.

    bdcdata-program = program.

    bdcdata-dynpro = dynpro.

    bdcdata-dynbegin = 'X'.

    APPEND bdcdata.

    ENDFORM. "BDC_DYNPRO

    ----


    • Insert field *

    ----


    FORM bdc_field USING fnam fval.

    CLEAR bdcdata.

    bdcdata-fnam = fnam.

    bdcdata-fval = fval.

    APPEND bdcdata.

    ENDFORM. "BDC_FIELD

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

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

    --


    Session Method--

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

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

    *DATA : BEGIN OF record OCCURS 0,

    • matnr_001(018),

    • maktx_003(040),

    • END OF record.

    *

    *DATA : bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

    *

    *PARAMETER : p_file TYPE rlgrap-filename.

    *

    *AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

    *

    • CALL FUNCTION 'F4_FILENAME'

    • IMPORTING

    • file_name = p_file.

    *

    *START-OF-SELECTION.

    *

    • PERFORM upload_file.

    • PERFORM open_group.

    • PERFORM bdcdata.

    • PERFORM close_group.

    *

    *&----


    **& Form upload_file

    *&----


    • text

    *----


    *FORM upload_file.

    *

    • DATA : loc_fil TYPE string.

    *

    • loc_fil = p_file.

    *

    • CALL FUNCTION 'GUI_UPLOAD'

    • EXPORTING

    • filename = loc_fil

    • filetype = 'ASC'

    • has_field_separator = 'X'

    • TABLES

    • data_tab = record

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

  • *

    *ENDFORM. "upload_file

    *

    *&----


    **& Form open_group

    *&----


    • text

    *----


    *FORM open_group.

    *

    • CALL FUNCTION 'BDC_OPEN_GROUP'

    • EXPORTING

    • client = sy-mandt

    • group = 'ZTEST_DS'

    • keep = 'X'

    • user = sy-uname

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

  • *

    *ENDFORM. "open_group

    *&----


    **& Form bdcdata

    *&----


    • text

    *----


    *FORM bdcdata.

    • LOOP AT record.

    *

    • PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.

    • PERFORM bdc_field USING 'BDC_CURSOR'

    • 'RMMG1-MATNR'.

    • PERFORM bdc_field USING 'BDC_OKCODE'

    • '=AUSW'.

    • PERFORM bdc_field USING 'RMMG1-MATNR'

    • record-matnr_001.

    • PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.

    • PERFORM bdc_field USING 'BDC_CURSOR'

    • 'MSICHTAUSW-DYTXT(01)'.

    • PERFORM bdc_field USING 'BDC_OKCODE'

    • '=ENTR'.

    • PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.

    • PERFORM bdc_field USING 'BDC_OKCODE'

    • '=BU'.

    • PERFORM bdc_field USING 'BDC_CURSOR'

    • 'MAKT-MAKTX'.

    • PERFORM bdc_field USING 'MAKT-MAKTX'

    • record-maktx_003.

    • PERFORM bdc_insert.

    *

    • ENDLOOP.

    *ENDFORM. "bdcdata

    *

    *&----


    **& Form close_group

    *&----


    • text

    *----


    *FORM close_group.

    • CALL FUNCTION 'BDC_CLOSE_GROUP'.

    • CALL TRANSACTION 'SM35'.

    *

    *ENDFORM. "close_group

    *

    *----


    • Start new screen *

    *----


    *FORM bdc_dynpro USING program dynpro.

    • CLEAR bdcdata.

    • bdcdata-program = program.

    • bdcdata-dynpro = dynpro.

    • bdcdata-dynbegin = 'X'.

    • APPEND bdcdata.

    *ENDFORM. "BDC_DYNPRO

    *

    *----


    • Insert field *

    *----


    *FORM bdc_field USING fnam fval.

    • CLEAR bdcdata.

    • bdcdata-fnam = fnam.

    • bdcdata-fval = fval.

    • APPEND bdcdata.

    *ENDFORM. "BDC_FIELD

    *

    *&----


    **& Form bdc_insert

    *&----


    • text

    *----


    *FORM bdc_insert.

    *

    • CALL FUNCTION 'BDC_INSERT'

    • EXPORTING

    • tcode = 'MM02'

    • TABLES

    • dynprotab = bdcdata.

    *

    *ENDFORM. "bdc_insert

Add a comment
10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 12:37 PM

    Hi

    *ASSIGNMENT – READING DATA FROM NOTE PAD INTO ITAB THEN INTO APPLICATION SERVER & DISPLAYING THE SAME IN TH ALV GRID DISPLAY.

    • USING SPLIT.

    TYPE-POOLS SLIS.

    DATA : FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV.

    DATA: WA_FIELDCATALOG TYPE SLIS_FIELDCAT_ALV.

    DATA: BEGIN OF I_VBAK OCCURS 0.

    DATA: MANDT LIKE VBAK-MANDT,

    VBELN LIKE VBAK-VBELN,

    ERDAT LIKE VBAK-ERDAT,

    ERZET LIKE VBAK-ERZET,

    ERNAM LIKE VBAK-ERNAM,

    ANGDT LIKE VBAK-ANGDT,

    END OF I_VBAK.

    DATA: BEGIN OF ITAB OCCURS 0,

    DATA TYPE STRING,

    END OF ITAB.

    DATA: FILE TYPE STRING .

    *DATA DATA TYPE STRING.

    START-OF-SELECTION.

    FILE = 'C:\Documents and Settings\ams03\Desktop\NOTE.TXT'.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    FILENAME = FILE

    FILETYPE = 'ASC'

    HAS_FIELD_SEPARATOR = 'X'

    • HEADER_LENGTH = 0

    • READ_BY_LINE = 'X'

    • DAT_MODE = ' '

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

    LOOP AT ITAB.

    SPLIT ITAB-DATA AT ',' INTO I_VBAK-MANDT I_VBAK-VBELN I_VBAK-ERDAT I_VBAK-ERZET I_VBAK-ERNAM I_VBAK-ANGDT.

    APPEND I_VBAK.

    CLEAR I_VBAK.

    ENDLOOP.

    *--OPEN DATASET.

    OPEN DATASET 'ZDANTEST' FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

    IF SY-SUBRC NE 0 .

    EXIT.

    ENDIF.

    IF SY-SUBRC EQ 0.

    LOOP AT I_VBAK.

    TRANSFER I_VBAK TO 'ZDANTEST'.

    ENDLOOP.

    *--CLOSE DATASET.

    CLOSE DATASET 'ZDANTEST'.

    WRITE : / 'FILE SUCCESSFULLY CREATED IN APPLICATION SERVER.'.

    ENDIF.

    *SPLIT NAMES AT ',' INTO ONE TWO THREE.

    LOOP AT I_VBAK.

    WRITE : / I_VBAK-MANDT, I_VBAK-VBELN, I_VBAK-ERDAT,

    I_VBAK-ERZET, I_VBAK-ERNAM,I_VBAK-ANGDT.

    ENDLOOP.

    INCLUDE ZFIELDCATLOG.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    • I_INTERFACE_CHECK = ' '

    • I_BYPASSING_BUFFER = ' '

    • I_BUFFER_ACTIVE = ' '

    • I_CALLBACK_PROGRAM = ' '

    • I_CALLBACK_PF_STATUS_SET = ' '

    • I_CALLBACK_USER_COMMAND = ' '

    • I_CALLBACK_TOP_OF_PAGE = ' '

    • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

    • I_CALLBACK_HTML_END_OF_LIST = ' '

    • I_STRUCTURE_NAME =

    • I_BACKGROUND_ID = ' '

    • I_GRID_TITLE =

    • I_GRID_SETTINGS =

    • IS_LAYOUT =

    IT_FIELDCAT = FIELDCATALOG

    • IT_EXCLUDING =

    • IT_SPECIAL_GROUPS =

    • IT_SORT =

    • IT_FILTER =

    • IS_SEL_HIDE =

    • I_DEFAULT = 'X'

    • I_SAVE = ' '

    • IS_VARIANT =

    • IT_EVENTS =

    • IT_EVENT_EXIT =

    • IS_PRINT =

    • IS_REPREP_ID =

    • I_SCREEN_START_COLUMN = 0

    • I_SCREEN_START_LINE = 0

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    • IT_ALV_GRAPHICS =

    • IT_HYPERLINK =

    • IT_ADD_FIELDCAT =

    • IT_EXCEPT_QINFO =

    • I_HTML_HEIGHT_TOP =

    • I_HTML_HEIGHT_END =

    • IMPORTING

    • E_EXIT_CAUSED_BY_CALLER =

    • ES_EXIT_CAUSED_BY_USER =

    TABLES

    T_OUTTAB = I_VBAK

    • EXCEPTIONS

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

    • INCLUDE PROGRAM

    &----


    *& Include ZFIELDCATLOG *

    &----


    WA_FIELDCATALOG-FIELDNAME = 'MANDT'.

    WA_FIELDCATALOG-REF_TABNAME = 'VBAK'.

    APPEND WA_FIELDCATALOG TO FIELDCATALOG.

    CLEAR WA_FIELDCATALOG.

    WA_FIELDCATALOG-FIELDNAME = 'VBELN'.

    WA_FIELDCATALOG-REF_TABNAME = 'VBAK'.

    WA_FIELDCATALOG-KEY = 'X'.

    APPEND WA_FIELDCATALOG TO FIELDCATALOG.

    CLEAR WA_FIELDCATALOG.

    WA_FIELDCATALOG-FIELDNAME = 'ERDAT'.

    WA_FIELDCATALOG-REF_TABNAME = 'VBAK'.

    APPEND WA_FIELDCATALOG TO FIELDCATALOG.

    CLEAR WA_FIELDCATALOG.

    WA_FIELDCATALOG-FIELDNAME = 'ERZET'.

    WA_FIELDCATALOG-REF_TABNAME = 'VBAK'.

    APPEND WA_FIELDCATALOG TO FIELDCATALOG.

    CLEAR WA_FIELDCATALOG.

    WA_FIELDCATALOG-FIELDNAME = 'ERNAM'.

    WA_FIELDCATALOG-REF_TABNAME = 'VBAK'.

    APPEND WA_FIELDCATALOG TO FIELDCATALOG.

    CLEAR WA_FIELDCATALOG.

    WA_FIELDCATALOG-FIELDNAME = 'ANGDT'.

    WA_FIELDCATALOG-REF_TABNAME = 'VBAK'.

    APPEND WA_FIELDCATALOG TO FIELDCATALOG.

    CLEAR WA_FIELDCATALOG.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 12:38 PM

    Hi

    the BDC program should be in this format

    Transaction Recorder (SHDB)

    How to Upload Presentation Server Flat file to SAP R/3 system???

    How to upload application server file to R/3 system?

    Definition

    Example - Call Transaction Method

    Transaction Recorder (SHDB)

    Before you work with the Batch Input methods, you should know the purpose of the tool

    Transaction Recorder.

    Use:

    You can use the transaction recorder to record a series of transactions and their screens.

    Features:

    You can use the recording to create

    Data transfer programs that use batch input or CALL TRANSACTION

    Batch input sessions

    Test data

    Function modules.

    Note: It doesn’t record F1, F4 and Scrollbar movements

    Upload Flat file from Presentation Server to SAP R/3

    CALL FUNCTION ‘GUI_UPLOAD'

    EXPORTING

    CODEPAGE = ‘IBM'

    FILENAME = P_UFILE

    FILETYPE = 'DAT'

    TABLES

    DATA_TAB = INT_TAB

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

    MESSAGE E999(FR) WITH 'ERROR IN FILE UPLOAD'.

    ENDIF.

    Upload file from application server to SAP R/3

    Open the the application server file

    OPEN DATASET <dsn> FOR INPUT <mode>

    Read the data from application server file

    READ DATASET <dsn> INTO <wa>

    And then close the application server file

    CLOSE DATASET <dsn>

    Definition- Declaring BDC Table

    DATA: BDC_TAB LIKE STANDARD TABLE OF

    BDCDATA INITIAL SIZE 6

    WITH HEADER LINE .

    The internal table used to collect the transaction’s information must be declared “LIKE BDCDATA”.

    Filling BDC Table – Method #1

    FORM FILL_BDC_TAB.

    REFRESH BDC_TAB.

    CLEAR BDC_TAB.

    BDC_TAB-PROGRAM = ‘SAPMF02K’.

    BDC_TAB-DYNPRO = ‘01016’.

    BDC_TAB-DYNBEGIN = ‘X’.

    APPEND BDC_TAB.

    CLEAR BDC_TAB.

    BDC_TAB-FNAM = ‘RF02K-LIFNR’.

    BDC_TAB-FVAL = ‘TEST1’.

    APPEND BDC_TAB.

    CLEAR BDC_TAB.

    BDC_TAB-FNAM = ‘RF02K-D0010’.

    BDC_TAB-FVAL = ‘X’.

    APPEND BDC_TAB.

    CLEAR BDC_TAB.

    BDC_TAB-PROGRAM = ‘SAPMF02K’.

    BDC_TAB-DYNPRO = ‘0110’.

    BDC_TAB-DYNBEGIN = ‘X’.

    APPEND BDC_TAB.

    CLEAR BDC_TAB.

    BDC_TAB-FNAM = ‘LFA1-STRAS’.

    BDC_TAB-FVAL = ‘123 Main St.’.

    APPEND BDC_TAB.

    CLEAR BDC_TAB.

    BDC_TAB-FNAM = ‘BDC_OKCODE’.

    BDC_TAB-FVAL = ‘/11’.

    APPEND BDC_TAB.

    ENDFORM.

    Filling BDC Table – Method #2

    FORM FILL_BDC_TAB.

    REFRESH BDC_TAB.

    PERFORM POPULATE_BDC_TAB

    USING:

    ‘1’ ‘SAPMF02K’ ‘0106’,

    ‘ ‘ ‘RF02K-LIFNR’ ‘TEST1’,

    ‘ ‘ ‘RF02K-D0010’ ‘X’,

    ‘1’ ‘SAPMF02K’ ‘0110’,

    ‘ ‘ ‘LFA1-STRAS’, ‘123 Main St.’,

    ‘ ‘ ‘BDC_OKCODE’, ‘/11’.

    ENDFORM.

    FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.

    CLEAR BDC_TAB.

    IF FLAG = ‘1’.

    BDC_TAB-PROGRAM = VAR1.

    BDC_TAB-DYNPRO = VAR2..

    BDC_TAB-DYNBEGIN = ‘X’.

    ELSE.

    BDC_TAB-FNAM = VAR1.

    BDC_TAB-FVAL = VAR2.

    ENDIF.

    APPEND BDC_TAB.

    ENDFORM.

    This two subroutine method to fill the BDC table is preferable because the “POPULATE_BDC_TABLE” subroutine is reusable throughout all batch input programs.

    Example #1 - Change Vendor (Call Transaction Method)

    Example #1- Declaration Section

    REPORT Y180DM10.

    DATA: BDC_TAB LIKE STANDARD TABLE OF

    BDCDATA INITIAL SIZE 6 WITH HEADER LINE.

    INFILE(20) VALUE ‘/tmp/bc180_file4’.

    DATA: BEGIN OF INREC.

    VENDNUM LIKE LFA1-LIFNR.

    STREET LIKE LFA1-STRAS.

    END OF INREC.

    PARAMETERS: DISPMODE DEFAULT ‘A’,

    UPDAMODE DEFAULT ‘S’.

    START-OF-SELECTION.

    OPEN DATASET INFILE

    FOR INPUT IN TEXT MODE.

    DO.

    READ DATASET INFILE INTO INREC.

    IF SY-SUBRC < > 0. EXIT. ENDIF.

    PERFORM FILL_BDC_TAB.

    CALL TRANSACTION ‘FK02’

    USING BDC_TAB

    MODE DISPMODE

    UPDATE UPDAMODE.

    IF SY-SUBRC < > 0.

    WRITE: /‘ERROR’.

    ENDIF.

    ENDDO.

    CLOSE DATASET INFILE.

    synchronous updating

    DO.

    ………

    PERFORM FILL_BDC_TAB.

    CALL TRANSACTION ‘FK02’

    USING BDC_TAB

    MODE ‘N’

    UPDATE ‘S’.

    IF SY-SUBRC < > 0.

    WRITE: /‘ERROR’.

    ENDIF.

    ENDDO.

    With synchronous updating, we can check SY-SUBRC to determine the success of the transaction and the actual update to the database.

    asynchronous updating

    DO.

    ………

    PERFORM FILL_BDC_TAB.

    CALL TRANSACTION ‘FK02’

    USING BDC_TAB

    MODE ‘N’

    UPDATE ‘A’.

    IF SY-SUBRC < > 0.

    WRITE: /‘ERROR’.

    ENDIF.

    ENDDO.

    With asynchronous updating, we can check SY-SUBRC to determine the success of the transaction only, not the actual update to the database.

    Error Handling

    Write an error report.

    Send the record(s) in error to an error file.

    Create a batch input session with the record(s) in error.

    To store error messages ( CALL TRANSACTION )

    data: begin of Tab_Mess occurs 0.

    include structure bdcmsgcoll.

    data : end of Tab_Mess,

    CALL TRANSACTION ‘FK02’ USING BDC_TAB MODE ‘N’ UPDATE ‘S’

    MESSAGES INTO TAB_MESS.

    IF SY-SUBRC NE 0.

    WRITE: / Tab_MESS-TCODE, Tab_MESS-DYNUMB, Tab_MESS-MSGTYP ,

    Tab_MESS-MSGID.

    ENDIF.

    i am giving you example for Change Vendor you practice for ur tcode

    For our example, we will use the “Change Vendor” transaction (“FK02”) to add a street address to an already existing vendor.

    Step #1

    Use “System&#61664;Status” menu path to determine online program name (SAPMF02K), screen number (0110)

    Step #2

    Use “F1” key and “Technical Info” pushbutton in each screen field to be filled to determine the field name.

    Step #3

    Determine how to proceed in the transaction

    (save the record by clicking on the ‘Save’ pushbutton or pressing the ‘F11’ key).

    BDC Table Contents

    After researching the transaction we can determine the contents of the BDC table.

    PROGRAM DYNPRO DYNBEGIN FNAM FVAL

    SAMPF02K 0106 X

    RF02K-LIFNR TEST1

    RF02K-D0110 X

    SAMPF02K 0110 X

    LFA1-STRAS 123 Main St.

    BDC_OKCODE /11

    Batch Input Methods

    “CALL TRANSACTION USING”

    STATEMENT

    Call transaction - for data transfer

    Processing batch input data with CALL TRANSACTION USING is the faster of the two recommended data transfer methods. In this method, legacy data is processed inline in your data transfer program.

    Syntax:

    CALL TRANSACTION <tcode>

    USING <bdc_tab>

    MODE <mode>

    UPDATE <update>

    A Display all

    E Display errors only

    N No display

    S Synchronous

    A Asynchronous

    L Local update

    The process flow of CALL TRANSACTION

    A program that uses CALL TRANSACTION USING to process legacy data should execute thefollowing steps:

    Prepare a BDCDATA structure for the transaction that you wish to run.

    Prepare a internal table to store error messages Tab_Mess like structure of BDCMSGCOLL.

    With a CALL TRANSACTION USING statement, call the transaction and prepare the BDCDATA structure. For example:

    CALL TRANSACTION ‘MM01' USING BDCDATA MODE 'A' UPDATE 'S'. MESSAGES INTO TAB_MESS.

    IF SY-SUBRC <> 0.

    <Error_handling>.

    ENDIF.

    Overview of Batch Input Session

    The first batch input method is to create a batch input session. It is the processing of this batch input session that updates the database, not the execution of the batch input program.

    check the below links also

    http://help.sap.com/saphelp_47x200/helpdata/en/fa/097022543b11d1898e0000e8322d00/frameset.htm

    chk this pdf file

    http://www.sappoint.com/abap/bdcconcept.pdf

    chk this for FAQs on BDC

    http://www.sap-img.com/abap/question-about-bdc-program.htm

    sample code for call transaction method

    http://www.sapdevelopment.co.uk/bdc/bdc_ctcode.htm

    chk this for BDC recording with screen shots

    http://www.sapdevelopment.co.uk/bdc/bdc_recording.htm

    BDC

    http://www.sap-img.com/bdc.htm

    Table control in BDC

    http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm

    check these..

    http://www.sap-img.com/abap/learning-bdc-programming.htm

    http://help.sap.com/saphelp_47x200/helpdata/en/69/c250684ba111d189750000e8322d00/frameset.htm

    http://myweb.dal.ca/hchinni/sap/bdc_home.htm

    http://www.sap-img.com/abap/learning-bdc-programming.htm

    http://www.sapdevelopment.co.uk/bdc/bdchome.htm

    http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm

    <b>Reward if useful</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 12:42 PM

    THIS IS CALL TRANSACTION METHOD.

    TCODE 'MK01'.

    Also Error handling Code.

    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.

    &----


    *& Form ERROR

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form ERROR .

    DATA: V_ER(250) TYPE C .

    READ TABLE I_MSG WITH KEY MSGTYP = 'E'.

    CALL FUNCTION 'FORMAT_MESSAGE'

    EXPORTING

    ID = SY-MSGID

    LANG = '-D'

    NO = SY-MSGNO

    V1 = SY-MSGV1

    V2 = SY-MSGV2

    V3 = SY-MSGV3

    V4 = SY-MSGV4

    IMPORTING

    MSG = V_ER

    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:/ 'ERROR MSG', V_ER.

    CLEAR:I_MSG, BDCDATA.

    REFRESH: I_MSG , BDCDATA.

    endform. " ERROR

    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.