Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

bdc upload excel file.

Former Member
0 Likes
4,476

hi ,

i having problem when i trying to upload excel file data to sap .

it execute correct  but not go inside loop .

i dont understand where is the actual problem.

if any understand tell me below is my code.

report ZSD_XD02_ALL
        no standard page heading line-size 255.

*----------------------------------------------------------------------*
*   data definition
*----------------------------------------------------------------------*
*       Batchinputdata of single transaction
DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.
*       messages of call transaction
DATA:   MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
*       error session opened (' ' or 'X')
DATA:   E_GROUP_OPENED.
*       message texts
TABLES: T100.


DATA: cnt TYPE i VALUE 0,
       cnt1 type i VALUE 0.

types: begin of ty_rec,
        kunnr type KUNNR,
         name1 type NAME1,
         abtnr type ABTNR,
         name2 type NAME1,
         sortl type SORTL,
         spras type SPRAS,
         stras type STRAS,
         ORT01 type ORT01,
         ORT02 type ORT02,
         pstlz type PSTLZ,
         land1 type LAND1,
         regio type REGIO,
         tzone type TZONE,
         telf1 type TELF1,
         telfx type TELFX,

         name3 type NAME1,
         abtnr1 type ABTNR,
         name4 type NAME1,
         sortl1 type SORTL,
         spras1 type SPRAS,
         stras1 type STRAS,
         ORT011 type ORT01,
         ORT021 type ORT02,
         pstlz1 type PSTLZ,
         land11 type LAND1,
         regio1 type REGIO,
         tzone1 type TZONE,
         telf11 type TELF1,
         telfx1 type TELFX,

         name5 type NAME1,
        PAFKT type PAFKT,
        gbdat type GBDAT,
         name6 type NAME1,
*        sortl2 type SORTL,
         spras2 type SPRAS,
         stras2 type STRAS,
         ORT012 type ORT01,
         ORT022 type ORT02,
         pstlz2 type PSTLZ,
         land12 type LAND1,
         regio2 type REGIO,
         tzone2 type TZONE,
         telf12 type TELF1,
         telfx2 type TELFX,

END OF ty_rec.

PARAMETERS p_FILE TYPE IBIPPARMS-PATH OBLIGATORY.

  DATA: lt_mat type TABLE OF TY_REC,
          wa_mat type TY_REC.

at SELECTION-SCREEN on VALUE-REQUEST FOR p_file.
   CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      PROGRAM_NAME        = SYST-CPROG
      DYNPRO_NUMBER       = SYST-DYNNR
    IMPORTING
      FILE_NAME           = P_FILE
             .
TYPES:
     ty_record1(4096) TYPE c OCCURS 0 .

         DATA:w_struct TYPE ty_record1.

         CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
           EXPORTING
            I_FIELD_SEPERATOR          = 'X'
            I_LINE_HEADER              = 'X'
             I_TAB_RAW_DATA             = W_STRUCT
             I_FILENAME                 = p_file
           TABLES
             I_TAB_CONVERTED_DATA       = LT_MAT
          EXCEPTIONS
            CONVERSION_FAILED          = 1
            OTHERS                     = 2
                   .
         IF SY-SUBRC <> 0.
* Implement suitable error handling here
         ENDIF.
*        break hasmukh.


start-of-selection.

*BREAK hasmukh.
loop at lt_mat into wa_mat.

   write:/ wa_mat-kunnr.

perform bdc_dynpro      using 'SAPMF02D' '0101'.
perform bdc_field       using 'BDC_CURSOR'
                               'RF02D-D0360'.
perform bdc_field       using 'BDC_OKCODE'
                               '/00'.
perform bdc_field       using 'RF02D-KUNNR'
                             wa_mat-kunnr.
perform bdc_field       using 'RF02D-D0360'
                               'X'.
perform bdc_dynpro      using 'SAPMF02D' '0360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-NAME1(01)'.
perform bdc_field       using 'BDC_OKCODE'
                               '=LSDP'.
perform bdc_field       using 'KNVK-NAME1(01)'
                               wa_mat-name1.
perform bdc_field       using 'KNVK-ABTNR(01)'
                               wa_mat-abtnr.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=ADRP'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'Work Address'.
*perform bdc_field       using 'KNVK-ABTNR'
*                              'Z001'.
perform bdc_dynpro      using 'SAPLSAD1' '0150'.
perform bdc_field       using 'BDC_CURSOR'
                               'SADR-TELFX'.
perform bdc_field       using 'BDC_OKCODE'
                               '=SAVE'.
perform bdc_field       using 'SADR-NAME1'
                              wa_mat-name2.
perform bdc_field       using 'SADR-SORTL'
                                wa_mat-sortl.
perform bdc_field       using 'SADR-SPRAS'
                            wa_mat-spras.
perform bdc_field       using 'SADR-STRAS'
                               wa_mat-stras.
perform bdc_field       using 'SADR-ORT01'
                                wa_mat-ORT01.
perform bdc_field       using 'SADR-PSTLZ'
                             wa_mat-pstlz.
perform bdc_field       using 'SADR-ORT02'
                                 wa_mat-ORT02.
perform bdc_field       using 'SADR-LAND1'
                                  wa_mat-land1.
perform bdc_field       using 'SADR-REGIO'
                             wa_mat-regio.
perform bdc_field       using 'SADR-TZONE'
                                    wa_mat-tzone.
perform bdc_field       using 'SADR-TELF1'
                             wa_mat-telf1.
perform bdc_field       using 'SADR-TELFX'
                              wa_mat-telfx.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=PF03'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'Work Address'.
*perform bdc_field       using 'KNVK-ABTNR'
*                              'Z001'.
perform bdc_dynpro      using 'SAPMF02D' '0360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-NAME1(02)'.
perform bdc_field       using 'BDC_OKCODE'
                               '=LSDP'.
perform bdc_field       using 'KNVK-NAME1(02)'
                                 wa_mat-name3.
perform bdc_field       using 'KNVK-ABTNR(02)'
                                      wa_mat-abtnr1.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=ADRP'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'Registered Address'.
*perform bdc_field       using 'KNVK-ABTNR'
*                              'Z002'.
perform bdc_dynpro      using 'SAPLSAD1' '0150'.
perform bdc_field       using 'BDC_CURSOR'
                               'SADR-TELFX'.
perform bdc_field       using 'BDC_OKCODE'
                               '=SAVE'.
perform bdc_field       using 'SADR-NAME1'
                            wa_mat-name4.
perform bdc_field       using 'SADR-SORTL'
                              wa_mat-sortl1.
perform bdc_field       using 'SADR-SPRAS'
                              wa_mat-spras1.
perform bdc_field       using 'SADR-STRAS'
                               wa_mat-stras1.
perform bdc_field       using 'SADR-ORT01'
                                  wa_mat-ORT011.
perform bdc_field       using 'SADR-PSTLZ'
                              wa_mat-pstlz1.
perform bdc_field       using 'SADR-ORT02'
                               wa_mat-ORT021.
perform bdc_field       using 'SADR-LAND1'
                                 wa_mat-LAND11.
perform bdc_field       using 'SADR-REGIO'
                                wa_mat-regio1.
perform bdc_field       using 'SADR-TZONE'
                                 wa_mat-tzone1.
perform bdc_field       using 'SADR-TELF1'
                                 wa_mat-telf11.
perform bdc_field       using 'SADR-TELFX'
                                wa_mat-telfx1.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=PF03'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'Registered Address'.
*perform bdc_field       using 'KNVK-ABTNR'
*                              'Z002'.
perform bdc_dynpro      using 'SAPMF02D' '0360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-NAME1(03)'.
perform bdc_field       using 'BDC_OKCODE'
                               '=LSDP'.
perform bdc_field       using 'KNVK-NAME1(03)'
                               wa_mat-name5.
perform bdc_field       using 'KNVK-PAFKT(03)'
                               wa_mat-pafkt.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
*perform bdc_field       using 'BDC_CURSOR'
*                              'KNVK-GBDAT'.
perform bdc_field       using 'BDC_OKCODE'
                               '=ADRP'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'hasu'.
perform bdc_field       using 'KNVK-GBDAT'
                               wa_mat-gbdat.
*perform bdc_field       using 'KNVK-PAFKT'
*                              '02'.
perform bdc_dynpro      using 'SAPLSAD1' '0150'.
perform bdc_field       using 'BDC_CURSOR'
                               'SADR-TELFX'.
perform bdc_field       using 'BDC_OKCODE'
                               '=SAVE'.
perform bdc_field       using 'SADR-NAME1'
                               wa_mat-name6.
**perform bdc_field       using 'SADR-SORTL'
*                              wa_mat-sortl2.
perform bdc_field       using 'SADR-SPRAS'
                               wa_mat-spras2.
perform bdc_field       using 'SADR-STRAS'
                               wa_mat-stras2.
perform bdc_field       using 'SADR-ORT01'
                               wa_mat-ORT012.
perform bdc_field       using 'SADR-PSTLZ'
                               wa_mat-pstlz2.
perform bdc_field       using 'SADR-ORT02'
                               wa_mat-ORT022.
perform bdc_field       using 'SADR-LAND1'
                               wa_mat-land12.
perform bdc_field       using 'SADR-REGIO'
                               wa_mat-regio2.
perform bdc_field       using 'SADR-TZONE'
                               wa_mat-tzone2.
perform bdc_field       using 'SADR-TELF1'
                               wa_mat-telf12.
perform bdc_field       using 'SADR-TELFX'
                               wa_mat-telfx2.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=UPDA'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'hasu'.
*perform bdc_field       using 'KNVK-GBDAT'
*                              '20.03.1990'.
*perform bdc_field       using 'KNVK-PAFKT'
*                              '02'.
perform bdc_transaction using 'XD02'.


ENDLOOP.

WRITE:/'sucess number of transactiocn:-',cnt.
WRITE:/'unsuccess number of transaction:-',cnt1.
*----------------------------------------------------------------------*
*        Start new transaction according to parameters                 *
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
   DATA: L_MSTRING(480).
   DATA: L_SUBRC LIKE SY-SUBRC.
* batch input session
     REFRESH MESSTAB.
     CALL TRANSACTION TCODE USING BDCDATA
                      MODE   'A'
                      UPDATE 'S'
                      MESSAGES INTO MESSTAB.
       WRITE: / 'CALL_TRANSACTION',
                TCODE,
                'returncode:'(I05),
                L_SUBRC,
                'RECORD:',
                SY-INDEX.
       if sy-SUBRC EQ 0 .
          cnt = cnt + 1.
      else.
          cnt1 = cnt1 + 1.
      ENDIF.
       LOOP AT MESSTAB.
         MESSAGE ID     MESSTAB-MSGID
                 TYPE   MESSTAB-MSGTYP
                 NUMBER MESSTAB-MSGNR
                 INTO L_MSTRING
                 WITH MESSTAB-MSGV1
                      MESSTAB-MSGV2
                      MESSTAB-MSGV3
                      MESSTAB-MSGV4.
         WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
       ENDLOOP.
   REFRESH BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
   CLEAR BDCDATA.
   BDCDATA-PROGRAM  = PROGRAM.
   BDCDATA-DYNPRO   = DYNPRO.
   BDCDATA-DYNBEGIN = 'X'.
   APPEND BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
   IF FVAL <> space.
     CLEAR BDCDATA.
     BDCDATA-FNAM = FNAM.
     BDCDATA-FVAL = FVAL.
     APPEND BDCDATA.
   ENDIF.
ENDFORM.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,393

Hi Hasmukh,

* Inorder to Upload Excel file to Sap ..Please follow these below steps..

1.First declare Internal table with the required fields.

DADTA:It_final type MARA. " For Example

2.Then declare type pools and internal table to hold excel data.

TYPE-POOLS : TRUXS.

DATA             :  IT_RAW TYPE TRUXS_T_TEXT_DATA.

3.Call function module to upload data to Raw table and convert it.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

   EXPORTING

*   I_FIELD_SEPERATOR          =

     I_LINE_HEADER              = 'X'

     i_tab_raw_data             = it_raw

     i_filename                 = p_file

   TABLES

     i_tab_converted_data       = it_final

* EXCEPTIONS

*   CONVERSION_FAILED          = 1

*   OTHERS                     = 2

           .

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.


* FInally It_final will hold the Data which you uploaded through Excel..


Regards,


    Rohan

hi ,

i having problem when i trying to upload excel file data to sap .

it execute correct  but not go inside loop .

i dont understand where is the actual problem.

if any understand tell me below is my code.

report ZSD_XD02_ALL
        no standard page heading line-size 255.

*----------------------------------------------------------------------*
*   data definition
*----------------------------------------------------------------------*
*       Batchinputdata of single transaction
DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.
*       messages of call transaction
DATA:   MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
*       error session opened (' ' or 'X')
DATA:   E_GROUP_OPENED.
*       message texts
TABLES: T100.


DATA: cnt TYPE i VALUE 0,
       cnt1 type i VALUE 0.

types: begin of ty_rec,
        kunnr type KUNNR,
         name1 type NAME1,
         abtnr type ABTNR,
         name2 type NAME1,
         sortl type SORTL,
         spras type SPRAS,
         stras type STRAS,
         ORT01 type ORT01,
         ORT02 type ORT02,
         pstlz type PSTLZ,
         land1 type LAND1,
         regio type REGIO,
         tzone type TZONE,
         telf1 type TELF1,
         telfx type TELFX,

         name3 type NAME1,
         abtnr1 type ABTNR,
         name4 type NAME1,
         sortl1 type SORTL,
         spras1 type SPRAS,
         stras1 type STRAS,
         ORT011 type ORT01,
         ORT021 type ORT02,
         pstlz1 type PSTLZ,
         land11 type LAND1,
         regio1 type REGIO,
         tzone1 type TZONE,
         telf11 type TELF1,
         telfx1 type TELFX,

         name5 type NAME1,
        PAFKT type PAFKT,
        gbdat type GBDAT,
         name6 type NAME1,
*        sortl2 type SORTL,
         spras2 type SPRAS,
         stras2 type STRAS,
         ORT012 type ORT01,
         ORT022 type ORT02,
         pstlz2 type PSTLZ,
         land12 type LAND1,
         regio2 type REGIO,
         tzone2 type TZONE,
         telf12 type TELF1,
         telfx2 type TELFX,

END OF ty_rec.

PARAMETERS p_FILE TYPE IBIPPARMS-PATH OBLIGATORY.

  DATA: lt_mat type TABLE OF TY_REC,
          wa_mat type TY_REC.

at SELECTION-SCREEN on VALUE-REQUEST FOR p_file.
   CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      PROGRAM_NAME        = SYST-CPROG
      DYNPRO_NUMBER       = SYST-DYNNR
    IMPORTING
      FILE_NAME           = P_FILE
             .
TYPES:
     ty_record1(4096) TYPE c OCCURS 0 .

         DATA:w_struct TYPE ty_record1.

         CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
           EXPORTING
            I_FIELD_SEPERATOR          = 'X'
            I_LINE_HEADER              = 'X'
             I_TAB_RAW_DATA             = W_STRUCT
             I_FILENAME                 = p_file
           TABLES
             I_TAB_CONVERTED_DATA       = LT_MAT
          EXCEPTIONS
            CONVERSION_FAILED          = 1
            OTHERS                     = 2
                   .
         IF SY-SUBRC <> 0.
* Implement suitable error handling here
         ENDIF.
*        break hasmukh.


start-of-selection.

*BREAK hasmukh.
loop at lt_mat into wa_mat.

   write:/ wa_mat-kunnr.

perform bdc_dynpro      using 'SAPMF02D' '0101'.
perform bdc_field       using 'BDC_CURSOR'
                               'RF02D-D0360'.
perform bdc_field       using 'BDC_OKCODE'
                               '/00'.
perform bdc_field       using 'RF02D-KUNNR'
                             wa_mat-kunnr.
perform bdc_field       using 'RF02D-D0360'
                               'X'.
perform bdc_dynpro      using 'SAPMF02D' '0360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-NAME1(01)'.
perform bdc_field       using 'BDC_OKCODE'
                               '=LSDP'.
perform bdc_field       using 'KNVK-NAME1(01)'
                               wa_mat-name1.
perform bdc_field       using 'KNVK-ABTNR(01)'
                               wa_mat-abtnr.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=ADRP'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'Work Address'.
*perform bdc_field       using 'KNVK-ABTNR'
*                              'Z001'.
perform bdc_dynpro      using 'SAPLSAD1' '0150'.
perform bdc_field       using 'BDC_CURSOR'
                               'SADR-TELFX'.
perform bdc_field       using 'BDC_OKCODE'
                               '=SAVE'.
perform bdc_field       using 'SADR-NAME1'
                              wa_mat-name2.
perform bdc_field       using 'SADR-SORTL'
                                wa_mat-sortl.
perform bdc_field       using 'SADR-SPRAS'
                            wa_mat-spras.
perform bdc_field       using 'SADR-STRAS'
                               wa_mat-stras.
perform bdc_field       using 'SADR-ORT01'
                                wa_mat-ORT01.
perform bdc_field       using 'SADR-PSTLZ'
                             wa_mat-pstlz.
perform bdc_field       using 'SADR-ORT02'
                                 wa_mat-ORT02.
perform bdc_field       using 'SADR-LAND1'
                                  wa_mat-land1.
perform bdc_field       using 'SADR-REGIO'
                             wa_mat-regio.
perform bdc_field       using 'SADR-TZONE'
                                    wa_mat-tzone.
perform bdc_field       using 'SADR-TELF1'
                             wa_mat-telf1.
perform bdc_field       using 'SADR-TELFX'
                              wa_mat-telfx.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=PF03'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'Work Address'.
*perform bdc_field       using 'KNVK-ABTNR'
*                              'Z001'.
perform bdc_dynpro      using 'SAPMF02D' '0360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-NAME1(02)'.
perform bdc_field       using 'BDC_OKCODE'
                               '=LSDP'.
perform bdc_field       using 'KNVK-NAME1(02)'
                                 wa_mat-name3.
perform bdc_field       using 'KNVK-ABTNR(02)'
                                      wa_mat-abtnr1.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=ADRP'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'Registered Address'.
*perform bdc_field       using 'KNVK-ABTNR'
*                              'Z002'.
perform bdc_dynpro      using 'SAPLSAD1' '0150'.
perform bdc_field       using 'BDC_CURSOR'
                               'SADR-TELFX'.
perform bdc_field       using 'BDC_OKCODE'
                               '=SAVE'.
perform bdc_field       using 'SADR-NAME1'
                            wa_mat-name4.
perform bdc_field       using 'SADR-SORTL'
                              wa_mat-sortl1.
perform bdc_field       using 'SADR-SPRAS'
                              wa_mat-spras1.
perform bdc_field       using 'SADR-STRAS'
                               wa_mat-stras1.
perform bdc_field       using 'SADR-ORT01'
                                  wa_mat-ORT011.
perform bdc_field       using 'SADR-PSTLZ'
                              wa_mat-pstlz1.
perform bdc_field       using 'SADR-ORT02'
                               wa_mat-ORT021.
perform bdc_field       using 'SADR-LAND1'
                                 wa_mat-LAND11.
perform bdc_field       using 'SADR-REGIO'
                                wa_mat-regio1.
perform bdc_field       using 'SADR-TZONE'
                                 wa_mat-tzone1.
perform bdc_field       using 'SADR-TELF1'
                                 wa_mat-telf11.
perform bdc_field       using 'SADR-TELFX'
                                wa_mat-telfx1.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=PF03'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'Registered Address'.
*perform bdc_field       using 'KNVK-ABTNR'
*                              'Z002'.
perform bdc_dynpro      using 'SAPMF02D' '0360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-NAME1(03)'.
perform bdc_field       using 'BDC_OKCODE'
                               '=LSDP'.
perform bdc_field       using 'KNVK-NAME1(03)'
                               wa_mat-name5.
perform bdc_field       using 'KNVK-PAFKT(03)'
                               wa_mat-pafkt.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
*perform bdc_field       using 'BDC_CURSOR'
*                              'KNVK-GBDAT'.
perform bdc_field       using 'BDC_OKCODE'
                               '=ADRP'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'hasu'.
perform bdc_field       using 'KNVK-GBDAT'
                               wa_mat-gbdat.
*perform bdc_field       using 'KNVK-PAFKT'
*                              '02'.
perform bdc_dynpro      using 'SAPLSAD1' '0150'.
perform bdc_field       using 'BDC_CURSOR'
                               'SADR-TELFX'.
perform bdc_field       using 'BDC_OKCODE'
                               '=SAVE'.
perform bdc_field       using 'SADR-NAME1'
                               wa_mat-name6.
**perform bdc_field       using 'SADR-SORTL'
*                              wa_mat-sortl2.
perform bdc_field       using 'SADR-SPRAS'
                               wa_mat-spras2.
perform bdc_field       using 'SADR-STRAS'
                               wa_mat-stras2.
perform bdc_field       using 'SADR-ORT01'
                               wa_mat-ORT012.
perform bdc_field       using 'SADR-PSTLZ'
                               wa_mat-pstlz2.
perform bdc_field       using 'SADR-ORT02'
                               wa_mat-ORT022.
perform bdc_field       using 'SADR-LAND1'
                               wa_mat-land12.
perform bdc_field       using 'SADR-REGIO'
                               wa_mat-regio2.
perform bdc_field       using 'SADR-TZONE'
                               wa_mat-tzone2.
perform bdc_field       using 'SADR-TELF1'
                               wa_mat-telf12.
perform bdc_field       using 'SADR-TELFX'
                               wa_mat-telfx2.
perform bdc_dynpro      using 'SAPMF02D' '1360'.
perform bdc_field       using 'BDC_CURSOR'
                               'KNVK-SORTL'.
perform bdc_field       using 'BDC_OKCODE'
                               '=UPDA'.
*perform bdc_field       using 'KNVK-NAME1'
*                              'hasu'.
*perform bdc_field       using 'KNVK-GBDAT'
*                              '20.03.1990'.
*perform bdc_field       using 'KNVK-PAFKT'
*                              '02'.
perform bdc_transaction using 'XD02'.


ENDLOOP.

WRITE:/'sucess number of transactiocn:-',cnt.
WRITE:/'unsuccess number of transaction:-',cnt1.
*----------------------------------------------------------------------*
*        Start new transaction according to parameters                 *
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION USING TCODE.
   DATA: L_MSTRING(480).
   DATA: L_SUBRC LIKE SY-SUBRC.
* batch input session
     REFRESH MESSTAB.
     CALL TRANSACTION TCODE USING BDCDATA
                      MODE   'A'
                      UPDATE 'S'
                      MESSAGES INTO MESSTAB.
       WRITE: / 'CALL_TRANSACTION',
                TCODE,
                'returncode:'(I05),
                L_SUBRC,
                'RECORD:',
                SY-INDEX.
       if sy-SUBRC EQ 0 .
          cnt = cnt + 1.
      else.
          cnt1 = cnt1 + 1.
      ENDIF.
       LOOP AT MESSTAB.
         MESSAGE ID     MESSTAB-MSGID
                 TYPE   MESSTAB-MSGTYP
                 NUMBER MESSTAB-MSGNR
                 INTO L_MSTRING
                 WITH MESSTAB-MSGV1
                      MESSTAB-MSGV2
                      MESSTAB-MSGV3
                      MESSTAB-MSGV4.
         WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
       ENDLOOP.
   REFRESH BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
   CLEAR BDCDATA.
   BDCDATA-PROGRAM  = PROGRAM.
   BDCDATA-DYNPRO   = DYNPRO.
   BDCDATA-DYNBEGIN = 'X'.
   APPEND BDCDATA.
ENDFORM.

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
   IF FVAL <> space.
     CLEAR BDCDATA.
     BDCDATA-FNAM = FNAM.
     BDCDATA-FVAL = FVAL.
     APPEND BDCDATA.
   ENDIF.
ENDFORM.

20 REPLIES 20
Read only

paul_bakker2
Active Contributor
0 Likes
4,393

Hi,

There's no need to post all your BDC code if the problem is in the initial XLS upload!

You say it doesn't enter the main loop - is the table LT_MAT filled?

cheers

Paul

Read only

0 Likes
4,393

sorry paul i dnt get where actaul problem in code .

so i  upload whole code.

if u understand question then answer if u know.

thanks.

Read only

Former Member
0 Likes
4,393

hi,

  did you check the internal table that comes out of xls function module.put breakpoint in CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'.check the value for lt_tab.

Read only

0 Likes
4,393

ya i try break point  in 'TEXT_CONVERT_XLS_TO_SAP' function module but it also skip that module and pass away.

Read only

0 Likes
4,393

hi,

  if you put break point on fmthen,during your file selection for p_file break point will be triggered.

Read only

0 Likes
4,393

ya i it taking file .

but not storing data into the lt_mat.

Read only

0 Likes
4,393

hi,

  so,your not getting values in lt_mat,then there may be problem with your excel sheet,

check the fields in excel sheet,and in internal table structure,there may be some issue.

Read only

0 Likes
4,393

in excel file same number of column which i declare in structure ty_rec.

Read only

0 Likes
4,393

Your text_convert_to_sap call is in the Value request event for p_File so it will only work if you press the F4 or Value-request button.

Rich

Read only

0 Likes
4,393

i pass the file then excute it by f8 after that problem occours ,mr.richard

Read only

0 Likes
4,393

You say you pass the file ?  How do you mean ?  Do you select it using F4 or do you manually enter it ?

If you manually enter it the code to upload the file will not be run.

And less of the emoticons.

Read only

0 Likes
4,393

hi mr.rechard i pass the file by presing f4 only.

cool man.

Read only

Former Member
0 Likes
4,394

Hi Hasmukh,

* Inorder to Upload Excel file to Sap ..Please follow these below steps..

1.First declare Internal table with the required fields.

DADTA:It_final type MARA. " For Example

2.Then declare type pools and internal table to hold excel data.

TYPE-POOLS : TRUXS.

DATA             :  IT_RAW TYPE TRUXS_T_TEXT_DATA.

3.Call function module to upload data to Raw table and convert it.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

   EXPORTING

*   I_FIELD_SEPERATOR          =

     I_LINE_HEADER              = 'X'

     i_tab_raw_data             = it_raw

     i_filename                 = p_file

   TABLES

     i_tab_converted_data       = it_final

* EXCEPTIONS

*   CONVERSION_FAILED          = 1

*   OTHERS                     = 2

           .

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.


* FInally It_final will hold the Data which you uploaded through Excel..


Regards,


    Rohan

Read only

0 Likes
4,393

thanks rohan it will work.

i dont know how . but thanks.

Read only

Former Member
0 Likes
4,393

Hi HashMukh,

Your FM declaration is perfect, can you see once excel file filed declarations some miss matching is there, FM not pick the data from Excel.

Regards

KMC

Read only

0 Likes
4,393

Yes - but it's in the wrong place.  It's in a value request event and not the start-of-selection so if I type in the parameter it will not be run.

Read only

Former Member
0 Likes
4,393

Hello HashMukh,

You are calling FM in wrong place, change FM with in the start-of-selection, PF below Example.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.

   CALL FUNCTION 'F4_FILENAME'

     EXPORTING

       program_name  = syst-cprog

       dynpro_number = syst-dynnr

       field_name    = 'p_infile'

     IMPORTING

       file_name     = p_infile.

START-OF-SELECTION.

   PERFORM upload_file.

   PERFORM process_order_data.

*&---------------------------------------------------------------------*

*&      Form  upload_file

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM upload_file.

   CALL FUNCTION 'AA_FILE_UPLOAD_EXCEL'

     EXPORTING

       i_filename                 = p_infile

*     I_TEST                     =

*     I_UCOMM                    =

*     I_MAXCOLS                  =

      i_delimiter                = ','

     TABLES

       et_filecontent             = itab

    EXCEPTIONS

      error_accessing_file       = 1

      OTHERS                     = 2

             .

   IF sy-subrc <> 0.

     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

        WITH sy-msgv1 sy-msgv2 sy-msgv3

Regards

KMC

Read only

0 Likes
4,393

Is this not what I have been saying all along ?

Read only

0 Likes
4,393

Yes you have Richard.

Read only

0 Likes
4,393

So finally we have an answer above - he only uses F4 to pass the file so in that case the process will work.  However,  I still content that the read is in the wrong place because then if the user types in a file name it will not work.

However,  I have copied the code and ran it myself.  The file was an XLSX file in native excel format and it loaded correctly with the internal table still being populated at the start of selection.  So my next question is is what is the actual format of your excel file ?

Rich