Flat file (BDC)

Hi friends........ now i want to upload the data from flat file  through recording method  to  "MMO1" tranction now how can i anlyze the data from flate file this data is related for particular field

Hi chakri,
If your flat file is of EXCEL file then in the first row write all your field name save Material No, Industry Sector, Material Group....and start uploading the data in the excel starting from 2nd row.
By which you can start uploading your material master from 2nd row and you can have heading for your field to know which value is of which field.
Cheers!!
VEnk@

Similar Messages

  • Line item -  flat file - BDC

    hi gurus.......
    could some one get me a real time flat file for BDC line items.
    maximum points will be rewarded.

    hi Rohit
    what I mean is , for T codes like XK01 we have a multiple line items for a single vendor.
    I need to practice BDC for T codes which has line items (ex  ME21) .
    It would be more helpfull for me if u provide me with flat file which u have use in real time for BDC , which has multiple line items for a single header.
    am I clear?

  • Problem in the BDC program to upload the data from a flat file.

    Hi,
    I am required to write a BDC program to upload the data from a flat file. The conditions are as mentioned below:-
    1) Selection Screen will be prompted to user and user needs to provide:- File Path on presentation server (with F4 help for this obligatory parameter) and File Separator e.g. @,#,$,%,... etc(fields in the file will be separated by using this special character) or fields may be separated by tab(tab delimited).
    2) Finally after the data is uploaded, following messages need to be displayed:-
    a) Total Number of records successfully uploaded.
    b) Session Name
    c) Number of Sessions created.
    Problem is when each record is fetched from flat file, the record needs to be split into individual fields separated by delimiter or in case tab separated, then proceeding in usual manner.
    It would be great if you provide me either the logic, pseudocode, or sample code for this BDC program.
    Thanks,

    Here is an example program,  if you require the delimitor to be a TAB, then enter TAB on the selection screen, if you require the delimitor to be a comma, slash, pipe, whatever, then simply enter that value.  This example is simply the uploading of the file, not the BDC, I assume that you know what to do once you have the data into the internal table.
    REPORT zrich_0001.
    TYPES: BEGIN OF ttab,
            rec TYPE string,
           END OF ttab.
    TYPES: BEGIN OF tdat,
           fld1(10) TYPE c,
           fld2(10) TYPE c,
           fld3(10) TYPE c,
           fld4(10) TYPE c,
           END OF tdat.
    DATA: itab TYPE TABLE OF ttab.
    data: xtab like line of itab.
    DATA: idat TYPE TABLE OF tdat.
    data: xdat like line of idat.
    DATA: file_str TYPE string.
    DATA: delimitor TYPE string.
    PARAMETERS: p_file TYPE localfile.
    PARAMETERS: p_del(5) TYPE c.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      DATA: ifiletab TYPE filetable.
      DATA: xfiletab LIKE LINE OF ifiletab.
      DATA: rc TYPE i.
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        CHANGING
          file_table = ifiletab
          rc         = rc.
      READ TABLE ifiletab INTO xfiletab INDEX 1.
      IF sy-subrc = 0.
        p_file = xfiletab-filename.
      ENDIF.
    START-OF-SELECTION.
      TRANSLATE p_del TO UPPER CASE.
      CASE p_del.
        WHEN 'TAB'.
          delimitor = cl_abap_char_utilities=>horizontal_tab.
        WHEN others.
          delimitor = p_del.
      ENDCASE.
      file_str = p_file.
      CALL METHOD cl_gui_frontend_services=>gui_upload
        EXPORTING
          filename = file_str
        CHANGING
          data_tab = itab.
      LOOP AT itab into xtab.
        CLEAR xdat.
        SPLIT xtab-rec AT delimitor INTO xdat-fld1
                                         xdat-fld2
                                         xdat-fld3
                                         xdat-fld4.
        APPEND xdat to idat.
      ENDLOOP.
      LOOP AT idat into xdat.
        WRITE:/ xdat-fld1, xdat-fld2, xdat-fld3, xdat-fld4.
      ENDLOOP.
    Regards,
    Rich Heilman

  • BDC ---Data maintainance at flat file

    Hi All,
    Iam a BI resource learning ABAP.
    I have started learning abap in that currently working with BDC.
    Here iam trying to extract data from flat file(note pad) for practice purpose and extraxting data by session method fore ground process.
    Here in flat file i want to maintain two table of data and want to insert this data in related tables.
    i have created note pad file
    for vendor data and customer data have maintained data horizontally like
    lifnr    name1     land1     kunnr    name1   land1
    1      xx               US      2        yyyy            UK
    Finally the data is geting inserted in the lfa1 and kna1 table are like
    lifnr 1 record s at vendor table and kunnr2 record is at customer table.
    but now i want to maintain data at note pad as in vertical like
    lifnr    name1     land1 (not maintaining these fileds in note pad only values giving in note pad)
    1      xx               US
    kunnr    name1   land1
    2        yyyy            UK
    So is there any way to maintain my data in note pad like this.
    please advice.
    regards
    Saha

    hie
    I hope i understood you well, you want to maintain many records in your flat file you are still able to pick them all.  Please elaborate what you mean by maintaining your records in vertical format???
    Vendor file
    1,200,ABC,02
    2,200,DEF,02
    Customer file
    1,200,QWE,02
    2,200,SDW,02
    The two sets of data seem to be different ie Customer and Vendor thus i think you should maintain the two as separate files and pick both at the same time.
    regards
    Isaac Prince

  • Reg : Error in flat file in BDC

    hi friends...
    let consider 10 records in my flat file...
    suppose 5th record is error means
    In BDC Session method, what happen records before and after the error record, its get update or not ? like
    In BDC Call Transaction method, what happen records before and after the error record, its get update or not ?
    please give me some detail...
    Regards
    Selva

    Hi,
    In call transaction method you will have an option of Displaying No screens, all screens and Error screens,
    If you select No screens all other records except error records will be process and messages will be collected by an internal table of type bdcmsgcoll.
    In all screens you need to process each screen manually yourself by selecting the OK code. It is kinda like debugging. So when you encounter the error screen you can change the error data and proceed.
    When you select error screens it will stop when the error occurs. So you need to correct the error and continue with the further processing.
    Regards,
    Pramod

  • Date format in flat file of bdc

    Hi Folks,
    In BDC I have a flat file which has to be uploaded from a flat file and 4 users are using each of one has their date format.
    so inorder to get their required date format what i need to do .

    Hi,
           use the below logic in your code.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-031.
    PARAMETERS: date1 RADIOBUTTON GROUP rad1 DEFAULT 'X',                                     "SAP date format YYYYDDMM
                date2 RADIOBUTTON GROUP rad1,                                                 "Date format like aprial31, 2006
                date3 RADIOBUTTON GROUP rad1,                                                 "Date format like 31 apr,2006
                date4 RADIOBUTTON GROUP rad1,                                                 "Date format like DD/MM/YYYY
                date5 RADIOBUTTON GROUP rad1.                                                 "Date format like DD.MM.YYYY
    SELECTION-SCREEN END OF BLOCK b2
    FORM getmonth .
      SELECT mnr
             ktx
             ltx
       INTO TABLE T_month
       FROM t247
       WHERE spras = 'EN'.
      IF sy-subrc NE '0'.
          MESSAGE I                                                          "Message - Not able to get month values from the table T247
      ENDIF.
    ENDFORM.                                                                               
    DATA : temp_date(16)  TYPE c,
             temp1_date(60) TYPE c,
             year(4)        TYPE c,
             daymonth(11)   TYPE c,
             daymonth1(11)  TYPE c,
             month(9)       TYPE c,
             day(2)         TYPE c,
             mon            LIKE t247-ktx,
             len            TYPE i   .
      MOVE date TO temp1_date .
      CONDENSE temp1_date NO-GAPS.
      MOVE temp1_date TO temp_date .
      IF date2 EQ 'X'.                                                                     "The date format is like Aprial 31, 2007
        CONDENSE temp_date NO-GAPS.
        SPLIT date AT ',' INTO daymonth year.
        IF STRLEN( year ) NE '4'.
          error = 'X'.
          WRITE :  'Invalid date format.'.
        ELSE.
          daymonth1 = daymonth.
          CONDENSE daymonth1 NO-GAPS.
          _len      = STRLEN( _daymonth1 ).
          l_len      = 13 - len.
          SHIFT daymonth1 RIGHT BY len PLACES.
          CONDENSE daymonth1 NO-GAPS.
          month    = daymonth1.
          CONDENSE month NO-GAPS.
          SORT t_month BY monthltx.
          READ TABLE t_month WITH KEY monthltx =  month.
          IF sy-subrc <> 0.
            error = 'X'.
            WRITE : 'Invalid date format.' .
          ELSE.
            len = STRLEN( month ).
            CONDENSE daymonth NO-GAPS.
            SHIFT daymonth LEFT BY len PLACES.
            day =  daymonth.
            CONDENSE day NO-GAPS.
            CONCATENATE year t_month-monthnumber day INTO o_date.
          ENDIF.
        ENDIF.
      ELSEIF p_date3 EQ 'X'.                                                                "The date format is like 31 apr, 2007
        CONDENSE temp_date NO-GAPS.
        SPLIT i_date AT ',' INTO daymonth year.
        IF STRLEN( year ) NE '4'.
          error = 'X'.
          WRITE :  'Invalid date format.'.
        ELSE.
          daymonth1 = daymonth.
          CONDENSE daymonth1 NO-GAPS.
          SHIFT daymonth1 LEFT BY 2 PLACES.
          CONDENSE daymonth1 NO-GAPS.
          month  = daymonth1.
          CONDENSE month NO-GAPS.
          TRANSLATE month TO UPPER CASE.
          SORT t_month BY monthstx.
          MOVE month to mon.
          READ TABLE t_month WITH KEY monthstx = mon.                                 
          IF sy-subrc <> 0.
            error = 'X'.
            WRITE : 'Invalid date format.' .
          ELSE.
            CONDENSE daymonth NO-GAPS.
            day =  daymonth+0(2).
            CONDENSE day NO-GAPS.
            CONCATENATE year t_month-monthnumber day INTO o_date.
         ENDIF.
       ENDIF.
      ELSEIF p_date4 EQ 'X' OR p_date5 EQ 'X'.                                             "Date format is like DD.MM.YYYY or DD/MM/YYYY
        CONDENSE temp_date NO-GAPS.
        IF STRLEN( temp_date ) EQ 10.
          o_date0(4) = temp_date6(4).
          o_date4(2) = temp_date3(2).
          o_date6(2) = temp_date0(2).
        ELSE.
          error = 'X'.
          WRITE : 'Invalid date format.' .
        ENDIF.
    ENDIF.
    IF STRLEN( o_date ) NE '8'.
         error = 'X'.
         WRITE : 'Invalid date format.'.
    ENDIf.
    ENDFORM.                                                                               
    regards

  • How To handle complex Flat File in BDC( V.V. Urgent)

    Hi All,
    Anybody help in these case.
    I have to write the BDC for a complex File.
    Here is the Scenario
    I An recording for Tcode CN21.
    1network -> many activities
    1 Activity ->many components
    Any body Help ifor this case,
    Points will be awarded.
    Regards,
    Jayasimha

    Hi Jayasimha
    Can u explain what is the problem that u are facing? we will be able to help u if u let u know what is the problem.
    as far as what u have mentioned, first do a recording in SHDB for the transaction CN21 and then in the program get all the data from the flat file into an internal table. then build a BDC.
    Cheers

  • Save flat file in bdc

    in bdc we have to save the flat file in desktop or c drive?plz tell
    Edited by: Alvaro Tejada Galindo on Feb 7, 2008 10:15 AM

    Hi,
    check the  code for better understanding.
    Regards
    Bala.M
    REPORT  zi_flatfile_zisobj.
    * Data Declaration
    * Internal Tables
    DATA : BEGIN OF itd_zisobj OCCURS 0 ,
    zinref        LIKE  zisobj-zinref,
    ziaccomtype   LIKE  zisobj-ziaccomtype,
    zietgnr       LIKE  zisobj-zietgnr,
    zioldnref     LIKE  zisobj-zioldnref,
    zicnttyp      LIKE  zisobjcnt-zicnttyp,
    END OF itd_zisobj.
    DATA : file_length TYPE i.
    START-OF-SELECTION.
    PERFORM data_selection_join.
    PERFORM gui_download_file.
    END-OF-SELECTION.
    *&      Form  data_selection_join
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM data_selection_join .
    * Data selection and Inner join based on Contract Type Eq 'U'.
    SELECT   a~zinref
    a~ziaccomtype
    a~zietgnr
    a~zioldnref
    b~zicnttyp
    INTO  CORRESPONDING FIELDS OF TABLE itd_zisobj
    FROM ( zisobj AS a INNER JOIN zisobjcnt AS b ON a~zicountry  = b~zicountry
    AND a~ziplace    = b~ziplace
    AND a~zihouse    = b~zihouse
    AND a~ziaccom    = b~ziaccom
    AND b~zicnttyp   = 'U' ) .
    ENDFORM.                    " data_selection_join
    *&      Form  gui_download_file
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM gui_download_file .
    * FM to download to the presentation server
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    *   BIN_FILESIZE                    =
    filename                        = 'H:\TEST1.TXT'
    filetype                        = 'ASC'
    append                          = ' '
    write_field_separator           = ','
    header                          = '00'
    trunc_trailing_blanks           = ' '
    write_lf                        = 'X'
    col_select                      = ' '
    col_select_mask                 = ' '
    dat_mode                        = ' '
    confirm_overwrite               = ' '
    no_auth_check                   = ' '
    codepage                        = ' '
    *   IGNORE_CERR                     = ABAP_TRUE
    replacement                     = '#'
    write_bom                       = ' '
    trunc_trailing_blanks_eol       = 'X'
    wk1_n_format                    = ' '
    wk1_n_size                      = ' '
    wk1_t_format                    = ' '
    wk1_t_size                      = ' '
    *   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
    *   SHOW_TRANSFER_STATUS            = ABAP_TRUE
    IMPORTING
    filelength                      =  file_length
    TABLES
    data_tab                       = itd_zisobj
    *   FIELDNAMES                      =
    EXCEPTIONS
    file_write_error                = 1
    no_batch                        = 2
    gui_refuse_filetransfer         = 3
    invalid_type                    = 4
    no_authority                    = 5
    unknown_error                   = 6
    header_not_allowed              = 7
    separator_not_allowed           = 8
    filesize_not_allowed            = 9
    header_too_long                 = 10
    dp_error_create                 = 11
    dp_error_send                   = 12
    dp_error_write                  = 13
    unknown_dp_error                = 14
    access_denied                   = 15
    dp_out_of_memory                = 16
    disk_full                       = 17
    dp_timeout                      = 18
    file_not_found                  = 19
    dataprovider_exception          = 20
    control_flush_error             = 21
    OTHERS                          = 22
    IF sy-subrc NE 0.
    MESSAGE e398(00) WITH 'Error in Downloading File' 'TEST1.TXT' 'Retry'.
    ENDIF.
    ENDFORM.                    " gui_download_file

  • Flat file in bdc

    hi experts ?
    who will create the flat file in real time ?
    who ll run that bdc program in real time ?
    what is abaper role exactly involved in bdc ? only coding or some thing else ? or we have to run that program ?

    Satish,
    Based on the structure given to you initially you have to build the bdc program. In the same way process team or functional folks will provide the file to you. Before you upload the data with the original file u have to test your program for all the test conditions to make sure  your program is working well.
    When comes to the point of running the BDC program it depends upon the requirement.
    If the requirement is to run the bdc program only once or twice then u have to run the program. If it is continous daily batch job then u need to schedule a background job or some other concerned persons will take care of that if you give your program name, variant and proper timings when this needs to be run.
    Role of the abaper would be.........
    Verifying the structure of the flat file along with all the fields, field lenghts and types then building the proper program, testing the program to make sure it will run with out any major problems and once u get the file make sure that file is in the correct format which is mentioned earlier.

  • Flat  file to upload data using BDC for transaction MM01

    Hi
    I am trying to update data using bdc code has been attached below using a txt file.
    It is updating the first set of data into the table mara ,but  for the rest it is not
    All the data from txt file has being loaded to internal table , but the problem is it does not gets updated from internal table to the database .
    Only the first set of data has been loaded ,<u><b> rest of the data is not loaded</b></u>
    <u><b>content of txt file</b></u>
    zsc     zsc     kg     
    zsv     zsv     kg     
    zsb     zsb     kg
    <u><b>Actual code</b></u>
    report ZMAT_UPLOAD
           no standard page heading line-size 255.
    types declaration..........................................................................
    types : begin of t_mat,
       matnr(20),
       desc(50),
       uom(5),
    end of t_mat.
    internal table and workarea declaration.......................................
    data : i_mat type table of t_mat.
    data : wa_mat type t_mat.
    include bdcrecx1.
    start-of-selection.
    moving the flat file content to internal table................................
    CALL FUNCTION 'UPLOAD'
         EXPORTING
             FILETYPE   = 'DAT'
         TABLES
             data_tab   = i_mat.
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    perform open_group.
    loop at i_mat into wa_mat.
    perform bdc_dynpro      using 'SAPLMGMM' '0060'.
    perform bdc_field       using 'BDC_CURSOR'
                                       'RMMG1-MATNR'.
    perform bdc_field       using 'BDC_OKCODE'
                                        '=AUSW'.
    perform bdc_field       using 'RMMG1-MATNR'
                                        wa_mat-matnr.
    perform bdc_field       using 'RMMG1-MBRSH'
                                        'P'.
    perform bdc_field       using 'RMMG1-MTART'
                                        'ZOH'.
    perform bdc_dynpro   using 'SAPLMGMM' '0070'.
    perform bdc_field       using 'BDC_CURSOR'
                                        'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field       using 'BDC_OKCODE'
                                        '=ENTR'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(01)'
                                        'X'.
    perform bdc_dynpro   using 'SAPLMGMM' '4004'.
    perform bdc_field       using 'BDC_OKCODE'
                                        '=BU'.
    perform bdc_field       using 'MAKT-MAKTX'
                                        wa_mat-desc.
    perform bdc_field       using 'BDC_CURSOR'
                                        'MARA-MEINS'.
    perform bdc_field       using 'MARA-MEINS'
                                        wa_mat-uom.
    perform bdc_field       using 'MARA-MTPOS_MARA'
                                        'NORM'.
    perform bdc_transaction using 'MM01'.
    endloop.
    Perform close_group.

    Hi Sumant,
    just concentrate on bold one
    report ZMAT_UPLOAD
    no standard page heading line-size 255.
    types declaration..........................................................................
    <b>
    data : begin of t_mat occurs 0,
    matnr(20),
    desc(50),
    uom(5),
    end of t_mat.</b>
    internal table and workarea declaration.......................................
    <b>*data : i_mat type table of t_mat.
    *data : wa_mat type t_mat.</b>
    include bdcrecx1.
    start-of-selection.
    moving the flat file content to internal table................................
    CALL FUNCTION 'UPLOAD'
    EXPORTING
    FILETYPE = 'DAT'
    TABLES
    <b>data_tab = i_mat.---> t_mat.</b>
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    perform open_group.
    <b>loop at i_mat into wa_mat.------>loop at t_mat.</b>
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_field using 'BDC_OKCODE'
    '=AUSW'.
    perform bdc_field using 'RMMG1-MATNR'
    <b>wa_mat-matnr.---->t_mat-matnr(change in this for ur wa to t_mat.</b>
    perform bdc_field using 'RMMG1-MBRSH'
    'P'.
    perform bdc_field using 'RMMG1-MTART'
    'ZOH'.
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_CURSOR'
    'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=ENTR'.
    perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
    'X'.
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE'
    '=BU'.
    perform bdc_field using 'MAKT-MAKTX'
    wa_mat-desc.
    perform bdc_field using 'BDC_CURSOR'
    'MARA-MEINS'.
    perform bdc_field using 'MARA-MEINS'
    wa_mat-uom.
    perform bdc_field using 'MARA-MTPOS_MARA'
    'NORM'.
    perform bdc_transaction using 'MM01'.
    endloop.
    Perform close_group.
    Reward points for helpful answers.
    Thanks
    Naveen khan
    Message was edited by:
            Pattan Naveen
    Message was edited by:
            Pattan Naveen

  • BDC (Flat File Data Validation) - Code

    I am trying to validate flat file data BEFORE performing BDC (Call Trans. or Session)..
    Pls help me out in below code for xk02..
    DATA: BEGIN OF itab occurs 0,  "ITAB having flat file data.
          lifnr(16) ,
          bukrs(4),
          ekorg(4),
          END OF itab.
    DATA: BEGIN OF int_final occurs 0,
          lifnr(16) ,
          bukrs(4),
          ekorg(4),
          status(6),
          message(6),
          END OF int_final.
    DATA: int_final TYPE TABLE OF int_final.
    DATA: wa_itab TYPE TABLE OF itab.
    DATA: validate_itab TYPE TABLE OF itab. "VALIDATE_ITAB having master data.
    DATA: wa_validate_itab TYPE TABLE OF itab.
    FORM data_validation .
    SELECT LFB1LIFNR LFB1BUKRS LFM1~EKORG INTO TABLE validate_itab
             FROM LFB1 INNER JOIN LFM1 ON LFB1LIFNR = LFM1LIFNR.
    IF sy-subrc = 0.
    SORT validate_itab BY lifnr bukrs ekorg.
    ENDIF.
    LOOP AT itab INTO wa_itab.
    READ TABLE validate_itab WITH KEY
    lifnr = itab-lifnr
    bukrs = itab-bukrs
    ekorg = itab-ekorg
    BINARY SEARCH.
    IF sy-subrc NE 0.
    PERFORM f_error_log USING text-005. "Invalid Value Set
    CONTINUE.
    ENDIF.
    ENDLOOP.
    ENDFORM.                    " data_validation
    *&      Form  f_error_log
    FORM f_error_log USING l_message TYPE string.
    CLEAR : fs_final.
    fs_final-lifnr = itab-lifnr.
    fs_final-bukrs = itab-bukrs.
    fs_final-ekorg = itab-ekorg.
    fs_final-status = text-014. "Error
    fs_final-message = l_message.
    APPEND fs_final TO int_final.
    ENDFORM.                    " f_error_log
    Thanks..

    Hi GAurav,
    I have a small question in th validation.
    In LFM1~LIFNR does not contian any value how u r comparing both and one more thing After getting the data using GUI_upload u will get the data into validate_tab.
    Loop at Vlidate_tab into wa_itab.
    SELECT LFB1LIFNR LFB1BUKRS LFM1~EKORG INTO TABLE validate_itab
    FROM LFB1 INNER JOIN LFM1 ON LFB1~LIFNR =  wa_itab-lifnr.
    endllop.
    Thanks,

  • BDC Uploading from flat file to VA01.

    i have a flat file, where i have to upload data  into VA01, but it should suppose to multiple materials under same customer and it should not get saved until end user decide whether data is ok or not. my problem is, how to make multiple entries of diff materials in VA01 for single customer. Please give me any solution, and if possible provide me any examples. thank you.

    Hi Kalyan,
    Here is the sample code for you ....... but i tis better you use the BAPI
    <b>BAPI_SALESORDER_CREATEFROMDAT1 or BAPI_SALESORDER_CREATEFROMDAT2</b>
    REPORT ZSD00001 MESSAGE-ID ZZ.
    TABLES: VBAK, VBAP.
    TABLES: ZSOM1, ZSOM2.
    SELECTION-SCREEN: BEGIN OF BLOCK FORT WITH FRAME TITLE TEXT-002.
    PARAMETERS: P_FILE RADIOBUTTON GROUP B2 DEFAULT 'X',
                P_TABLE RADIOBUTTON GROUP B2,
                P_REPORT RADIOBUTTON GROUP B2.
    SELECTION-SCREEN SKIP 1.
    PARAMETER: VIEW RADIOBUTTON GROUP VIEW,
               ERRORS RADIOBUTTON GROUP VIEW,
               NO_DIS RADIOBUTTON GROUP VIEW DEFAULT 'X'.
    SELECTION-SCREEN: END OF BLOCK FORT.
    SELECTION-SCREEN: BEGIN OF BLOCK FILE WITH FRAME TITLE TEXT-001.
    PARAMETERS:
                IDLEX RADIOBUTTON GROUP B1 DEFAULT 'X',
                DBLEX RADIOBUTTON GROUP B1,
                BDC_NAME(12)     TYPE C DEFAULT 'idllapso',
                IDLH(99)         TYPE C DEFAULT
            '/usr/sap/D01/DVEBMGS00/ISAP/interfaces/laptop/in/idlordht.txt',
                IDLI(99)         TYPE C DEFAULT
            '/usr/sap/D01/DVEBMGS00/ISAP/interfaces/laptop/in/idlordit.txt',
                ARC_FIL DEFAULT ' ' AS CHECKBOX.
    SELECTION-SCREEN: END OF BLOCK FILE.
    SELECTION-SCREEN: BEGIN OF BLOCK TAB WITH FRAME TITLE TEXT-003.
    SELECT-OPTIONS: O_IHREZ FOR ZSOM1-IHREZ,
                    O_VBELN FOR ZSOM1-IHREZ,
                    O_MESS FOR ZSOM1-MESS DEFAULT 'W'.
    SELECTION-SCREEN: END OF BLOCK TAB.
    DATA:
    * Data counters.
           RECS_IN(4)            TYPE N  VALUE 0,
           BDC_RECS_OUT(4)       TYPE N  VALUE 0,
           BDC_RECS_ERR(4)       TYPE N  VALUE 0,
           DATA_IN_RECS(4)        TYPE N  VALUE 0,
    * Data constants
           TRUE(1)               TYPE C  VALUE 'X',
           FALSE(1)              TYPE C  VALUE ' ',
    * Data variables
           ABAPNAME              LIKE SY-REPID,
           ABAPTITLE             LIKE SY-TITLE,
           SAVE_UCOMM            LIKE SY-UCOMM,
           V_IHREZ               LIKE VBAK-IHREZ.
    * inbound header structure
    DATA: BEGIN OF IDLORDH OCCURS 1000,
    SO-NUMBER(5)          TYPE N,  "The order number given by the Vax - Alwa
    ORDER-TYPE(1)         TYPE N,  "1 - Under-Bond Sale  3 - Duty-Paid Order
    CUST-NO(7)            TYPE N,          "Id for customer
    BRANCH-NO(4)          TYPE N,          "Id of customer's branch
    PC-DATE-REQD(8)       TYPE C,  "Date that customer required the order
    IDL-ORDER-NO(5)       TYPE N,          "Laptop's Order Number
    SPEC-INS-1(40)        TYPE C,  "Text detailing special instruction for t
    SPEC-INS-2(40)        TYPE C,          "Part 2 of above
    PC-ORDER-DATE(8)      TYPE C,  "Date order was entered on the Laptop
    ORDER-METHOD(1)       TYPE N,          "Always 5 for laptop
    FOR-COLLECTION(1)     TYPE C,  "Y if customers is collecting order else
    CASH-RECEIVED(9)      TYPE N,          "N/A
    CASH-SHEET-NO(6)      TYPE N,          "N/A
    CUST-ORDER-NO(14)     TYPE C,  "Customers Order Number - Optional
    HOLD-FOR-PRICING(1)   TYPE C,  "Y if this order is held because no price
    PC-PRICE-EFF-DATE(8)  TYPE C,          "Defaults to order date
    NO-ITEMS(4)           TYPE N,  "Number of items for this order in detail
    TOTAL-QTY-ORDERED(9)  TYPE N,          "Number of cases on this order
    TOTAL-CE-ORDERED(9)   TYPE N,  "Number of case equivalents on this order
    ORDER-STATUS(1)       TYPE N,          "Always 0 for new orders
    SITE-PREFIX(1)        TYPE C,  "Plant from where the delivery will be ma
    PC-USER-NO(3)         TYPE N.          "laptop user who crested order
    DATA: END OF IDLORDH.
    DATA: BEGIN OF IDLORDI OCCURS 1000,
    SO-NUMBER(5)         TYPE N,  "The order number given by the Vax - Alway
    ORDER-ENTRY-CODE(5)  TYPE N,           "Part Id
    PC-DATE-REQD(8)      TYPE C,  "Date the customer required order.
    QTY-TO-ORDER(4)      TYPE N,           "Number of units on the order.
    PC-USER-NO(3)        TYPE N,           "Id of rep. Who created the order
    IDL-ORDER-NO(5)      TYPE N,           "Laptop's Order Number
    FREE-QTY-ORDERED(4)  TYPE N,  "Number of free units on the order.
    PROMOTION-NO(4)      TYPE N.  "If Free units on the order, this is promo
    DATA: END OF IDLORDI.
    * Internal table to hold the mapped data.
    DATA:  BEGIN OF DATA_IN OCCURS 1000,
              RTYPE(1) TYPE C,
    * header
              AUART LIKE VBAK-AUART,       "order type
              VKORG LIKE VBAK-VKORG,       "sales org
              VTWEG LIKE VBAK-VTWEG,       "dist.channel
              SPART LIKE VBAK-SPART,       "division
              KUNNR LIKE KUAGV-KUNNR,      "customer num
    *         vkbur like vbak-vkbur,  "sales off
    *         vkgrp like vbak-vkgrp,  "sales grp
              BSTNK LIKE VBAK-BSTNK,       "po num
              IHREZ LIKE VBAK-IHREZ,       "po reference
              BSTDK LIKE VBAK-BSTDK,       "po date
              KPRGBZ  LIKE RV45A-KPRGBZ,   "date type
    *         ketdat  like rv45a-ketdat, "req delivery date
              KETDAT(8) TYPE C         ,   "req delivery date
              PRSDT    LIKE VBKD-PRSDT,    "pricing date
              LIFSK   LIKE VBAK-LIFSK,     "delivery block
              INCO1   LIKE  VBKD-INCO1,    "inco terms
              INCO2   LIKE VBKD-INCO2,     "inco descript.
              FAKSK   LIKE VBAK-FAKSK,     "biling block
              KUNDE   LIKE RV02P-KUNDE,    "shipto
              ltext1(256) type c,          "Special text1
              ltext2(256) type c,          "Special text2
              BSARK    LIKE VBAK-BSARK,    "ordering method
              BNAME    LIKE VBAK-BNAME,    "orderer
              WERKS LIKE VBAP-WERKS,       "Site Prefix
    * item
              POSNR LIKE VBAP-POSNR,       "item
              MATNR LIKE VBAP-MATNR,       "material
              MENGE(15) TYPE C,                                 "qty
              FREE_MENGE(15) TYPE C,       "Free qty ordered
              PSTYV LIKE VBAP-PSTYV,       "item category
              ROUTE LIKE VBAP-ROUTE,       "Collect or not
    *         vrkme(3) type c,        "uom
    *         itext(40),              "item txt
    END OF DATA_IN.
    DATA: BEGIN OF I_MATERIAL OCCURS 0,
          MATNR LIKE MARA-MATNR,
          ORDER LIKE IDLORDI-ORDER-ENTRY-CODE,
          END OF I_MATERIAL.
    DATA: BEGIN OF I_MAIL OCCURS 0.
          INCLUDE STRUCTURE SOLI.
    DATA: END OF I_MAIL.
    * Internal table to contain BDC data.
    DATA: BEGIN OF BDCDATA OCCURS 1000.
            INCLUDE STRUCTURE BDCDATA.
    DATA: END OF BDCDATA.
    DATA: BEGIN OF MESSTAB OCCURS 0.
            INCLUDE STRUCTURE BDCMSGCOLL.
    DATA: END OF MESSTAB.
    DATA: BEGIN OF I_OUTPUT OCCURS 1000.
            INCLUDE STRUCTURE DATA_IN.
    DATA: END OF I_OUTPUT.
    DATA: OLD_RTYPE LIKE DATA_IN-RTYPE,
          V_VBELN LIKE VBAK-VBELN,
          V_ITEM_NO(2) TYPE N,
          V_MAIL(1) TYPE C,
          V_VIEW(1) TYPE C,
          V_IDL-ORDER-NO LIKE IDLORDH-IDL-ORDER-NO,
          V_PC-USER-NO LIKE IDLORDH-PC-USER-NO.
    AT SELECTION-SCREEN.
    * Check name of BDC session has been supplied.
      IF BDC_NAME EQ SPACE.
        SET CURSOR FIELD 'BDC_NAME'.
        MESSAGE E002 WITH 'No batch-input session name supplied'.
      ENDIF.
    START-OF-SELECTION.
      MOVE: SY-REPID TO ABAPNAME,
            SY-TITLE TO ABAPTITLE.
      IF VIEW  = 'X'. V_VIEW = 'A'. ENDIF.
      IF ERRORS  = 'X'. V_VIEW = 'E'. ENDIF.
      IF NO_DIS  = 'X'. V_VIEW = 'N'. ENDIF.
      IF P_FILE = 'X'.
    * Read the input files.
        PERFORM READ_FILES.
    * Map the data.
        PERFORM MAP_DATA.
    * Create the BDC sessions.
        PERFORM CREATE_BDC_SESSIONS.
      MESSAGE I002 WITH 'Run the Report to check which orders have been
                                                                CREATED'.
      ELSEIF P_TABLE = 'X'.
       V_VIEW = 'A'.
    * Load Data from table.
        PERFORM F_TABLE_LOAD.
    * Create the BDC sessions.
        PERFORM CREATE_BDC_SESSIONS.
      MESSAGE I002 WITH 'Run the Report to check which orders have been
                                                                CREATED'.
      ELSEIF P_REPORT = 'X'.
    *Submit report.
       SUBMIT ZSDRLAPS AND RETURN
       USING SELECTION-SETS OF PROGRAM 'ZSDILAPT'
        WITH O_IHREZ IN O_IHREZ
        WITH O_VBELN IN O_VBELN
        WITH O_MESS IN O_MESS.
      ENDIF.
    * Archive the input file.
      IF ARC_FIL NE SPACE.
        PERFORM DEL_INP_FILE.
      ENDIF.
    IF V_MAIL = 1.
    MOVE 'CTRL F6 to Execute the LAPTOP Error log Program' TO I_MAIL-LINE.
    APPEND I_MAIL.
    CLEAR I_MAIL.
       CALL FUNCTION 'Z_SEND_MESSAGE'
            EXPORTING
                 MAIL_TO        = 'LAPTOPS'
                 MAIL_TITLE     = 'LAPTOP SALES ORDERS'
                 ATTACH_TYPE    = 'R'
                 NAME           = 'ZSDRLAPS'
            TABLES
                 CONTENTS       = I_MAIL
            EXCEPTIONS
                 PERS_NO_USERID = 1
                 OTHERS         = 2.
    ENDIF.
    END-OF-SELECTION.
    *        FORM CREATE_BDC_SESSION                                       *
    * This form will create a BDC session.                                 *
    FORM CREATE_BDC_SESSIONS.
      REFRESH BDCDATA.
      CLEAR   BDCDATA.
      OLD_RTYPE = SPACE.
      READ TABLE DATA_IN INDEX 1.
      OLD_RTYPE = DATA_IN-RTYPE.
      CLEAR DATA_IN.
      LOOP AT DATA_IN.
        IF OLD_RTYPE EQ '2' AND DATA_IN-RTYPE EQ '1'.
          PERFORM BDC_FIELD USING 'BDC_OKCODE'   '/11'.
          CALL TRANSACTION 'VA01' USING BDCDATA MODE V_VIEW UPDATE 'S'
                                                MESSAGES INTO MESSTAB.
    *  if sy-subrc ne 0.
          PERFORM F_MESSAGE_ANALYSIS.
    *  endif.
          REFRESH BDCDATA.
        ENDIF.
        IF DATA_IN-RTYPE = 1.
          PERFORM TRANS_VA01_HEADER.
        ELSE.
          PERFORM TRANS_VA01_ITEM.
        ENDIF.
        OLD_RTYPE = DATA_IN-RTYPE.
        MOVE-CORRESPONDING DATA_IN TO I_OUTPUT.
        APPEND I_OUTPUT.
        CLEAR I_OUTPUT.
      ENDLOOP.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'   '/11'.
    * Call transaction
      CALL TRANSACTION 'VA01' USING BDCDATA MODE V_VIEW UPDATE 'S'
                                             MESSAGES INTO MESSTAB.
    *  if sy-subrc ne 0.
      PERFORM F_MESSAGE_ANALYSIS.
    *  endif.
      REFRESH BDCDATA.
    ENDFORM.
    *   FORM RANS_va01_header.                                            *
    *   Set up BDCDATA table for transaction VA01.                        *
    FORM TRANS_VA01_HEADER.
    * Process program SAPMV45a screen 0101
    * CREATE sales order Initial screen
      PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0101'.
      PERFORM BDC_FIELD USING 'VBAK-AUART'  DATA_IN-AUART.
      PERFORM BDC_FIELD USING 'VBAK-VKORG'  DATA_IN-VKORG.
      PERFORM BDC_FIELD USING 'VBAK-VTWEG'  DATA_IN-VTWEG.
      PERFORM BDC_FIELD USING 'VBAK-SPART'  DATA_IN-SPART.
    * perform bdc_field using 'VBAK-VKBUR'  data_in-vkbur.
    * perform bdc_field using 'VBAK-VKGRP'  data_in-vkgrp.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  '/0'.
    * Process program SAPMV45a screen 0402
      PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0402'.
    * Overview screen
      PERFORM BDC_FIELD USING 'KUAGV-KUNNR'  DATA_IN-KUNNR.
      PERFORM BDC_FIELD USING 'VBAK-BSTNK'  DATA_IN-BSTNK.
      PERFORM BDC_FIELD USING 'VBAK-BSTDK'  DATA_IN-BSTDK.
      PERFORM BDC_FIELD USING 'RV45A-KPRGBZ'  DATA_IN-KPRGBZ.
      PERFORM BDC_FIELD USING 'RV45A-KETDAT'  DATA_IN-KETDAT.
    * perform bdc_field using 'VBKD-PRSDT'  data_in-prsdt.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  'KKAU'.
    * Header Bus data
      PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0300'.
      PERFORM BDC_FIELD USING 'VBAK-LIFSK'  DATA_IN-LIFSK.
      PERFORM BDC_FIELD USING 'VBKD-INCO1'  DATA_IN-INCO1.
      PERFORM BDC_FIELD USING 'VBKD-INCO2'  DATA_IN-INCO1.
      PERFORM BDC_FIELD USING 'VBAK-FAKSK'  DATA_IN-FAKSK.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  'KPAR'.
    * Partner
      PERFORM BDC_NEW_DYNPRO USING 'SAPDV02P' '0624'.
      PERFORM BDC_FIELD USING 'RV02P-KUNDE(4)'  DATA_IN-KUNDE.
    * text
      IF DATA_IN-LTEXT1 NE SPACE.
        PERFORM CREATE_TEXT.
      ENDIF.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  'KBES'.
    * Purchase order data
      PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0351'.
      PERFORM BDC_FIELD USING 'VBAK-BSARK'  DATA_IN-BSARK.
      PERFORM BDC_FIELD USING 'VBAK-BNAME'  DATA_IN-BNAME.
      PERFORM BDC_FIELD USING 'VBAK-IHREZ'  DATA_IN-IHREZ.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  'UER1'.
    ENDFORM.
    *       FORM TRANS_VA01_ITEM                                          *
    FORM TRANS_VA01_ITEM.
      PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0402'.
      IF OLD_RTYPE = '1'.                  "ie, this is the first item.
        PERFORM BDC_FIELD USING 'VBAP-MATNR(001)' DATA_IN-MATNR.
        PERFORM BDC_FIELD USING 'RV45A-KWMENG(001)' DATA_IN-MENGE.
        PERFORM BDC_FIELD USING 'BDC_OKCODE' '/0'.
        PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0402'.
        PERFORM BDC_FIELD USING 'RV45A-VBAP_SELKZ(001)' 'X'.
        PERFORM BDC_FIELD USING 'BDC_OKCODE' 'PKAU'.
        PERFORM TRANS_VA01_ITEM_DETAILS.
      ELSE.
        PERFORM BDC_FIELD USING 'BDC_OKCODE' 'POAN'.       "create item
        PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0402'.
        PERFORM BDC_FIELD USING 'VBAP-MATNR(002)' DATA_IN-MATNR.
        IF DATA_IN-MENGE = SPACE.
          PERFORM BDC_FIELD USING 'RV45A-KWMENG(002)' DATA_IN-FREE_MENGE.
        ELSE.
          PERFORM BDC_FIELD USING 'RV45A-KWMENG(002)' DATA_IN-MENGE.
        ENDIF.
        PERFORM BDC_FIELD USING 'BDC_OKCODE' '/0'.
        PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0402'.
        PERFORM BDC_FIELD USING 'RV45A-VBAP_SELKZ(002)' 'X'.
        PERFORM BDC_FIELD USING 'BDC_OKCODE' 'PKAU'.
        PERFORM TRANS_VA01_ITEM_DETAILS.
      ENDIF.
    ENDFORM.
    *&      Form  TRANS_VA01_ITEM_DETAILS
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM TRANS_VA01_ITEM_DETAILS.
    *Business Data
      PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0450'.
      PERFORM BDC_FIELD USING 'VBAP-WERKS' DATA_IN-WERKS.
      IF DATA_IN-MENGE = SPACE.
        PERFORM BDC_FIELD USING 'VBAP-PSTYV' 'TANN'.
      ENDIF.
    *  perform bdc_field using 'VBAP-PSTYV' 'TAN'.
    * route mapping
      IF DATA_IN-ROUTE = 'D'.
        PERFORM BDC_FIELD USING 'VBAP-ROUTE' '000001'.
      ELSE.
      ENDIF.
      PERFORM BDC_FIELD USING 'VBAP-FAKSK' DATA_IN-FAKSK.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  'UER1'.
    ENDFORM.                               " TRANS_VA01_ITEM_DETAILS
    *       FORM BDC_NEW_DYNPRO                                           *
    *       Updates the BDCDATA table with the program and screen number  *
    *       of the next screen.                                           *
    FORM BDC_NEW_DYNPRO USING PROGRAM DYNPRO.
      CLEAR BDCDATA.
      BDCDATA-PROGRAM = PROGRAM.
      BDCDATA-DYNPRO  = DYNPRO.
      BDCDATA-DYNBEGIN = 'X'.
      APPEND BDCDATA.
    ENDFORM.
    *       FORM BDC_FIELD                                                *
    *       Updates the BDCDATA table with the field name and value of    *
    *       the current screen.                                           *
    *  -->  FIELD  -  Field name                                          *
    *  -->  VALUE  -  Field value                                         *
    FORM BDC_FIELD USING FIELD VALUE.
      IF VALUE NE SPACE.
        CLEAR BDCDATA.
        BDCDATA-FNAM = FIELD.
        BDCDATA-FVAL = VALUE.
        APPEND BDCDATA.
      ENDIF.
    ENDFORM.
    *&      Form  READ_FILE
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM READ_FILES.
    * Read order headers
      OPEN DATASET IDLH FOR INPUT IN TEXT MODE.
      IF SY-SUBRC NE 0.
        MESSAGE E002(ZZ) WITH 'Cannot find file in directory'.
      ENDIF.
      DO.
        READ DATASET IDLH INTO IDLORDH.
        IF SY-SUBRC NE 0.
          EXIT.
        ENDIF.
        APPEND IDLORDH.
      ENDDO.
      CLOSE DATASET IDLH.
    * Read order items
      OPEN DATASET IDLI FOR INPUT IN TEXT MODE.
      IF SY-SUBRC NE 0.
        MESSAGE E002(ZZ) WITH 'Cannot find file in directory'.
      ENDIF.
      DO.
        READ DATASET IDLI INTO IDLORDI.
        IF SY-SUBRC NE 0.
          EXIT.
        ENDIF.
        APPEND IDLORDI.
      ENDDO.
      CLOSE DATASET IDLI.
    ENDFORM.                               " READ_FILE_INTO_CUST
    *&      Form  DEL_INP_FILE
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM DEL_INP_FILE.
      DATA: PARAX(128).
      DATA: PARAM(200).
      DATA: CMDSTR(18),
            CMD_RESULT  LIKE BTCXPM OCCURS 10 WITH HEADER LINE,
            LINES TYPE I.
      DATA: PATH1(60) TYPE C.
      DATA: PATH2(60) TYPE C.
      DATA: NAME(20) TYPE C.
      DATA: INTNAME(20) TYPE C VALUE 'LAPTOP',
            V_FILENAME1(20) TYPE C VALUE 'ORDHT',
            V_FILENAME2(20) TYPE C VALUE 'ORDIT'.
      DATA: V_DATE LIKE SY-DATUM.
      V_DATE = SY-DATUM+4(4).
      CLEAR PARAX.
    * build IN directory
      PATH1 ='/'.
      WRITE SY-SYSID TO PATH1+1(3).        "D01 or T01 or P01 !
      WRITE 'INT/'    TO PATH1+4(4).       "Interfaces
      WRITE INTNAME TO PATH1+8(20).
      CONDENSE PATH1 NO-GAPS.
      WRITE '/IN' TO PATH1+30(5).
      CONDENSE PATH1 NO-GAPS.
    * build ARCH directory
      PATH2 ='/'.
      WRITE SY-SYSID TO PATH2+1(3).        "D01 or T01 or P01 !
      WRITE 'INT/'    TO PATH2+4(4).       "Interfaces
      WRITE INTNAME TO PATH2+8(20).
      CONDENSE PATH2 NO-GAPS.
      WRITE '/ARCH' TO PATH2+30(5).
      CONDENSE PATH2 NO-GAPS.
      DO 2 TIMES.
        CASE SY-INDEX.
          WHEN 1.
            IF IDLEX = 'X'.
              CONCATENATE 'IDL' V_FILENAME1 INTO NAME.
            ELSE.
              CONCATENATE 'DB' V_FILENAME1 INTO NAME.
            ENDIF.
    *   name = filename1.
          WHEN 2.
            IF IDLEX = 'X'.
              CONCATENATE 'IDL' V_FILENAME2 INTO NAME.
            ELSE.
              CONCATENATE 'DB'  V_FILENAME2 INTO NAME.
            ENDIF.
    *    name = filename2.
        ENDCASE.
        CMDSTR = 'ZMOV'.
        WRITE ' OBJ( TO PARAM.
        WRITE PATH1 TO PARAM+7(50).
        WRITE '/'   TO PARAM+50(1).
        CONDENSE PARAM NO-GAPS.
        WRITE NAME TO PARAM+70(12).
        CONDENSE PARAM NO-GAPS.
        WRITE )@TOOBJ( TO PARAM+70(13).
        CONDENSE PARAM NO-GAPS.
        WRITE PATH2 TO PARAM+82(60).
        CONDENSE PARAM NO-GAPS.
        WRITE '/'   TO PARAM+140(1).
        CONDENSE PARAM NO-GAPS.
        WRITE V_DATE TO PARAM+140(4).
        CONDENSE PARAM NO-GAPS.
        WRITE NAME TO PARAM+140(15).
        CONDENSE PARAM NO-GAPS.
        WRITE )' TO PARAM+142(5).
        CONDENSE PARAM NO-GAPS.
        REPLACE '@' WITH ' ' INTO PARAM.
    *  replace '@' with ' ' into param.
        MOVE PARAM(127) TO PARAX(127).
        CALL FUNCTION 'SXPG_CALL_SYSTEM'
             EXPORTING
                  COMMANDNAME       = CMDSTR
                  PARAMETERS        = PARAX
             TABLES
                  EXEC_PROTOCOL     = CMD_RESULT
             EXCEPTIONS
                  NO_PERMISSION     = 1
                  COMMAND_NOT_FOUND = 2
                  OTHERS            = 4.
        IF SY-SUBRC <> 0.                  "extenal command not executed
        MESSAGE I002 WITH 'error calling external command - call sys admin'.
        ENDIF.
      ENDDO.
    ENDFORM.                               " DEL_INP_FILE
    *&      Form  CREATE_TEXT
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM CREATE_TEXT.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  'KTEX'.
    * Text overview
      PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0150'.
      PERFORM BDC_FIELD USING 'RTEXT-SELKZ(02)' 'X'.
      PERFORM BDC_FIELD USING 'RTEXT-SPRAS(02)' 'E'.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  'TEDE'.
    * Text editor
      PERFORM BDC_NEW_DYNPRO USING 'SAPLSTXX' '1100'.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  '/06'.
      PERFORM BDC_NEW_DYNPRO USING 'SAPLSTXX' '1100'.
      PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RSTXT-TXLINE(02)'.
      PERFORM BDC_FIELD USING 'RSTXT-TXLINE(02)' DATA_IN-LTEXT2(70).
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  '/06'.
      PERFORM BDC_NEW_DYNPRO USING 'SAPLSTXX' '1100'.
      PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RSTXT-TXLINE(02)'.
      PERFORM BDC_FIELD USING 'RSTXT-TXLINE(02)' DATA_IN-LTEXT1(70).
      PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RSTXT-TXLINE(04)'.
    * perform bdc_field using 'BDC_OKCODE'  '/06'.
    * perform bdc_new_dynpro using 'SAPLSTXX' '1100'.
    *  PERFORM BDC_FIELD USING 'RSTXT-TXLINE(004)' DATA_IN-ltext+140(70).
    *  PERFORM BDC_FIELD USING 'BDC_OKCODE'  '/06'.
    *  PERFORM BDC_NEW_DYNPRO USING 'SAPLSTXX' '1100'.
    *  PERFORM BDC_FIELD USING 'RSTXT-TXLINE(005)' DATA_IN-ltext+210(46).
    *  PERFORM BDC_FIELD USING 'BDC_OKCODE'  '/06'.
      PERFORM BDC_NEW_DYNPRO USING 'SAPLSTXX' '1100'.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  'TXVB'.
      PERFORM BDC_NEW_DYNPRO USING 'SAPLSTXX' '1100'.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'  'TXEX'.
      PERFORM BDC_NEW_DYNPRO USING 'SAPMV45A' '0150'.
    ENDFORM.                               " CREATE_TEXT
    *&      Form  MAP_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM MAP_DATA.
      TABLES: KNB1, CABN, AUSP.
      TABLES: ZPM1.
      DATA: V_CUST_NO(11) TYPE C.
      CLEAR IDLORDH.
      CLEAR DATA_IN.
      SELECT * FROM CABN
            WHERE ATNAM = 'ORDER_ENTRY_CODE'.
        EXIT.
      ENDSELECT.
      SELECT OBJEK ATWRT INTO (I_MATERIAL-MATNR, I_MATERIAL-ORDER)
            FROM AUSP
            WHERE ATINN = CABN-ATINN.
      APPEND I_MATERIAL.
    ENDSELECT.
    LOOP AT IDLORDH.
      MOVE '1' TO DATA_IN-RTYPE.
    * Order type.
      DATA_IN-AUART = 'ZOR'.
    * Sales organisation
      IF IDLEX EQ 'X'.
        DATA_IN-VKORG = '1100'.            "idl domestic.
      ELSE.
        DATA_IN-VKORG = '1350'.            "dillion bass domestic.
      ENDIF.
    * Distribution Channel
      DATA_IN-VTWEG = '10'.
    * Division
      DATA_IN-SPART = '10'.
    * Customer Number
      IF IDLORDH-CUST-NO(1) = SPACE.
        CONCATENATE '0' IDLORDH-CUST-NO INTO V_CUST_NO.
        CONDENSE V_CUST_NO NO-GAPS.
      ELSE.
        V_CUST_NO = IDLORDH-CUST-NO.
      ENDIF.
      DO 4 TIMES.
        IF IDLORDH-BRANCH-NO CS SPACE.
          REPLACE SPACE WITH '0' INTO IDLORDH-BRANCH-NO.
        ENDIF.
      ENDDO.
      move idlordh-branch-no to v_cust_no+7(4).
      select * from knb1 where eikto = v_cust_no.
        EXIT.
      ENDSELECT.
      MOVE KNB1-KUNNR TO DATA_IN-KUNNR.
    * Sales Office
    *ata_in-vkbur.
    * Sales Group
    *ata_in-vkgrp
    * PO number
      DATA_IN-BSTNK = IDLORDH-CUST-ORDER-NO.
    * PO ref number
      IF IDLORDH-IDL-ORDER-NO(1) EQ SPACE.
        MOVE IDLORDH-IDL-ORDER-NO TO V_IDL-ORDER-NO.
        REPLACE SPACE WITH '0' INTO V_IDL-ORDER-NO.
      ENDIF.
      MOVE IDLORDH-PC-USER-NO TO V_PC-USER-NO.
      DO 3 TIMES.
        REPLACE SPACE WITH '0' INTO V_PC-USER-NO.
      ENDDO.
      CONCATENATE V_IDL-ORDER-NO '-' V_PC-USER-NO INTO V_IHREZ.
      DATA_IN-IHREZ = V_IHREZ.
    * PO Date
      DATA_IN-BSTDK = IDLORDH-PC-ORDER-DATE.
      DO 2 TIMES.
        REPLACE '/' WITH '.' INTO IDLORDH-PC-ORDER-DATE.
      ENDDO.
      DATA_IN-BSTDK = IDLORDH-PC-ORDER-DATE.
    * Date Type
    *ata_in-kprgbz
    * Required Delivery Date
      DO 2 TIMES.
        REPLACE '/' WITH '.' INTO IDLORDH-PC-DATE-REQD.
      ENDDO.
      DATA_IN-KETDAT = IDLORDH-PC-DATE-REQD.
    *pricing date
    *ata_in-prsdt
    *delivery block
    *ata_in-lifsk
    *inco terms.
      IF IDLORDH-FOR-COLLECTION = 'Y'.
        DATA_IN-INCO1 = 'EXW'.
      ELSE.
        DATA_IN-INCO1 = 'CIF'.
      ENDIF.
    *inco description
    *ata_in-inco2
    *billing block
      IF IDLORDH-HOLD-FOR-PRICING = 'Y'.
        DATA_IN-FAKSK = '99'.
      ENDIF.
    *shipto
    *ata_in-kunde
    *special text
      DATA_IN-LTEXT1 = IDLORDH-SPEC-INS-1.
      DATA_IN-LTEXT2 = IDLORDH-SPEC-INS-2.
    *ordering method
      DATA_IN-BSARK = 'LAPT'.
    *plant.
      SELECT * FROM ZPM1
         WHERE ZLPLANT = IDLORDH-SITE-PREFIX.
        EXIT.
      ENDSELECT.
      DATA_IN-WERKS = ZPM1-ZWERKS.
    *orderer
    *data_in-bname
      APPEND DATA_IN.
      CLEAR DATA_IN.
      LOOP AT IDLORDI WHERE IDL-ORDER-NO = IDLORDH-IDL-ORDER-NO AND
                            PC-USER-NO = IDLORDH-PC-USER-NO.
        MOVE '2' TO DATA_IN-RTYPE.
    *item
    *material no.
        READ TABLE I_MATERIAL WITH KEY ORDER = IDLORDI-ORDER-ENTRY-CODE.
        DATA_IN-MATNR = I_MATERIAL-MATNR.
    *Order quantity
        DATA_IN-MENGE = IDLORDI-QTY-TO-ORDER.
        DATA_IN-FREE_MENGE = IDLORDI-FREE-QTY-ORDERED.
    *plant.
        DATA_IN-WERKS = ZPM1-ZWERKS.
    *ata_in-pstyv
    *       route
    *       vrkme
    *       itext
        APPEND DATA_IN.
        IF  IDLORDI-FREE-QTY-ORDERED > 0.
          CLEAR DATA_IN-MENGE.
          APPEND DATA_IN.
        ENDIF.
        CLEAR DATA_IN.
      ENDLOOP.
    ENDLOOP.
    ENDFORM.                               " MAP_DATA
    *&      Form  F_MESSAGE_ANALYSIS
    *  <--  p2        text
    FORM F_MESSAGE_ANALYSIS.
      DATA: V_FIRST(1) TYPE C VALUE '1',
            V_COUNT(2) TYPE N,
            V_MESSAGE(1) TYPE C,
            V_MESSLINES(2) TYPE N.
      CLEAR: V_IHREZ, V_MESSLINES.
      DESCRIBE TABLE MESSTAB LINES V_MESSLINES.
      READ TABLE MESSTAB WITH KEY MSGTYP = 'S' MSGID = 'V1' MSGNR = '311'.
      IF SY-SUBRC = 0.
        IF V_MESSLINES = 1.
          V_MESSAGE = 'S'.
        ELSE.
          V_MESSAGE = 'W'.
          V_MAIL = 1.
        ENDIF.
        V_VBELN = MESSTAB-MSGV2(08).
      ELSE.
        V_MESSAGE = 'E'.
        V_MAIL = 1.
      ENDIF.
      V_FIRST = 1.
      LOOP AT I_OUTPUT.
        IF V_FIRST = 1.
          MOVE I_OUTPUT-IHREZ TO V_IHREZ.
          CLEAR V_FIRST.
        ENDIF.
        ZSOM1-VBELN = V_VBELN.
        ZSOM1-ITEM_NO = V_ITEM_NO.
        ZSOM1-MESS = V_MESSAGE.
        MOVE-CORRESPONDING I_OUTPUT TO ZSOM1.
        ZSOM1-IHREZ = V_IHREZ.
        MODIFY ZSOM1.
        CLEAR ZSOM1.
        V_ITEM_NO = V_ITEM_NO + 1.
      ENDLOOP.
      LOOP AT MESSTAB.
        V_COUNT = V_COUNT + 1.
        ZSOM2-MCOUNT = V_COUNT.
        ZSOM2-IHREZ = V_IHREZ.
        CASE MESSTAB-MSGTYP.
          WHEN 'E'.
            MOVE-CORRESPONDING MESSTAB TO ZSOM2.
          WHEN 'A'.
            MOVE-CORRESPONDING MESSTAB TO ZSOM2.
          WHEN 'W'.
            MOVE V_VBELN TO ZSOM2-VBELN.
            MOVE-CORRESPONDING MESSTAB TO ZSOM2.
          WHEN 'I'.
            MOVE V_VBELN TO ZSOM2-VBELN.
            MOVE-CORRESPONDING MESSTAB TO ZSOM2.
          WHEN 'S'.
            MOVE V_VBELN TO ZSOM2-VBELN.
            MOVE-CORRESPONDING MESSTAB TO ZSOM2.
        ENDCASE.
        MODIFY ZSOM2.
        CLEAR ZSOM2.
      ENDLOOP.
      REFRESH: MESSTAB, I_OUTPUT.
      CLEAR: MESSTAB, I_OUTPUT.
      CLEAR: V_FIRST, V_VBELN, V_IHREZ, V_ITEM_NO, V_COUNT, V_MESSAGE.
    ENDFORM.                               " F_MESSAGE_ANALYSIS
    *&      Form  F_TABLE_LOAD
    FORM F_TABLE_LOAD.
      SELECT * FROM ZSOM1
       WHERE IHREZ IN O_IHREZ
         AND MESS = 'E'.
        IF NOT ZSOM1-VBELN IS INITIAL.
          CHECK ZSOM1-VBELN IN O_VBELN.
        ENDIF.
        MOVE-CORRESPONDING ZSOM1 TO DATA_IN.
        APPEND DATA_IN.
        CLEAR DATA_IN.
      ENDSELECT.
    ENDFORM.                               " F_TABLE_LOAD

  • Bdc - errors in flat file

    hi,
    in BDC,
    after uploading data from flat file,
    how to find if there are any errors in flat file,
    before starting the session.

    Hi,
    You have to create internal tables for all the mandatory fields. see the following code :
    I am giving an example for XK01 Transaction.
    TYPES:BEGIN OF TY_XK01,
          LIFNR(10)      TYPE  C ,          "VENDOR'S ACCOUNT NUMBER
          BUKRS(4)       TYPE  C ,          "COMPANY CODE
          EKORG(4)       TYPE  C ,          "PURCHASING ORGANISATION
          KTOKK(4)       TYPE  C ,          "VENDOR ACCOUNT GROUP
          NAME1(35)      TYPE  C ,                              "NAME1
          SORTL(10)      TYPE  C ,          "SORT FIELD
          STRAS(35)      TYPE  C ,          "STREET
          PSTLZ(10)      TYPE  C ,          "POSTAL CODE
          ORT01(35)      TYPE  C ,          "CITY
          LAND1(3)       TYPE  C ,          "COUNTRY KEY
          REGIO(3)       TYPE  C ,          "REGION
          TIME_ZONE(6)   TYPE  C ,          "ADDRESS TIME ZONE
          LANGU(1)       TYPE  C ,          "LANGUAGE KEY
          TELF1(16)      TYPE  C ,          "TELEPHONE NUMBER
          TELFX(31)      TYPE  C ,          "FAX NUMBER
          SMTP_ADDR(241) TYPE  C ,          "E-MAIL ADDRESS
          URI_SCREEN(132) TYPE  C ,     "UNIFORM RESOURCE LOCATOR
          AKONT(10)      TYPE  C ,          "RECONCILITATION ACCOUNT
          ZUAWA(3)       TYPE  C ,          "KEY FOR SORTING ACCORDING TO ASSIGNMENT NUMBERS
          MINDK(3)       TYPE  C ,          "MINORITY INDICATORS
          ALTKN(10)      TYPE  C ,          "PREVIOUS MASTER RECORD NUMBER
          ZTERM(4)       TYPE  C ,          "TERMS OF PAYMENT KEY
          ZWELS(10)      TYPE  C ,          "LIST OF THE PAYMENT METHODS
          WAERS(5)       TYPE  C ,          "PURCHASE ORDER CURRENCY
          END OF TY_XK01,
    BEGIN OF TY_LIFNR,
         LIFNR(10)  TYPE  C ,
         END OF TY_LIFNR,
         BEGIN OF TY_BUKRS,
         BUKRS(4)  TYPE  C ,
         END OF TY_BUKRS,
         BEGIN OF TY_EKORG,
         EKORG(4)  TYPE  C ,
         END OF TY_EKORG,
         BEGIN OF TY_KTOKK,
         KTOKK(4)  TYPE  C ,
         END OF TY_KTOKK,
         BEGIN OF TY_LAND1,
         LAND1(3)  TYPE  C ,
         END OF TY_LAND1,
         BEGIN OF TY_LANGU,
         LANGU(1)  TYPE  C ,
         END OF TY_LANGU,
         BEGIN OF TY_AKONT,
         AKONT(10) TYPE  C ,
         END OF TY_AKONT,
         BEGIN OF TY_ZUAWA,
         ZUAWA(3)  TYPE  C ,
         END OF TY_ZUAWA,
         BEGIN OF TY_MINDK,
         MINDK(3) TYPE  C ,
         END OF TY_MINDK,
         BEGIN OF TY_WAERS,
         WAERS(5)  TYPE  C ,
         END OF TY_WAERS.
    DATA : I_XK01     TYPE TABLE OF  TY_XK01,     "FOR HOLDING DATA FROM FLAT FILE
           I_SUCCMESG TYPE TABLE OF  TY_MESG,     "FOR SUCCESS RECORDS DETAILS
           I_ERRMESG  TYPE TABLE OF  TY_MESG,     "FOR ERROR RECORDS DETAILS
           I_ERROR TYPE TABLE OF TY_ERROR,
    I_LIFNR TYPE TABLE OF TY_LIFNR,
    I_BUKRS TYPE TABLE OF TY_BUKRS,
    I_EKORG TYPE TABLE OF TY_EKORG,
    I_KTOKK TYPE TABLE OF TY_KTOKK,
    I_LAND1 TYPE TABLE OF TY_LAND1,
    I_LANGU TYPE TABLE OF TY_LANGU,
    I_AKONT TYPE TABLE OF TY_AKONT,
    I_ZUAWA TYPE TABLE OF TY_ZUAWA,
    I_MINDK TYPE TABLE OF TY_MINDK,
    I_WAERS TYPE TABLE OF TY_WAERS,
    I_FINALMESG TYPE TABLE OF TY_ERROR,
    I_MESG TYPE TABLE OF TY_MESG.
    *& WORK AREA DECLARATION
    DATA:  WA_XK01     TYPE TY_XK01,               "FOR HOLDING DATA FROM FLAT FILE
           WA_SUCCMESG TYPE TY_MESG,               "FOR SUCCESS RECORDS DETAILS
           WA_ERRMESG  TYPE TY_MESG,               "FOR ERROR RECORDS DETAILS
           WA_ERROR TYPE TY_ERROR,
    WA_LIFNR TYPE TY_LIFNR,
    WA_BUKRS TYPE TY_BUKRS,
    WA_EKORG TYPE TY_EKORG,
    WA_KTOKK TYPE TY_KTOKK,
    WA_LAND1 TYPE TY_LAND1,
    WA_LANGU TYPE TY_LANGU,
    WA_AKONT TYPE TY_AKONT,
    WA_ZUAWA TYPE TY_ZUAWA,
    WA_MINDK TYPE TY_MINDK,
    WA_WAERS TYPE TY_WAERS,
    WA_MESG TYPE TY_MESG,
    WA_FINALMESG TYPE TY_ERROR.
    INITIALIZATION.
    SELECT LIFNR FROM LFA1 INTO TABLE I_LIFNR.
      SELECT BUKRS FROM T001 INTO TABLE I_BUKRS .
      SELECT EKORG FROM T024E INTO TABLE I_EKORG .
      SELECT KTOKK FROM T077K INTO TABLE I_KTOKK .
      SELECT LAND1 FROM T005 INTO TABLE I_LAND1.
      SELECT SPRAS FROM T002 INTO TABLE I_LANGU.
      SELECT SAKNR FROM SKA1 INTO TABLE I_AKONT .
      SELECT ZUAWA FROM TZUN INTO TABLE I_ZUAWA .
      SELECT MINDK FROM T059M INTO TABLE I_MINDK .
      SELECT WAERS FROM TCURC INTO TABLE I_WAERS.
    LOOP AT I_XK01 INTO WA_XK01.
          TRANSLATE WA_XK01-LIFNR TO UPPER CASE.
          READ TABLE I_LIFNR INTO WA_LIFNR WITH KEY LIFNR = WA_XK01-LIFNR.
          IF SY-SUBRC = 0 .
            CONCATENATE WA_MESG-MESG TEXT-100 WA_XK01-LIFNR TEXT-101  ' , ' INTO WA_MESG-MESG.
          ENDIF.
          TRANSLATE WA_XK01-BUKRS TO UPPER CASE.
          READ TABLE I_BUKRS INTO WA_BUKRS WITH KEY BUKRS = WA_XK01-BUKRS.
          IF SY-SUBRC <> 0 .
            CONCATENATE WA_MESG-MESG  TEXT-102 WA_XK01-BUKRS TEXT-103  ' , ' INTO WA_MESG-MESG.
          ENDIF.
          TRANSLATE WA_XK01-EKORG TO UPPER CASE.
          READ TABLE I_EKORG INTO WA_EKORG WITH KEY EKORG = WA_XK01-EKORG.
          IF SY-SUBRC <> 0 .
            CONCATENATE WA_MESG-MESG TEXT-104    WA_XK01-EKORG  TEXT-103  ',' INTO WA_MESG-MESG.
          ENDIF.
          TRANSLATE WA_XK01-KTOKK TO UPPER CASE.
          READ TABLE I_KTOKK INTO WA_KTOKK WITH KEY KTOKK = WA_XK01-KTOKK.
          IF SY-SUBRC <> 0 .
            CONCATENATE WA_MESG-MESG TEXT-105   WA_XK01-KTOKK  TEXT-103   ',' INTO WA_MESG-MESG.
          ENDIF.
          TRANSLATE WA_XK01-LAND1 TO UPPER CASE.
          READ TABLE I_LAND1 INTO WA_LAND1 WITH KEY LAND1 = WA_XK01-LAND1.
          IF SY-SUBRC <> 0 .
            CONCATENATE WA_MESG-MESG TEXT-106   WA_XK01-LAND1  TEXT-103   ',' INTO WA_MESG-MESG.
          ENDIF.
          TRANSLATE WA_XK01-LANGU TO UPPER CASE.
          READ TABLE I_LANGU INTO WA_LANGU WITH KEY LANGU = WA_XK01-LANGU.
          IF SY-SUBRC <> 0 .
            CONCATENATE WA_MESG-MESG TEXT-107  WA_XK01-LANGU  TEXT-103   ',' INTO WA_MESG-MESG.
          ENDIF.
          READ TABLE I_AKONT INTO WA_AKONT WITH KEY AKONT = WA_XK01-AKONT.
          IF SY-SUBRC <> 0 .
            CONCATENATE WA_MESG-MESG TEXT-108   WA_XK01-AKONT  TEXT-103  ',' INTO WA_MESG-MESG.
          ENDIF.
          READ TABLE I_ZUAWA INTO WA_ZUAWA WITH KEY ZUAWA = WA_XK01-ZUAWA.
          IF SY-SUBRC <> 0 .
            CONCATENATE WA_MESG-MESG TEXT-109    WA_XK01-ZUAWA  TEXT-103   ',' INTO WA_MESG-MESG.
          ENDIF.
          READ TABLE I_MINDK INTO WA_MINDK WITH KEY MINDK = WA_XK01-MINDK.
          IF SY-SUBRC <> 0 .
            CONCATENATE WA_MESG-MESG TEXT-110    WA_XK01-MINDK  TEXT-103   ',' INTO WA_MESG-MESG.
          ENDIF.
          TRANSLATE WA_XK01-WAERS TO UPPER CASE.
          READ TABLE I_WAERS INTO WA_WAERS WITH KEY WAERS = WA_XK01-WAERS.
          IF SY-SUBRC <> 0 .
            CONCATENATE WA_MESG-MESG TEXT-111   WA_XK01-WAERS  TEXT-103   ',' INTO WA_MESG-MESG.
          ENDIF.
    append wa_mesg to err_mesg. 
    endloop.
    I am populating the error messages into workarea using concatenate statement.
    Hope this  solves the problem.
    Reward points if helpful.
    Thanks and Regards,
    Narayana.

  • BDC flat file

    HI gurus,
         In my BDC program I'm using 2 structures.The first one is for the session method and the second one for the call transaction method. my doubt is do i need to create 2 flat files for it. if yes then how to create a flat file using these fields.this is very urgent please help.
    Structure for session method:
    DATA : BEGIN OF it_idata OCCURS 0,
            ematn(18), "Material Number.
            menge(13), "Qyantity.
            netpr(11), "Net Price.
            werks(4),  "Plant.
            ebelp(5),  "Item Number.
           END OF it_idata.
    Structure for Call Transaction:
    DATA : BEGIN OF it_me21 OCCURS 0,
            lifnr(10), "Vendor A/c No.
            bsart(4),  "A/c Type.
            bedat(8),  "Date of creation of PO.
            ekorg(4),  "Purchasing Organisation.
            ekgrp(3),  "Purchasing Group.
            x_data LIKE TABLE OF it_idata,
           END OF it_me21.
    regards,
        abaper
    Edited by: abaper sap on Mar 17, 2008 10:54 AM

    Hi,
    From wht you have given it seems that they are from different table,
    so different data will be there.
    So you have to create a tab delimited file for the data in sequence of the screen data.
    If you dont want to give value  then you can use 'X' in the flat file.
    different files will be needed, go to table in which the data is stored and then accordingly put data in the flat file.
    HTH
    Regards,
    Dhruv Shah

  • BDC for ME21N (Flat file format)

    Hello,
         I have to write a BDC for ME21N(stock transfer).... Someone pls give me the format of flat file... we need separate files for header and items or only one file is enough??? pls someone send me the format and code......
    my email id is [email protected]
    Thanks in advance...
    Regards,
    Maya.

    Hi
    see this and do accordingly
    REPORT zmm_bdcp_purchaseorderkb02
    NO STANDARD PAGE HEADING LINE-SIZE 255.
    Declaring internal tables *
    *-----Declaring line structure
    DATA : BEGIN OF it_dummy OCCURS 0,
    dummy(255) TYPE c,
    END OF it_dummy.
    *-----Internal table for line items
    DATA : BEGIN OF it_idata OCCURS 0,
    ematn(18), "Material Number.
    menge(13), "Qyantity.
    netpr(11), "Net Price.
    werks(4), "Plant.
    ebelp(5), "Item Number.
    END OF it_idata.
    *-----Deep structure for header data and line items
    DATA : BEGIN OF it_me21 OCCURS 0,
    lifnr(10), "Vendor A/c No.
    bsart(4), "A/c Type.
    bedat(8), "Date of creation of PO.
    ekorg(4), "Purchasing Organisation.
    ekgrp(3), "Purchasing Group.
    x_data LIKE TABLE OF it_idata,
    END OF it_me21.
    DATA : x_idata LIKE LINE OF it_idata.
    DATA : v_delimit VALUE ','.
    DATA : v_indx(3) TYPE n.
    DATA : v_fnam(30) TYPE c.
    DATA : v_count TYPE n.
    DATA : v_ne TYPE i.
    DATA : v_ns TYPE i.
    *include bdcrecx1.
    INCLUDE zmm_incl_purchaseorderkb01.
    Search help for file *
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
    program_name = syst-cprog
    dynpro_number = syst-dynnr
    IMPORTING
    file_name = p_file.
    START-OF-SELECTION.
    To upload the data into line structure *
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
    filename = p_file
    filetype = 'DAT'
    TABLES
    data_tab = it_dummy.
    Processing the data from line structure to internal tables *
    REFRESH:it_me21.
    CLEAR :it_me21.
    LOOP AT it_dummy.
    IF it_dummy-dummy+0(01) = 'H'.
    v_indx = v_indx + 1.
    CLEAR it_idata.
    REFRESH it_idata.
    CLEAR it_me21-x_data.
    REFRESH it_me21-x_data.
    SHIFT it_dummy.
    SPLIT it_dummy AT v_delimit INTO it_me21-lifnr
    it_me21-bsart
    it_me21-bedat
    it_me21-ekorg
    it_me21-ekgrp.
    APPEND it_me21.
    ELSEIF it_dummy-dummy+0(01) = 'L'.
    SHIFT it_dummy.
    SPLIT it_dummy AT v_delimit INTO it_idata-ematn
    it_idata-menge
    it_idata-netpr
    it_idata-werks
    it_idata-ebelp.
    APPEND it_idata TO it_me21-x_data.
    MODIFY it_me21 INDEX v_indx.
    ENDIF.
    ENDLOOP.
    To open the group *
    PERFORM open_group.
    To populate the bdcdata table for header data *
    LOOP AT it_me21.
    v_count = v_count + 1.
    REFRESH it_bdcdata.
    PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0100',
    ' ' 'BDC_CURSOR' 'EKKO-LIFNR',
    ' ' 'BDC_OKCODE' '/00',
    ' ' 'EKKO-LIFNR' it_me21-lifnr,
    ' ' 'RM06E-BSART' it_me21-bsart,
    ' ' 'RM06E-BEDAT' it_me21-bedat,
    ' ' 'EKKO-EKORG' it_me21-ekorg,
    ' ' 'EKKO-EKGRP' it_me21-ekgrp,
    ' ' 'RM06E-LPEIN' 'T'.
    PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0120',
    ' ' 'BDC_CURSOR' 'RM06E-EBELP',
    ' ' 'BDC_OKCODE' '/00'.
    MOVE 1 TO v_indx.
    *-----To populate the bdcdata table for line item data
    LOOP AT it_me21-x_data INTO x_idata.
    CONCATENATE 'EKPO-EMATN(' v_indx ')' INTO v_fnam.
    PERFORM subr_bdc_table USING ' ' v_fnam x_idata-ematn.
    CONCATENATE 'EKPO-MENGE(' v_indx ')' INTO v_fnam.
    PERFORM subr_bdc_table USING ' ' v_fnam x_idata-menge.
    CONCATENATE 'EKPO-NETPR(' v_indx ')' INTO v_fnam.
    PERFORM subr_bdc_table USING ' ' v_fnam x_idata-netpr.
    CONCATENATE 'EKPO-WERKS(' v_indx ')' INTO v_fnam.
    PERFORM subr_bdc_table USING ' ' v_fnam x_idata-werks.
    v_indx = v_indx + 1.
    PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0120',
    ' ' 'BDC_CURSOR' 'RM06E-EBELP',
    ' ' 'BDC_OKCODE' '/00'.
    ENDLOOP.
    PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0120',
    ' ' 'BDC_CURSOR' 'RM06E-EBELP',
    ' ' 'BDC_OKCODE' '=BU'.
    PERFORM bdc_transaction USING 'ME21'.
    ENDLOOP.
    PERFORM close_group.
    End of selection event *
    END-OF-SELECTION.
    IF session NE 'X'.
    *-----To display the successful records
    WRITE :/10 text-001. "Sucess records
    WRITE :/10 SY-ULINE(20).
    SKIP.
    IF it_sucess IS INITIAL.
    WRITE :/ text-002.
    ELSE.
    WRITE :/ text-008, "Total number of Succesful records
    35 v_ns.
    SKIP.
    WRITE:/ text-003, "Vendor Number
    17 text-004, "Record number
    30 text-005. "Message
    ENDIF.
    LOOP AT it_sucess.
    WRITE:/4 it_sucess-lifnr,
    17 it_sucess-tabix CENTERED,
    30 it_sucess-sucess_rec.
    ENDLOOP.
    SKIP.
    *-----To display the erroneous records
    WRITE:/10 text-006. "Error Records
    WRITE:/10 SY-ULINE(17).
    SKIP.
    IF it_error IS INITIAL.
    WRITE:/ text-007. "No error records
    ELSE.
    WRITE:/ text-009, "Total number of erroneous records
    35 v_ne.
    SKIP.
    WRITE:/ text-003, "Vendor Number
    17 text-004, "Record number
    30 text-005. "Message
    ENDIF.
    LOOP AT it_error.
    WRITE:/4 it_error-lifnr,
    17 it_error-tabix CENTERED,
    30 it_error-error_rec.
    ENDLOOP.
    REFRESH it_sucess.
    REFRESH it_error.
    ENDIF.
    CODE IN INCLUDE.
    Include ZMM_INCL_PURCHASEORDERKB01
    DATA: it_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
    DATA: it_MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
    DATA: E_GROUP_OPENED.
    *-----Internal table to store sucess records
    DATA:BEGIN OF it_sucess OCCURS 0,
    msgtyp(1) TYPE c,
    lifnr LIKE ekko-lifnr,
    tabix LIKE sy-tabix,
    sucess_rec(125),
    END OF it_sucess.
    DATA: g_mess(125) type c.
    *-----Internal table to store error records
    DATA:BEGIN OF it_error OCCURS 0,
    msgtyp(1) TYPE c,
    lifnr LIKE ekko-lifnr,
    tabix LIKE sy-tabix,
    error_rec(125),
    END OF it_error.
    Selection screen
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS session RADIOBUTTON GROUP ctu. "create session
    SELECTION-SCREEN COMMENT 3(20) text-s07 FOR FIELD session.
    SELECTION-SCREEN POSITION 45.
    PARAMETERS ctu RADIOBUTTON GROUP ctu. "call transaction
    SELECTION-SCREEN COMMENT 48(20) text-s08 FOR FIELD ctu.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 3(20) text-s01 FOR FIELD group.
    SELECTION-SCREEN POSITION 25.
    PARAMETERS group(12). "group name of session
    SELECTION-SCREEN COMMENT 48(20) text-s05 FOR FIELD ctumode.
    SELECTION-SCREEN POSITION 70.
    PARAMETERS ctumode LIKE ctu_params-dismode DEFAULT 'N'.
    "A: show all dynpros
    "E: show dynpro on error only
    "N: do not display dynpro
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 48(20) text-s06 FOR FIELD cupdate.
    SELECTION-SCREEN POSITION 70.
    PARAMETERS cupdate LIKE ctu_params-updmode DEFAULT 'L'.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 3(20) text-s03 FOR FIELD keep.
    SELECTION-SCREEN POSITION 25.
    PARAMETERS: keep AS CHECKBOX. "' ' = delete session if finished
    "'X' = keep session if finished
    SELECTION-SCREEN COMMENT 48(20) text-s09 FOR FIELD e_group.
    SELECTION-SCREEN POSITION 70.
    PARAMETERS e_group(12). "group name of error-session
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 51(17) text-s03 FOR FIELD e_keep.
    SELECTION-SCREEN POSITION 70.
    PARAMETERS: e_keep AS CHECKBOX. "' ' = delete session if finished
    "'X' = keep session if finished
    SELECTION-SCREEN END OF LINE.
    PARAMETERS:p_file LIKE rlgrap-filename.
    at selection screen *
    AT SELECTION-SCREEN.
    group and user must be filled for create session
    IF SESSION = 'X' AND
    GROUP = SPACE. "OR USER = SPACE.
    MESSAGE E613(MS).
    ENDIF.
    create batchinput session *
    FORM OPEN_GROUP.
    IF SESSION = 'X'.
    SKIP.
    WRITE: /(20) 'Create group'(I01), GROUP.
    SKIP.
    *----open batchinput group
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
    CLIENT = SY-MANDT
    GROUP = GROUP
    USER = sy-uname.
    WRITE:/(30) 'BDC_OPEN_GROUP'(I02),
    (12) 'returncode:'(I05),
    SY-SUBRC.
    ENDIF.
    ENDFORM. "OPEN_GROUP
    end batchinput session *
    FORM CLOSE_GROUP.
    IF SESSION = 'X'.
    *------close batchinput group
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
    (12) 'returncode:'(I05),
    SY-SUBRC.
    ELSE.
    IF E_GROUP_OPENED = 'X'.
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    WRITE: /.
    WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).
    ENDIF.
    ENDIF.
    ENDFORM. "CLOSE_GROUP
    Start new transaction according to parameters *
    FORM BDC_TRANSACTION USING TCODE TYPE ANY.
    DATA: L_SUBRC LIKE SY-SUBRC.
    *------batch input session
    IF SESSION = 'X'.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
    TCODE = TCODE
    TABLES
    DYNPROTAB = it_BDCDATA.
    WRITE: / 'BDC_INSERT'(I03),
    TCODE,
    'returncode:'(I05),
    SY-SUBRC,
    'RECORD:',
    SY-INDEX.
    ELSE.
    REFRESH it_MESSTAB.
    CALL TRANSACTION TCODE USING it_BDCDATA
    MODE CTUMODE
    UPDATE CUPDATE
    MESSAGES INTO it_MESSTAB.
    L_SUBRC = SY-SUBRC.
    WRITE: / 'CALL_TRANSACTION',
    TCODE,
    'returncode:'(I05),
    L_SUBRC,
    'RECORD:',
    SY-INDEX.
    ENDIF.
    Message handling for Call Transaction *
    perform subr_mess_hand using g_mess.
    *-----Erzeugen fehlermappe
    IF L_SUBRC <> 0 AND E_GROUP <> SPACE.
    IF E_GROUP_OPENED = ' '.
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
    CLIENT = SY-MANDT
    GROUP = E_GROUP
    USER = sy-uname
    KEEP = E_KEEP.
    E_GROUP_OPENED = 'X'.
    ENDIF.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
    TCODE = TCODE
    TABLES
    DYNPROTAB = it_BDCDATA.
    ENDIF.
    REFRESH it_BDCDATA.
    ENDFORM. "BDC_TRANSACTION
    Form subr_bdc_table *
    text
    -->P_0220 text *
    -->P_0221 text *
    -->P_0222 text *
    FORM subr_bdc_table USING VALUE(P_0220) TYPE ANY
    VALUE(P_0221) TYPE ANY
    VALUE(P_0222) TYPE ANY.
    CLEAR it_bdcdata.
    IF P_0220 = ' '.
    CLEAR it_bdcdata.
    it_bdcdata-fnam = P_0221.
    it_bdcdata-fval = P_0222.
    APPEND it_bdcdata.
    ELSE.
    it_bdcdata-dynbegin = P_0220.
    it_bdcdata-program = P_0221.
    it_bdcdata-dynpro = P_0222.
    APPEND it_bdcdata.
    ENDIF.
    ENDFORM. " subr_bdc_table
    Form subr_mess_hand *
    text *
    -->P_G_MESS text *
    FORM subr_mess_hand USING P_G_MESS TYPE ANY.
    LOOP AT IT_MESSTAB.
    CALL FUNCTION 'FORMAT_MESSAGE'
    EXPORTING
    ID = it_messtab-msgid
    LANG = it_messtab-msgspra
    NO = it_messtab-msgnr
    v1 = it_messtab-msgv1
    v2 = it_messtab-msgv2
    IMPORTING
    MSG = P_G_MESS
    EXCEPTIONS
    OTHERS = 0.
    CASE it_messtab-msgtyp.
    when 'E'.
    it_error-error_rec = P_G_MESS.
    it_error-lifnr = it_me21-lifnr.
    it_error-tabix = v_count.
    APPEND IT_ERROR.
    when 'S'.
    it_sucess-sucess_rec = P_G_MESS.
    it_sucess-lifnr = it_me21-lifnr.
    it_sucess-tabix = v_count.
    APPEND IT_SUCESS.
    endcase.
    ENDLOOP.
    Describe table it_sucess lines v_ns.
    Describe table it_error lines v_ne.
    ENDFORM. " subr_mess_hand
    Regards
    Anji

Maybe you are looking for