Insert Vs BDC

Hi all,
i want to upload foriegn exchage rate to SAP tcode OB08.
1. i'm directly insert (using INSERT command) to  TCURR table.
is it ok or we can write BDC which one is best.
but TCURR table is a configuration table.
pleae suggest which method is best.
thanks

Hi,
Never insert data into Std. tables just like that. It will lead to operational issues. Always use BDC or BAPI. If you find a BAPI for this good. Or else write a BDC.
When writing a BDC Remember if you have to put data into a table control. every field is identified by a line no.
For example:
Consider the field Dir.Quot RFCU9-KURSP if you want to update a new value in this field. Each Line item will be represented as
RFCU9-KURSP(1)
RFCU9-KURSP(2)
RFCU9-KURSP(3)
RFCU9-KURSP(4)
RFCU9-KURSP(5)
Regards,
VIjay

Similar Messages

  • Issue while inserting a BDC program in Inbound Proxy.JDBC-- PI-- SAP.

    The scenerio is jdbcsender-sappi-inboundproxy(ECC6.0).
    The issue is related to SAP Plant Maintenance Module where  We have a requirement for creating Maintenance item
    programmatically from (SQLDatabase)Legacy Data for one of the interface.
    since there are no standard BAPIS/Idocs or function modules available from SAP side for creating the maintenance item. So I
    have written BDC program and with the help of submit statement in inbound proxy program, I am calling BDC program for
    creation of the maintenance item.
    When I tested the program independently on proxy side  the Maintenance Item is getting created successfully but when I
    executed from end-to-end ie.  SQLDATABASE->SAP PI-->SAP. The message is getting strucked into the queue and queue  got stopped on SAP.
    ECC side and the status of the message is scheduled state  on SXMB_MONI  transaction of SAP ECC.
    As the message  is in scheduled state multiple number of Maintenance Items are getting created with the same values.
    Has any one of our SAP friends, encountered this type of issue while inserting a BDC program in inbound proxy, please help 
    in fixing this issue. FYI... I am using sap pi7.0 with service pack 24 and ecc6.0
    Waiting for your kind expert guidance...
    cheers,
    Ram

    Raj,
    Thanks for the reply. I have tried registering the queues but still the same problem. the message got stuck in the queue of ECC and showing below message in queue.
    function module                                    StatusText
    SXMS_ASYNC_EXEC                  connection closed (no data)
    I have checked in the forums especially  for this issue but no one has provided the answer for this.
    Thanks and Regards
    Ram

  • Differences between LSMW and BDC

    Hi All
    Please can you give me the few points about the differences between LSMW and BDC?
    Awaiting for your Responce
    Praveen

    Hai Check with the following document
    GOOD
    THERE IS THREE TYPE OF METHOD IN BDC
    BDC SESSION
    CALL TRANSACTION
    CALL DIALOG
    What is BDC or batch input
    The Batch Input is a SAP technic that allows automating the input in transactions. It lies on a BDC (Batch Data Commands) scenario.
    BDC functions:
    · BDC_OPEN_GROUP : Opens a session group
    · BDC_CLOSE_GROUP : Closes a session
    · BDC_INSERT : Insert a BDC scenario in the session
    · The ABAP statement "CALL TRANSACTION" is also called to run directly a transaction from its BDC table.
    It runs the program RSBDCSUB in order to launch automatically the session. The session management is done through the transaction code SM35.
    The object itself is maintanable through the transaction SE24.
    BDC methods:
    Method
    Description
    Parameters
    OPEN_SESSION
    Opens a session
    SUBRC (Return Code – 0 OK)
    SESSIONNAME (Session to be created)
    CLOSE_SESSION
    Closes a session
    None
    RESET_BDCDATA
    Resets the BDC Internal Table...
    None. Normally, for internal purpose…
    BDC_DYNPRO
    Handles a new screen
    PROGNAME (Name of the program)
    DYNPRONR (Screen Number)
    BDC_FIELD
    Puts a value on the screen
    FIELDNAME (Name of the field)
    FIELDVALUE (Value to be passed)
    CONSTRUCTOR
    Constructor - Initializes NO_DATA
    NODATA (No data character). The constructor is called automatically when the object is created.
    RUN_SESSION
    Launches a session with RSBDCBTC
    None
    CALL_TRANSACTION
    Calls a transaction with the current BDC Data
    MODE (Display Mode)
    UPDATE (Update Mode)
    TCODE (Transaction to be called)
    BDC_INSERT
    Inserts the BDC scenario in the session
    TCODE (Transaction to be called)
    BDC techniques used in programs:
    1) Building a BDC table and calling a transaction,
    2) Building a session and a set of BDC scenarios and keeping the session available in SM35,
    3) Building a session and lauching the transaction right after closing the session.
    BDC using Call Transaction
    BDC using Call transaction involves calling an SAP transaction in back ground from within the ABAP
    program. The process involves building an Internal BDC table containing the screen information needed to
    execute the required transaction and then passing this to the Call transaction command (See code example).
    The full procedure for creating a BDC program is as follows:
    What is the difference between batch input and call transaction in BDC?
    Session method.
    1) synchronous processing.
    2) can tranfer large amount of data.
    3) processing is slower.
    4) error log is created
    5) data is not updated until session is processed.
    Call transaction.
    1) asynchronous processing
    2) can transfer small amount of data
    3) processing is faster.
    4) errors need to be handled explicitly
    5) data is updated automatically
    BATINPUT/DIRECT INPUT
    A: Batch-inputs can not be used to fill the "delivery due list" screen because it is not a dynpro. This is a standard SAP report. A SAP report (check with "System -> Status") may be called using SUBMIT sentence with the appropriate options . It is preferred to call a report than create a Batch-input program.
    GO THROUGH THIS LINK
    http://www.guidancetech.com/people/holland/sap/abap/zzsni001.htm
    The LSM Workbench is an SAP R/3 based tool that supports the one-time or periodic transfer of data from non-SAP systems ("legacy systems") to SAP systems.
    The LSM Workbench helps you to organize your data migration project and guides you through the process by using a clear sequence of steps.
    The most common conversion rules are predefined. Reusable conversion rules assure consistent data conversion for different data objects.
    LSMW vs DX Workbench
    The LSM Workbench covers the following steps:
    Read the legacy data from one or several files (e.g. spreadsheet tables, sequential files).
    Convert the data from source format to target format.
    Import the data using standard interfaces (Batch Input, Direct Input, BAPI, IDoc).
    Experiences made in successful implementation projects have shown that using the LSM Workbench significantly contributes to accelerating data migration.
    SAP provides this tool along with documentation to customers and partners free of charge.
    Users of the LSM Workbench receive the usual support via SAP Net - R/3 Frontend (component BC-SRV-DX-LSM).
    Releases:
    Version 1.7.2 of the LSM Workbench ("LSMW 1.7.2") available
    Attention : LSMW 1.7.2 requires an SAP R/3 system with SAP R/3 4.0 or SAP R/3 4.5.
    Version 1.8.0 of the LSM Workbench (1.21mb) ("LSMW 1.8.0") available
    Attention : LSMW 1.8.0 requires an SAP R/3 system with SAP R/3 4.6.
    Version 3.0 of the LSM Workbench (1.89mb) ("LSMW 3.0") available for Web Application Server 6.10
    Attention : LSMW 3.0 requires a SAP WAS 6.10. Functionality of version 1.7.2 and 3.0 are identical !
    Version 4.0 of the LSM Workbench ("LSMW 4.0") integrated in Web Application Server 6.20
    Attention : LSMW 4.0 is an integrated part of SAP WAS 6.20.
    Thanks & regards
    Sreenivasulu P
    Message was edited by: Sreenivasulu Ponnadi

  • BDC report for BOM master

    can any body help me to do one bdc for
    BOM master?? i m doing this first time so i need some input
    thanks well in advance.
    points ll be rewarded...
    Message was edited by:
            soumya shekhar

    hi
    good
    When you try to create, you would find a pushbutton 'INSERT NEW LINES' or something simialr to enter your data in the next line. Say you're entering the Material inthe first row, its field position would be MARA-MATNR(01). Now when you click the Insert Pushbitton the cursor always is at positon 2. so you have to loop the remaining data to enter in MARA-MATNR(02). Yougenereally set a counter and pass that counter value (in this case the counter value is 2 always)
    The other case when you don't have a push button to Insert. Enter all the rows and then do a Page down. Now your cursor would sit back at position 2 again. Say if there are 20 rows in the first screen. You would keep incrementing the counter and then when it is 21 you do a pagedown and then reset the counter to 2. You loop the pagedown and in it you loop the counter.
    I have attached a BDC where I use the second case (no push button). Do a recording and then you would know all the answers by yourself.
    *& REPORT ZPP0122 *
    *& Module : PP |
    *& Application : The program loads the Material Assignment of Routings |
    *& |
    REPORT zpp0122 NO STANDARD PAGE HEADING
    MESSAGE-ID z0
    LINE-SIZE 132
    LINE-COUNT 65(2).
    Internal Tables *
    *Internal table for the Routing fields.
    DATA: BEGIN OF i_rout OCCURS 0,
    plnnr(8),
    plnal(2),
    matnr(18),
    werks(4),
    END OF i_rout.
    DATA:
    g_my_rec_in LIKE i_rout.
    Declare internal table for Call Transaction and BDC Session
    DATA: i_bdc_table LIKE bdcdata OCCURS 0 WITH HEADER LINE.
    Global Variables *
    DATA: g_counter(2) TYPE n,
    g_field_name(18) TYPE c,
    zc_yes TYPE syftype VALUE 'X'.
    Selection Screen *
    SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
    PARAMETERS: p_fname1 TYPE localfile .
    SELECTION-SCREEN SKIP 1.
    SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
    PARAMETERS: p_rloc1 AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-005.
    PARAMETERS p_group(12) OBLIGATORY DEFAULT 'ZROUTING'.
    SELECTION-SCREEN END OF BLOCK c.
    SELECTION-SCREEN END OF BLOCK b.
    SELECTION-SCREEN END OF BLOCK a.
    **WRITE the report header
    TOP-OF-PAGE.
    INCLUDE zheading.
    Start of selection *
    START-OF-SELECTION.
    Load Input file
    PERFORM f_load_input_file.
    Create BDC records.
    PERFORM create_bdc_records .
    *& Form Create_BDC_records
    perform the BDC for the records in the internal table
    FORM create_bdc_records .
    IF NOT i_rout[] IS INITIAL.
    Open BDC session
    PERFORM open_bdc_session.
    LOOP AT i_rout.
    g_my_rec_in = i_rout.
    AT NEW plnnr.
    CLEAR i_bdc_table[].
    PERFORM insert_screen_header.
    ENDAT.
    CONCATENATE 'MAPL-PLNAL(' g_counter ')' INTO g_field_name.
    PERFORM bdc_field USING g_field_name i_rout-plnal.
    CONCATENATE 'MAPL-MATNR(' g_counter ')' INTO g_field_name.
    PERFORM bdc_field USING g_field_name i_rout-matnr.
    CONCATENATE 'MAPL-WERKS(' g_counter ')' INTO g_field_name.
    PERFORM bdc_field USING g_field_name i_rout-werks.
    PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
    g_counter = g_counter + 1.
    Page Down for further entries
    IF g_counter = 19.
    PERFORM bdc_field USING 'BDC_OKCODE' '=P+'.
    PERFORM bdc_dynpro USING 'SAPLCZDI' '1010'.
    g_counter = 2.
    ENDIF.
    AT END OF plnnr.
    PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'.
    PERFORM bdc_dynpro USING 'SAPLCPDI' '1200'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.
    PERFORM insert_bdc_new.
    ENDAT.
    ENDLOOP.
    CLEAR i_rout[].
    PERFORM close_bdc_session.
    Release the BDC sessions created
    PERFORM release_bdc.
    ENDIF.
    ENDFORM. " open_group
    *& Form bdc_dynpro_start
    Call the screen for the input of fields
    -->P_G_PROGRAM_1
    -->P_G_SCREEN
    FORM bdc_dynpro USING p_g_program_1
    p_g_screen.
    CLEAR i_bdc_table.
    i_bdc_table-program = p_g_program_1.
    i_bdc_table-dynpro = p_g_screen.
    i_bdc_table-dynbegin = 'X'.
    APPEND i_bdc_table.
    ENDFORM. " bdc_dynpro_start
    *& Form bdc_field
    Insert field *
    FORM bdc_field USING f_name f_value.
    IF f_value <> space.
    CLEAR i_bdc_table.
    i_bdc_table-fnam = f_name.
    i_bdc_table-fval = f_value.
    APPEND i_bdc_table.
    ENDIF.
    ENDFORM. "bdc_insert_field
    *& Form open_bdc_session
    Create the BDC session
    FORM open_bdc_session .
    Open BDC session and creat and update condition records
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
    client = sy-mandt
    DEST = FILLER8
    group = p_group
    HOLDDATE = FILLER8
    keep = 'X'
    user = sy-uname
    RECORD = FILLER1
    PROG = SY-CPROG
    IMPORTING
    QID =
    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. " create_bdc_session
    *& Form insert_screen_header
    Header Data inserted
    FORM insert_screen_header .
    g_counter = 1.
    First screen
    PERFORM bdc_dynpro USING 'SAPLCPDI' '1010'.
    PERFORM bdc_field USING 'BDC_CURSOR' 'RC271-PLNNR'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=ALUE'.
    PERFORM bdc_field USING 'RC271-PLNNR' g_my_rec_in-plnnr.
    PERFORM bdc_field USING 'RC27M-MATNR' ' '.
    PERFORM bdc_field USING 'RC27M-WERKS' ' '.
    PERFORM bdc_field USING 'RC271-PLNAL' ' '.
    *next screen
    PERFORM bdc_dynpro USING 'SAPLCPDI' '1200'.
    PERFORM bdc_field USING 'BDC_OKCODE' '=MTUE'.
    *next screen
    PERFORM bdc_dynpro USING 'SAPLCZDI' '1010'.
    ENDFORM. " insert_screen_header
    *& Form insert_bdc
    Insert the BDC for the transaction
    FORM insert_bdc_new .
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
    tcode = 'CA02'
    POST_LOCAL = NOVBLOCAL
    PRINTING = NOPRINT
    SIMUBATCH = ' '
    CTUPARAMS = ' '
    TABLES
    dynprotab = i_bdc_table
    EXCEPTIONS
    internal_error = 1
    not_open = 2
    queue_error = 3
    tcode_invalid = 4
    printing_invalid = 5
    posting_invalid = 6
    OTHERS = 7
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    CLEAR i_bdc_table[].
    ENDFORM. " insert_bdc
    *& Form close_bdc_session
    Close the session
    FORM close_bdc_session .
    CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
    not_open = 1
    queue_error = 2
    OTHERS = 3.
    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. " close_bdc_session
    *& Form f_load_input_file
    Load the data file
    FORM f_load_input_file.
    The data file is from Presentation server
    IF p_rloc1 = zc_yes.
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
    filename = p_fname1
    filetype = 'DAT'
    TABLES
    data_tab = i_rout
    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.
    EXIT.
    ENDIF.
    ENDIF.
    ENDFORM. " f_load_input_file
    *& Form release_bdc
    Release BDC session
    FORM release_bdc.
    SUBMIT rsbdcsub WITH mappe EQ p_group
    WITH von EQ sy-datum
    WITH bis EQ sy-datum
    WITH fehler EQ '.'
    EXPORTING LIST TO MEMORY
    AND RETURN.
    ENDFORM.
    reward point if helpful.
    thanks
    mrutyun^

  • BDC using session method

    hai
    can anyone post me bdc using session method plz

    Hi,
    ABAP BDC SESSION METHOD SAMPLE CODE
    pool of form routines
    include zmppn001.
    Define BDC Table Structure
    data: begin of itab_bdc_tab occurs 0.
    include structure bdcdata.
    data: end of itab_bdc_tab.
    Input record layout of Leagcy File
    data: begin of itab_xcel occurs 0,
    matnr(18) type c,
    werks(4) type c,
    alnag(2) type c,
    verid(4) type c,
    text1(40) type c,
    bstmi like mkal-bstmi,
    bstma like mkal-bstma,
    adatu(10) type c,
    bdatu(10) type c,
    stlal(2) type c,
    stlan(1) type c,
    serkz(1) type c,
    mdv01(8) type c,
    elpro(4) type c,
    alort(4) type c,
    end of itab_xcel.
    data: begin of lt_pp04_cache occurs 0,
    matnr like itab_xcel-matnr,
    werks like itab_xcel-werks,
    alnag like itab_xcel-alnag,
    plnnr like mapl-plnnr,
    arbpl like crhd-arbpl,
    ktext like crtx-ktext,
    end of lt_pp04_cache.
    data: v_ssnnr(4) type n,
    v_lines_in_xcel like sy-tabix,
    v_ssnname like apqi-groupid,
    v_trans_in_ssn type i,
    wa_xcel LIKE itab_xcel,
    l_tabix like sy-tabix,
    v_matnr like rc27m-matnr,
    v_plnnr like mapl-plnnr,
    v_plnal like mapl-plnal,
    v_tcode like sy-tcode value 'C223',
    v_plnty like plas-plnty value 'R',
    v_objty like crhd-objty value 'A',
    v_plpo_steus like plpo-steus value 'PP04',
    v_verwe like crhd-verwe value '0007'.
    Parameters
    selection-screen: skip 3.
    selection-screen: begin of block 1 with frame.
    parameters: p_name like rlgrap-filename
    default 'C:\My Documents\InputFile.txt'
    obligatory,
    bdc session name prefix
    p_bdcpfx(6) default 'ZPVCRT'
    obligatory,
    number for transction per BDC session
    p_trnssn type i
    default 2000 obligatory,
    retain the BDC session after successfull execution
    p_keep like apqi-qerase
    default 'X',
    user who will be executing BDC session
    p_uname like apqi-userid
    default sy-uname
    obligatory.
    selection-screen: end of block 1.
    possible entry list (F4 dropdown) for input file name
    at selection-screen on value-request for p_name.
    *-SELECT FILE FROM USERS LOCAL PC
    call function 'WS_FILENAME_GET'
    exporting
    DEF_FILENAME = ' '
    def_path = 'C:\Temp\'
    mask = ',.,..'
    mode = 'O'
    title = 'Select File '(007)
    importing
    filename = p_name
    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.
    begin the show
    start-of-selection.
    read data from input file
    perform transfer_xcel_to_itab.
    loop at itab_xcel.
    hang on to xcel line num
    l_tabix = sy-tabix.
    each line in the xcel file marks begining of new prod.version defn
    if num-of-trnas-in-session = 0, create new BDC session
    if v_trans_in_ssn is initial.
    perform bdc_session_open.
    endif.
    begin new bdc script for rtg create trans
    fill in bdc-data for prod.version maintenance screens
    perform bdc_build_script.
    insert the bdc script as a BDC transaction
    perform bdc_submit_transaction.
    keep track of how many BDC transactions were inserted in the BDC
    session
    add 1 to v_trans_in_ssn.
    if the user-specified num of trans in BDC session is reached OR
    if end of input file is reached, close the BDC session
    if v_trans_in_ssn = p_trnssn or
    l_tabix = v_lines_in_xcel.
    perform bdc_session_close.
    clear v_trans_in_ssn.
    endif.
    endloop.
    top-of-page.
    call function 'Z_HEADER'
    EXPORTING
    FLEX_TEXT1 =
    FLEX_TEXT2 =
    FLEX_TEXT3 =
    FORM TRANSFER_XCEL_TO_ITAB *
    Transfer Xcel Spreadsheet to SAP Internal Table *
    form transfer_xcel_to_itab.
    Read the tab-delimited file into itab
    call function 'WS_UPLOAD'
    exporting
    filename = p_name
    filetype = 'DAT'
    IMPORTING
    filelength = flength
    tables
    data_tab = itab_xcel
    exceptions
    conversion_error = 1
    file_open_error = 2
    file_read_error = 3
    invalid_table_width = 4
    invalid_type = 5
    no_batch = 6
    unknown_error = 7
    others = 8.
    if sy-subrc = 0.
    sort the data
    sort itab_xcel by matnr werks.
    clear v_lines_in_xcel.
    if no data in the file - error out
    describe table itab_xcel lines v_lines_in_xcel.
    if v_lines_in_xcel is initial.
    write: / 'No data in input file'.
    stop.
    endif.
    else.
    if file upload failed - error out
    write: / 'Error reading input file'.
    stop.
    endif.
    endform.
    FORM BDC_SESSION_OPEN *
    Open BDC Session *
    form bdc_session_open.
    create bdc session name = prefix-from-selectn-screen + nnnn
    add 1 to v_ssnnr.
    concatenate p_bdcpfx v_ssnnr into v_ssnname.
    open new bdc session
    call function 'BDC_OPEN_GROUP'
    exporting
    client = sy-mandt
    group = v_ssnname
    keep = p_keep
    user = p_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.
    endform.
    FORM BDC_BUILD_SCRIPT *
    Build BDC *
    form bdc_build_script.
    data: l_arbpl like crhd-arbpl,
    l_text1 like mkal-text1,
    l_mdv01 like mkal-mdv01,
    l_mapl like mapl.
    clear bdc-data itab - begin of new bdc transaction
    clear itab_bdc_tab.
    refresh itab_bdc_tab.
    read material cross reference tables to determine sap part#
    clear : v_matnr, v_plnnr, v_plnal.
    perform read_matnr_cross_ref using itab_xcel-matnr
    itab_xcel-werks
    changing v_matnr.
    determine the version description to use
    if itab_xcel-text1 is initial.
    l_text1 = itab_xcel-verid.
    else.
    l_text1 = itab_xcel-text1.
    endif.
    determine the routing group# and group ctr# to use
    perform read_routing .
    determine the production line to use
    if itab_xcel-mdv01 is initial.
    if not provided in the file then:
    prod line = work ctr on the last PP04 op of the rtg determined above
    perform read_wc_on_last_pp04 using v_plnnr v_plnal
    changing l_mdv01.
    NOTE: when executing the above form\routine, if v_plnnr is initial
    or v_plnal is initial, THEN l_mdv01 will automatically be
    returned blank (ie initial)
    else.
    l_mdv01 = itab_xcel-mdv01.
    endif.
    build bdc script
    perform bdc_build_script_record
    fill in initial screen
    using: 'X' 'SAPLCMFV' '1000',
    ' ' 'BDC_OKCODE' '=ENTE',
    ' ' 'MKAL-WERKS' itab_xcel-werks,
    ' ' 'MKAL-MATNR' v_matnr,
    ' ' 'MKAL_ADMIN-DISPO' space,
    ' ' 'MKAL-PLNNR' space,
    ' ' 'MKAL_ADMIN-STTAG' space,
    ' ' 'MKAL-PLNNG' space,
    ' ' 'MKAL-MDV01' space,
    ' ' 'MKAL-PLNNM' space,
    click create button on initial screen and go to detail screen
    'X' 'SAPLCMFV' '1000',
    ' ' 'BDC_OKCODE' '=CREA',
    fill in the detail screen and go back to initial screen
    'X' 'SAPLCMFV' '2000',
    ' ' 'BDC_OKCODE' '=CLOS',
    ' ' 'MKAL_EXPAND-MATNR' v_matnr,
    ' ' 'MKAL_EXPAND-VERID' itab_xcel-verid,
    ' ' 'MKAL_EXPAND-TEXT1' l_text1,
    ' ' 'MKAL_EXPAND-BSTMI' itab_xcel-bstmi,
    ' ' 'MKAL_EXPAND-BSTMA' itab_xcel-bstma,
    ' ' 'MKAL_EXPAND-ADATU' itab_xcel-adatu,
    ' ' 'MKAL_EXPAND-BDATU' itab_xcel-bdatu,
    ' ' 'MKAL_EXPAND-PLTYG' v_plnty,
    ' ' 'MKAL_EXPAND-PLNNG' v_plnnr,
    ' ' 'MKAL_EXPAND-ALNAG' v_plnal,
    ' ' 'MKAL_EXPAND-STLAL' itab_xcel-stlal,
    ' ' 'MKAL_EXPAND-STLAN' itab_xcel-stlan,
    ' ' 'MKAL_EXPAND-SERKZ' itab_xcel-serkz,
    ' ' 'MKAL_EXPAND-MDV01' l_mdv01,
    ' ' 'MKAL_EXPAND-ELPRO' itab_xcel-elpro,
    ' ' 'MKAL_EXPAND-ALORT' itab_xcel-alort,
    save the production version from initial screen
    'X' 'SAPLCMFV' '1000',
    ' ' 'BDC_OKCODE' '=SAVE'.
    endform.
    FORM BDC_SUBMIT_TRANSACTION *
    Submit BDC Session *
    form bdc_submit_transaction.
    Load BDC script as a trqansction in BDC session
    call function 'BDC_INSERT'
    exporting
    tcode = v_tcode
    tables
    dynprotab = itab_bdc_tab
    exceptions
    internal_error = 01
    not_open = 02
    queue_error = 03
    tcode_invalid = 04.
    endform.
    FORM BDC_BUILD_SCRIPT_RECORD *
    form bdc_build_script_record using dynbegin name value.
    clear itab_bdc_tab.
    if dynbegin = 'X'.
    move: name to itab_bdc_tab-program,
    value to itab_bdc_tab-dynpro,
    'X' to itab_bdc_tab-dynbegin.
    else.
    move: name to itab_bdc_tab-fnam,
    value to itab_bdc_tab-fval.
    shift itab_bdc_tab-fval left deleting leading space.
    endif.
    append itab_bdc_tab.
    endform.
    FORM BDC_SESSION_CLOSE *
    Close BDC Session *
    form bdc_session_close.
    close the session
    call function 'BDC_CLOSE_GROUP'
    exceptions
    not_open = 1
    queue_error = 2
    others = 3.
    skip 2.
    if sy-subrc ne 0.
    write: / 'Error Closing BDC Session ' , 'RETURN CODE: ', sy-subrc.
    else.
    write : / 'Session created:', v_ssnname,
    50 '# of transactions:', v_trans_in_ssn.
    endif.
    endform.
    *& Form read_routing_cache
    *FORM read_routing_cache USING pi_matnr
    pi_werks
    pi_alnag
    pi_verid
    pi_mdv01.
    DATA: BEGIN OF lt_plpo OCCURS 0,
    vornr LIKE plpo-vornr,
    objty LIKE crhd-objty,
    objid LIKE crhd-objid,
    arbpl LIKE crhd-arbpl,
    END OF lt_plpo,
    l_mapl_plnnr LIKE mapl-plnnr.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    IF sy-subrc = 0.
    do nothing - lt_pp04_cache header line has rtg#
    ELSE.
    get the routing group # from MAPL
    SELECT plnnr INTO l_mapl_plnnr
    FROM mapl UP TO 1 ROWS
    WHERE matnr = pi_matnr AND
    werks = pi_werks AND
    plnty = 'R' AND
    plnal = pi_alnag AND
    loekz = space.
    ENDSELECT.
    put it in the cache internal table
    IF NOT l_mapl_plnnr IS INITIAL.
    lt_pp04_cache-matnr = pi_matnr.
    lt_pp04_cache-werks = pi_werks.
    lt_pp04_cache-alnag = pi_alnag.
    lt_pp04_cache-plnnr = l_mapl_plnnr.
    APPEND lt_pp04_cache.
    ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
    lt_pp04_cache-arbpl IS INITIAL AND
    ( pi_verid IS INITIAL OR
    pi_mdv01 IS INITIAL ).
    read the last PP04 operation
    CLEAR lt_plpo.
    REFRESH lt_plpo.
    SELECT vornr eobjty eobjid e~arbpl
    INTO CORRESPONDING FIELDS OF TABLE lt_plpo
    FROM plas AS b
    INNER JOIN plpo AS c
    ON bplnty = cplnty AND
    bplnnr = cplnnr AND
    bzaehl = czaehl
    INNER JOIN crhd AS e
    ON carbid = eobjid
    WHERE b~plnty = v_plnty AND
    b~plnnr = lt_pp04_cache-plnnr AND
    b~plnal = lt_pp04_cache-alnag AND
    c~loekz = space AND
    c~steus = v_plpo_steus AND
    e~objty = v_objty AND
    e~werks = lt_pp04_cache-werks AND
    e~verwe = v_verwe.
    SORT lt_plpo BY vornr DESCENDING.
    READ TABLE lt_plpo INDEX 1.
    IF NOT lt_plpo-arbpl IS INITIAL.
    lt_pp04_cache-arbpl = lt_plpo-arbpl.
    read work center description
    SELECT SINGLE ktext INTO lt_pp04_cache-ktext
    FROM crtx WHERE objty = lt_plpo-objty AND
    objid = lt_plpo-objid AND
    spras = sy-langu.
    the following read will get the index of the correct record to be
    updated in the cache
    READ TABLE lt_pp04_cache
    WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    MODIFY lt_pp04_cache
    INDEX sy-tabix
    TRANSPORTING arbpl ktext.
    ENDIF.
    ENDIF.
    *ENDFORM. " read_last_pp04_operation_cache
    *& Form read_routing
    form read_routing.
    data: begin of lt_mapl occurs 0,
    plnnr like mapl-plnnr,
    plnal like mapl-plnal,
    end of lt_mapl,
    l_arbpl like crhd-arbpl.
    get all the rtg# and grp ctr# from MAPL
    select plnnr plnal
    into corresponding fields of table lt_mapl
    from mapl
    where matnr = v_matnr and
    werks = itab_xcel-werks and
    plnty = v_plnty and "Rate Routing
    loekz = space. "with del flag = OFF
    sort lt_mapl by plnal.
    if not itab_xcel-verid is initial.
    if the verid=0001 then use the 1st good rtg-grp# and grp-ctr#
    if itab_xcel-verid = '0001'.
    read table lt_mapl index 1.
    v_plnnr = lt_mapl-plnnr.
    v_plnal = lt_mapl-plnal.
    else.
    if the verid<>0001 then use the rtg-grp# and grp-ctr# of the routing
    whose work center on the last PP04 operation matches the given verid
    loop at lt_mapl.
    clear l_arbpl.
    get the work center from the last PP04 operation
    perform read_wc_on_last_pp04 using lt_mapl-plnnr
    lt_mapl-plnal
    changing l_arbpl.
    if itab_xcel-verid = l_arbpl.
    v_plnnr = lt_mapl-plnnr.
    v_plnal = lt_mapl-plnal.
    exit.
    endif.
    endloop.
    endif.
    else.
    do nothing
    endif.
    For version IDs that are other then '0000' or 'ZWIP' :--
    if itab_xcel-verid NE '0000' and
    itab_xcel-verid NE 'ZWIP'.
    if routing group# or group counter was not determined, make the
    valid-to date 99/99/9999 so that the BDC, on execution, errors out.
    if v_plnnr is initial or
    v_plnal is initial.
    itab_xcel-bdatu = '99/99/9999'.
    endif.
    endif.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    IF sy-subrc = 0.
    do nothing - lt_pp04_cache header line has rtg#
    ELSE.
    get the routing group # from MAPL
    put it in the cache internal table
    IF NOT l_mapl_plnnr IS INITIAL.
    lt_pp04_cache-matnr = pi_matnr.
    lt_pp04_cache-werks = pi_werks.
    lt_pp04_cache-alnag = pi_alnag.
    lt_pp04_cache-plnnr = l_mapl_plnnr.
    APPEND lt_pp04_cache.
    ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
    lt_pp04_cache-arbpl IS INITIAL AND
    ( pi_verid IS INITIAL OR
    pi_mdv01 IS INITIAL ).
    read the last PP04 operation
    CLEAR lt_plpo.
    REFRESH lt_plpo.
    SELECT vornr eobjty eobjid e~arbpl
    INTO CORRESPONDING FIELDS OF TABLE lt_plpo
    FROM plas AS b
    INNER JOIN plpo AS c
    ON bplnty = cplnty AND
    bplnnr = cplnnr AND
    bzaehl = czaehl
    INNER JOIN crhd AS e
    ON carbid = eobjid
    WHERE b~plnty = v_plnty AND
    b~plnnr = lt_pp04_cache-plnnr AND
    b~plnal = lt_pp04_cache-alnag AND
    c~loekz = space AND
    c~steus = v_plpo_steus AND
    e~objty = v_objty AND
    e~werks = lt_pp04_cache-werks AND
    e~verwe = v_verwe.
    SORT lt_plpo BY vornr DESCENDING.
    READ TABLE lt_plpo INDEX 1.
    IF NOT lt_plpo-arbpl IS INITIAL.
    lt_pp04_cache-arbpl = lt_plpo-arbpl.
    read work center description
    SELECT SINGLE ktext INTO lt_pp04_cache-ktext
    FROM crtx WHERE objty = lt_plpo-objty AND
    objid = lt_plpo-objid AND
    spras = sy-langu.
    the following read will get the index of the correct record to be
    updated in the cache
    READ TABLE lt_pp04_cache
    WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    MODIFY lt_pp04_cache
    INDEX sy-tabix
    TRANSPORTING arbpl ktext.
    ENDIF.
    ENDIF.
    endform. " read_last_pp04_operation_cache
    *& Form read_wc_on_last_pp04
    form read_wc_on_last_pp04 using pi_plnnr
    pi_plnal
    changing pe_arbpl.
    data: begin of lt_plpo occurs 0,
    vornr like plpo-vornr,
    objty like crhd-objty,
    objid like crhd-objid,
    arbpl like crhd-arbpl,
    end of lt_plpo.
    get all the PP04 operations for the given rtg# & grp-ctr#
    select vornr eobjty eobjid e~arbpl
    into corresponding fields of table lt_plpo
    from plas as b
    inner join plpo as c
    on bplnty = cplnty and
    bplnnr = cplnnr and
    bzaehl = czaehl
    inner join crhd as e
    on carbid = eobjid
    where b~plnty = v_plnty and "Rate Routing
    b~plnnr = pi_plnnr and
    b~plnal = pi_plnal and
    c~loekz = space and "Oper Del Flag = OFF
    c~steus = v_plpo_steus and "PP04
    e~objty = v_objty. "WC Obj Type = 'A'
    read the last operation
    sort lt_plpo by vornr descending.
    read table lt_plpo index 1.
    pe_arbpl = lt_plpo-arbpl.
    endform.
    Reward Points if useful
    Raghunath.S
    9986076729

  • Bom upload using bdc

    While uploading bom using bdc method how to upload item details into subscreen table.explain table control in bdc

    hi,
    When you try to create, you would find a pushbutton 'INSERT NEW LINES' or something simialr to enter your data in the next line. Say you're entering the Material inthe first row, its field position would be MARA-MATNR(01). Now when you click the Insert Pushbitton the cursor always is at positon 2. so you have to loop the remaining data to enter in MARA-MATNR(02). Yougenereally set a counter and pass that counter value (in this case the counter value is 2 always) 
    The other case when you don't have a push button to Insert. Enter all the rows and then do a Page down. Now your cursor would sit back at position 2 again. Say if there are 20 rows in the first screen. You would keep incrementing the counter and then when it is 21 you do a pagedown and then reset the counter to 2. You loop the pagedown and in it you loop the counter. 
    I have attached a BDC where I use the second case (no push button). Do a recording and then you would know all the answers by yourself.
    *&   REPORT ZPP0122                                                    *
    *& Module : PP                                                         |
    *& Application : The program loads the Material Assignment of Routings |
    *&                                                                     |
    REPORT zpp0122 NO STANDARD PAGE HEADING
                                      MESSAGE-ID z0
                                      LINE-SIZE  132
                                      LINE-COUNT 65(2).
                         Internal Tables                                 *
    *Internal table for the Routing fields.
    DATA: BEGIN OF i_rout OCCURS 0,
          plnnr(8),
          plnal(2),
          matnr(18),
          werks(4),
            END OF i_rout.
    DATA:
      g_my_rec_in   LIKE i_rout.
    Declare internal table for Call Transaction and BDC Session
    DATA: i_bdc_table LIKE bdcdata OCCURS 0 WITH HEADER LINE.
                         Global Variables                                *
    DATA: g_counter(2) TYPE n,
          g_field_name(18) TYPE c,
          zc_yes  TYPE syftype VALUE 'X'.
                         Selection Screen                                *
    SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
    PARAMETERS: p_fname1 TYPE localfile .
    SELECTION-SCREEN SKIP 1.
    SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
    PARAMETERS: p_rloc1 AS CHECKBOX  DEFAULT 'X'.
    SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-005.
    PARAMETERS p_group(12) OBLIGATORY DEFAULT 'ZROUTING'.
    SELECTION-SCREEN END OF BLOCK c.
    SELECTION-SCREEN END OF BLOCK b.
    SELECTION-SCREEN END OF BLOCK a.
    **WRITE the report header
    TOP-OF-PAGE.
      INCLUDE zheading.
                         Start of selection                              *
    START-OF-SELECTION.
    Load Input file
      PERFORM f_load_input_file.
    Create BDC records.
      PERFORM create_bdc_records .
    *&      Form  Create_BDC_records
           perform the BDC for the records in the internal table
    FORM create_bdc_records .
      IF NOT i_rout[] IS INITIAL.
    Open BDC session
        PERFORM open_bdc_session.
        LOOP AT i_rout.
          g_my_rec_in = i_rout.
          AT NEW plnnr.
            CLEAR i_bdc_table[].
            PERFORM insert_screen_header.
          ENDAT.
          CONCATENATE 'MAPL-PLNAL('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_rout-plnal.
          CONCATENATE 'MAPL-MATNR('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_rout-matnr.
          CONCATENATE 'MAPL-WERKS('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_rout-werks.
          PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
          g_counter = g_counter + 1.
    Page Down for further entries
          IF g_counter = 19.
            PERFORM bdc_field       USING 'BDC_OKCODE' '=P+'.
            PERFORM bdc_dynpro      USING 'SAPLCZDI' '1010'.
            g_counter = 2.
          ENDIF.
          AT END OF plnnr.
            PERFORM bdc_field       USING 'BDC_OKCODE' '=BACK'.
            PERFORM bdc_dynpro      USING 'SAPLCPDI' '1200'.
            PERFORM bdc_field       USING 'BDC_OKCODE' '=BU'.
            PERFORM insert_bdc_new.
          ENDAT.
        ENDLOOP.
        CLEAR i_rout[].
        PERFORM close_bdc_session.
    Release the BDC sessions created
        PERFORM release_bdc.
      ENDIF.
    ENDFORM.                    " open_group
    *&      Form  bdc_dynpro_start
         Call the screen for the input of fields
         -->P_G_PROGRAM_1
         -->P_G_SCREEN
    FORM bdc_dynpro USING    p_g_program_1
                                    p_g_screen.
      CLEAR i_bdc_table.
      i_bdc_table-program  = p_g_program_1.
      i_bdc_table-dynpro   = p_g_screen.
      i_bdc_table-dynbegin = 'X'.
      APPEND i_bdc_table.
    ENDFORM.                    " bdc_dynpro_start
    *&      Form  bdc_field
           Insert field                                                  *
    FORM bdc_field USING f_name f_value.
    IF f_value <> space.
      CLEAR i_bdc_table.
      i_bdc_table-fnam = f_name.
      i_bdc_table-fval = f_value.
      APPEND i_bdc_table.
    ENDIF.
    ENDFORM.                    "bdc_insert_field
    *&      Form  open_bdc_session
          Create the BDC session
    FORM open_bdc_session .
    Open BDC session and creat and update condition records
      CALL FUNCTION 'BDC_OPEN_GROUP'
        EXPORTING
          client                    = sy-mandt
          DEST                      = FILLER8
          group                     = p_group
          HOLDDATE                  = FILLER8
          keep                      = 'X'
          user                      = sy-uname
          RECORD                    = FILLER1
          PROG                      = SY-CPROG
        IMPORTING
          QID                       =
    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.                    " create_bdc_session
    *&      Form  insert_screen_header
          Header Data inserted
    FORM insert_screen_header .
      g_counter = 1.
    First screen
      PERFORM bdc_dynpro  USING 'SAPLCPDI' '1010'.
      PERFORM bdc_field   USING 'BDC_CURSOR' 'RC271-PLNNR'.
      PERFORM bdc_field   USING 'BDC_OKCODE' '=ALUE'.
      PERFORM bdc_field   USING 'RC271-PLNNR' g_my_rec_in-plnnr.
      PERFORM bdc_field   USING 'RC27M-MATNR' ' '.
      PERFORM bdc_field   USING 'RC27M-WERKS' ' '.
      PERFORM bdc_field   USING 'RC271-PLNAL' ' '.
    *next screen
      PERFORM bdc_dynpro  USING 'SAPLCPDI' '1200'.
      PERFORM bdc_field   USING 'BDC_OKCODE' '=MTUE'.
    *next screen
      PERFORM bdc_dynpro  USING 'SAPLCZDI' '1010'.
    ENDFORM.                    " insert_screen_header
    *&      Form  insert_bdc
          Insert the BDC for the transaction
    FORM insert_bdc_new .
      CALL FUNCTION 'BDC_INSERT'
         EXPORTING
           tcode                  = 'CA02'
          POST_LOCAL             = NOVBLOCAL
          PRINTING               = NOPRINT
          SIMUBATCH              = ' '
          CTUPARAMS              = ' '
         TABLES
           dynprotab              = i_bdc_table
      EXCEPTIONS
        internal_error         = 1
        not_open               = 2
        queue_error            = 3
        tcode_invalid          = 4
        printing_invalid       = 5
        posting_invalid        = 6
        OTHERS                 = 7
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CLEAR i_bdc_table[].
    ENDFORM.                    " insert_bdc
    *&      Form  close_bdc_session
          Close the session
    FORM close_bdc_session .
      CALL FUNCTION 'BDC_CLOSE_GROUP'
           EXCEPTIONS
                not_open    = 1
                queue_error = 2
                OTHERS      = 3.
      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.                    " close_bdc_session
    *&      Form  f_load_input_file
         Load the data file
    FORM f_load_input_file.
    The data file is from Presentation server
      IF p_rloc1 = zc_yes.
        CALL FUNCTION 'WS_UPLOAD'
             EXPORTING
                  filename                = p_fname1
                  filetype                = 'DAT'
             TABLES
                  data_tab                = i_rout
             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.
          EXIT.
        ENDIF.
      ENDIF.
    ENDFORM.                    " f_load_input_file
    *&      Form  release_bdc
         Release BDC session
    FORM release_bdc.
      SUBMIT rsbdcsub WITH mappe EQ p_group
                      WITH von EQ sy-datum
                      WITH bis EQ sy-datum
                      WITH fehler EQ '.'
                      EXPORTING LIST TO MEMORY
                      AND RETURN.
    ENDFORM.
    Regards
    Sudheer

  • Help with BDC, user exits and BAPI

    Hello all:
    1) I posted a question before about BDC documentation and people sent me lot of helpful material. Thanks to all of them. I am very new to ABAP coming from VB background and wondering if someone can tell me how to practice one simple BDC program starting from scratch. What do I first need to do to get started? I have Mini WAS 6.20 test version and like to practice BDC programming.
    2) What are user exits and BADI and can anyone provide some documentation and sample code if possible.
    Thanks everyone in advance.
    --Mithun.

    Hai Mithun Dha
    Go through the following Documentation & Example Code
    Just check these links.
    Diff. between LSMW & BDC?
    BDC SESSION
    CALL TRANSACTION
    CALL DIALOG
    What is BDC or batch input
    The Batch Input is a SAP technic that allows automating the input in transactions. It lies on a BDC (Batch Data Commands) scenario.
    BDC functions:
    E BDC_OPEN_GROUP : Opens a session group
    E BDC_CLOSE_GROUP : Closes a session
    E BDC_INSERT : Insert a BDC scenario in the session
    E The ABAP statement "CALL TRANSACTION" is also called to run directly a transaction from its BDC table.
    It runs the program RSBDCSUB in order to launch automatically the session. The session management is done through the transaction code SM35.
    The object itself is maintanable through the transaction SE24.
    BDC methods:
    Method
    Description
    Parameters
    OPEN_SESSION
    Opens a session
    SUBRC (Return Code ? 0 OK)
    SESSIONNAME (Session to be created)
    CLOSE_SESSION
    Closes a session
    None
    RESET_BDCDATA
    Resets the BDC Internal Table...
    None. Normally, for internal purposec
    BDC_DYNPRO
    Handles a new screen
    PROGNAME (Name of the program)
    DYNPRONR (Screen Number)
    BDC_FIELD
    Puts a value on the screen
    FIELDNAME (Name of the field)
    FIELDVALUE (Value to be passed)
    CONSTRUCTOR
    Constructor - Initializes NO_DATA
    NODATA (No data character). The constructor is called automatically when the object is created.
    RUN_SESSION
    Launches a session with RSBDCBTC
    None
    CALL_TRANSACTION
    Calls a transaction with the current BDC Data
    MODE (Display Mode)
    UPDATE (Update Mode)
    TCODE (Transaction to be called)
    BDC_INSERT
    Inserts the BDC scenario in the session
    TCODE (Transaction to be called)
    BDC techniques used in programs:
    1) Building a BDC table and calling a transaction,
    2) Building a session and a set of BDC scenarios and keeping the session available in SM35,
    3) Building a session and lauching the transaction right after closing the session.
    BDC using Call Transaction
    BDC using Call transaction involves calling an SAP transaction in back ground from within the ABAP
    program. The process involves building an Internal BDC table containing the screen information needed to
    execute the required transaction and then passing this to the Call transaction command (See code example).
    The full procedure for creating a BDC program is as follows:
    What is the difference between batch input and call transaction in BDC?
    Session method.
    1) synchronous processing.
    2) can tranfer large amount of data.
    3) processing is slower.
    4) error log is created
    5) data is not updated until session is processed.
    Call transaction.
    1) asynchronous processing
    2) can transfer small amount of data
    3) processing is faster.
    4) errors need to be handled explicitly
    5) data is updated automatically
    BATINPUT/DIRECT INPUT
    A: Batch-inputs can not be used to fill the "delivery due list" screen because it is not a dynpro. This is a standard SAP report. A SAP report (check with "System -> Status") may be called using SUBMIT sentence with the appropriate options . It is preferred to call a report than create a Batch-input program.
    GO THROUGH THIS LINK
    http://www.guidancetech.com/people/holland/sap/abap/zzsni001.htm
    check with this code
    include bdcrecx1.
    tables : mara.
    data : begin of it_mara occurs 0,
    matnr like mara-matnr,
    mbrsh like mara-mbrsh,
    mtart like mara-mtart,
    maktx like makt-maktx,
    meins like mara-meins,
    end of it_mara.
    start-of-selection.
    perform upload_data.
    perform open_group.
    loop at it_mara.
    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'
    it_mara-matnr.
    perform bdc_field using 'RMMG1-MBRSH'
    it_mara-mbrsh.
    perform bdc_field using 'RMMG1-MTART'
    it_mara-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'
    it_mara-maktx.
    perform bdc_field using 'BDC_CURSOR'
    'MARA-MEINS'.
    perform bdc_field using 'MARA-MEINS'
    it_mara-meins.
    perform bdc_field using 'MARA-MTPOS_MARA'
    'NORM'.
    perform bdc_transaction using 'MM01'.
    endloop.
    perform close_group.
    *& Form upload_data
    text
    --> p1 text
    <-- p2 text
    FORM upload_data .
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    FILENAME = 'c:\mat_bdc.txt'
    FILETYPE = 'ASC'
    TABLES
    DATA_TAB = it_mara.
    IF SY-SUBRC = 0.
    SORT IT_MARA BY MATNR.
    ENDIF.
    ENDFORM. " upload_data
    flat file structure is
    PRANIT_011 CCOUP This is Testing material kg
    PRANIT_012 CCOUP This is Testing material kg
    PRANIT_013 CCOUP This is Testing material kg
    PRANIT_014 CCOUP This is Testing material kg
    PRANIT_015 CCOUP This is Testing material kg
    when your selecting views
    this particular material will belongs to Po/Sales or some other areas .
    when you select basic 1 --it gives description
    select basic 2 -- it gives tax ,amount, base unit of measurement
    BDC TO BAPI
    The steps to be followed are :
    1. Find out the relevant BAPI (BAPI_SALESORDER_CHANGE for VA02).
    [for VA01 use BAPI_SALESORDER_CREATEFROMDAT2]
    2. Create a Z program and call the BAPi (same as a Funtion module call).
    2. Now, if you see this BAPi, it has
    -> Importing structures.
    eg: SALESDOCUMENT: this will take the Sales order header data as input.
    -> Tables parameters:
    eg: ORDER_ITEM_IN: this will take the line item data as input.
    Note :
    Only specify fields that should be changed
    Select these fields by entering an X in the checkboxes
    Enter a U in the UPDATEFLAG field
    Always specify key fields when changing the data, including in the checkboxes
    The configuration is an exception here. If this needs to be changed, you need to complete it again fully.
    Maintain quantities and dates in the schedule line data
    Possible UPDATEFLAGS:
    U = change
    D = delete
    I = add
    Example
    1. Delete the whole order
    2. Delete order items
    3. Change the order
    4. Change the configuration
    Notes
    1. Minimum entry:
    You must enter the order number in the SALESDOCUMENT structure.
    You must always enter key fields for changes.
    You must always specify the update indicator in the ORDER_HEADER_INX.
    2. Commit control:
    The BAPI does not run a database Commit, which means that the application must trigger the Commit so that the changes are read to the database. To do this, use the BAPI_TRANSACTION_COMMIT BAPI.
    For further details... refer to the Function Module documentation for the BAPi.
    For User Exits
    User Exits
    Screen exits are exits that allow you to use a reserved part of the screen (A subscreen) to display or input data.
    It is determined be SAP where the sub screen will be displayed.
    The syntax is: CALL CUSTOMER-SUBSCREEN
    The screen exit is not processed untill the corresponding subscreen has been created in an enhancement project,
    and the project has been activated.
    Note:
    Function codes are only processed in the main screens flow logic
    You are not allowed to enter a name for the subscreens command field
    You are not allowed to define GUI stauses
    You are not allowed to enter a value for Next screen
    The global data of the program is not available for the subscreen. Data for the subscreen is provided by function modules.
    These function modules belongs to the same function group as the subscreen Subscreens are edited with transaction CMOD.
    When you activate a project containg subscreens, the calling screen is regenerated and the subscreen is displayed next
    time you display the calling screen
    The developer must create the subscreen and the corresponding PBO and PAI modules
    How to identify screen exits
    Look after CALL CUSTOMER-SUBSCREEN in the screenprogram of the screen you want to modify.
    Use transaction CMOD menu Utillities -> SAP enhancements to search for screen exits
    MENU EXITS
    Menu exits allow you to add your own functionallity to menus. Menu exits are implemented by SAP, and are reserved menu
    entries in the GUI interface. The developer can add his/her own text and logic for the menu.
    Function codes for menu exits all start with "+"
    Example
    We want to create a new menu item in the Office menu. The text for the menu should be "Run ZTEST", and the menu will
    run report ZTEST.
    Goto transaction SE43 Area Menu Maintenance
    In Area Menu Paramenter type 'S000' (S triple Zero)
    Select Change and ignore all the warning screens
    Expand the office menu. In the buttom of the office tree you will find a menu named "Customer function"
    Double click on the text. In the pop-up screen change the text to "Run ZTEST". Note that the trsnaction code is +C01
    Goto transaction SE93 and create transaction +C01 that calls report ZTEST.
    Now you will se the menu displayed in the office tree. If you delete transaction +C01 again, the new menu will dissapear.
    USER EXITS
    User exits (Function module exits) are exits developed by SAP. The exit is implementerd as a call to a functionmodule.
    The code for the function module is writeen by the developer. You are not writing the code directly in the function module,
    but in the include that is implemented in the function module.
    The naming standard of function modules for functionmodule exits is: EXIT_<program name><3 digit suffix>
    The call to a functionmodule exit is implemented as: CALL CUSTOMER.-FUNCTION <3 digit suffix>
    Example:
    The program for transaction VA01 Create salesorder is SAPMV45A
    If you search for CALL CUSTOMER-FUNCTION i program SAPMV45A you will find ( Among other user exits):
    CALL CUSTOMER-FUNCTION '003'
    exporting
    xvbak = vbak
    xvbuk = vbuk
    xkomk = tkomk
    importing
    lvf_subrc = lvf_subrc
    tables
    xvbfa = xvbfa
    xvbap = xvbap
    xvbup = xvbup.
    The exit calls function module EXIT_SAPMV45A_003
    2. How to find user exits
    Display the program where you are searching for and exit and search for CALL CUSTOMER-EXIT
    If you know the Exit name, go to transaction CMOD. Choose menu Utillities->SAP Enhancements.
    Enter the exit name and press enter.
    You will now come to a screen that shows the function module exits for the exit.
    3. Using Project management of SAP Enhancements
    We want to create a project to enahance trasnaction VA01
    Go to transaction CMOD
    Create a project called ZVA01
    Choose the Enhancement assign radio button and press the Change button
    In the first column enter V45A0002 Predefine sold-to party in sales document . Note that an enhancement can only
    be used i 1 project. If the enhancement is allready in use, and error message will be displayed
    Press Save
    Press Components. You can now see that enhancement uses user exit EXIT_SAPMV45A_002. Double click on the exit.
    Now the function module is displayed. Double click on include ZXVVAU04 in the function module
    Insert the following code into the include: E_KUNNR = '2155'.
    Activate the include program. Go back to CMOD and activate the project.
    Goto transaction VA01 and craete a salesorder. Note that Sold-to-party now automatically is "2155"
    Have look at this links
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIOFFI/BCCIOFFI.pdf
    http://www.sapgenie.com/abap/ole.htm
    http://help.sap.com/saphelp_46c/helpdata/en/59/ae3f2e488f11d189490000e829fbbd/frameset.htm
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIOFFI/BCCIOFFI.pdf
    Creation of Field Exits
    Step by step procedure for creating Field Exits
    There are eight steps to creating a field exit:
    Step 1: Determine Data Element
    Step 2: Go To Field Exit Transaction
    Step 3: Create Field Exit
    Step 4: Create Function Module
    Step 5: Code Function Module
    Step 6: Activate Function Module
    Step 7: Assign Program/Screen
    Step 8: Activate Field Exit
    Step 1: Determine Data Element
    - Before you can begin adding the functionality for a field exit, you must know the corresponding data element.
    - An easy way to determine the data element associated to a particular screen field is to:
    Go the appropriate screen.
    Position the cursor in the appropriate field.
    Press eF1f for field-level help.
    Click on the eTechnical infof pushbutton (or press eF9f) on the help dialog box.
    On this Technical Information dialog box, the data element will be specified if the field is 'painted' from the ABAP/4 Dictionary.
    Step 2: Go To Field Exit Transaction
    - The transaction to create field exits is CMOD.
    - You can use the menu path Tools -> ABAP/4 Workbench -> Utilities -> Enhancements -> Project management.
    - From the initial screen of transaction CMOD, choose the Text enhancements -> Field exits menu path.
    - After choosing this menu path, you will be taken to the field exits screen. From here, you can create a field exit.
    NOTE : Even though you use transaction CMOD to maintain field exits, you do not need to create a project to activate field exits.
    Step 3: Create Field Exit
    - From the field exit screen of transaction CMOD, choose the Field exit -> Create menu path.
    - After choosing this menu path, a dialog box will prompt you for the appropriate data element .
    - Enter the data element name and click the eContinuef pushbutton.
    - Now, you will be able to create the function module associated to the data elementfs field exit.
    Step 4: Create Function Module
    - You will automatically be taken to the Function Library (SE37) after entering a data element name and clicking the eContinuef pushbutton.
    - In the eFunction modulef field, a function module name will be defaulted by the system based on the data element specified. This name will have the following convention:
    FIELD_EXIT_<data element>
    - You can add an identifier (an underscore followed by a single character ).
    - The first function module for a data elementfs field exit must be created without an identifier.
    - To create the function module, click on the eCreatef pushbutton, choose menu path Function module -> Create, or press eF5f.
    - After choosing to create the function module, you will get the warning: "Function module name is reserved for SAP". This message is just a warning so a developer does not accidentally create a function module in the field exit name range. By pressing eEnterf, you will be able to go ahead and create the function module.
    - Before coding the function module, you will have to specify the function modules attributes -- function group, application, and short text.
    Step 5: Code Function Module
    - From the function modulefs attributes screen, click on the eSource codef pushbutton or choose the Goto -> Function module menu path to the code of the function module.
    - Here you will add your desired functionality for the field exit.
    - Remember that field exitfs function module will have two parameters -- one importing parameter called "INPUT" and one exporting parameter called "OUTPUT". These parameters will be set up automatically by the system.
    - You must remember to assign a value to the OUTPUT field. Even if the value does not change, it must be moved from the INPUT field to the OUTPUT field.
    Step 6: Activate Function Module
    - After coding the function module, you must remember to activate it.
    - Use the Function module -> Activate menu path to activate the function module.
    - At this point, you can return to the field exit transaction.
    - You should be able to 'green arrow' back to this transaction.
    - When you return to the field exit transaction, you will see an entry for the newly created field exit.
    - At this point, the field exit is global. That is, it applies to all screens that use a particular data element. On any screen that uses the data element, the corresponding field exit function module will be triggered, once it is active.
    - Also, the field exit will not be triggered yet because it is inactive.
    Step 7: Assign Program/Screen
    - This step is only needed if you want to make a field exit local.
    - To make a field exit local, select the field exit and click on the eAssign prog./screenf pushbutton.
    - In the dialog box , indicate the appropriate program name and screen number.
    This information indicates that the field exit is local to the specified screen in the specified program.
    - In the dialog box, you determine which function module gets executed for the field exit by specifying the identifier in the eFld. Exitf field.
    - If this field is left blank, the function module triggered will be 'FIELD_EXIT_<data element>'.
    - If a single-character identifier is entered into the field, the function module triggered will be 'FIELD_EXIT_<data element>_<identifier>'.
    Step 8: Activate Field Exit
    - The field exit must be active for it to be triggered by the system.
    - Activate the field exit by choosing the Field exit -> Activate menu path.
    - After assigning the field exit to a change request, its status will change to eActivef and it will be triggered automatically on the appropriate screen(s).
    NOTE : In order to activate the field exit the profile parameter abap/fieldexit = YES must be set on all application servers
    Thanks & regards
    Sreenivasulu P

  • BDC SESSION METHOD EXPLAINED

    Hi,
    Eplained BDC Session Method
    flat file upload into sap

    ABAP BDC SESSION METHOD SAMPLE CODE
    pool of form routines
    include zmppn001.
    Define BDC Table Structure
    data: begin of itab_bdc_tab occurs 0.
    include structure bdcdata.
    data: end of itab_bdc_tab.
    Input record layout of Leagcy File
    data: begin of itab_xcel occurs 0,
    matnr(18) type c,
    werks(4) type c,
    alnag(2) type c,
    verid(4) type c,
    text1(40) type c,
    bstmi like mkal-bstmi,
    bstma like mkal-bstma,
    adatu(10) type c,
    bdatu(10) type c,
    stlal(2) type c,
    stlan(1) type c,
    serkz(1) type c,
    mdv01(8) type c,
    elpro(4) type c,
    alort(4) type c,
    end of itab_xcel.
    data: begin of lt_pp04_cache occurs 0,
    matnr like itab_xcel-matnr,
    werks like itab_xcel-werks,
    alnag like itab_xcel-alnag,
    plnnr like mapl-plnnr,
    arbpl like crhd-arbpl,
    ktext like crtx-ktext,
    end of lt_pp04_cache.
    data: v_ssnnr(4) type n,
    v_lines_in_xcel like sy-tabix,
    v_ssnname like apqi-groupid,
    v_trans_in_ssn type i,
    wa_xcel LIKE itab_xcel,
    l_tabix like sy-tabix,
    v_matnr like rc27m-matnr,
    v_plnnr like mapl-plnnr,
    v_plnal like mapl-plnal,
    v_tcode like sy-tcode value 'C223',
    v_plnty like plas-plnty value 'R',
    v_objty like crhd-objty value 'A',
    v_plpo_steus like plpo-steus value 'PP04',
    v_verwe like crhd-verwe value '0007'.
    Parameters
    selection-screen: skip 3.
    selection-screen: begin of block 1 with frame.
    parameters: p_name like rlgrap-filename
    default 'C:\My Documents\InputFile.txt'
    obligatory,
    bdc session name prefix
    p_bdcpfx(6) default 'ZPVCRT'
    obligatory,
    number for transction per BDC session
    p_trnssn type i
    default 2000 obligatory,
    retain the BDC session after successfull execution
    p_keep like apqi-qerase
    default 'X',
    user who will be executing BDC session
    p_uname like apqi-userid
    default sy-uname
    obligatory.
    selection-screen: end of block 1.
    possible entry list (F4 dropdown) for input file name
    at selection-screen on value-request for p_name.
    *-SELECT FILE FROM USERS LOCAL PC
    call function 'WS_FILENAME_GET'
    exporting
    DEF_FILENAME = ' '
    def_path = 'C:\Temp\'
    mask = ',.,..'
    mode = 'O'
    title = 'Select File '(007)
    importing
    filename = p_name
    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.
    begin the show
    start-of-selection.
    read data from input file
    perform transfer_xcel_to_itab.
    loop at itab_xcel.
    hang on to xcel line num
    l_tabix = sy-tabix.
    each line in the xcel file marks begining of new prod.version defn
    if num-of-trnas-in-session = 0, create new BDC session
    if v_trans_in_ssn is initial.
    perform bdc_session_open.
    endif.
    begin new bdc script for rtg create trans
    fill in bdc-data for prod.version maintenance screens
    perform bdc_build_script.
    insert the bdc script as a BDC transaction
    perform bdc_submit_transaction.
    keep track of how many BDC transactions were inserted in the BDC
    session
    add 1 to v_trans_in_ssn.
    if the user-specified num of trans in BDC session is reached OR
    if end of input file is reached, close the BDC session
    if v_trans_in_ssn = p_trnssn or
    l_tabix = v_lines_in_xcel.
    perform bdc_session_close.
    clear v_trans_in_ssn.
    endif.
    endloop.
    top-of-page.
    call function 'Z_HEADER'
    EXPORTING
    FLEX_TEXT1 =
    FLEX_TEXT2 =
    FLEX_TEXT3 =
    FORM TRANSFER_XCEL_TO_ITAB *
    Transfer Xcel Spreadsheet to SAP Internal Table *
    form transfer_xcel_to_itab.
    Read the tab-delimited file into itab
    call function 'WS_UPLOAD'
    exporting
    filename = p_name
    filetype = 'DAT'
    IMPORTING
    filelength = flength
    tables
    data_tab = itab_xcel
    exceptions
    conversion_error = 1
    file_open_error = 2
    file_read_error = 3
    invalid_table_width = 4
    invalid_type = 5
    no_batch = 6
    unknown_error = 7
    others = 8.
    if sy-subrc = 0.
    sort the data
    sort itab_xcel by matnr werks.
    clear v_lines_in_xcel.
    if no data in the file - error out
    describe table itab_xcel lines v_lines_in_xcel.
    if v_lines_in_xcel is initial.
    write: / 'No data in input file'.
    stop.
    endif.
    else.
    if file upload failed - error out
    write: / 'Error reading input file'.
    stop.
    endif.
    endform.
    FORM BDC_SESSION_OPEN *
    Open BDC Session *
    form bdc_session_open.
    create bdc session name = prefix-from-selectn-screen + nnnn
    add 1 to v_ssnnr.
    concatenate p_bdcpfx v_ssnnr into v_ssnname.
    open new bdc session
    call function 'BDC_OPEN_GROUP'
    exporting
    client = sy-mandt
    group = v_ssnname
    keep = p_keep
    user = p_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.
    endform.
    FORM BDC_BUILD_SCRIPT *
    Build BDC *
    form bdc_build_script.
    data: l_arbpl like crhd-arbpl,
    l_text1 like mkal-text1,
    l_mdv01 like mkal-mdv01,
    l_mapl like mapl.
    clear bdc-data itab - begin of new bdc transaction
    clear itab_bdc_tab.
    refresh itab_bdc_tab.
    read material cross reference tables to determine sap part#
    clear : v_matnr, v_plnnr, v_plnal.
    perform read_matnr_cross_ref using itab_xcel-matnr
    itab_xcel-werks
    changing v_matnr.
    determine the version description to use
    if itab_xcel-text1 is initial.
    l_text1 = itab_xcel-verid.
    else.
    l_text1 = itab_xcel-text1.
    endif.
    determine the routing group# and group ctr# to use
    perform read_routing .
    determine the production line to use
    if itab_xcel-mdv01 is initial.
    if not provided in the file then:
    prod line = work ctr on the last PP04 op of the rtg determined above
    perform read_wc_on_last_pp04 using v_plnnr v_plnal
    changing l_mdv01.
    NOTE: when executing the above form\routine, if v_plnnr is initial
    or v_plnal is initial, THEN l_mdv01 will automatically be
    returned blank (ie initial)
    else.
    l_mdv01 = itab_xcel-mdv01.
    endif.
    build bdc script
    perform bdc_build_script_record
    fill in initial screen
    using: 'X' 'SAPLCMFV' '1000',
    ' ' 'BDC_OKCODE' '=ENTE',
    ' ' 'MKAL-WERKS' itab_xcel-werks,
    ' ' 'MKAL-MATNR' v_matnr,
    ' ' 'MKAL_ADMIN-DISPO' space,
    ' ' 'MKAL-PLNNR' space,
    ' ' 'MKAL_ADMIN-STTAG' space,
    ' ' 'MKAL-PLNNG' space,
    ' ' 'MKAL-MDV01' space,
    ' ' 'MKAL-PLNNM' space,
    click create button on initial screen and go to detail screen
    'X' 'SAPLCMFV' '1000',
    ' ' 'BDC_OKCODE' '=CREA',
    fill in the detail screen and go back to initial screen
    'X' 'SAPLCMFV' '2000',
    ' ' 'BDC_OKCODE' '=CLOS',
    ' ' 'MKAL_EXPAND-MATNR' v_matnr,
    ' ' 'MKAL_EXPAND-VERID' itab_xcel-verid,
    ' ' 'MKAL_EXPAND-TEXT1' l_text1,
    ' ' 'MKAL_EXPAND-BSTMI' itab_xcel-bstmi,
    ' ' 'MKAL_EXPAND-BSTMA' itab_xcel-bstma,
    ' ' 'MKAL_EXPAND-ADATU' itab_xcel-adatu,
    ' ' 'MKAL_EXPAND-BDATU' itab_xcel-bdatu,
    ' ' 'MKAL_EXPAND-PLTYG' v_plnty,
    ' ' 'MKAL_EXPAND-PLNNG' v_plnnr,
    ' ' 'MKAL_EXPAND-ALNAG' v_plnal,
    ' ' 'MKAL_EXPAND-STLAL' itab_xcel-stlal,
    ' ' 'MKAL_EXPAND-STLAN' itab_xcel-stlan,
    ' ' 'MKAL_EXPAND-SERKZ' itab_xcel-serkz,
    ' ' 'MKAL_EXPAND-MDV01' l_mdv01,
    ' ' 'MKAL_EXPAND-ELPRO' itab_xcel-elpro,
    ' ' 'MKAL_EXPAND-ALORT' itab_xcel-alort,
    save the production version from initial screen
    'X' 'SAPLCMFV' '1000',
    ' ' 'BDC_OKCODE' '=SAVE'.
    endform.
    FORM BDC_SUBMIT_TRANSACTION *
    Submit BDC Session *
    form bdc_submit_transaction.
    Load BDC script as a trqansction in BDC session
    call function 'BDC_INSERT'
    exporting
    tcode = v_tcode
    tables
    dynprotab = itab_bdc_tab
    exceptions
    internal_error = 01
    not_open = 02
    queue_error = 03
    tcode_invalid = 04.
    endform.
    FORM BDC_BUILD_SCRIPT_RECORD *
    form bdc_build_script_record using dynbegin name value.
    clear itab_bdc_tab.
    if dynbegin = 'X'.
    move: name to itab_bdc_tab-program,
    value to itab_bdc_tab-dynpro,
    'X' to itab_bdc_tab-dynbegin.
    else.
    move: name to itab_bdc_tab-fnam,
    value to itab_bdc_tab-fval.
    shift itab_bdc_tab-fval left deleting leading space.
    endif.
    append itab_bdc_tab.
    endform.
    FORM BDC_SESSION_CLOSE *
    Close BDC Session *
    form bdc_session_close.
    close the session
    call function 'BDC_CLOSE_GROUP'
    exceptions
    not_open = 1
    queue_error = 2
    others = 3.
    skip 2.
    if sy-subrc ne 0.
    write: / 'Error Closing BDC Session ' , 'RETURN CODE: ', sy-subrc.
    else.
    write : / 'Session created:', v_ssnname,
    50 '# of transactions:', v_trans_in_ssn.
    endif.
    endform.
    *& Form read_routing_cache
    *FORM read_routing_cache USING pi_matnr
    pi_werks
    pi_alnag
    pi_verid
    pi_mdv01.
    DATA: BEGIN OF lt_plpo OCCURS 0,
    vornr LIKE plpo-vornr,
    objty LIKE crhd-objty,
    objid LIKE crhd-objid,
    arbpl LIKE crhd-arbpl,
    END OF lt_plpo,
    l_mapl_plnnr LIKE mapl-plnnr.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    IF sy-subrc = 0.
    do nothing - lt_pp04_cache header line has rtg#
    ELSE.
    get the routing group # from MAPL
    SELECT plnnr INTO l_mapl_plnnr
    FROM mapl UP TO 1 ROWS
    WHERE matnr = pi_matnr AND
    werks = pi_werks AND
    plnty = 'R' AND
    plnal = pi_alnag AND
    loekz = space.
    ENDSELECT.
    put it in the cache internal table
    IF NOT l_mapl_plnnr IS INITIAL.
    lt_pp04_cache-matnr = pi_matnr.
    lt_pp04_cache-werks = pi_werks.
    lt_pp04_cache-alnag = pi_alnag.
    lt_pp04_cache-plnnr = l_mapl_plnnr.
    APPEND lt_pp04_cache.
    ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
    lt_pp04_cache-arbpl IS INITIAL AND
    ( pi_verid IS INITIAL OR
    pi_mdv01 IS INITIAL ).
    read the last PP04 operation
    CLEAR lt_plpo.
    REFRESH lt_plpo.
    SELECT vornr eobjty eobjid e~arbpl
    INTO CORRESPONDING FIELDS OF TABLE lt_plpo
    FROM plas AS b
    INNER JOIN plpo AS c
    ON bplnty = cplnty AND
    bplnnr = cplnnr AND
    bzaehl = czaehl
    INNER JOIN crhd AS e
    ON carbid = eobjid
    WHERE b~plnty = v_plnty AND
    b~plnnr = lt_pp04_cache-plnnr AND
    b~plnal = lt_pp04_cache-alnag AND
    c~loekz = space AND
    c~steus = v_plpo_steus AND
    e~objty = v_objty AND
    e~werks = lt_pp04_cache-werks AND
    e~verwe = v_verwe.
    SORT lt_plpo BY vornr DESCENDING.
    READ TABLE lt_plpo INDEX 1.
    IF NOT lt_plpo-arbpl IS INITIAL.
    lt_pp04_cache-arbpl = lt_plpo-arbpl.
    read work center description
    SELECT SINGLE ktext INTO lt_pp04_cache-ktext
    FROM crtx WHERE objty = lt_plpo-objty AND
    objid = lt_plpo-objid AND
    spras = sy-langu.
    the following read will get the index of the correct record to be
    updated in the cache
    READ TABLE lt_pp04_cache
    WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    MODIFY lt_pp04_cache
    INDEX sy-tabix
    TRANSPORTING arbpl ktext.
    ENDIF.
    ENDIF.
    *ENDFORM. " read_last_pp04_operation_cache
    *& Form read_routing
    form read_routing.
    data: begin of lt_mapl occurs 0,
    plnnr like mapl-plnnr,
    plnal like mapl-plnal,
    end of lt_mapl,
    l_arbpl like crhd-arbpl.
    get all the rtg# and grp ctr# from MAPL
    select plnnr plnal
    into corresponding fields of table lt_mapl
    from mapl
    where matnr = v_matnr and
    werks = itab_xcel-werks and
    plnty = v_plnty and "Rate Routing
    loekz = space. "with del flag = OFF
    sort lt_mapl by plnal.
    if not itab_xcel-verid is initial.
    if the verid=0001 then use the 1st good rtg-grp# and grp-ctr#
    if itab_xcel-verid = '0001'.
    read table lt_mapl index 1.
    v_plnnr = lt_mapl-plnnr.
    v_plnal = lt_mapl-plnal.
    else.
    if the verid<>0001 then use the rtg-grp# and grp-ctr# of the routing
    whose work center on the last PP04 operation matches the given verid
    loop at lt_mapl.
    clear l_arbpl.
    get the work center from the last PP04 operation
    perform read_wc_on_last_pp04 using lt_mapl-plnnr
    lt_mapl-plnal
    changing l_arbpl.
    if itab_xcel-verid = l_arbpl.
    v_plnnr = lt_mapl-plnnr.
    v_plnal = lt_mapl-plnal.
    exit.
    endif.
    endloop.
    endif.
    else.
    do nothing
    endif.
    For version IDs that are other then '0000' or 'ZWIP' :--
    if itab_xcel-verid NE '0000' and
    itab_xcel-verid NE 'ZWIP'.
    if routing group# or group counter was not determined, make the
    valid-to date 99/99/9999 so that the BDC, on execution, errors out.
    if v_plnnr is initial or
    v_plnal is initial.
    itab_xcel-bdatu = '99/99/9999'.
    endif.
    endif.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    IF sy-subrc = 0.
    do nothing - lt_pp04_cache header line has rtg#
    ELSE.
    get the routing group # from MAPL
    put it in the cache internal table
    IF NOT l_mapl_plnnr IS INITIAL.
    lt_pp04_cache-matnr = pi_matnr.
    lt_pp04_cache-werks = pi_werks.
    lt_pp04_cache-alnag = pi_alnag.
    lt_pp04_cache-plnnr = l_mapl_plnnr.
    APPEND lt_pp04_cache.
    ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
    lt_pp04_cache-arbpl IS INITIAL AND
    ( pi_verid IS INITIAL OR
    pi_mdv01 IS INITIAL ).
    read the last PP04 operation
    CLEAR lt_plpo.
    REFRESH lt_plpo.
    SELECT vornr eobjty eobjid e~arbpl
    INTO CORRESPONDING FIELDS OF TABLE lt_plpo
    FROM plas AS b
    INNER JOIN plpo AS c
    ON bplnty = cplnty AND
    bplnnr = cplnnr AND
    bzaehl = czaehl
    INNER JOIN crhd AS e
    ON carbid = eobjid
    WHERE b~plnty = v_plnty AND
    b~plnnr = lt_pp04_cache-plnnr AND
    b~plnal = lt_pp04_cache-alnag AND
    c~loekz = space AND
    c~steus = v_plpo_steus AND
    e~objty = v_objty AND
    e~werks = lt_pp04_cache-werks AND
    e~verwe = v_verwe.
    SORT lt_plpo BY vornr DESCENDING.
    READ TABLE lt_plpo INDEX 1.
    IF NOT lt_plpo-arbpl IS INITIAL.
    lt_pp04_cache-arbpl = lt_plpo-arbpl.
    read work center description
    SELECT SINGLE ktext INTO lt_pp04_cache-ktext
    FROM crtx WHERE objty = lt_plpo-objty AND
    objid = lt_plpo-objid AND
    spras = sy-langu.
    the following read will get the index of the correct record to be
    updated in the cache
    READ TABLE lt_pp04_cache
    WITH KEY matnr = pi_matnr
    werks = pi_werks
    alnag = pi_alnag.
    MODIFY lt_pp04_cache
    INDEX sy-tabix
    TRANSPORTING arbpl ktext.
    ENDIF.
    ENDIF.
    endform. " read_last_pp04_operation_cache
    *& Form read_wc_on_last_pp04
    form read_wc_on_last_pp04 using pi_plnnr
    pi_plnal
    changing pe_arbpl.
    data: begin of lt_plpo occurs 0,
    vornr like plpo-vornr,
    objty like crhd-objty,
    objid like crhd-objid,
    arbpl like crhd-arbpl,
    end of lt_plpo.
    get all the PP04 operations for the given rtg# & grp-ctr#
    select vornr eobjty eobjid e~arbpl
    into corresponding fields of table lt_plpo
    from plas as b
    inner join plpo as c
    on bplnty = cplnty and
    bplnnr = cplnnr and
    bzaehl = czaehl
    inner join crhd as e
    on carbid = eobjid
    where b~plnty = v_plnty and "Rate Routing
    b~plnnr = pi_plnnr and
    b~plnal = pi_plnal and
    c~loekz = space and "Oper Del Flag = OFF
    c~steus = v_plpo_steus and "PP04
    e~objty = v_objty. "WC Obj Type = 'A'
    read the last operation
    sort lt_plpo by vornr descending.
    read table lt_plpo index 1.
    pe_arbpl = lt_plpo-arbpl.
    endform.
    Regards.

  • Example of BDC Session method

    Hello Friends,
    Can you guide me how to create BDC with SESSION method.?
    Please mantion examples.
    Thanks in advance.
    Regards,
    nimesh master

    See below example code :
    Call three FM : BDC_OPEN_GROUP,BDC_INSERT and BDC_CLOSE_GROUP.
    Once you execute the program and it creates the session at SM35 Transaction.
    Report     : ZMPPC011
    Type       : Data upload
    Author     : Chetan Shah
    Date       : 05/05/2005
    Transport  : DV3K919557
    Transaction: ??
    Description: This ABAP/4 Program creates new Production Versions
                 (C223). It accepts tab-delimited spreadsheet input and
                 creates BDC sessions.
                        Modification Log
    Date       Programmer    Request #    Description
    06/10/2005 Chetan Shah   DV3K919557   Initial coding
    report zmppc011 no standard page heading line-size 120 line-count 55
       message-id zz.
    pool of form routines
    include zmppn001.
    Define BDC Table Structure
    data: begin of itab_bdc_tab occurs 0.
            include structure bdcdata.
    data: end of itab_bdc_tab.
    Input record layout of Leagcy File
    data: begin of itab_xcel occurs 0,
            matnr(18)  type c,
            werks(4)   type c,
            alnag(2)   type c,
            verid(4)   type c,
            text1(40)  type c,
            bstmi      like mkal-bstmi,
            bstma      like mkal-bstma,
            adatu(10)  type c,
            bdatu(10)  type c,
            stlal(2)   type c,
            stlan(1)   type c,
            serkz(1)   type c,
            mdv01(8)   type c,
            elpro(4)   type c,
            alort(4)   type c,
          end of itab_xcel.
    data: begin of lt_pp04_cache occurs 0,
            matnr like itab_xcel-matnr,
            werks like itab_xcel-werks,
            alnag like itab_xcel-alnag,
            plnnr like mapl-plnnr,
            arbpl like crhd-arbpl,
            ktext like crtx-ktext,
          end of lt_pp04_cache.
    data: v_ssnnr(4)      type n,
          v_lines_in_xcel like sy-tabix,
          v_ssnname       like apqi-groupid,
          v_trans_in_ssn  type i,
         wa_xcel         LIKE itab_xcel,
          l_tabix         like sy-tabix,
          v_matnr         like rc27m-matnr,
          v_plnnr         like mapl-plnnr,
          v_plnal         like mapl-plnal,
          v_tcode         like sy-tcode value 'C223',
          v_plnty         like plas-plnty value 'R',
          v_objty         like crhd-objty value 'A',
          v_plpo_steus    like plpo-steus value 'PP04',
          v_verwe         like crhd-verwe value '0007'.
    Parameters
    selection-screen: skip 3.
    selection-screen: begin of block 1 with frame.
    parameters: p_name        like rlgrap-filename
                              default 'C:\My Documents\InputFile.txt'
                              obligatory,
    bdc session name prefix
                p_bdcpfx(6)   default 'ZPVCRT'
                              obligatory,
    number for transction per BDC session
                p_trnssn      type i
                              default 2000 obligatory,
    retain the BDC session after successfull execution
                p_keep        like apqi-qerase
                              default 'X',
    user who will be executing BDC session
                p_uname       like apqi-userid
                              default sy-uname
                              obligatory.
    selection-screen: end of block 1.
    possible entry list (F4 dropdown) for input file name
    at selection-screen on value-request for p_name.
    *-SELECT FILE FROM USERS LOCAL PC
      call function 'WS_FILENAME_GET'
          exporting
             DEF_FILENAME     = ' '
               def_path         = 'C:\Temp\'
               mask             = ',.,..'
               mode             = 'O'
               title            = 'Select File '(007)
          importing
               filename         = p_name
             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.
    begin the show
    start-of-selection.
    read data from input file
      perform transfer_xcel_to_itab.
      loop at itab_xcel.
      hang on to xcel line num
        l_tabix = sy-tabix.
      each line in the xcel file marks begining of new prod.version defn
      if num-of-trnas-in-session = 0, create new BDC session
        if v_trans_in_ssn is initial.
          perform bdc_session_open.
        endif.
      begin new bdc script for rtg create trans
      fill in bdc-data for prod.version maintenance screens
        perform bdc_build_script.
      insert the bdc script as a BDC transaction
        perform bdc_submit_transaction.
      keep track of how many BDC transactions were inserted in the BDC
      session
        add 1 to v_trans_in_ssn.
      if the user-specified num of trans in BDC session is reached OR
      if end of input file is reached, close the BDC session
        if v_trans_in_ssn = p_trnssn or
           l_tabix = v_lines_in_xcel.
          perform bdc_session_close.
          clear v_trans_in_ssn.
        endif.
      endloop.
    top-of-page.
      call function 'Z_HEADER'
    EXPORTING
      FLEX_TEXT1       =
      FLEX_TEXT2       =
      FLEX_TEXT3       =
          FORM TRANSFER_XCEL_TO_ITAB                                    *
          Transfer Xcel Spreadsheet to SAP Internal Table               *
    form transfer_xcel_to_itab.
    Read the tab-delimited file into itab
      call function 'WS_UPLOAD'
           exporting
                filename            = p_name
                filetype            = 'DAT'
          IMPORTING
               filelength          = flength
           tables
                data_tab            = itab_xcel
           exceptions
                conversion_error    = 1
                file_open_error     = 2
                file_read_error     = 3
                invalid_table_width = 4
                invalid_type        = 5
                no_batch            = 6
                unknown_error       = 7
                others              = 8.
      if sy-subrc = 0.
      sort the data
        sort itab_xcel by matnr werks.
        clear v_lines_in_xcel.
      if no data in the file - error out
        describe table itab_xcel lines v_lines_in_xcel.
        if v_lines_in_xcel is initial.
          write: / 'No data in input file'.
          stop.
        endif.
      else.
      if file upload failed - error out
        write: / 'Error reading input file'.
        stop.
      endif.
    endform.
          FORM BDC_SESSION_OPEN                                         *
          Open BDC Session                                              *
    form bdc_session_open.
    create bdc session name = prefix-from-selectn-screen + nnnn
      add 1 to v_ssnnr.
      concatenate p_bdcpfx v_ssnnr into v_ssnname.
    open new bdc session
      call function 'BDC_OPEN_GROUP'
           exporting
                client              = sy-mandt
                group               = v_ssnname
                keep                = p_keep
                user                = p_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.
    endform.
          FORM BDC_BUILD_SCRIPT                                         *
          Build BDC                                                     *
    form bdc_build_script.
      data: l_arbpl like crhd-arbpl,
            l_text1 like mkal-text1,
            l_mdv01 like mkal-mdv01,
            l_mapl  like mapl.
    clear bdc-data itab - begin of new bdc transaction
      clear   itab_bdc_tab.
      refresh itab_bdc_tab.
    read material cross reference tables to determine sap part#
      clear : v_matnr, v_plnnr, v_plnal.
      perform read_matnr_cross_ref using itab_xcel-matnr
                                         itab_xcel-werks
                                   changing v_matnr.
    determine the version description to use
      if itab_xcel-text1 is initial.
        l_text1 = itab_xcel-verid.
      else.
        l_text1 = itab_xcel-text1.
      endif.
    determine the routing group# and group ctr# to use
      perform read_routing .
    determine the production line to use
      if itab_xcel-mdv01 is initial.
      if not provided in the file then:
      prod line = work ctr on the last PP04 op of the rtg determined above
        perform read_wc_on_last_pp04 using v_plnnr v_plnal
                                  changing l_mdv01.
      NOTE: when executing the above form\routine, if v_plnnr is initial
            or v_plnal is initial, THEN l_mdv01 will automatically be
            returned blank (ie initial)
      else.
        l_mdv01 = itab_xcel-mdv01.
      endif.
    build bdc script
      perform bdc_build_script_record
    fill in initial screen
              using: 'X' 'SAPLCMFV'         '1000',
                     ' ' 'BDC_OKCODE'       '=ENTE',
                     ' ' 'MKAL-WERKS'       itab_xcel-werks,
                     ' ' 'MKAL-MATNR'       v_matnr,
                     ' ' 'MKAL_ADMIN-DISPO' space,
                     ' ' 'MKAL-PLNNR'       space,
                     ' ' 'MKAL_ADMIN-STTAG' space,
                     ' ' 'MKAL-PLNNG'       space,
                     ' ' 'MKAL-MDV01'       space,
                     ' ' 'MKAL-PLNNM'       space,
    click create button on initial screen and go to detail screen
                     'X' 'SAPLCMFV'         '1000',
                     ' ' 'BDC_OKCODE'       '=CREA',
    fill in the detail screen and go back to initial screen
                     'X' 'SAPLCMFV'           '2000',
                     ' ' 'BDC_OKCODE'         '=CLOS',
                     ' ' 'MKAL_EXPAND-MATNR'  v_matnr,
                     ' ' 'MKAL_EXPAND-VERID'  itab_xcel-verid,
                     ' ' 'MKAL_EXPAND-TEXT1'  l_text1,
                     ' ' 'MKAL_EXPAND-BSTMI'  itab_xcel-bstmi,
                     ' ' 'MKAL_EXPAND-BSTMA'  itab_xcel-bstma,
                     ' ' 'MKAL_EXPAND-ADATU'  itab_xcel-adatu,
                     ' ' 'MKAL_EXPAND-BDATU'  itab_xcel-bdatu,
                     ' ' 'MKAL_EXPAND-PLTYG'  v_plnty,
                     ' ' 'MKAL_EXPAND-PLNNG'  v_plnnr,
                     ' ' 'MKAL_EXPAND-ALNAG'  v_plnal,
                     ' ' 'MKAL_EXPAND-STLAL'  itab_xcel-stlal,
                     ' ' 'MKAL_EXPAND-STLAN'  itab_xcel-stlan,
                     ' ' 'MKAL_EXPAND-SERKZ'  itab_xcel-serkz,
                     ' ' 'MKAL_EXPAND-MDV01'  l_mdv01,
                     ' ' 'MKAL_EXPAND-ELPRO'  itab_xcel-elpro,
                     ' ' 'MKAL_EXPAND-ALORT'  itab_xcel-alort,
    save the production version from initial screen
                     'X' 'SAPLCMFV'           '1000',
                     ' ' 'BDC_OKCODE'         '=SAVE'.
    endform.
          FORM BDC_SUBMIT_TRANSACTION                                   *
          Submit BDC Session                                            *
    form bdc_submit_transaction.
    Load BDC script as a trqansction in BDC session
      call function 'BDC_INSERT'
           exporting
                tcode          = v_tcode
           tables
                dynprotab      = itab_bdc_tab
           exceptions
                internal_error = 01
                not_open       = 02
                queue_error    = 03
                tcode_invalid  = 04.
    endform.
          FORM BDC_BUILD_SCRIPT_RECORD                                  *
    form bdc_build_script_record using dynbegin name value.
      clear itab_bdc_tab.
      if dynbegin = 'X'.
        move: name  to itab_bdc_tab-program,
              value to itab_bdc_tab-dynpro,
              'X'   to itab_bdc_tab-dynbegin.
      else.
        move: name  to itab_bdc_tab-fnam,
              value to itab_bdc_tab-fval.
        shift itab_bdc_tab-fval left deleting leading space.
      endif.
      append itab_bdc_tab.
    endform.
          FORM BDC_SESSION_CLOSE                                        *
          Close BDC Session                                             *
    form bdc_session_close.
    close the session
      call function 'BDC_CLOSE_GROUP'
           exceptions
                not_open    = 1
                queue_error = 2
                others      = 3.
      skip 2.
      if sy-subrc ne 0.
        write: / 'Error Closing BDC Session ' , 'RETURN CODE: ', sy-subrc.
      else.
        write : /  'Session created:', v_ssnname,
                50 '# of transactions:', v_trans_in_ssn.
      endif.
    endform.
    *&      Form  read_routing_cache
    *FORM read_routing_cache USING    pi_matnr
                                    pi_werks
                                    pi_alnag
                                    pi_verid
                                    pi_mdv01.
    DATA: BEGIN OF lt_plpo OCCURS 0,
             vornr LIKE plpo-vornr,
             objty LIKE crhd-objty,
             objid LIKE crhd-objid,
             arbpl LIKE crhd-arbpl,
           END OF lt_plpo,
           l_mapl_plnnr LIKE mapl-plnnr.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
                                       werks = pi_werks
                                       alnag = pi_alnag.
    IF sy-subrc = 0.
      do nothing - lt_pp04_cache header line has rtg#
    ELSE.
      get the routing group # from MAPL
       SELECT plnnr INTO l_mapl_plnnr
         FROM mapl UP TO 1 ROWS
        WHERE matnr = pi_matnr    AND
              werks = pi_werks    AND
              plnty = 'R'         AND
              plnal = pi_alnag    AND
              loekz = space.
       ENDSELECT.
      put it in the cache internal table
       IF NOT l_mapl_plnnr IS INITIAL.
         lt_pp04_cache-matnr = pi_matnr.
         lt_pp04_cache-werks = pi_werks.
         lt_pp04_cache-alnag = pi_alnag.
         lt_pp04_cache-plnnr = l_mapl_plnnr.
         APPEND lt_pp04_cache.
       ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
            lt_pp04_cache-arbpl IS INITIAL AND
        ( pi_verid IS INITIAL OR
          pi_mdv01 IS INITIAL ).
      read the last PP04 operation
       CLEAR   lt_plpo.
       REFRESH lt_plpo.
       SELECT vornr eobjty eobjid e~arbpl
         INTO CORRESPONDING FIELDS OF TABLE lt_plpo
         FROM plas AS b
              INNER JOIN plpo AS c
                    ON bplnty = cplnty AND
                       bplnnr = cplnnr AND
                       bzaehl = czaehl
              INNER JOIN crhd AS e
                    ON carbid = eobjid
        WHERE b~plnty = v_plnty             AND
              b~plnnr = lt_pp04_cache-plnnr AND
              b~plnal = lt_pp04_cache-alnag AND
              c~loekz = space               AND
              c~steus = v_plpo_steus        AND
              e~objty = v_objty             AND
              e~werks = lt_pp04_cache-werks AND
              e~verwe = v_verwe.
       SORT lt_plpo BY vornr DESCENDING.
       READ TABLE lt_plpo INDEX 1.
       IF NOT lt_plpo-arbpl IS INITIAL.
         lt_pp04_cache-arbpl = lt_plpo-arbpl.
        read work center description
         SELECT SINGLE ktext INTO lt_pp04_cache-ktext
           FROM crtx WHERE objty = lt_plpo-objty AND
                           objid = lt_plpo-objid AND
                           spras = sy-langu.
        the following read will get the index of the correct record to be
        updated in the cache
         READ TABLE lt_pp04_cache
              WITH KEY matnr = pi_matnr
                       werks = pi_werks
                       alnag = pi_alnag.
         MODIFY lt_pp04_cache
                INDEX sy-tabix
                TRANSPORTING arbpl ktext.
       ENDIF.
    ENDIF.
    *ENDFORM.                    " read_last_pp04_operation_cache
    *&      Form  read_routing
    form read_routing.
      data: begin of lt_mapl occurs 0,
              plnnr like mapl-plnnr,
              plnal like mapl-plnal,
            end of lt_mapl,
            l_arbpl like crhd-arbpl.
    get all the rtg# and grp ctr# from MAPL
      select plnnr plnal
        into corresponding fields of table lt_mapl
        from mapl
       where matnr = v_matnr          and
             werks = itab_xcel-werks  and
             plnty = v_plnty          and     "Rate Routing
             loekz = space.                   "with del flag = OFF
      sort lt_mapl by plnal.
      if not itab_xcel-verid is initial.
      if the verid=0001 then use the 1st good rtg-grp# and grp-ctr#
        if itab_xcel-verid = '0001'.
          read table lt_mapl index 1.
          v_plnnr = lt_mapl-plnnr.
          v_plnal = lt_mapl-plnal.
        else.
      if the verid<>0001 then use the rtg-grp# and grp-ctr# of the routing
      whose work center on the last PP04 operation matches the given verid
          loop at lt_mapl.
            clear l_arbpl.
          get the work center from the last PP04 operation
            perform read_wc_on_last_pp04 using lt_mapl-plnnr
                                               lt_mapl-plnal
                                      changing l_arbpl.
            if itab_xcel-verid = l_arbpl.
              v_plnnr = lt_mapl-plnnr.
              v_plnal = lt_mapl-plnal.
              exit.
            endif.
          endloop.
        endif.
      else.
      do nothing
      endif.
    For version IDs that are other then '0000' or 'ZWIP' :--
      if itab_xcel-verid NE '0000' and
         itab_xcel-verid NE 'ZWIP'.
      if routing group# or group counter was not determined, make the
      valid-to date 99/99/9999 so that the BDC, on execution, errors out.
        if v_plnnr is initial or
           v_plnal is initial.
          itab_xcel-bdatu = '99/99/9999'.
        endif.
      endif.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
                                       werks = pi_werks
                                       alnag = pi_alnag.
    IF sy-subrc = 0.
      do nothing - lt_pp04_cache header line has rtg#
    ELSE.
      get the routing group # from MAPL
      put it in the cache internal table
       IF NOT l_mapl_plnnr IS INITIAL.
         lt_pp04_cache-matnr = pi_matnr.
         lt_pp04_cache-werks = pi_werks.
         lt_pp04_cache-alnag = pi_alnag.
         lt_pp04_cache-plnnr = l_mapl_plnnr.
         APPEND lt_pp04_cache.
       ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
            lt_pp04_cache-arbpl IS INITIAL AND
        ( pi_verid IS INITIAL OR
          pi_mdv01 IS INITIAL ).
      read the last PP04 operation
       CLEAR   lt_plpo.
       REFRESH lt_plpo.
       SELECT vornr eobjty eobjid e~arbpl
         INTO CORRESPONDING FIELDS OF TABLE lt_plpo
         FROM plas AS b
              INNER JOIN plpo AS c
                    ON bplnty = cplnty AND
                       bplnnr = cplnnr AND
                       bzaehl = czaehl
              INNER JOIN crhd AS e
                    ON carbid = eobjid
        WHERE b~plnty = v_plnty             AND
              b~plnnr = lt_pp04_cache-plnnr AND
              b~plnal = lt_pp04_cache-alnag AND
              c~loekz = space               AND
              c~steus = v_plpo_steus        AND
              e~objty = v_objty             AND
              e~werks = lt_pp04_cache-werks AND
              e~verwe = v_verwe.
       SORT lt_plpo BY vornr DESCENDING.
       READ TABLE lt_plpo INDEX 1.
       IF NOT lt_plpo-arbpl IS INITIAL.
         lt_pp04_cache-arbpl = lt_plpo-arbpl.
        read work center description
         SELECT SINGLE ktext INTO lt_pp04_cache-ktext
           FROM crtx WHERE objty = lt_plpo-objty AND
                           objid = lt_plpo-objid AND
                           spras = sy-langu.
        the following read will get the index of the correct record to be
        updated in the cache
         READ TABLE lt_pp04_cache
              WITH KEY matnr = pi_matnr
                       werks = pi_werks
                       alnag = pi_alnag.
         MODIFY lt_pp04_cache
                INDEX sy-tabix
                TRANSPORTING arbpl ktext.
       ENDIF.
    ENDIF.
    endform.                    " read_last_pp04_operation_cache
    *&      Form  read_wc_on_last_pp04
    form read_wc_on_last_pp04 using    pi_plnnr
                                       pi_plnal
                              changing pe_arbpl.
      data: begin of lt_plpo occurs 0,
              vornr like plpo-vornr,
              objty like crhd-objty,
              objid like crhd-objid,
              arbpl like crhd-arbpl,
            end of lt_plpo.
    get all the PP04 operations for the given rtg# & grp-ctr#
      select vornr eobjty eobjid e~arbpl
        into corresponding fields of table lt_plpo
        from plas as b
             inner join plpo as c
                   on bplnty = cplnty and
                      bplnnr = cplnnr and
                      bzaehl = czaehl
             inner join crhd as e
                   on carbid = eobjid
       where b~plnty = v_plnty          and           "Rate Routing
             b~plnnr = pi_plnnr         and
             b~plnal = pi_plnal         and
             c~loekz = space            and           "Oper Del Flag = OFF
             c~steus = v_plpo_steus     and           "PP04
             e~objty = v_objty.                       "WC Obj Type = 'A'
    read the last operation
      sort lt_plpo by vornr descending.
      read table lt_plpo index 1.
      pe_arbpl = lt_plpo-arbpl.
    endform.                    " read_wc_on_last_pp04
    Reward Points if it is useful
    Thanks
    Seshu

  • BDC book needed

    Anybody can introduce a good BDC BOOK including detail on session method, call transaction method. I have a friend, he want to learn BDC. Thanks a lot.

    Hai
    Go through the following Document & Examples
    Just check these links.
    Diff. between LSMW & BDC?
    BDC SESSION
    CALL TRANSACTION
    CALL DIALOG
    What is BDC or batch input
    The Batch Input is a SAP technic that allows automating the input in transactions. It lies on a BDC (Batch Data Commands) scenario.
    BDC functions:
    E BDC_OPEN_GROUP : Opens a session group
    E BDC_CLOSE_GROUP : Closes a session
    E BDC_INSERT : Insert a BDC scenario in the session
    E The ABAP statement "CALL TRANSACTION" is also called to run directly a transaction from its BDC table.
    It runs the program RSBDCSUB in order to launch automatically the session. The session management is done through the transaction code SM35.
    The object itself is maintanable through the transaction SE24.
    BDC methods:
    Method
    Description
    Parameters
    OPEN_SESSION
    Opens a session
    SUBRC (Return Code ? 0 OK)
    SESSIONNAME (Session to be created)
    CLOSE_SESSION
    Closes a session
    None
    RESET_BDCDATA
    Resets the BDC Internal Table...
    None. Normally, for internal purposec
    BDC_DYNPRO
    Handles a new screen
    PROGNAME (Name of the program)
    DYNPRONR (Screen Number)
    BDC_FIELD
    Puts a value on the screen
    FIELDNAME (Name of the field)
    FIELDVALUE (Value to be passed)
    CONSTRUCTOR
    Constructor - Initializes NO_DATA
    NODATA (No data character). The constructor is called automatically when the object is created.
    RUN_SESSION
    Launches a session with RSBDCBTC
    None
    CALL_TRANSACTION
    Calls a transaction with the current BDC Data
    MODE (Display Mode)
    UPDATE (Update Mode)
    TCODE (Transaction to be called)
    BDC_INSERT
    Inserts the BDC scenario in the session
    TCODE (Transaction to be called)
    BDC techniques used in programs:
    1) Building a BDC table and calling a transaction,
    2) Building a session and a set of BDC scenarios and keeping the session available in SM35,
    3) Building a session and lauching the transaction right after closing the session.
    BDC using Call Transaction
    BDC using Call transaction involves calling an SAP transaction in back ground from within the ABAP
    program. The process involves building an Internal BDC table containing the screen information needed to
    execute the required transaction and then passing this to the Call transaction command (See code example).
    The full procedure for creating a BDC program is as follows:
    What is the difference between batch input and call transaction in BDC?
    Session method.
    1) synchronous processing.
    2) can tranfer large amount of data.
    3) processing is slower.
    4) error log is created
    5) data is not updated until session is processed.
    Call transaction.
    1) asynchronous processing
    2) can transfer small amount of data
    3) processing is faster.
    4) errors need to be handled explicitly
    5) data is updated automatically
    BATINPUT/DIRECT INPUT
    A: Batch-inputs can not be used to fill the "delivery due list" screen because it is not a dynpro. This is a standard SAP report. A SAP report (check with "System -> Status") may be called using SUBMIT sentence with the appropriate options . It is preferred to call a report than create a Batch-input program.
    GO THROUGH THIS LINK
    http://www.guidancetech.com/people/holland/sap/abap/zzsni001.htm
    check with this code
    include bdcrecx1.
    tables : mara.
    data : begin of it_mara occurs 0,
    matnr like mara-matnr,
    mbrsh like mara-mbrsh,
    mtart like mara-mtart,
    maktx like makt-maktx,
    meins like mara-meins,
    end of it_mara.
    start-of-selection.
    perform upload_data.
    perform open_group.
    loop at it_mara.
    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'
    it_mara-matnr.
    perform bdc_field using 'RMMG1-MBRSH'
    it_mara-mbrsh.
    perform bdc_field using 'RMMG1-MTART'
    it_mara-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'
    it_mara-maktx.
    perform bdc_field using 'BDC_CURSOR'
    'MARA-MEINS'.
    perform bdc_field using 'MARA-MEINS'
    it_mara-meins.
    perform bdc_field using 'MARA-MTPOS_MARA'
    'NORM'.
    perform bdc_transaction using 'MM01'.
    endloop.
    perform close_group.
    *& Form upload_data
    text
    --> p1 text
    <-- p2 text
    FORM upload_data .
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    FILENAME = 'c:\mat_bdc.txt'
    FILETYPE = 'ASC'
    TABLES
    DATA_TAB = it_mara.
    IF SY-SUBRC = 0.
    SORT IT_MARA BY MATNR.
    ENDIF.
    ENDFORM. " upload_data
    flat file structure is
    PRANIT_011 CCOUP This is Testing material kg
    PRANIT_012 CCOUP This is Testing material kg
    PRANIT_013 CCOUP This is Testing material kg
    PRANIT_014 CCOUP This is Testing material kg
    PRANIT_015 CCOUP This is Testing material kg
    The steps to be followed are :
    1. Find out the relevant BAPI (BAPI_SALESORDER_CHANGE for VA02).
    [for VA01 use BAPI_SALESORDER_CREATEFROMDAT2]
    2. Create a Z program and call the BAPi (same as a Funtion module call).
    2. Now, if you see this BAPi, it has
    -> Importing structures.
    eg: SALESDOCUMENT: this will take the Sales order header data as input.
    -> Tables parameters:
    eg: ORDER_ITEM_IN: this will take the line item data as input.
    Note :
    Only specify fields that should be changed
    Select these fields by entering an X in the checkboxes
    Enter a U in the UPDATEFLAG field
    Always specify key fields when changing the data, including in the checkboxes
    The configuration is an exception here. If this needs to be changed, you need to complete it again fully.
    Maintain quantities and dates in the schedule line data
    Possible UPDATEFLAGS:
    U = change
    D = delete
    I = add
    Example
    1. Delete the whole order
    2. Delete order items
    3. Change the order
    4. Change the configuration
    Notes
    1. Minimum entry:
    You must enter the order number in the SALESDOCUMENT structure.
    You must always enter key fields for changes.
    You must always specify the update indicator in the ORDER_HEADER_INX.
    2. Commit control:
    The BAPI does not run a database Commit, which means that the application must trigger the Commit so that the changes are read to the database. To do this, use the BAPI_TRANSACTION_COMMIT BAPI.
    For further details... refer to the Function Module documentation for the BAPi.
    Go through the following Document
    BDC SESSION
    CALL TRANSACTION
    CALL DIALOG
    What is BDC or batch input
    The Batch Input is a SAP technic that allows automating the input in transactions. It lies on a BDC (Batch Data Commands) scenario.
    BDC functions:
    E BDC_OPEN_GROUP : Opens a session group
    E BDC_CLOSE_GROUP : Closes a session
    E BDC_INSERT : Insert a BDC scenario in the session
    E The ABAP statement "CALL TRANSACTION" is also called to run directly a transaction from its BDC table.
    It runs the program RSBDCSUB in order to launch automatically the session. The session management is done through the transaction code SM35.
    The object itself is maintanable through the transaction SE24.
    BDC methods:
    Method
    Description
    Parameters
    OPEN_SESSION
    Opens a session
    SUBRC (Return Code ? 0 OK)
    SESSIONNAME (Session to be created)
    CLOSE_SESSION
    Closes a session
    None
    RESET_BDCDATA
    Resets the BDC Internal Table...
    None. Normally, for internal purposec
    BDC_DYNPRO
    Handles a new screen
    PROGNAME (Name of the program)
    DYNPRONR (Screen Number)
    BDC_FIELD
    Puts a value on the screen
    FIELDNAME (Name of the field)
    FIELDVALUE (Value to be passed)
    CONSTRUCTOR
    Constructor - Initializes NO_DATA
    NODATA (No data character). The constructor is called automatically when the object is created.
    RUN_SESSION
    Launches a session with RSBDCBTC
    None
    CALL_TRANSACTION
    Calls a transaction with the current BDC Data
    MODE (Display Mode)
    UPDATE (Update Mode)
    TCODE (Transaction to be called)
    BDC_INSERT
    Inserts the BDC scenario in the session
    TCODE (Transaction to be called)
    BDC techniques used in programs:
    1) Building a BDC table and calling a transaction,
    2) Building a session and a set of BDC scenarios and keeping the session available in SM35,
    3) Building a session and lauching the transaction right after closing the session.
    BDC using Call Transaction
    BDC using Call transaction involves calling an SAP transaction in back ground from within the ABAP
    program. The process involves building an Internal BDC table containing the screen information needed to
    execute the required transaction and then passing this to the Call transaction command (See code example).
    The full procedure for creating a BDC program is as follows:
    What is the difference between batch input and call transaction in BDC?
    Session method.
    1) synchronous processing.
    2) can tranfer large amount of data.
    3) processing is slower.
    4) error log is created
    5) data is not updated until session is processed.
    Call transaction.
    1) asynchronous processing
    2) can transfer small amount of data
    3) processing is faster.
    4) errors need to be handled explicitly
    5) data is updated automatically
    BATINPUT/DIRECT INPUT
    A: Batch-inputs can not be used to fill the "delivery due list" screen because it is not a dynpro. This is a standard SAP report. A SAP report (check with "System -> Status") may be called using SUBMIT sentence with the appropriate options . It is preferred to call a report than create a Batch-input program.
    GO THROUGH THIS LINK
    http://www.guidancetech.com/people/holland/sap/abap/zzsni001.htm
    The LSM Workbench is an SAP R/3 based tool that supports the one-time or periodic transfer of data from non-SAP systems ("legacy systems") to SAP systems.
    The LSM Workbench helps you to organize your data migration project and guides you through the process by using a clear sequence of steps.
    The most common conversion rules are predefined. Reusable conversion rules assure consistent data conversion for different data objects.
    LSMW vs DX Workbench
    The LSM Workbench covers the following steps:
    Read the legacy data from one or several files (e.g. spreadsheet tables, sequential files).
    Convert the data from source format to target format.
    Import the data using standard interfaces (Batch Input, Direct Input, BAPI, IDoc).
    Experiences made in successful implementation projects have shown that using the LSM Workbench significantly contributes to accelerating data migration.
    SAP provides this tool along with documentation to customers and partners free of charge.
    Users of the LSM Workbench receive the usual support via SAP Net - R/3 Frontend (component BC-SRV-DX-LSM).
    Releases:
    Version 1.7.2 of the LSM Workbench ("LSMW 1.7.2") available
    Attention : LSMW 1.7.2 requires an SAP R/3 system with SAP R/3 4.0 or SAP R/3 4.5.
    Version 1.8.0 of the LSM Workbench (1.21mb) ("LSMW 1.8.0") available
    Attention : LSMW 1.8.0 requires an SAP R/3 system with SAP R/3 4.6.
    Version 3.0 of the LSM Workbench (1.89mb) ("LSMW 3.0") available for Web Application Server 6.10
    Attention : LSMW 3.0 requires a SAP WAS 6.10. Functionality of version 1.7.2 and 3.0 are identical !
    Version 4.0 of the LSM Workbench ("LSMW 4.0") integrated in Web Application Server 6.20
    Attention : LSMW 4.0 is an integrated part of SAP WAS 6.20.
    Regards
    Sreeni

  • Bdc session sample program

    Hi,
    Please any body send a sample program for bdc session method.
    Thanks,
    sreedhar.

    See the BDC Session method program :
    report zmppc011 no standard page heading line-size 120 line-count 55
       message-id zz.
    pool of form routines
    include zmppn001.
    Define BDC Table Structure
    data: begin of itab_bdc_tab occurs 0.
            include structure bdcdata.
    data: end of itab_bdc_tab.
    Input record layout of Leagcy File
    data: begin of itab_xcel occurs 0,
            matnr(18)  type c,
            werks(4)   type c,
            alnag(2)   type c,
            verid(4)   type c,
            text1(40)  type c,
            bstmi      like mkal-bstmi,
            bstma      like mkal-bstma,
            adatu(10)  type c,
            bdatu(10)  type c,
            stlal(2)   type c,
            stlan(1)   type c,
            serkz(1)   type c,
            mdv01(8)   type c,
            elpro(4)   type c,
            alort(4)   type c,
          end of itab_xcel.
    data: begin of lt_pp04_cache occurs 0,
            matnr like itab_xcel-matnr,
            werks like itab_xcel-werks,
            alnag like itab_xcel-alnag,
            plnnr like mapl-plnnr,
            arbpl like crhd-arbpl,
            ktext like crtx-ktext,
          end of lt_pp04_cache.
    data: v_ssnnr(4)      type n,
          v_lines_in_xcel like sy-tabix,
          v_ssnname       like apqi-groupid,
          v_trans_in_ssn  type i,
         wa_xcel         LIKE itab_xcel,
          l_tabix         like sy-tabix,
          v_matnr         like rc27m-matnr,
          v_plnnr         like mapl-plnnr,
          v_plnal         like mapl-plnal,
          v_tcode         like sy-tcode value 'C223',
          v_plnty         like plas-plnty value 'R',
          v_objty         like crhd-objty value 'A',
          v_plpo_steus    like plpo-steus value 'PP04',
          v_verwe         like crhd-verwe value '0007'.
    Parameters
    selection-screen: skip 3.
    selection-screen: begin of block 1 with frame.
    parameters: p_name        like rlgrap-filename
                              default 'C:\My Documents\InputFile.txt'
                              obligatory,
    bdc session name prefix
                p_bdcpfx(6)   default 'ZPVCRT'
                              obligatory,
    number for transction per BDC session
                p_trnssn      type i
                              default 2000 obligatory,
    retain the BDC session after successfull execution
                p_keep        like apqi-qerase
                              default 'X',
    user who will be executing BDC session
                p_uname       like apqi-userid
                              default sy-uname
                              obligatory.
    selection-screen: end of block 1.
    possible entry list (F4 dropdown) for input file name
    at selection-screen on value-request for p_name.
    *-SELECT FILE FROM USERS LOCAL PC
      call function 'WS_FILENAME_GET'
          exporting
             DEF_FILENAME     = ' '
               def_path         = 'C:\Temp\'
               mask             = ',.,..'
               mode             = 'O'
               title            = 'Select File '(007)
          importing
               filename         = p_name
             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.
    begin the show
    start-of-selection.
    read data from input file
      perform transfer_xcel_to_itab.
      loop at itab_xcel.
      hang on to xcel line num
        l_tabix = sy-tabix.
      each line in the xcel file marks begining of new prod.version defn
      if num-of-trnas-in-session = 0, create new BDC session
        if v_trans_in_ssn is initial.
          perform bdc_session_open.
        endif.
      begin new bdc script for rtg create trans
      fill in bdc-data for prod.version maintenance screens
        perform bdc_build_script.
      insert the bdc script as a BDC transaction
        perform bdc_submit_transaction.
      keep track of how many BDC transactions were inserted in the BDC
      session
        add 1 to v_trans_in_ssn.
      if the user-specified num of trans in BDC session is reached OR
      if end of input file is reached, close the BDC session
        if v_trans_in_ssn = p_trnssn or
           l_tabix = v_lines_in_xcel.
          perform bdc_session_close.
          clear v_trans_in_ssn.
        endif.
      endloop.
    top-of-page.
      call function 'Z_HEADER'
    EXPORTING
      FLEX_TEXT1       =
      FLEX_TEXT2       =
      FLEX_TEXT3       =
          FORM TRANSFER_XCEL_TO_ITAB                                    *
          Transfer Xcel Spreadsheet to SAP Internal Table               *
    form transfer_xcel_to_itab.
    Read the tab-delimited file into itab
      call function 'WS_UPLOAD'
           exporting
                filename            = p_name
                filetype            = 'DAT'
          IMPORTING
               filelength          = flength
           tables
                data_tab            = itab_xcel
           exceptions
                conversion_error    = 1
                file_open_error     = 2
                file_read_error     = 3
                invalid_table_width = 4
                invalid_type        = 5
                no_batch            = 6
                unknown_error       = 7
                others              = 8.
      if sy-subrc = 0.
      sort the data
        sort itab_xcel by matnr werks.
        clear v_lines_in_xcel.
      if no data in the file - error out
        describe table itab_xcel lines v_lines_in_xcel.
        if v_lines_in_xcel is initial.
          write: / 'No data in input file'.
          stop.
        endif.
      else.
      if file upload failed - error out
        write: / 'Error reading input file'.
        stop.
      endif.
    endform.
          FORM BDC_SESSION_OPEN                                         *
          Open BDC Session                                              *
    form bdc_session_open.
    create bdc session name = prefix-from-selectn-screen + nnnn
      add 1 to v_ssnnr.
      concatenate p_bdcpfx v_ssnnr into v_ssnname.
    open new bdc session
      call function 'BDC_OPEN_GROUP'
           exporting
                client              = sy-mandt
                group               = v_ssnname
                keep                = p_keep
                user                = p_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.
    endform.
          FORM BDC_BUILD_SCRIPT                                         *
          Build BDC                                                     *
    form bdc_build_script.
      data: l_arbpl like crhd-arbpl,
            l_text1 like mkal-text1,
            l_mdv01 like mkal-mdv01,
            l_mapl  like mapl.
    clear bdc-data itab - begin of new bdc transaction
      clear   itab_bdc_tab.
      refresh itab_bdc_tab.
    read material cross reference tables to determine sap part#
      clear : v_matnr, v_plnnr, v_plnal.
      perform read_matnr_cross_ref using itab_xcel-matnr
                                         itab_xcel-werks
                                   changing v_matnr.
    determine the version description to use
      if itab_xcel-text1 is initial.
        l_text1 = itab_xcel-verid.
      else.
        l_text1 = itab_xcel-text1.
      endif.
    determine the routing group# and group ctr# to use
      perform read_routing .
    determine the production line to use
      if itab_xcel-mdv01 is initial.
      if not provided in the file then:
      prod line = work ctr on the last PP04 op of the rtg determined above
        perform read_wc_on_last_pp04 using v_plnnr v_plnal
                                  changing l_mdv01.
      NOTE: when executing the above form\routine, if v_plnnr is initial
            or v_plnal is initial, THEN l_mdv01 will automatically be
            returned blank (ie initial)
      else.
        l_mdv01 = itab_xcel-mdv01.
      endif.
    build bdc script
      perform bdc_build_script_record
    fill in initial screen
              using: 'X' 'SAPLCMFV'         '1000',
                     ' ' 'BDC_OKCODE'       '=ENTE',
                     ' ' 'MKAL-WERKS'       itab_xcel-werks,
                     ' ' 'MKAL-MATNR'       v_matnr,
                     ' ' 'MKAL_ADMIN-DISPO' space,
                     ' ' 'MKAL-PLNNR'       space,
                     ' ' 'MKAL_ADMIN-STTAG' space,
                     ' ' 'MKAL-PLNNG'       space,
                     ' ' 'MKAL-MDV01'       space,
                     ' ' 'MKAL-PLNNM'       space,
    click create button on initial screen and go to detail screen
                     'X' 'SAPLCMFV'         '1000',
                     ' ' 'BDC_OKCODE'       '=CREA',
    fill in the detail screen and go back to initial screen
                     'X' 'SAPLCMFV'           '2000',
                     ' ' 'BDC_OKCODE'         '=CLOS',
                     ' ' 'MKAL_EXPAND-MATNR'  v_matnr,
                     ' ' 'MKAL_EXPAND-VERID'  itab_xcel-verid,
                     ' ' 'MKAL_EXPAND-TEXT1'  l_text1,
                     ' ' 'MKAL_EXPAND-BSTMI'  itab_xcel-bstmi,
                     ' ' 'MKAL_EXPAND-BSTMA'  itab_xcel-bstma,
                     ' ' 'MKAL_EXPAND-ADATU'  itab_xcel-adatu,
                     ' ' 'MKAL_EXPAND-BDATU'  itab_xcel-bdatu,
                     ' ' 'MKAL_EXPAND-PLTYG'  v_plnty,
                     ' ' 'MKAL_EXPAND-PLNNG'  v_plnnr,
                     ' ' 'MKAL_EXPAND-ALNAG'  v_plnal,
                     ' ' 'MKAL_EXPAND-STLAL'  itab_xcel-stlal,
                     ' ' 'MKAL_EXPAND-STLAN'  itab_xcel-stlan,
                     ' ' 'MKAL_EXPAND-SERKZ'  itab_xcel-serkz,
                     ' ' 'MKAL_EXPAND-MDV01'  l_mdv01,
                     ' ' 'MKAL_EXPAND-ELPRO'  itab_xcel-elpro,
                     ' ' 'MKAL_EXPAND-ALORT'  itab_xcel-alort,
    save the production version from initial screen
                     'X' 'SAPLCMFV'           '1000',
                     ' ' 'BDC_OKCODE'         '=SAVE'.
    endform.
          FORM BDC_SUBMIT_TRANSACTION                                   *
          Submit BDC Session                                            *
    form bdc_submit_transaction.
    Load BDC script as a trqansction in BDC session
      call function 'BDC_INSERT'
           exporting
                tcode          = v_tcode
           tables
                dynprotab      = itab_bdc_tab
           exceptions
                internal_error = 01
                not_open       = 02
                queue_error    = 03
                tcode_invalid  = 04.
    endform.
          FORM BDC_BUILD_SCRIPT_RECORD                                  *
    form bdc_build_script_record using dynbegin name value.
      clear itab_bdc_tab.
      if dynbegin = 'X'.
        move: name  to itab_bdc_tab-program,
              value to itab_bdc_tab-dynpro,
              'X'   to itab_bdc_tab-dynbegin.
      else.
        move: name  to itab_bdc_tab-fnam,
              value to itab_bdc_tab-fval.
        shift itab_bdc_tab-fval left deleting leading space.
      endif.
      append itab_bdc_tab.
    endform.
          FORM BDC_SESSION_CLOSE                                        *
          Close BDC Session                                             *
    form bdc_session_close.
    close the session
      call function 'BDC_CLOSE_GROUP'
           exceptions
                not_open    = 1
                queue_error = 2
                others      = 3.
      skip 2.
      if sy-subrc ne 0.
        write: / 'Error Closing BDC Session ' , 'RETURN CODE: ', sy-subrc.
      else.
        write : /  'Session created:', v_ssnname,
                50 '# of transactions:', v_trans_in_ssn.
      endif.
    endform.
    *&      Form  read_routing_cache
    *FORM read_routing_cache USING    pi_matnr
                                    pi_werks
                                    pi_alnag
                                    pi_verid
                                    pi_mdv01.
    DATA: BEGIN OF lt_plpo OCCURS 0,
             vornr LIKE plpo-vornr,
             objty LIKE crhd-objty,
             objid LIKE crhd-objid,
             arbpl LIKE crhd-arbpl,
           END OF lt_plpo,
           l_mapl_plnnr LIKE mapl-plnnr.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
                                       werks = pi_werks
                                       alnag = pi_alnag.
    IF sy-subrc = 0.
      do nothing - lt_pp04_cache header line has rtg#
    ELSE.
      get the routing group # from MAPL
       SELECT plnnr INTO l_mapl_plnnr
         FROM mapl UP TO 1 ROWS
        WHERE matnr = pi_matnr    AND
              werks = pi_werks    AND
              plnty = 'R'         AND
              plnal = pi_alnag    AND
              loekz = space.
       ENDSELECT.
      put it in the cache internal table
       IF NOT l_mapl_plnnr IS INITIAL.
         lt_pp04_cache-matnr = pi_matnr.
         lt_pp04_cache-werks = pi_werks.
         lt_pp04_cache-alnag = pi_alnag.
         lt_pp04_cache-plnnr = l_mapl_plnnr.
         APPEND lt_pp04_cache.
       ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
            lt_pp04_cache-arbpl IS INITIAL AND
        ( pi_verid IS INITIAL OR
          pi_mdv01 IS INITIAL ).
      read the last PP04 operation
       CLEAR   lt_plpo.
       REFRESH lt_plpo.
       SELECT vornr eobjty eobjid e~arbpl
         INTO CORRESPONDING FIELDS OF TABLE lt_plpo
         FROM plas AS b
              INNER JOIN plpo AS c
                    ON bplnty = cplnty AND
                       bplnnr = cplnnr AND
                       bzaehl = czaehl
              INNER JOIN crhd AS e
                    ON carbid = eobjid
        WHERE b~plnty = v_plnty             AND
              b~plnnr = lt_pp04_cache-plnnr AND
              b~plnal = lt_pp04_cache-alnag AND
              c~loekz = space               AND
              c~steus = v_plpo_steus        AND
              e~objty = v_objty             AND
              e~werks = lt_pp04_cache-werks AND
              e~verwe = v_verwe.
       SORT lt_plpo BY vornr DESCENDING.
       READ TABLE lt_plpo INDEX 1.
       IF NOT lt_plpo-arbpl IS INITIAL.
         lt_pp04_cache-arbpl = lt_plpo-arbpl.
        read work center description
         SELECT SINGLE ktext INTO lt_pp04_cache-ktext
           FROM crtx WHERE objty = lt_plpo-objty AND
                           objid = lt_plpo-objid AND
                           spras = sy-langu.
        the following read will get the index of the correct record to be
        updated in the cache
         READ TABLE lt_pp04_cache
              WITH KEY matnr = pi_matnr
                       werks = pi_werks
                       alnag = pi_alnag.
         MODIFY lt_pp04_cache
                INDEX sy-tabix
                TRANSPORTING arbpl ktext.
       ENDIF.
    ENDIF.
    *ENDFORM.                    " read_last_pp04_operation_cache
    *&      Form  read_routing
    form read_routing.
      data: begin of lt_mapl occurs 0,
              plnnr like mapl-plnnr,
              plnal like mapl-plnal,
            end of lt_mapl,
            l_arbpl like crhd-arbpl.
    get all the rtg# and grp ctr# from MAPL
      select plnnr plnal
        into corresponding fields of table lt_mapl
        from mapl
       where matnr = v_matnr          and
             werks = itab_xcel-werks  and
             plnty = v_plnty          and     "Rate Routing
             loekz = space.                   "with del flag = OFF
      sort lt_mapl by plnal.
      if not itab_xcel-verid is initial.
      if the verid=0001 then use the 1st good rtg-grp# and grp-ctr#
        if itab_xcel-verid = '0001'.
          read table lt_mapl index 1.
          v_plnnr = lt_mapl-plnnr.
          v_plnal = lt_mapl-plnal.
        else.
      if the verid<>0001 then use the rtg-grp# and grp-ctr# of the routing
      whose work center on the last PP04 operation matches the given verid
          loop at lt_mapl.
            clear l_arbpl.
          get the work center from the last PP04 operation
            perform read_wc_on_last_pp04 using lt_mapl-plnnr
                                               lt_mapl-plnal
                                      changing l_arbpl.
            if itab_xcel-verid = l_arbpl.
              v_plnnr = lt_mapl-plnnr.
              v_plnal = lt_mapl-plnal.
              exit.
            endif.
          endloop.
        endif.
      else.
      do nothing
      endif.
    For version IDs that are other then '0000' or 'ZWIP' :--
      if itab_xcel-verid NE '0000' and
         itab_xcel-verid NE 'ZWIP'.
      if routing group# or group counter was not determined, make the
      valid-to date 99/99/9999 so that the BDC, on execution, errors out.
        if v_plnnr is initial or
           v_plnal is initial.
          itab_xcel-bdatu = '99/99/9999'.
        endif.
      endif.
    determine the routing group#
    CLEAR lt_pp04_cache.
    chk if its in the cache first, if not then get it from MAPL table
    and put it in the cache
    READ TABLE lt_pp04_cache WITH KEY matnr = pi_matnr
                                       werks = pi_werks
                                       alnag = pi_alnag.
    IF sy-subrc = 0.
      do nothing - lt_pp04_cache header line has rtg#
    ELSE.
      get the routing group # from MAPL
      put it in the cache internal table
       IF NOT l_mapl_plnnr IS INITIAL.
         lt_pp04_cache-matnr = pi_matnr.
         lt_pp04_cache-werks = pi_werks.
         lt_pp04_cache-alnag = pi_alnag.
         lt_pp04_cache-plnnr = l_mapl_plnnr.
         APPEND lt_pp04_cache.
       ENDIF.
    ENDIF.
    if the rtg# was determined AND
    -- the work center was not determined yet AND
    -- work center was really needed for this line in the input file
    then
    -- read the work center from last PP04 operation on the routing
    -- update the cache accordingly
    IF NOT lt_pp04_cache-plnnr IS INITIAL AND
            lt_pp04_cache-arbpl IS INITIAL AND
        ( pi_verid IS INITIAL OR
          pi_mdv01 IS INITIAL ).
      read the last PP04 operation
       CLEAR   lt_plpo.
       REFRESH lt_plpo.
       SELECT vornr eobjty eobjid e~arbpl
         INTO CORRESPONDING FIELDS OF TABLE lt_plpo
         FROM plas AS b
              INNER JOIN plpo AS c
                    ON bplnty = cplnty AND
                       bplnnr = cplnnr AND
                       bzaehl = czaehl
              INNER JOIN crhd AS e
                    ON carbid = eobjid
        WHERE b~plnty = v_plnty             AND
              b~plnnr = lt_pp04_cache-plnnr AND
              b~plnal = lt_pp04_cache-alnag AND
              c~loekz = space               AND
              c~steus = v_plpo_steus        AND
              e~objty = v_objty             AND
              e~werks = lt_pp04_cache-werks AND
              e~verwe = v_verwe.
       SORT lt_plpo BY vornr DESCENDING.
       READ TABLE lt_plpo INDEX 1.
       IF NOT lt_plpo-arbpl IS INITIAL.
         lt_pp04_cache-arbpl = lt_plpo-arbpl.
        read work center description
         SELECT SINGLE ktext INTO lt_pp04_cache-ktext
           FROM crtx WHERE objty = lt_plpo-objty AND
                           objid = lt_plpo-objid AND
                           spras = sy-langu.
        the following read will get the index of the correct record to be
        updated in the cache
         READ TABLE lt_pp04_cache
              WITH KEY matnr = pi_matnr
                       werks = pi_werks
                       alnag = pi_alnag.
         MODIFY lt_pp04_cache
                INDEX sy-tabix
                TRANSPORTING arbpl ktext.
       ENDIF.
    ENDIF.
    endform.                    " read_last_pp04_operation_cache
    *&      Form  read_wc_on_last_pp04
    form read_wc_on_last_pp04 using    pi_plnnr
                                       pi_plnal
                              changing pe_arbpl.
      data: begin of lt_plpo occurs 0,
              vornr like plpo-vornr,
              objty like crhd-objty,
              objid like crhd-objid,
              arbpl like crhd-arbpl,
            end of lt_plpo.
    get all the PP04 operations for the given rtg# & grp-ctr#
      select vornr eobjty eobjid e~arbpl
        into corresponding fields of table lt_plpo
        from plas as b
             inner join plpo as c
                   on bplnty = cplnty and
                      bplnnr = cplnnr and
                      bzaehl = czaehl
             inner join crhd as e
                   on carbid = eobjid
       where b~plnty = v_plnty          and           "Rate Routing
             b~plnnr = pi_plnnr         and
             b~plnal = pi_plnal         and
             c~loekz = space            and           "Oper Del Flag = OFF
             c~steus = v_plpo_steus     and           "PP04
             e~objty = v_objty.                       "WC Obj Type = 'A'
    read the last operation
      sort lt_plpo by vornr descending.
      read table lt_plpo index 1.
      pe_arbpl = lt_plpo-arbpl.
    endform.                    " read_wc_on_last_pp04

  • How we load Bom through bdc pgm

    Hi I want to load BOM through BDC pgm in wich i am unbale to record the screect flow b coz it asking abt materical not matiching so can u plz send me the navigation screen flow and exple of fields in with i can enter in BOM throus cs01 transaction ... this is very urgent.. Thanking U

    Hi
    See the Below sample Program ....
    Program Loads the Bill of Material
    *&   REPORT ZPP0120                                                    *
    *& Module : PP                                                         |
    *& Application : The program loads the Bill of Material                |
    *&                                                                     |
    *| Modification Log                                                    |
    *| ----------------                                                    |
    REPORT zpp0120 NO STANDARD PAGE HEADING
                                      MESSAGE-ID z0
                                      LINE-SIZE  132
                                      LINE-COUNT 65(2).
    *                      Internal Tables                                 *
    *Internal table for the BOM file.
    DATA: BEGIN OF i_bom OCCURS 0,
          matnr(18),
          werks(4),
          stlan(1),
          stlal(2),
          stktx(40),
          bmeng(16),
          menge(16),
          posnr(4),
          postp(1),
          meins(3),
          datuv(10),
          fmeng(1),
          idnrk(18),
          potx1(40),
          ausch(7),
          END OF i_bom.
    * Extracting Document and Doc type for POSTP = D.
    DATA : BEGIN OF i_stpo OCCURS 1,
           doknr(25),
           dokar(3),
           posnr(4),
           stlnr LIKE mast-stlnr,
           END   OF i_stpo.
    * Local work area
    DATA:  g_my_rec_in   LIKE i_bom.
    ** Declare internal table for Call Transaction and BDC Session
    DATA: i_bdc_table LIKE bdcdata OCCURS 0 WITH HEADER LINE.
    *                      Global Variables                                *
    DATA: g_counter(2) TYPE n,
          g_field_name(18) TYPE c,
          zc_yes  TYPE syftype VALUE 'X'.
    *                      Selection Screen                                *
    SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
    PARAMETERS: p_fname1 TYPE localfile .
    SELECTION-SCREEN SKIP 1.
    SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
    PARAMETERS: p_rloc1 AS CHECKBOX  DEFAULT 'X'.
    SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-005.
    PARAMETERS p_group(12) OBLIGATORY DEFAULT 'ZBOM'.
    SELECTION-SCREEN END OF BLOCK c.
    SELECTION-SCREEN END OF BLOCK b.
    SELECTION-SCREEN END OF BLOCK a.
    **WRITE the report header
    TOP-OF-PAGE.
      INCLUDE zheading.
    *                      Start of selection                              *
    START-OF-SELECTION.
    * Load Input file
      PERFORM f_load_input_file.
    * Create BDC records.
      PERFORM create_bdc_records .
    *&      Form  Create_BDC_records
    *       text:* perform the BDC for the records in the internal table
    *  -->  p1        text
    *  <--  p2        text
    FORM create_bdc_records .
      DATA: v_stlnr LIKE mast-stlnr.
      DATA: v_postp(1) VALUE 'D'.
      IF NOT i_bom[] IS INITIAL.
    ** Open BDC session
        PERFORM open_bdc_session.
        SORT i_bom BY matnr werks posnr.
        SELECT  SINGLE stlnr  INTO v_stlnr
        FROM mast
        WHERE    matnr = i_bom-matnr
         AND     werks = i_bom-werks.
        SELECT doknr dokar posnr stlnr
                    INTO TABLE i_stpo
                    FROM stpo
                    FOR ALL ENTRIES IN i_bom
                    WHERE postp = v_postp
                    AND   posnr = i_bom-posnr
                    AND   stlnr = v_stlnr.
        SORT i_stpo BY posnr stlnr.
        LOOP AT i_bom.
          g_my_rec_in = i_bom.
          READ TABLE i_stpo WITH KEY posnr = i_bom-posnr
                                     stlnr = v_stlnr
                                     BINARY SEARCH.
          AT NEW matnr.
            CLEAR i_bdc_table[].
            PERFORM insert_screen_header.
          ENDAT.
    * Setting up counter for 20 line items
          IF g_counter = 20.
            g_counter = 1.
          ENDIF.
          PERFORM bdc_field  USING 'BDC_OKCODE'
                                        '/00'.
    *next screen
          PERFORM bdc_dynpro USING 'SAPLCSDI' '0140'.
          PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29P-FMENG(01)'.
          PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
          CONCATENATE 'RC29P-POSNR('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-posnr.
          CONCATENATE 'RC29P-IDNRK('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-idnrk.
          CONCATENATE 'RC29P-MENGE('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-menge.
          CONCATENATE 'RC29P-MEINS('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-meins.
          CONCATENATE 'RC29P-POSTP('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-postp.
          CONCATENATE 'RC29P-FMENG('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-fmeng.
    *next screen
          PERFORM bdc_dynpro USING 'SAPLCSDI' '0130'.
          PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
    * Check the Item category to direct the screen flow accordingly.
          CASE i_bom-postp.
            WHEN 'B'.
              PERFORM item_text_insert.
            WHEN 'Z'.
              PERFORM item_text_insert.
            WHEN 'T'.
              PERFORM item_text_insert.
            WHEN 'N'.
              PERFORM bdc_field   USING 'BDC_CURSOR' 'RC29P-AUSCH'.
              PERFORM bdc_field   USING 'RC29P-AUSCH' i_bom-ausch.
    * next screen
              PERFORM item_text_insert.
    *next screen
              PERFORM bdc_dynpro  USING 'SAPLCSDI' '0133'.
              PERFORM bdc_field   USING 'BDC_OKCODE' '/00'.
              PERFORM bdc_field   USING 'RC29P-EKORG' ' '.
            WHEN 'D'.
              PERFORM bdc_field   USING 'RC29P-DOKNR' i_stpo-doknr.
              PERFORM bdc_field   USING 'RC29P-DOKAR' i_stpo-dokar.
    * next screen
              PERFORM item_text_insert.
    * When POSTP = X, L.
            WHEN OTHERS.
              PERFORM bdc_field   USING 'BDC_CURSOR' 'RC29P-AUSCH'.
              PERFORM bdc_field   USING 'RC29P-AUSCH' i_bom-ausch.
    * next screen
              PERFORM item_text_insert.
          ENDCASE.
          g_counter = g_counter + 1.
    * next screen
          PERFORM bdc_dynpro      USING 'SAPLCSDI' '0140'.
          PERFORM bdc_field       USING 'BDC_CURSOR' 'RC29P-POSNR(01)'.
          PERFORM bdc_field       USING 'BDC_OKCODE' '=FCBU'.
          AT END OF matnr.
            PERFORM insert_bdc_new.
          ENDAT.
        ENDLOOP.
        CLEAR i_bom[].
        PERFORM close_bdc_session.
    ** Release the BDC sessions created
        PERFORM release_bdc.
      ENDIF.
    ENDFORM.                    " open_group
    *&      Form  bdc_dynpro_start
    *       Initialize the screen
    *      -->P_G_PROGRAM_1
    *      -->P_G_SCREEN
    FORM bdc_dynpro USING    p_g_program_1
                                    p_g_screen.
      CLEAR i_bdc_table.
      i_bdc_table-program  = p_g_program_1.
      i_bdc_table-dynpro   = p_g_screen.
      i_bdc_table-dynbegin = 'X'.
      APPEND i_bdc_table.
    ENDFORM.                    " bdc_dynpro_start
    *&      Form  bdc_field
    *        Insert field                                                  *
    FORM bdc_field USING f_name f_value.
      CLEAR i_bdc_table.
      i_bdc_table-fnam = f_name.
      i_bdc_table-fval = f_value.
      APPEND i_bdc_table.
    ENDFORM.                    "bdc_insert_field
    *&      Form  open_bdc_session
    *      Open the BDC session
    FORM open_bdc_session .
    ** Open BDC session and creat and update condition records
      CALL FUNCTION 'BDC_OPEN_GROUP'
        EXPORTING
          client                    = sy-mandt
    *       DEST                      = FILLER8
          group                     = p_group
    *       HOLDDATE                  = FILLER8
          keep                      = 'X'
          user                      = sy-uname
    *       RECORD                    = FILLER1
    *       PROG                      = SY-CPROG
    *     IMPORTING
    *       QID                       =
    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.                    " create_bdc_session
    *&      Form  insert_screen_header
    *       Insert the Header data into the screens
    FORM insert_screen_header .
      g_counter = 1.
      PERFORM bdc_dynpro USING 'SAPLCSDI' '0100'.
      PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29N-STLAL'.
      PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
      PERFORM bdc_field  USING 'RC29N-MATNR' g_my_rec_in-matnr.
      PERFORM bdc_field  USING 'RC29N-WERKS' g_my_rec_in-werks.
      PERFORM bdc_field  USING 'RC29N-STLAN' g_my_rec_in-stlan.
      PERFORM bdc_field  USING 'RC29N-STLAL' g_my_rec_in-stlal.
      PERFORM bdc_field  USING 'RC29N-DATUV' g_my_rec_in-datuv.
    * next screen
      PERFORM bdc_dynpro USING 'SAPLCSDI' '0110'.
      PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29K-BMENG'.
      PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
      PERFORM bdc_field  USING 'RC29K-STKTX' g_my_rec_in-stktx.
      PERFORM bdc_field  USING 'RC29K-BMENG' g_my_rec_in-bmeng.
    *next screen
      PERFORM bdc_dynpro USING 'SAPLCSDI' '0111'.
      PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29K-LABOR'.
    ENDFORM.                    " insert_screen_header
    *&      Form  insert_bdc
    *      Insert the BDC session
    FORM insert_bdc_new .
      CALL FUNCTION 'BDC_INSERT'
         EXPORTING
           tcode                  = 'CS01'
    *       POST_LOCAL             = NOVBLOCAL
    *       PRINTING               = NOPRINT
    *       SIMUBATCH              = ' '
    *       CTUPARAMS              = ' '
         TABLES
           dynprotab              = i_bdc_table
      EXCEPTIONS
        internal_error         = 1
        not_open               = 2
        queue_error            = 3
        tcode_invalid          = 4
        printing_invalid       = 5
        posting_invalid        = 6
        OTHERS                 = 7
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CLEAR i_bdc_table[].
    ENDFORM.                    " insert_bdc
    *&      Form  close_bdc_session
    *       Close the BDC session
    FORM close_bdc_session .
      CALL FUNCTION 'BDC_CLOSE_GROUP'
           EXCEPTIONS
                not_open    = 1
                queue_error = 2
                OTHERS      = 3.
      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.                    " close_bdc_session
    *&      Form  f_load_input_file
    *      Load the file into the Internal table
    FORM f_load_input_file.
      IF p_rloc1 = zc_yes.
        CALL FUNCTION 'WS_UPLOAD'
             EXPORTING
                  filename                = p_fname1
                  filetype                = 'DAT'
             TABLES
                  data_tab                = i_bom
             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.
          STOP.
        ENDIF.
      ENDIF.
    ENDFORM.                    " f_load_input_file
    *&      Form  release_bdc
    *      Release BDC session
    FORM release_bdc.
      SUBMIT rsbdcsub WITH mappe EQ p_group
                      WITH von EQ sy-datum
                      WITH bis EQ sy-datum
                      WITH fehler EQ '.'
                      EXPORTING LIST TO MEMORY
                      AND RETURN.
    ENDFORM.                    " release_bdc
    *&      Form  item_text_insert
    *       Repetitive code in the screen flow
    FORM item_text_insert.
      PERFORM bdc_dynpro USING 'SAPLCSDI' '0131'.
      PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
      PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29P-POTX1'.
      PERFORM bdc_field  USING 'RC29P-POTX1' i_bom-potx1.
    ENDFORM.                    " item_text_insert

  • Logic needed Pls help

    Hi
    I have to add 'Upload excel file' option in Material consumption program. Current logic is Uploading Unix file. Can any one give me some idea pls.
    following is my coding
    PROGRAM ZMDM0081 MESSAGE-ID ZM.
    TABLES: MARA.
    * Resource file record structure
    DATA: BEGIN OF RECORD,
            MATERIAL_NUMBER(10),
            PLANT(5),
            CORRECTED_VALUE_19(11),
            CORRECTED_VALUE_18(11),
            CORRECTED_VALUE_17(11),
            CORRECTED_VALUE_16(11),
            CORRECTED_VALUE_15(11),
            CORRECTED_VALUE_14(11),
            CORRECTED_VALUE_13(11),
            CORRECTED_VALUE_12(11),
            CORRECTED_VALUE_11(11),
            CORRECTED_VALUE_10(11),
            CORRECTED_VALUE_09(11),
            CORRECTED_VALUE_08(11),
            CORRECTED_VALUE_07(11),
            CORRECTED_VALUE_06(11),
            CORRECTED_VALUE_05(11),
            CORRECTED_VALUE_04(11),
            CORRECTED_VALUE_03(11),
            CORRECTED_VALUE_02(11),
            CORRECTED_VALUE_01(11),
          END OF RECORD.
    * Working variables
    DATA: RECORD_READ(6)   TYPE P,
          RECORD_INSERT(6) TYPE P,
          RECORD_OMIT(6)   TYPE P,
          MATERIAL_NUMBER  LIKE MARA-MATNR,
          G_BRGEW          LIKE MARA-BRGEW,
          N_NTGEW          LIKE MARA-NTGEW,
          PLANT            LIKE MARC-WERKS,
          REMARKS(50),
          FLAG(1),
          RECORD_FLAG(1),
          INTENSIFIED_FLAG(1),
          NUMBER(6)        TYPE P.
    * Constant variables
    CONSTANTS: VALID   VALUE '1',
               INVALID VALUE '0',
               ON      VALUE '1',
               OFF     VALUE '0'.
    * Reporting groups
    FIELD-GROUPS HEADER.
    * Insert into groups
    INSERT MATERIAL_NUMBER
           PLANT
           REMARKS
           INTO HEADER.
    * BDC parameters
    SELECTION-SCREEN BEGIN OF BLOCK ONE WITH FRAME TITLE TEXT-010.
    PARAMETERS: FILE(30) TYPE C
                          DEFAULT '/export/remote/data.txt'
                          LOWER CASE
                          OBLIGATORY,
                 SESSION  LIKE RL04I-MAPPE
                          OBLIGATORY
                          DEFAULT '8301_MM02',
                          UNAME LIKE SY-UNAME DEFAULT SY-UNAME.
    SELECTION-SCREEN END OF BLOCK ONE.
    * Data conversion parameters
    SELECTION-SCREEN BEGIN OF BLOCK TWO WITH FRAME TITLE TEXT-020.
    PARAMETERS MONTH(2) TYPE N DEFAULT 1.
    SELECTION-SCREEN END OF BLOCK TWO.
    * Notes to user
    SELECTION-SCREEN BEGIN OF BLOCK THREE WITH FRAME TITLE TEXT-030.
    SELECTION-SCREEN COMMENT /5(70) TEXT-040.
    SELECTION-SCREEN COMMENT /5(70) TEXT-050.
    SELECTION-SCREEN END OF BLOCK THREE.
    MOVE UNAME TO SY-UNAME.
    * Including SAP R/3 BDC customized include
    INCLUDE ZSIN0001.
    * Verifying the path & file name
    AT SELECTION-SCREEN ON FILE.
      PERFORM RESOURCE_FILE_OPEN.
    * Processing BDC
    START-OF-SELECTION.
      PERFORM SESSION_OPEN.
      PERFORM SESSION_GENERATION.
      PERFORM SESSION_CLOSE.
      CLOSE DATASET FILE.
    * Printing execution report
    END-OF-SELECTION.
      SKIP.
      WRITE  /15 'BDC & SYSTEM PARAMETERS -' COLOR 3.
      SKIP.
      WRITE: /15 'Resource path & filename ..........', FILE,
             /15 'Session name ......................', SESSION,
             /15 'ABAP/4 Program name ...............', SY-REPID,
             /15 'Client ............................', SY-MANDT,
             /15 'SAP System ID .....................', SY-SYSID,
             /15 'SAP Release .......................', SY-SAPRL,
             /15 'Host ..............................', SY-HOST,
             /15 'Operating system ..................', SY-OPSYS,
             /15 'Database system ...................', SY-DBSYS,
             /15 'User ID ...........................', SY-UNAME,
             /15 'Date ..............................', SY-DATUM,
             /15 'Time ..............................', SY-UZEIT.
      SKIP 3.
      WRITE  /15 'DATA CONVERSION DEFAULT PARAMETERS -' COLOR 3.
      SKIP.
      WRITE: /15 'Start at previous month ............', MONTH.
      SKIP 3.
      WRITE  /15 'EXECUTION REPORT -' COLOR 3.
      SKIP.
      WRITE: /15 'Total records read form file ......', RECORD_READ,
             /15 'Total records insert to BDC .......', RECORD_INSERT,
             /15 'Total records omitted .............', RECORD_OMIT.
      NEW-PAGE.
      SORT.
      LOOP.
        ADD 1 TO NUMBER.
        IF INTENSIFIED_FLAG EQ ON.
          FORMAT COLOR 2 INTENSIFIED ON.
          MOVE OFF TO INTENSIFIED_FLAG.
        ELSE.
          FORMAT COLOR 2 INTENSIFIED OFF.
          MOVE ON TO INTENSIFIED_FLAG.
        ENDIF.
        WRITE: /1 NUMBER, MATERIAL_NUMBER, PLANT, REMARKS.
        POSITION SY-LINSZ.
        WRITE ' '.
      ENDLOOP.
    * Reading resource file and generating BDC session
    FORM SESSION_GENERATION.
      DO.
        READ DATASET FILE INTO RECORD.
        IF SY-SUBRC NE 0 OR RECORD IS INITIAL.
          EXIT.
        ENDIF.
        ADD 1 TO RECORD_READ.
        PERFORM RECORD_CONDENSATION.
        PERFORM RECORD_VERIFICATION.
        CHECK RECORD_FLAG EQ VALID.
        REFRESH BDCDATA.
        PERFORM SCREEN_SEQUENCE.
        PERFORM BDC_TRANSACTION USING 'MM02'.
        IF SY-SUBRC EQ 0 .
          ADD 1 TO RECORD_INSERT.
        ELSE.
          ADD 1 TO RECORD_OMIT.
        ENDIF.
      ENDDO.
    ENDFORM.                    "SESSION_GENERATION
    * Condensing the record fields
    FORM RECORD_CONDENSATION.
      CONDENSE: RECORD-MATERIAL_NUMBER,
                RECORD-PLANT,
                RECORD-CORRECTED_VALUE_19,
                RECORD-CORRECTED_VALUE_18,
                RECORD-CORRECTED_VALUE_17,
                RECORD-CORRECTED_VALUE_16,
                RECORD-CORRECTED_VALUE_15,
                RECORD-CORRECTED_VALUE_14,
                RECORD-CORRECTED_VALUE_13,
                RECORD-CORRECTED_VALUE_12,
                RECORD-CORRECTED_VALUE_11,
                RECORD-CORRECTED_VALUE_10,
                RECORD-CORRECTED_VALUE_09,
                RECORD-CORRECTED_VALUE_08,
                RECORD-CORRECTED_VALUE_07,
                RECORD-CORRECTED_VALUE_06,
                RECORD-CORRECTED_VALUE_05,
                RECORD-CORRECTED_VALUE_04,
                RECORD-CORRECTED_VALUE_03,
                RECORD-CORRECTED_VALUE_02,
                RECORD-CORRECTED_VALUE_01.
    ENDFORM.                    "RECORD_CONDENSATION
    * Verifying record fields
    FORM RECORD_VERIFICATION.
      MOVE VALID TO RECORD_FLAG.
      UNPACK RECORD-MATERIAL_NUMBER TO MATERIAL_NUMBER.
      SELECT SINGLE * FROM MARA
                          WHERE MATNR EQ MATERIAL_NUMBER.
      IF SY-SUBRC NE 0.
        ADD 1 TO RECORD_OMIT.
        MOVE: RECORD-PLANT TO PLANT,
              TEXT-060     TO REMARKS,
              INVALID      TO RECORD_FLAG.
        EXTRACT HEADER.
        EXIT.
      ELSE.
        IF MARA-NTGEW > MARA-BRGEW.     "add to check for net weight > grow
          MOVE '1' TO FLAG.
        ELSE.
          MOVE ' ' TO FLAG.
        ENDIF.
      ENDIF.
      MOVE RECORD-PLANT TO PLANT.
      SELECT SINGLE MATNR WERKS INTO  (PLANT, MATERIAL_NUMBER)
                                FROM  ('MARC')
                                WHERE MATNR EQ MATERIAL_NUMBER
                                AND   WERKS EQ PLANT.
      IF SY-SUBRC NE 0.
        ADD 1 TO RECORD_OMIT.
        MOVE: TEXT-070 TO REMARKS,
              INVALID  TO RECORD_FLAG.
        EXTRACT HEADER.
      ENDIF.
    ENDFORM.                    "RECORD_VERIFICATION
    * Performing the screen sequence
    FORM SCREEN_SEQUENCE.
      PERFORM SCREEN_SAPLMGMM_0060.
      PERFORM SCREEN_SAPLMGMM_0070.
      PERFORM SCREEN_SAPLMGMM_3005.
      PERFORM SCREEN_SAPLMGMM_0081.
      PERFORM SCREEN_SAPLMGMM_3006.
      PERFORM SCREEN_SAPLMGMM_3110.
    ENDFORM.                    "SCREEN_SEQUENCE
    * Change Material: Initial Screen
    FORM SCREEN_SAPLMGMM_0060.
      PERFORM BDC_DYNPRO USING 'SAPLMGMM'   '0060'.
      PERFORM BDC_FIELD  USING 'RMMG1-MATNR' RECORD-MATERIAL_NUMBER.
      PERFORM BDC_FIELD  USING 'BDC_OKCODE'  '/5'. " Select view(s)
    ENDFORM.                    "SCREEN_SAPLMGMM_0060
    * Select view(s)
    FORM SCREEN_SAPLMGMM_0070.
      PERFORM BDC_DYNPRO USING 'SAPLMGMM'            '0070'.
      PERFORM BDC_FIELD  USING 'MSICHTAUSW-KZSEL(01)' 'X'.
      PERFORM BDC_FIELD  USING 'BDC_OKCODE'           '/0'. " Enter
    ENDFORM.                    "SCREEN_SAPLMGMM_0070
    * Change Material: Basic data
    FORM SCREEN_SAPLMGMM_3005.
      PERFORM BDC_DYNPRO USING 'SAPLMGMM'   '3005'.
      PERFORM BDC_FIELD  USING 'BDC_OKCODE' 'SP08'.             " MRP 1
      IF FLAG EQ '1'.
        PERFORM BDC_DYNPRO USING 'SAPLMGMM'   '3005'.
        PERFORM BDC_FIELD  USING 'BDC_OKCODE'           '/0'.
      ENDIF.
    ENDFORM.                    "SCREEN_SAPLMGMM_3005
    * Organizational levels
    FORM SCREEN_SAPLMGMM_0081.
      PERFORM BDC_DYNPRO USING 'SAPLMGMM'    '0081'.
      PERFORM BDC_FIELD  USING 'RMMG1-WERKS' RECORD-PLANT.
      PERFORM BDC_FIELD  USING 'BDC_OKCODE'  '=ENTR'.  "Continue
    ENDFORM.                    "SCREEN_SAPLMGMM_0081
    * Change Material: MRP 1
    FORM SCREEN_SAPLMGMM_3006.
      PERFORM BDC_DYNPRO USING 'SAPLMGMM'   '3006'.
      PERFORM BDC_FIELD  USING 'BDC_OKCODE' 'ZU11'. " Consumption
    ENDFORM.                    "SCREEN_SAPLMGMM_3006
    * Change Material: Consumption
    FORM SCREEN_SAPLMGMM_3110.
      CONSTANTS: PREVIOUS_MONTH VALUE 'X',
                 THIS_MONTH     VALUE ' '.
      DATA: ROW_POSITION(2)      TYPE N VALUE 0,
            WS_POSITION(2)       TYPE C,
            FIELDNAME            LIKE BDCDATA-FNAM,
            CONSUMPTION_QUANTITY LIKE RECORD-CORRECTED_VALUE_01.
      PERFORM BDC_DYNPRO USING 'SAPLMGMM' '3110'.
    *  if month eq previous_month.
    *    move 1 to row_position.
    *  elseif month eq this_month.
    *    move 0 to row_position.
    *  endif.
      MOVE MONTH TO ROW_POSITION.
      DO 19 TIMES VARYING CONSUMPTION_QUANTITY
                  FROM RECORD-CORRECTED_VALUE_01
                  NEXT RECORD-CORRECTED_VALUE_02.
        IF ROW_POSITION GT 11.
          MOVE 1 TO ROW_POSITION.
          PERFORM BDC_FIELD  USING 'BDC_OKCODE' 'VWNP'. " Page down
          PERFORM BDC_DYNPRO USING 'SAPLMGMM'   '3110'.
        ENDIF.
        UNPACK ROW_POSITION TO WS_POSITION.
        CONCATENATE 'RM03M-VBWRT(' WS_POSITION ')' INTO FIELDNAME.
        IF CONSUMPTION_QUANTITY+0(1) EQ '-'.
          SHIFT CONSUMPTION_QUANTITY LEFT BY 1 PLACES.
          CONCATENATE CONSUMPTION_QUANTITY '-' INTO CONSUMPTION_QUANTITY.
        ENDIF.
        PERFORM BDC_FIELD USING FIELDNAME CONSUMPTION_QUANTITY.
        ADD 1 TO ROW_POSITION.
      ENDDO.
      PERFORM BDC_DYNPRO USING 'SAPLMGMM' '3110'.
      PERFORM BDC_FIELD  USING 'BDC_OKCODE' '/11'. " Save
    ENDFORM.                    "SCREEN_SAPLMGMM_3110
    Include Program
    * BDC data table and record structure defination
    DATA BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
    * Opening a resource file
    FORM RESOURCE_FILE_OPEN.
      DATA ERROR_MESSAGE(40).
    *Begin of changes Mod01
    *  OPEN DATASET FILE FOR INPUT IN TEXT MODE MESSAGE ERROR_MESSAGE.
      OPEN DATASET FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE
                                                          ERROR_MESSAGE.
    *End of changes Mod01
      IF SY-SUBRC NE 0.
        MESSAGE E000 WITH FILE ERROR_MESSAGE.
      ENDIF.
    ENDFORM.
    * Opening of BDC session
    FORM SESSION_OPEN.
      CALL FUNCTION 'BDC_OPEN_GROUP'
           EXPORTING  CLIENT              = SY-MANDT
                      DEST                = SY-HOST
                      GROUP               = SESSION
                      USER                = SY-UNAME
                      KEEP                = 'X'
           EXCEPTIONS CLIENT_INVALID      = 01
                      DESTINATION_INVALID = 02
                      GROUP_INVALID       = 03
                      HOLDDATE_INVALID    = 04
                      INTERNAL_ERROR      = 05
                      QUEUE_ERROR         = 06
                      RUNNING             = 07
                      USER_INVALID        = 08.
      CASE SY-SUBRC.
        WHEN 01. MESSAGE E001 WITH SY-MANDT.
        WHEN 02. MESSAGE E002.
        WHEN 03. MESSAGE E003.
        WHEN 04. MESSAGE E004.
        WHEN 05. MESSAGE E005.
        WHEN 06. MESSAGE E006.
        WHEN 07. MESSAGE E007.
        WHEN 08. MESSAGE E007.
      ENDCASE.
    ENDFORM.
    * Closing BDC session
    FORM SESSION_CLOSE.
      CALL FUNCTION 'BDC_CLOSE_GROUP'
        EXCEPTIONS NOT_OPEN    = 01
                   QUEUE_ERROR = 02.
      CASE SY-SUBRC.
        WHEN 01. MESSAGE E009.
        WHEN 02. MESSAGE E010.
      ENDCASE.
    ENDFORM.
    * Inserting data into BDC
    FORM BDC_TRANSACTION USING TRANSACTION_CODE.
      CALL FUNCTION 'BDC_INSERT'
           EXPORTING  TCODE          = TRANSACTION_CODE
           TABLES     DYNPROTAB      = BDCDATA
           EXCEPTIONS INTERNAL_ERROR = 1
                      NOT_OPEN       = 2
                      QUEUE_ERROR    = 3
                      TCODE_INVALID  = 4
                      OTHERS         = 5.
    ENDFORM.
    * Insert program name & screen number
    FORM BDC_DYNPRO USING PROGRAM DYNPRO.
      CLEAR BDCDATA.
      MOVE: PROGRAM TO BDCDATA-PROGRAM,
            DYNPRO  TO BDCDATA-DYNPRO,
            'X'     TO BDCDATA-DYNBEGIN.
      APPEND BDCDATA.
    ENDFORM.
    * Inserting field name/BDC_OKCODE/BDC_CUESOR and value
    FORM BDC_FIELD USING FNAM FVAL.
      CLEAR BDCDATA.
      MOVE: FNAM TO BDCDATA-FNAM,
            FVAL TO BDCDATA-FVAL.
      APPEND BDCDATA.
    ENDFORM.

    i have changed the selection screen as follows
    SELECTION-SCREEN BEGIN OF BLOCK one WITH FRAME TITLE text-010.
    *                                                          "1)
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS p_unix RADIOBUTTON GROUP rad1 .                 "
    SELECTION-SCREEN COMMENT 5(26) text-008.
    SELECTION-SCREEN POSITION 33.                              "
    PARAMETERS: file(128) TYPE c
                          DEFAULT '/export/remote/data.txt' LOWER CASE.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS p_xls RADIOBUTTON GROUP rad1 .                 "excel file
    SELECTION-SCREEN COMMENT 5(26) text-009.
    SELECTION-SCREEN POSITION 33.                              "
    PARAMETERS: filf(128).
    SELECTION-SCREEN END OF LINE.
    *>>
    *PARAMETERS: file(128) TYPE c
    *                      DEFAULT '/export/remote/data.txt' LOWER CASE OBLIGATORY,
    PARAMETERS:  session  LIKE rl04i-mappe OBLIGATORY
                          DEFAULT '8301_MM02',
                 uname LIKE sy-uname DEFAULT sy-uname.
    SELECTION-SCREEN END OF BLOCK one.
    * Data conversion parameters
    SELECTION-SCREEN BEGIN OF BLOCK two WITH FRAME TITLE text-020.
    PARAMETERS month(2) TYPE n DEFAULT 1.
    SELECTION-SCREEN END OF BLOCK two.
    * Notes to user
    SELECTION-SCREEN BEGIN OF BLOCK three WITH FRAME TITLE text-030.
    SELECTION-SCREEN COMMENT /5(70) text-040.
    SELECTION-SCREEN COMMENT /5(70) text-050.
    SELECTION-SCREEN END OF BLOCK three.

  • Scheduled back ground job not finishing

    hie gurus, i need your help with back ground scheduling , i have created a background schedule to run my program after every 30min .  in the job overview it shows my job released and active but its not finishing processing . the program being run picks up data from an external data base and then inserting via BDC call transaction. i have tried with a different program that inserts data into a database table and its executing and finishing well in the back ground. What could be the problem ? and how can i debug a back ground job ??

    Daniel,
    To start, BDCs are very out-dated.  I would look for a BAPI if you are calling std SAP functionality.
    Also - direct updates into std SAP tables is a HUGE "no-no"... I hope that you are updating custom tables only.
    Pass that - to debug a b/g job---> 
    1) Set a breakpoint in your program
    2) select the job in SM37
    3) enter JDBG into the SAP fastpath of the SM37 screen and press ENTER
    This will navigate you into a b/g debug - you can then press the debugger buttons to move to your breakpoint.
    Hope that helps.

  • Please give me some sample program releated BOM

    please give me some sample program releated BOM

    Hi,
    *& Module : PP                                                         |
    *& Application : The program loads the Bill of Material                |
    *&                                                                     |
    *| Modification Log                                                    |
    *| -
                                                        |
    *| Programmer                                                          |
    *|                                                       Change        |
    *| -
    |
    REPORT zpp0120 NO STANDARD PAGE HEADING
                                      MESSAGE-ID z0
                                      LINE-SIZE  132
                                      LINE-COUNT 65(2).
                         Internal Tables                                 *
    *Internal table for the BOM file.
    DATA: BEGIN OF i_bom OCCURS 0,
          matnr(18),
          werks(4),
          stlan(1),
          stlal(2),
          stktx(40),
          bmeng(16),
          menge(16),
          posnr(4),
          postp(1),
          meins(3),
          datuv(10),
          fmeng(1),
          idnrk(18),
          potx1(40),
          ausch(7),
          END OF i_bom.
    Extracting Document and Doc type for POSTP = D.
    DATA : BEGIN OF i_stpo OCCURS 1,
           doknr(25),
           dokar(3),
           posnr(4),
           stlnr LIKE mast-stlnr,
           END   OF i_stpo.
    Local work area
    DATA:  g_my_rec_in   LIKE i_bom.
    Declare internal table for Call Transaction and BDC Session
    DATA: i_bdc_table LIKE bdcdata OCCURS 0 WITH HEADER LINE.
                         Global Variables                                *
    DATA: g_counter(2) TYPE n,
          g_field_name(18) TYPE c,
          zc_yes  TYPE syftype VALUE 'X'.
                         Selection Screen                                *
    SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
    PARAMETERS: p_fname1 TYPE localfile .
    SELECTION-SCREEN SKIP 1.
    SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.
    PARAMETERS: p_rloc1 AS CHECKBOX  DEFAULT 'X'.
    SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-005.
    PARAMETERS p_group(12) OBLIGATORY DEFAULT 'ZBOM'.
    SELECTION-SCREEN END OF BLOCK c.
    SELECTION-SCREEN END OF BLOCK b.
    SELECTION-SCREEN END OF BLOCK a.
    **WRITE the report header
    TOP-OF-PAGE.
      INCLUDE zheading.
                         Start of selection                              *
    START-OF-SELECTION.
    Load Input file
      PERFORM f_load_input_file.
    Create BDC records.
      PERFORM create_bdc_records .
    *&      Form  Create_BDC_records
          text:* perform the BDC for the records in the internal table
    -->  p1        text
    <--  p2        text
    FORM create_bdc_records .
      DATA: v_stlnr LIKE mast-stlnr.
      DATA: v_postp(1) VALUE 'D'.
      IF NOT i_bom[] IS INITIAL.
    Open BDC session
        PERFORM open_bdc_session.
        SORT i_bom BY matnr werks posnr.
        SELECT  SINGLE stlnr  INTO v_stlnr
        FROM mast
        WHERE    matnr = i_bom-matnr
         AND     werks = i_bom-werks.
        SELECT doknr dokar posnr stlnr
                    INTO TABLE i_stpo
                    FROM stpo
                    FOR ALL ENTRIES IN i_bom
                    WHERE postp = v_postp
                    AND   posnr = i_bom-posnr
                    AND   stlnr = v_stlnr.
        SORT i_stpo BY posnr stlnr.
        LOOP AT i_bom.
          g_my_rec_in = i_bom.
          READ TABLE i_stpo WITH KEY posnr = i_bom-posnr
                                     stlnr = v_stlnr
                                     BINARY SEARCH.
          AT NEW matnr.
            CLEAR i_bdc_table[].
            PERFORM insert_screen_header.
          ENDAT.
    Setting up counter for 20 line items
          IF g_counter = 20.
            g_counter = 1.
          ENDIF.
          PERFORM bdc_field  USING 'BDC_OKCODE'
                                        '/00'.
    *next screen
          PERFORM bdc_dynpro USING 'SAPLCSDI' '0140'.
          PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29P-FMENG(01)'.
          PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
          CONCATENATE 'RC29P-POSNR('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-posnr.
          CONCATENATE 'RC29P-IDNRK('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-idnrk.
          CONCATENATE 'RC29P-MENGE('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-menge.
          CONCATENATE 'RC29P-MEINS('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-meins.
          CONCATENATE 'RC29P-POSTP('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-postp.
          CONCATENATE 'RC29P-FMENG('  g_counter  ')' INTO g_field_name.
          PERFORM bdc_field USING g_field_name i_bom-fmeng.
    *next screen
          PERFORM bdc_dynpro USING 'SAPLCSDI' '0130'.
          PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
    Check the Item category to direct the screen flow accordingly.
          CASE i_bom-postp.
            WHEN 'B'.
              PERFORM item_text_insert.
            WHEN 'Z'.
              PERFORM item_text_insert.
            WHEN 'T'.
              PERFORM item_text_insert.
            WHEN 'N'.
              PERFORM bdc_field   USING 'BDC_CURSOR' 'RC29P-AUSCH'.
              PERFORM bdc_field   USING 'RC29P-AUSCH' i_bom-ausch.
    next screen
              PERFORM item_text_insert.
    *next screen
              PERFORM bdc_dynpro  USING 'SAPLCSDI' '0133'.
              PERFORM bdc_field   USING 'BDC_OKCODE' '/00'.
              PERFORM bdc_field   USING 'RC29P-EKORG' ' '.
            WHEN 'D'.
              PERFORM bdc_field   USING 'RC29P-DOKNR' i_stpo-doknr.
              PERFORM bdc_field   USING 'RC29P-DOKAR' i_stpo-dokar.
    next screen
              PERFORM item_text_insert.
    When POSTP = X, L.
            WHEN OTHERS.
              PERFORM bdc_field   USING 'BDC_CURSOR' 'RC29P-AUSCH'.
              PERFORM bdc_field   USING 'RC29P-AUSCH' i_bom-ausch.
    next screen
              PERFORM item_text_insert.
          ENDCASE.
          g_counter = g_counter + 1.
    next screen
          PERFORM bdc_dynpro      USING 'SAPLCSDI' '0140'.
          PERFORM bdc_field       USING 'BDC_CURSOR' 'RC29P-POSNR(01)'.
          PERFORM bdc_field       USING 'BDC_OKCODE' '=FCBU'.
          AT END OF matnr.
            PERFORM insert_bdc_new.
          ENDAT.
        ENDLOOP.
        CLEAR i_bom[].
        PERFORM close_bdc_session.
    Release the BDC sessions created
        PERFORM release_bdc.
      ENDIF.
    ENDFORM.                    " open_group
    *&      Form  bdc_dynpro_start
          Initialize the screen
         -->P_G_PROGRAM_1
         -->P_G_SCREEN
    FORM bdc_dynpro USING    p_g_program_1
                                    p_g_screen.
      CLEAR i_bdc_table.
      i_bdc_table-program  = p_g_program_1.
      i_bdc_table-dynpro   = p_g_screen.
      i_bdc_table-dynbegin = 'X'.
      APPEND i_bdc_table.
    ENDFORM.                    " bdc_dynpro_start
    *&      Form  bdc_field
           Insert field                                                  *
    FORM bdc_field USING f_name f_value.
      CLEAR i_bdc_table.
      i_bdc_table-fnam = f_name.
      i_bdc_table-fval = f_value.
      APPEND i_bdc_table.
    ENDFORM.                    "bdc_insert_field
    *&      Form  open_bdc_session
         Open the BDC session
    FORM open_bdc_session .
    Open BDC session and creat and update condition records
      CALL FUNCTION 'BDC_OPEN_GROUP'
        EXPORTING
          client                    = sy-mandt
          DEST                      = FILLER8
          group                     = p_group
          HOLDDATE                  = FILLER8
          keep                      = 'X'
          user                      = sy-uname
          RECORD                    = FILLER1
          PROG                      = SY-CPROG
        IMPORTING
          QID                       =
    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.                    " create_bdc_session
    *&      Form  insert_screen_header
          Insert the Header data into the screens
    FORM insert_screen_header .
      g_counter = 1.
      PERFORM bdc_dynpro USING 'SAPLCSDI' '0100'.
      PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29N-STLAL'.
      PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
      PERFORM bdc_field  USING 'RC29N-MATNR' g_my_rec_in-matnr.
      PERFORM bdc_field  USING 'RC29N-WERKS' g_my_rec_in-werks.
      PERFORM bdc_field  USING 'RC29N-STLAN' g_my_rec_in-stlan.
      PERFORM bdc_field  USING 'RC29N-STLAL' g_my_rec_in-stlal.
      PERFORM bdc_field  USING 'RC29N-DATUV' g_my_rec_in-datuv.
    next screen
      PERFORM bdc_dynpro USING 'SAPLCSDI' '0110'.
      PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29K-BMENG'.
      PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
      PERFORM bdc_field  USING 'RC29K-STKTX' g_my_rec_in-stktx.
      PERFORM bdc_field  USING 'RC29K-BMENG' g_my_rec_in-bmeng.
    *next screen
      PERFORM bdc_dynpro USING 'SAPLCSDI' '0111'.
      PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29K-LABOR'.
    ENDFORM.                    " insert_screen_header
    *&      Form  insert_bdc
         Insert the BDC session
    FORM insert_bdc_new .
      CALL FUNCTION 'BDC_INSERT'
         EXPORTING
           tcode                  = 'CS01'
          POST_LOCAL             = NOVBLOCAL
          PRINTING               = NOPRINT
          SIMUBATCH              = ' '
          CTUPARAMS              = ' '
         TABLES
           dynprotab              = i_bdc_table
      EXCEPTIONS
        internal_error         = 1
        not_open               = 2
        queue_error            = 3
        tcode_invalid          = 4
        printing_invalid       = 5
        posting_invalid        = 6
        OTHERS                 = 7
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CLEAR i_bdc_table[].
    ENDFORM.                    " insert_bdc
    *&      Form  close_bdc_session
          Close the BDC session
    FORM close_bdc_session .
      CALL FUNCTION 'BDC_CLOSE_GROUP'
           EXCEPTIONS
                not_open    = 1
                queue_error = 2
                OTHERS      = 3.
      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.                    " close_bdc_session
    *&      Form  f_load_input_file
         Load the file into the Internal table
    FORM f_load_input_file.
      IF p_rloc1 = zc_yes.
        CALL FUNCTION 'WS_UPLOAD'
             EXPORTING
                  filename                = p_fname1
                  filetype                = 'DAT'
             TABLES
                  data_tab                = i_bom
             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.
          STOP.
        ENDIF.
      ENDIF.
    ENDFORM.                    " f_load_input_file
    *&      Form  release_bdc
         Release BDC session
    FORM release_bdc.
      SUBMIT rsbdcsub WITH mappe EQ p_group
                      WITH von EQ sy-datum
                      WITH bis EQ sy-datum
                      WITH fehler EQ '.'
                      EXPORTING LIST TO MEMORY
                      AND RETURN.
    ENDFORM.                    " release_bdc
    *&      Form  item_text_insert
          Repetitive code in the screen flow
    FORM item_text_insert.
      PERFORM bdc_dynpro USING 'SAPLCSDI' '0131'.
      PERFORM bdc_field  USING 'BDC_OKCODE' '/00'.
      PERFORM bdc_field  USING 'BDC_CURSOR' 'RC29P-POTX1'.
      PERFORM bdc_field  USING 'RC29P-POTX1' i_bom-potx1.
    ENDFORM.                    " item_text_insert

Maybe you are looking for