Flat files in BDC

hi......to everybody.....
i am working on session method with two application(transaction)s.
i have the data in two flat files separate related to those applications in presentation server.
how to update the data into the data base?
Message was edited by:
        Alvaro Tejada Galindo

HI,
there is no difference as far as the code is concerned for the BDC.. only change is u use bdc_open_group,bdc_insert and bdc_close_group function modules instead of call transaction..
See the example
REPORT Z_PCA_PL
                     MESSAGE-ID ZYFI
                     NO STANDARD PAGE HEADING
                     LINE-SIZE  100.
Progname    : ZF_BDCP_PCPLANE_01                                     *
Request no  : RTDK905785
Description : Profit center plan data upload for KIMO dates
LOGICAL DB  :            VERSION OF :                                *
AUTHOR      : Krishna M
DATE        : 28/04/2004
MODIFICATION LOG (latest change first):                              *
  TABLES
*-- Imternal table declaration.
DATA : BEGIN OF IT_UPLOAD OCCURS 0,
       YEAR(4),                        " Year Variable
       PROFIT(10),                     " Profit Center Variable
       GLACCOUNT(13),                  " GL account Variable
       AMOUNT(10),                     " Amount Variable
       END OF IT_UPLOAD.
*-- Declaration of bdc data.
DATA: IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
*-Internal table for message control
*data : msgtab like bdcmsgcoll occurs 0 with header line.
*--Selection screen declaration
SELECTION-SCREEN  BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
          PARAMETERS:  P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
         A T  S E L E C T I O N - S C R E E N .
*--Value request for the file.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  PERFORM VALUE_REQUEST.
               S T A R T - O F - S E L E C T I O N
START-OF-SELECTION.
*-- Upload data into internal table it_upload.
  PERFORM UPLOAD.
  PERFORM PROFIT_CENTER.
  PERFORM BDC_OPEN_GROUP.
  PERFORM CALL_TRANSACTION.
*-- Close the bdc group
    PERFORM BDC_CLOSE_GROUP.
*&      Form  upload
Uploading of the flat file into the internal table
FORM UPLOAD.
  CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            FILENAME            = P_FILE
            FILETYPE            = 'DAT'
       TABLES
            DATA_TAB            = IT_UPLOAD
       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 .
    MESSAGE E999 WITH TEXT-002.      "File cannot be Uploaded
  ENDIF.
ENDFORM.                    " upload
*&      Form  value_request
      IN PUT HEPL REQUEST
FORM VALUE_REQUEST.
  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            DEF_FILENAME     = ' '
            DEF_PATH         = 'C:\'
            MASK             = ',.txt,.*.'
            MODE             = 'S'
            TITLE            = TEXT-003  "'Upload'
       IMPORTING
            FILENAME         = P_FILE
       EXCEPTIONS
            INV_WINSYS       = 1
            NO_BATCH         = 2
            SELECTION_CANCEL = 3
            SELECTION_ERROR  = 4
            OTHERS           = 5.
  CASE SY-SUBRC.
    WHEN 3.
      MESSAGE I999 WITH TEXT-004.        "Selection Cancel
    WHEN 4.
      MESSAGE I999 WITH TEXT-005.        "Selection Error'.
  ENDCASE.
ENDFORM.                    " value_request
        form call_transaction.
FORM CALL_TRANSACTION.
  IF NOT IT_UPLOAD[] IS INITIAL.
    LOOP AT IT_UPLOAD.   " loop at it_upload
      PERFORM FILL_BDC.
    ENDLOOP.
  ELSE.
    MESSAGE E999 WITH TEXT-010. " 'No records found'.
  ENDIF.
ENDFORM.
*&      Form  fill_bdc
     This form is used to fill the bdcdata & call the transaction    *
FORM FILL_BDC.
      PERFORM PROFIT_CENTER_UPLOAD.
ENDFORM.
*&      Form  Profit_Center_Upload.
FORM PROFIT_CENTER_UPLOAD.
   PERFORM FILL_BDCDATA USING:
    'SAPLKPP0'               '1000'                           'X',
    'bdc_cursor'             'kpp0b-value(03)'                ' ',
    'kpp0b-value(03)'        IT_UPLOAD-YEAR                   ' ',
    'bdc_cursor'             'kpp0b-value(06)'                ' ',
    'kpp0b-value(06)'        IT_UPLOAD-PROFIT                 ' ',
    'bdc_cursor'             'kpp0b-value(09)'                ' ',
    'kpp0b-value(09)'        IT_UPLOAD-GLACCOUNT              ' ',
    'bdc_okcode'              '/00'                           ' ',
    'BDC_OKCODE'              '=CSUB'                         ' ',
    'SAPLKPP2'               '0103'                           'X',
    'bdc_cursor'             'BDC03(01)'                      ' ',
    'BDC03(01)'              IT_UPLOAD-AMOUNT                 ' ',
    'BDC_OKCODE'              '/00'                           ' ',
    'BDC_OKCODE'              '=CBUC'                         ' '.
PERFORM BDC_INSERT.
ENDFORM.
*&      Form  fill_bdcdata
This form is used to fill the IT_BDCDATA table                      *
FORM FILL_BDCDATA USING PROGRAM  TYPE C
                          DYNPRO   TYPE ANY
                          DYNBEGIN TYPE C.
  IF DYNBEGIN = 'X'.
    IT_BDCDATA-PROGRAM  = PROGRAM.
    IT_BDCDATA-DYNPRO   = DYNPRO.
    IT_BDCDATA-DYNBEGIN = DYNBEGIN.
  ELSE.
    IT_BDCDATA-FNAM     = PROGRAM.
    IT_BDCDATA-FVAL     = DYNPRO.
  ENDIF.
  APPEND IT_BDCDATA.
  CLEAR  IT_BDCDATA.
ENDFORM.                  " fill_bdcdata
form profit_center
FORM PROFIT_CENTER.
  PERFORM FILL_BDCDATA USING:
    'SAPLSPO4'               '0300'                           'X',
    'SVALD-VALUE(01)'        '0100'                           ' ',
    'BDC_OKCODE'             '=FURT'                          ' ',
    'SAPLKPP6'               '1007'                           'X',
    'RKPP6-PLPROF'           'RTA-PC-K'                       ' ',
    'BDC_OKCODE'             '=CWEI'                          ' '.
ENDFORM.
      form bdc_open_group.
FORM BDC_OPEN_GROUP.
  CALL FUNCTION 'BDC_OPEN_GROUP'
       EXPORTING
            CLIENT = SY-MANDT
            GROUP  = '7KE1'
            KEEP   = 'X'
            USER   = SY-UNAME.
  IF SY-SUBRC NE 0.                    "Error in Opening error session
    MESSAGE E999 WITH TEXT-007.        "'Unable to open BDC Group'.
  ELSE.
    MESSAGE S999 WITH TEXT-008.       "Session created successfully"
  ENDIF.
ENDFORM.
       form bdc_insert
FORM BDC_INSERT.
CALL FUNCTION 'BDC_INSERT'
    EXPORTING
         TCODE            = '7KE1'
     TABLES
          DYNPROTAB        = IT_BDCDATA[]
     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 E999 WITH TEXT-006.
    'Unable to Insert using Transaction 7KE1'.
  ENDIF.
  REFRESH IT_BDCDATA.
  CLEAR   IT_BDCDATA.
ENDFORM.
*&      Form  BDC_CLOSE_GROUP
   This form is used to close the group that is opend.
FORM BDC_CLOSE_GROUP.
  CALL FUNCTION 'BDC_CLOSE_GROUP'
       EXCEPTIONS
            NOT_OPEN    = 1
            QUEUE_ERROR = 2
            OTHERS      = 3.
ENDFORM.                    " BDC_CLOSE_GROUP
Thanks
Mahesh

Similar Messages

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

  • How to capture errors records in flat file in BDC

    hi ,
        i would like to know how to capture error records while  uploading a flat file to screen through BDC .
    appreciatable solutions are rewarded.
    thanks,
    shan

    Hi shan,
    write this code, it will solve your problem.
    DATA : BDCTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
    DATA : I_MSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
    DATA : BEGIN OF I_ERR OCCURS 0,
              MATNR(18),
              FLAG(1),
              MSG(100),
           END OF I_ERR.
    DATA :V_LINES TYPE I.
    LOOP AT ITAB.
    REFRESH BDCTAB.
    PERFORM SCREEN USING: 'SAPLMGMM' '0060'.
    PERFORM FIELD USING: 'RMMG1-MATNR'  ITAB-MATNR,
                          'RMMG1-MBRSH' ITAB-MBRSH ,
                          'RMMG1-MTART' ITAB-MTART,
                          'BDC_OKCODE' '/00'.
    PERFORM SCREEN USING: 'SAPLMGMM' '0070'.
    PERFORM FIELD USING: 'MSICHTAUSW-KZSEL(01)' 'X' ,
                         'MSICHTAUSW-KZSEL(02)' 'X' ,
                         'MSICHTAUSW-KZSEL(09)' 'X' ,
                         'BDC_OKCODE' '=ENTR'.
    PERFORM SCREEN USING: 'SAPLMGMM' '0080'.
    PERFORM FIELD USING: 'RMMG1-WERKS' ITAB-WERKS,
                         'BDC_OKCODE' '=ENTR'.
    PERFORM SCREEN USING: 'SAPLMGMM' '4004'.
    PERFORM FIELD USING:  'MAKT-MAKTX' ITAB-MAKTX,
                          'MARA-MEINS' 'EA' ,
                          'MARA-MATKL' '001',
                          'BDC_OKCODE' '/00'.
    PERFORM SCREEN USING: 'SAPLMGMM' '4004'.
    PERFORM FIELD USING:  'BDC_OKCODE' '/00'.
    PERFORM SCREEN USING: 'SAPLMGMM' '4000'.
    PERFORM FIELD USING:  'MAKT-MAKTX' ITAB-MAKTX,
                          'MARA-MEINS' 'EA',
                          'MARC-EKGRP' '001',
                          'MARA-MATKL' '001',
                          'BDC_OKCODE' '=BU'.
    CALL TRANSACTION 'MM01' USING BDCTAB
                            MODE 'A'
                            MESSAGES INTO I_MSG.
    FINDING LAST MESSAGE IN THE I_MSG TABLE*****
    DESCRIBE TABLE I_MSG LINES V_LINES.
    ACCORDING TO THE V_LINES NUMBER TABLE WILL BE READ****
    READ TABLE I_MSG INDEX V_LINES.
    CALL FUNCTION 'FORMAT_MESSAGE'
    EXPORTING
       ID              = I_MSG-MSGID
       LANG            = '-D'
       NO              = I_MSG-MSGNR
       V1              = I_MSG-MSGV1
       V2              = I_MSG-MSGV2
       V3              = I_MSG-MSGV3
       V4              = I_MSG-MSGV4
    IMPORTING
       MSG             = I_ERR-MSG
    EXCEPTIONS
       NOT_FOUND       = 1
       OTHERS          = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    IF I_MSG-MSGID EQ 'M3' AND I_MSG-MSGNR EQ '800'.
    I_ERR-FLAG = 'S'.
    ELSE.
    I_ERR-FLAG = 'E'.
    ENDIF.
    I_ERR-MATNR = ITAB-MATNR.
    APPEND I_ERR.
    CLEAR I_ERR.
    ENDLOOP.
    WRITE:/ 'SUCCESS RECORDS' COLOR COL_POSITIVE.
    SKIP.
    WRITE:/ 'MATERIAL' COLOR COL_HEADING, 20 'MESSAGE' COLOR COL_HEADING.
    LOOP AT I_ERR WHERE FLAG EQ 'S'.
    WRITE:/ I_ERR-MATNR, 20 I_ERR-MSG.
    ENDLOOP.
    SKIP 2.
    WRITE:/ 'ERROR RECORDS' COLOR COL_NEGATIVE.
    SKIP.
    WRITE:/ 'MATERIAL' COLOR COL_HEADING, 20 'MESSAGE' COLOR COL_HEADING.
    LOOP AT I_ERR WHERE FLAG EQ 'E'.
    WRITE:/ I_ERR-MATNR, 20 I_ERR-MSG.
    ENDLOOP.
    *&      Form  SCREEN
         SCREEN
    form SCREEN  using P_PROG P_SCREEN.
    BDCTAB-PROGRAM = P_PROG.
    BDCTAB-DYNPRO = P_SCREEN.
    BDCTAB-DYNBEGIN = 'X'.
    APPEND BDCTAB.
    CLEAR  BDCTAB.
    endform.                    " SCREEN
    *&      Form  FIELD
       FIELD
    form FIELD  using  FNAME FVAL .
    BDCTAB-FNAM = FNAME.
    BDCTAB-FVAL = FVAL.
    APPEND BDCTAB.
    CLEAR BDCTAB.
    endform.                    " FIELD
    Thanks,
    Murali

  • 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

  • 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

Maybe you are looking for

  • Select words at one in Pages 5.2.2

    Hi ! I can't select words from different paragraphs at one in Pages 5.2.2 I usually did it on the other version of Pages. Can somebody help me ? Thank you

  • My original computer's hard drive crashed!!!

    I had a very large (1,800 song) library on my old computer, which had iTunes version 6, and was synched with my iPod. I purchased a new computer, transfered the PURCHASED (53) SONGS FROM MY IPOD TO THE NEW COMPUTER BY AUTHORIZING IT AS THE 2ND OF 5.

  • Current Dir path

    I want to be able to load Images into my Swing app from a standard directory. Is there such a thing as relative paths in Java ImageIcon class? Basically I don't want to hard code the path names. For obvious reasons. What is the starting path?

  • Cannot not click on menu that appears when i right click my taskbar, as the right click menu dissapears when i move mouse over to the right click menu

    PROBLEM: RIGHT CLICK CONTEXT MENU DISAPPEARS WHEN TRYING TO LEFT CLICK AN OPTION Hi, Im using Windows 7, and i could always go down to my TaskBar and Right Click Icons, and active icons, which would bring up the standard Right Click Menu list. PROBLE

  • AirPlay:  Audio is choppy but video is fine

    Whether trying to stream via Mac mini, iPod or iPad to my Apple TV 2 the video has no problems at all but the audio is impossibly choppy.  This is the case whether using Netflix, streaming ALAC from iTunes or streaming 192kbps mp3s from iOS devices.