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

Code required for uploading xls in XK02 Tcode using BCD Call Transaction

Former Member
0 Likes
2,108

hello,


I need the code to upload an excel file with 2 columns (Vendor id of type RF02K-LIFNR & Mail-id of type LFA1-LFURL) in XK02 T-code using BDC Call transaction method. I know that we need to use 'ALSM_EXCEL_TO_INTERNAL_TABLE' FM to upload an excel. I've used a check loop to see if the values are being populated properly or not as follows :

*Source table

data : begin of itab occurs 1,

       f1 type RF02K-lifnr,

       f2 type LFA1-lfurl,

       end of itab.

*Target table

data : bdcdata type bdcdata occurs 1 with header line.


CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

  EXPORTING

    FILENAME                      = 'E:\My Documents\Downloads\Vendor Email_1.xls'

    I_BEGIN_COL                   = 1

    I_BEGIN_ROW                   = 1

    I_END_COL                     = 2

    I_END_ROW                     = 1480

  TABLES

    INTERN                        = itab

EXCEPTIONS

   INCONSISTENT_PARAMETERS       = 1

   UPLOAD_OLE                    = 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.


**********************

Check loop

**********************

loop at itab.

  write : / itab-f1,

            itab-f2.

endloop.



It shows syntactically correct. But throwing run-time error PERFORM_CONFLICT_TAB_TYPE  (Exception : CX_SY_DYN_CALL_ILLEGAL_TYPE). Please help me out with the correct code.  Would really appreciate if code is a complete solution, but otherwise I know the remaining process of running SHDB to record XK02 and generate the required subroutines and use the "Call Transaction" feature.

Thanks in advance to all for your time and patience.

13 REPLIES 13
Read only

Former Member
0 Likes
1,840

Hi

The definition of your internal table ITAB is wrong, it has to be like ALSMEX_TABLINE:

*DATA : BEGIN OF ITAB OCCURS 1,

*       F1 TYPE RF02K-LIFNR,

*       F2 TYPE LFA1-LFURL,

*       END OF ITAB.

DATA: ITAB TYPE STANDARD TABLE OF ALSMEX_TABLINE WITH HEADER LINE.

Max

Read only

0 Likes
1,840

That was really helpful. Thanks a lot. I got rid of the RTE.

Read only

0 Likes
1,840

Hi max,

Check my program, its running the same Vendor Id and entering the same mail ID everytime..When I execute it instead of taking all the IDs. I've recorded XK02 through SHDB using one vendor ID and then on the next page entering its corresponding mail id.Let me know whats wrong.

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

*& Report  ZCALLTRANS_XK02

*&

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

*&

*&

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

REPORT  ZCALLTRANS_XK02.

*source internal table

DATA: ITAB TYPE STANDARD TABLE OF ALSMEX_TABLINE WITH HEADER LINE.

*target internal table

data : bdcdata type bdcdata occurs 1 with header line.

*Upload data

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

  EXPORTING

    FILENAME                = 'E:\My Documents\Downloads\Vendor Email_1.xls'

    I_BEGIN_COL             = 1

    I_BEGIN_ROW             = 1

    I_END_COL               = 2

    I_END_ROW               = 1480

  TABLES

    INTERN                  = itab

  EXCEPTIONS

    INCONSISTENT_PARAMETERS = 1

    UPLOAD_OLE              = 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.

  

loop at itab.

*******************************************************

*  write : / itab-row,

*            itab-value.

  refresh bdcdata.

  perform bdc_dynpro      using 'SAPMF02K' '0101'.

  perform bdc_field       using 'BDC_CURSOR'

                                'RF02K-BUKRS'.

  perform bdc_field       using 'BDC_OKCODE'

                                '/00'.

  perform bdc_field       using 'RF02K-LIFNR'

                                '1300017'.

  perform bdc_dynpro      using 'SAPMF02K' '0101'.

  perform bdc_field       using 'BDC_CURSOR'

                                'RF02K-D0110'.

  perform bdc_field       using 'BDC_OKCODE'

                                '/00'.

  perform bdc_field       using 'RF02K-LIFNR'

                                '1300017'.

  perform bdc_field       using 'RF02K-BUKRS'

                                'seml'.

  perform bdc_field       using 'RF02K-EKORG'

                                'sepo'.

  perform bdc_field       using 'RF02K-D0110'

                                'X'.

  perform bdc_dynpro      using 'SAPMF02K' '0110'.

  perform bdc_field       using 'BDC_CURSOR'

                                'LFA1-LFURL'.

  perform bdc_field       using 'BDC_OKCODE'

                                '/00'.

  perform bdc_field       using 'LFA1-NAME1'

                                'AGRASEN ENGINEERING WORKS'.

  perform bdc_field       using 'LFA1-SORTL'

                                'AGRASEN EN'.

  perform bdc_field       using 'LFA1-STRAS'

                                'K K ROAD   MODHAPARA'.

  perform bdc_field       using 'LFA1-ORT01'

                                'RAIPUR'.

  perform bdc_field       using 'LFA1-PSTLZ'

                                '492001'.

  perform bdc_field       using 'LFA1-LAND1'

                                'IN'.

  perform bdc_field       using 'LFA1-REGIO'

                                '33'.

  perform bdc_field       using 'LFA1-SPRAS'

                                'EN'.

  perform bdc_field       using 'LFA1-TELF1'

                                '07712523275'.

  perform bdc_field       using 'LFA1-TELF2'

                                '07714030875'.

  perform bdc_field       using 'LFA1-LFURL'

                                'abhi_ryp@yahoo.com'.

************************************************************************

***PUSH DATA

call transaction 'XK02' using bdcdata mode 'A'.

endloop.

***Check loop***

loop at bdcdata.

  write : /05 bdcdata-program,

           20 bdcdata-dynpro,

           30 bdcdata-dynbegin,

           40 bdcdata-fnam,

           60 bdcdata-fval.

endloop.

***End of Check loop***

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

*        Start new screen                                              *

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

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

  CLEAR BDCDATA.

  BDCDATA-PROGRAM  = PROGRAM.

  BDCDATA-DYNPRO   = DYNPRO.

  BDCDATA-DYNBEGIN = 'X'.

  APPEND BDCDATA.

ENDFORM.                    "BDC_DYNPRO

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

*        Insert field                                                  *

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

FORM BDC_FIELD USING FNAM FVAL.

  IF FVAL <> SPACE.

    CLEAR BDCDATA.

    BDCDATA-FNAM = FNAM.

    BDCDATA-FVAL = FVAL.

    APPEND BDCDATA.

  ENDIF.

ENDFORM.                    "BDC_FIELD


Read only

former_member212913
Participant
0 Likes
1,840

Hi,

     here you have sample code to upload excel file..

DATA:it_bdcdata TYPE TABLE OF BDCDATA,
      wa_bdcdata  TYPE BDCDATA.

*TABLE & Work area for error data
DATA:it_error TYPE TABLE OF BDCMSGCOLL,
       wa_error TYPE BDCMSGCOLL.

*Selection screen
SELECTION-SCREEN BEGIN OF BLOCK blck WITH FRAME TITLE text-011.
PARAMETERs : p_file TYPE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK blck.

*Data declarations
DATA: wa_path TYPE string ,
*     wa_error TYPE string,
       wa_cnt   TYPE i,
       w_mode    TYPE c,
       wa_cnt1(2) TYPE n.
*  it_output type table of ty_s_error,
*  wa_output like line of it_output.


*Code for F4 help
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
   PERFORM file_path.
*  include bdcrecx1.

start-of-selection.
  PERFORM UPLOAD_EXCEL.
  perform RECORD_BDC_DATA.
*&-

FORM FILE_PATH .
CALL FUNCTION 'F4_FILENAME'
     EXPORTING
       program_name  = syst-cprog
       dynpro_number = syst-dynnr
       field_name    = ' '
     IMPORTING
       file_name     = p_file.


ENDFORM.                    " FILE_PATH
*&---------------------------------------------------------------------*
*&      Form  UPLOAD_EXCEL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM UPLOAD_EXCEL .

     TYPES: fs_struct(4096) TYPE c OCCURS 0 .

     DATA: w_struct TYPE fs_struct.

* Uploading excel file.
   CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
     EXPORTING
       i_field_seperator          = 'X'
*   I_LINE_HEADER              =
       i_tab_raw_data             = w_struct
       i_filename                 = p_file
     TABLES
       i_tab_converted_data       = it_data
     EXCEPTIONS
       conversion_failed          = 1
       OTHERS                     = 2
             .
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.


ENDFORM.                    " UPLOAD_EXCEL

Regards,

Mahipal.

Read only

0 Likes
1,840

Hello Mahipal,

I have tried the above code to update email IDs in xk02 as per vendor IDs. It is populating the flat file records into the screen of xk02 as per my recording in shdb. But after doing ENTER ('BDC_OKCODE' '=UPDA'), it says "No changes were made".  It is also not allowing me to come out of loop after entering the records. On an overall, no changes are being done to adr6-smtp_addr(email address) field. It still stays on xk02 screen. Now I've very less time and need to deliver before EOD. So I request to give me the exact code which can be used to update email IDs from flat file in xk02 as per vendor IDs.

Flat file is of type

1234567890i@sap.com
3123445555e@sap.com
4532466564u@sap.com

I request to give me the exact code which works,if possible or give suggestions if  they are accurate to be made.

Thanks in advance.

Read only

Former Member
0 Likes
1,840

Hi,

     Before coding FM execute or check its parameters. Try this code.

TYPES: BEGIN OF TY_ALSMEX_TABLINE,
              ROW TYPE ALSMEX_TABLINE-ROW,
              COL TYPE ALSMEX_TABLINE-COL,
              VALUE TYPE ALSMEX_TABLINE-VALUE,
            END OF TY_ALSMEX_TABLINE.

DATA: ITAB TYPE STANDARD TABLE OF TY_ALSMEX_TABLINE,

           WA TYPE TY_ALSMEX_TABLINE.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

  EXPORTING

    FILENAME                      = 'E:\My Documents\Downloads\Vendor Email_1.xls'

    I_BEGIN_COL                   = 1

    I_BEGIN_ROW                   = 1

    I_END_COL                     = 2

    I_END_ROW                     = 1480

  TABLES

    INTERN                        = itab

EXCEPTIONS

   INCONSISTENT_PARAMETERS       = 1

   UPLOAD_OLE                    = 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.

LOOP AT ITAB INTO WA.

     WRITE:/ WA-ROW, WA-COL, WA-VALUE.

ENDLOOP.

In this internal table each line item holds details of each cell in sheet. You can get clear idea when you perform this code.

Hope this helps you.

Cheers,

Dineshwar Singh Eswar.


Read only

0 Likes
1,840

Hi

Yes, Dineshwar Singh Eswar is right

You need to consider the fm (reads the excel file) returns the value of every single cell, so if your excel file is arranged like following:

Vendor Code
ID mail
1234567890i@sap.com
3123445555e@sap.com
yyyyyyyyyyu@sap.com

The fm returns the following result:

ROW
COL
VALUE
111234567890
12i@sap.com
213123445555
22e@sap.com
31yyyyyyyyyy
32u@sap.com

So probably it's better to move the data from ITAB to a new table arranged like you need, something like this:

DATA : BEGIN OF ITAB2 OCCURS 1,

                F1 TYPE RF02K-LIFNR,

                F2 TYPE LFA1-LFURL,

           END OF ITAB2.

DATA: COUNT_CELL TYPE I.

FIELD-SYMBOLS: <FS_CELL> TYPE ANY.

LOOP AT ITAB.

    COUNT_CELL = COUNT_CELL + 1.

   ASSIGN COMPONENT COUNT_CELL OF STRUCTURE ITAB2 TO <FS_CELL>.

   

   AT END OF ROW.

        APPEND ITAB2.

        COUNT_CELL = 0.

    ENDAT.

ENDLOOP.

Max

Read only

0 Likes
1,840

*source internal table

DATA: ITAB TYPE STANDARD TABLE OF ALSMEX_TABLINE WITH HEADER LINE.

*target internal table

data : bdcdata type bdcdata occurs 1 with header line.

*Upload data

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

  EXPORTING

    FILENAME                = 'E:\My Documents\Downloads\Vendor Email_1.xls'

    I_BEGIN_COL             = 1

    I_BEGIN_ROW             = 1

    I_END_COL               = 2

    I_END_ROW               = 1480

  TABLES

    INTERN                  = itab

  EXCEPTIONS

    INCONSISTENT_PARAMETERS = 1

    UPLOAD_OLE              = 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.

***Moving data from itab to itab2

DATA : BEGIN OF ITAB2 OCCURS 1,

                F1 TYPE RF02K-LIFNR,

                F2 TYPE LFA1-LFURL,

           END OF ITAB2.

 

DATA: COUNT_CELL TYPE I.

 

FIELD-SYMBOLS: <FS_CELL> TYPE ANY.

  LOOP AT ITAB.

    COUNT_CELL = COUNT_CELL + 1.

   ASSIGN COMPONENT COUNT_CELL OF STRUCTURE ITAB2 TO <FS_CELL>.

 

   AT END OF ROW.

        APPEND ITAB2.

        COUNT_CELL = 0.

    ENDAT.

ENDLOOP.

loop at itab2.

write : / itab2-f1, itab2-f2.

endloop.

I have added a small loop for itab2 at end of your code, after incorporating it in my program. But f1 and f2 of itab2 do not return any values? Please let me know hoe we can get our desired values in itab2 and later how do we use it to run xk02 through rec&run from shdb.

My excel has exactly the same type of values arranged in the same fashion as you have shown.

Thanks.

Read only

0 Likes
1,840

Hi

Sorry I've forgotten the MOVE statament:

LOOP AT ITAB.

     COUNT_CELL = COUNT_CELL + 1.

     ASSIGN COMPONENT COUNT_CELL OF STRUCTURE ITAB2 TO <FS_VALUE>.

     MOVE ITAB-VALUE TO <FS_VALUE>.

     AT END OF ROW.

       APPEND ITAB2.

       COUNT_CELL = 0.

     ENDAT.

   ENDLOOP.

   LOOP AT ITAB2.

     WRITE: / ITAB2-F1, ITAB2-F2.

   ENDLOOP.

Max

Read only

0 Likes
1,840

Hi max,

Good Morning! I am finally able to upload data using xls and txt file also by converting it into Text (tab delimited). I preferred using the GUI_UPLOAD fm and used the text file only. When I am running the prog, it is showing all the vendor IDs and mail IDs entered in the corresponding screens. But its not committing the changes. I mean the email IDs are not being updated in the DB. Please find the code that I used below. Please let me know how to commit the changes and ensure that the IDs are updated in adr6 table as per the ADRNR field of lfa1 table:

*Source internal table (when text file)

data : begin of itab occurs 1,

       f1 type RF02K-lifnr,

       f2 type LFA1-lfurl,

       end of itab.

*target internal table

data : bdcdata type bdcdata occurs 1 with header line.

*Upload data from text file.

CALL FUNCTION 'GUI_UPLOAD'

  EXPORTING

    FILENAME                      = 'C:\Documents and Settings\auditor\Desktop\Vendor Email_2.txt'

   FILETYPE                       = 'ASC'

    HAS_FIELD_SEPARATOR           =  'X'

  TABLES

    DATA_TAB                      = itab.

loop at itab.

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

refresh bdcdata.

************************************************************

perform bdc_dynpro      using 'SAPMF02K' '0101'.

perform bdc_field       using 'BDC_CURSOR'

                              'RF02K-D0110'.

perform bdc_field       using 'BDC_OKCODE'

                              '/00'.

perform bdc_field       using 'RF02K-LIFNR'

                               itab-f1.

perform bdc_field       using 'RF02K-BUKRS'

                              'seml'.

perform bdc_field       using 'RF02K-EKORG'

                              'sepo'.

perform bdc_field       using 'RF02K-D0110'

                              'X'.

perform bdc_dynpro      using 'SAPMF02K' '0110'.

perform bdc_field       using 'BDC_CURSOR'

                              'LFA1-ANRED'.

perform bdc_field       using 'BDC_OKCODE'

                              '/00'.

perform bdc_field       using 'LFA1-LFURL'

                               itab-f2.

************************************************************************

***PUSH DATA

CALL TRANSACTION 'XK02' USING BDCDATA MODE 'A'.

endloop.

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

    

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

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

Read only

0 Likes
1,840

Hello Dineshwar,

I have tried the above code to update email IDs in xk02 as per vendor IDs. It is populating the flat file records into the screen of xk02 as per my recording in shdb. But after doing ENTER ('BDC_OKCODE' '=UPDA'), it says "No changes were made".  It is also not allowing me to come out of loop after entering the records. On an overall, no changes are being done to adr6-smtp_addr(email address) field. It still stays on xk02 screen. Now I've very less time and need to deliver before EOD. So I request to give me the exact code which can be used to update email IDs from flat file in xk02 as per vendor IDs.

Flat file is of type

1234567890i@sap.com
3123445555e@sap.com
4532466564u@sap.com

I request to give me the exact code which works,if possible or give suggestions if  they are accurate to be made.

Thanks in advance.

Read only

0 Likes
1,840

Hi

You don't need a COMMIT, because you're updating the data by CALL TRANSACTION, so the commit is just called by XD02.

You can try to check the SY-SUBRC (after call transaction) and messages in order to check the result of updating, but if you want to make sure to update the DB you should read the table after calling the transaction XD02.

In this last case you should call the transaction in synchronous way (i.e. S) instead of asynchronous

Max

Read only

0 Likes
1,840

Max. Thanks for the info. Its working now.