Skip to Content

BDC

Hi All,

Please provide me the details about uploading Header & Items while working with BDC.How can we make the Header & item uploads.

How the flatfile looks like??

Regards,

Sudhir

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2008 at 06:22 AM

    Hi

    The flat file will look in sequential manner.

    For example.. first the header fields then the line item fields, for every line item the header fields are also given..

    When u write the bdc loop, you pick up the line items based on header key field.

    For example

    header: item:

    vendor docdate plant material.

    The first two fields are header and the next two are line items.

    Regards,

    Vishwa.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2008 at 07:49 AM

    Hi sudhir,

    I agree with the first answer wise prepare your EXCEL or txt file such tht your header data will in one line and followed by next item details but take care that the unique number for header and item are same so that when u are looping the item details there wont be any errors.

    Hopes this helps you....still not clear revert me back.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2008 at 09:27 AM

    Hi,

    ****flat file for creation of table in se11****

    H,X,Tablename,Recorded Table,A,X

    I,mandt,X,clnt,3,Client

    I,ENO,X,char,6,Employee Number

    I,ENAME, ,Char,20,Employee Name

    I,deptno, ,char,10,Department Number

    I,salary, ,int4, ,Salary

    H,X,Tablename,Recorded Table,A,X

    I,mandt,X,clnt,3,Client

    I,ENO,X,char,6,Employee Number

    I,ENAME, ,Char,20,Employee Name

    I,deptno, ,char,10,Department Number

    I,salary, ,int4, ,Salary

    check this bdc recording code....

    *"Selection screen elements............................................
    
    PARAMETERS:
      p_file LIKE rlgrap-filename.
    
    *" Data declarations...................................................
    *"--------------------------------------------------------------------*
    * Work variables                                                      *
    *"--------------------------------------------------------------------*
    DATA w_file TYPE string.
    DATA wa(80) TYPE c.
    DATA : w_fname(20),
        w_tabix(2) TYPE n,
        w_table(20),
        w_index,
        w_fkey(20),
        w_ftype(20),
        w_flen(20),
        w_fdesc(20).
    
    *" Internal table declarations.........................................
    
    *"--------------------------------------------------------------------*
    * Internal table to hold 		                                    *
    *"--------------------------------------------------------------------*
    DATA:
      BEGIN OF itab_fields OCCURS 0,
        count,
        fname(20),
        fkey,
        ftype(10),
        flen(10),
        fdesc(30),
      END OF itab_fields.
    
    DATA:
      BEGIN OF itab_header OCCURS 0,
        dbcheck,
        tname(20),
        tdesc(40),
        devclass,
        maintain,
      END OF itab_header.
    
    DATA t_data LIKE STANDARD TABLE OF wa .
    DATA:
      t_bdcdata LIKE
       STANDARD TABLE OF bdcdata WITH HEADER LINE.
    DATA w_count TYPE i.
    *"--------------------------------------------------------------------*
    *       AT SELECTION-SCREEN ON VALUE-REQUEST EVENT                    *
    *"--------------------------------------------------------------------*
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    
      CALL FUNCTION 'F4_FILENAME'
    * EXPORTING
    *   PROGRAM_NAME        = SYST-CPROG
    *   DYNPRO_NUMBER       = SYST-DYNNR
    *   FIELD_NAME          = ' '
       IMPORTING
         file_name           = p_file
                .
    
      w_file = p_file.
    
    *"--------------------------------------------------------------------*
    *                       START-OF-SELECTION EVENT                      *
    *"--------------------------------------------------------------------*
    
    START-OF-SELECTION.
    
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                      = w_file
         filetype                      = 'ASC'
    *   HAS_FIELD_SEPARATOR           = 'X'
    *   HEADER_LENGTH                 = 0
    *   READ_BY_LINE                  = 'X'
    *   DAT_MODE                      = ' '
    *   CODEPAGE                      = ' '
    *   IGNORE_CERR                   = ABAP_TRUE
    *   REPLACEMENT                   = '#'
    * IMPORTING
    *   FILELENGTH                    =
    *   HEADER                        =
        TABLES
          data_tab                      = t_data
       EXCEPTIONS
         file_open_error               = 1
         file_read_error               = 2
         no_batch                      = 3
         gui_refuse_filetransfer       = 4
         invalid_type                  = 5
         no_authority                  = 6
         unknown_error                 = 7
         bad_data_format               = 8
         header_not_allowed            = 9
         separator_not_allowed         = 10
         header_too_long               = 11
         unknown_dp_error              = 12
         access_denied                 = 13
         dp_out_of_memory              = 14
         disk_full                     = 15
         dp_timeout                    = 16
         OTHERS                        = 17
                .
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
      LOOP AT t_data INTO wa.
        IF wa+0(1) EQ 'H'.
          SHIFT wa BY 2 PLACES LEFT.
          SPLIT wa AT ',' INTO itab_header-dbcheck
          itab_header-tname
          itab_header-tdesc
          itab_header-devclass
          itab_header-maintain.
          APPEND itab_header.
          CLEAR itab_header.
          ADD 1 TO w_count.
        ELSE.
          SHIFT wa BY 2 PLACES LEFT.
          SPLIT wa AT ',' INTO itab_fields-fname
          itab_fields-fkey
          itab_fields-ftype
          itab_fields-flen
          itab_fields-fdesc.
          WRITE w_count TO itab_fields-count.
          APPEND itab_fields.
          CLEAR itab_fields.
        ENDIF.
      ENDLOOP.
      CALL FUNCTION 'BDC_OPEN_GROUP'
       EXPORTING
         client                    = sy-mandt
    *   DEST                      = FILLER8
         group                     = 'PADMA'
    *   HOLDDATE                  = FILLER8
    *   KEEP                      = FILLER1
         user                      = sy-uname
    *   RECORD                    = FILLER1
    *   PROG                      = SY-CPROG
    * IMPORTING
    *   QID                       =
       EXCEPTIONS
         client_invalid            = 1
         destination_invalid       = 2
         group_invalid             = 3
         group_is_locked           = 4
         holddate_invalid          = 5
         internal_error            = 6
         queue_error               = 7
         running                   = 8
         system_lock_error         = 9
         user_invalid              = 10
         OTHERS                    = 11
                .
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      LOOP AT itab_header.
        w_table = itab_header-tname.
        w_index = sy-tabix.
        REFRESH t_bdcdata.
        PERFORM populate_se11.
    
        CALL FUNCTION 'BDC_INSERT'
         EXPORTING
           tcode                  = 'SE11'
    *    POST_LOCAL             = NOVBLOCAL
    *    PRINTING               = NOPRINT
    *    SIMUBATCH              = ' '
    *    CTUPARAMS              = ' '
          TABLES
            dynprotab              = t_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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    
        REFRESH t_bdcdata.
    
        PERFORM populate_se13.
        CALL FUNCTION 'BDC_INSERT'
         EXPORTING
           tcode                  = 'SE13'
    *    POST_LOCAL             = NOVBLOCAL
    *    PRINTING               = NOPRINT
    *    SIMUBATCH              = ' '
    *    CTUPARAMS              = ' '
          TABLES
            dynprotab              = t_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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    
        REFRESH t_bdcdata.
    
        PERFORM activate.
    
        CALL FUNCTION 'BDC_INSERT'
         EXPORTING
           tcode                  = 'SE11'
    *    POST_LOCAL             = NOVBLOCAL
    *    PRINTING               = NOPRINT
    *    SIMUBATCH              = ' '
    *    CTUPARAMS              = ' '
          TABLES
            dynprotab              = t_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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    
      ENDLOOP.
    
      CALL FUNCTION 'BDC_CLOSE_GROUP'
        EXCEPTIONS
          not_open    = 1
          queue_error = 2
          OTHERS      = 3.
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    *&---------------------------------------------------------------------*
    *&      Form  POPULATE_SE11
    *&---------------------------------------------------------------------*
    *    This subroutine is used to populate SE11 transaction data         *
    *----------------------------------------------------------------------*
    *     No interface parameters                                          *
    *----------------------------------------------------------------------*
    FORM populate_se11 .
    
      PERFORM bdc_dynpro      USING 'SAPMSRD0' '0102'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'RSRD1-TBMA_VAL'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=ADD'.
      PERFORM bdc_field       USING 'RSRD1-TBMA'
                                    itab_header-dbcheck.
      PERFORM bdc_field       USING 'RSRD1-TBMA_VAL'
                                    itab_header-tname.
      PERFORM bdc_dynpro      USING 'SAPLSD41' '2200'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=CHANGE_MAINTFLAG'.
      PERFORM bdc_field       USING 'DD02D-DDTEXT'
                                    itab_header-tdesc.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'DD02D-MAINFLAG'.
      PERFORM bdc_field       USING 'DD02D-CONTFLAG'
                                    itab_header-devclass.
      PERFORM bdc_field       USING 'DD02D-MAINFLAG'
                                    itab_header-maintain.
      PERFORM bdc_dynpro      USING 'SAPLSD41' '2200'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=DEF'.
      PERFORM bdc_field       USING 'DD02D-CONTFLAG'
                                    'A'.
      PERFORM bdc_field       USING 'DD02D-MAINFLAG'
                                    'X'.
      PERFORM bdc_dynpro      USING 'SAPLSD41' '2200'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=FTYP'.
      w_tabix = 0.
      LOOP AT itab_fields WHERE count EQ w_index.
        ADD 1 TO w_tabix.
    
        IF w_tabix gt 13.
    
          PERFORM bdc_dynpro      USING 'SAPLSD41' '2200'.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                       w_fname.
    
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=P+'.
          w_tabix = 2.
        ENDIF.
        CONCATENATE 'DD03P-FIELDNAME(' w_tabix ')' INTO w_fname.
        CONCATENATE 'DD03P-KEYFLAG(' w_tabix ')' INTO w_fkey.
        CONCATENATE 'DD03D-DATATYPE(' w_tabix ')' INTO w_ftype.
        CONCATENATE 'DD03P-LENG(' w_tabix ')' INTO w_flen.
        CONCATENATE 'DD03P-DDTEXT(' w_tabix ')' INTO w_fdesc.
    
        PERFORM bdc_dynpro      USING 'SAPLSD41' '2200'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '/00'.
        PERFORM bdc_field       USING w_fname
                                      itab_fields-fname.
        PERFORM bdc_field       USING w_fkey
                                      itab_fields-fkey.
        PERFORM bdc_field       USING w_ftype
                                      itab_fields-ftype.
        PERFORM bdc_field       USING w_flen
                                        itab_fields-flen.
        PERFORM bdc_field       USING w_fdesc
                                      itab_fields-fdesc.
    
    
      ENDLOOP.
    
      PERFORM bdc_dynpro      USING 'SAPLSD41' '2200'.
    
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=WB_SAVE'.
    
      PERFORM bdc_dynpro      USING 'SAPLSTRD' '0100'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=ADD'.
      PERFORM bdc_field       USING 'KO007-L_DEVCLASS'
                                    'YH1139'.
      PERFORM bdc_field       USING 'KO007-L_AUTHOR'
                                    'SAPDEV02'.
      PERFORM bdc_dynpro      USING 'SAPLSTRD' '0300'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=LOCK'.
      PERFORM bdc_field       USING 'KO008-TRKORR'
                                    'TR1K900085'.
    
      PERFORM bdc_dynpro      USING 'SAPLSD41' '2200'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'DD03P-DDTEXT(03)'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=BACK'.
      PERFORM bdc_dynpro      USING 'SAPMSRD0' '0102'.
      PERFORM bdc_field       USING 'BDC_CURSOR'
                                    'RSRD1-TBMA_VAL'.
    
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=BACK'.
    
    
      .
    ENDFORM.                    " POPULATE_SE11
    *&---------------------------------------------------------------------*
    *&      Form  POPULATE_SE13
    *&---------------------------------------------------------------------*
    *    This subroutine is used to populate SE13 data                     *
    *----------------------------------------------------------------------*
    *     No interface parameters                                          *
    *----------------------------------------------------------------------*
    FORM populate_se13 .
    
      PERFORM bdc_dynpro      USING 'SAPMSEDS' '0010'.
      PERFORM bdc_field       USING 'DD09V-TABNAME'
                                    w_table.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    'PFLG'.
      PERFORM bdc_dynpro      USING 'SAPMSEDS' '0050'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=SICH'.
      PERFORM bdc_field       USING 'DD09V-TABART'
                                    'APPL0'.
      PERFORM bdc_field       USING 'DD09V-TABKAT'
                                    '0'.
      PERFORM bdc_field       USING 'ALLOWSTATE-NOT_ALLOWED'
                                    'X'.
      PERFORM bdc_dynpro      USING 'SAPMSEDS' '0050'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=BACK'.
      PERFORM bdc_field       USING 'DD09V-TABART'
                                    'APPL0'.
      PERFORM bdc_field       USING 'DD09V-TABKAT'
                                    '0'.
      PERFORM bdc_field       USING 'ALLOWSTATE-NOT_ALLOWED'
                                    'X'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                   '=WB_BACK'.
      PERFORM bdc_dynpro      USING 'SAPMSEDS' '0050'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=BACK'.
    
      PERFORM bdc_dynpro      USING 'SAPMSEDS' '0010'.
    
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=BACK'.
    
    ENDFORM.                    " POPULATE_SE13
    *&---------------------------------------------------------------------*
    *&      Form  ACTIVATE
    *&---------------------------------------------------------------------*
    *     This subroutine is used to activate the table from SE11          *
    *----------------------------------------------------------------------*
    *     No interface parameters.                                         *
    *----------------------------------------------------------------------*
    FORM activate .
    
      PERFORM bdc_dynpro      USING 'SAPMSRD0' '0102'.
      PERFORM bdc_field       USING 'RSRD1-TBMA'
                                    'X'.
      PERFORM bdc_field       USING 'RSRD1-TBMA_VAL'
                                    w_table.
    
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    'ACT'.
      PERFORM bdc_dynpro      USING 'SAPLSEWORKINGAREA' '0205'.
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=WEIT'.
    
      PERFORM bdc_dynpro      USING 'SAPMSRD0' '0102'.
    
      PERFORM bdc_field       USING 'BDC_OKCODE'
                                    '=BACK'.
    
    
    ENDFORM.                    " ACTIVATE
    *&---------------------------------------------------------------------*
    *&      Form  bdc_dynpro
    *&---------------------------------------------------------------------*
    *    This subroutine is used to populate the screen information        *
    *----------------------------------------------------------------------*
    *      -->prgname   Program name
    *      -->screenno  Screen number
    *----------------------------------------------------------------------*
    FORM bdc_dynpro  USING    value(prgname)
                              value(screenno).
    
      CLEAR t_bdcdata.
      t_bdcdata-program = prgname.
      t_bdcdata-dynpro = screenno.
      t_bdcdata-dynbegin = 'X'.
      APPEND t_bdcdata.
    
    ENDFORM.                    " bdc_dynpro
    *&---------------------------------------------------------------------*
    *&      Form  bdc_field
    *&---------------------------------------------------------------------*
    *     This subroutine is used to populate the field values             *
    *----------------------------------------------------------------------*
    *      -->fnam   Field name                                            *
    *      -->fval   Field value                                           *
    *----------------------------------------------------------------------*
    FORM bdc_field  USING    value(fnam)
                             value(fval).
      CLEAR t_bdcdata.
    
      t_bdcdata-fnam = fnam.
      t_bdcdata-fval = fval.
      APPEND t_bdcdata.
    
    ENDFORM.                    " bdc_field

    regards

    padma

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 19, 2008 at 09:46 AM

    HI,

    Separate the header and item data into 2 files and have index mapped with header and item data. this will solve your problem.

    Regards

    Santosh.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

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

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