Application Development 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: 

Not able to import data from Excel through BDC

0 Kudos
984

Internal Table: IT_FINAL

Work Area: WA_FINAL

Excel File Below

Custom Table Below

BDC recording Process: SE11-- Display Table--- Create Entries --- Save.

REPORT YBDC_PROJECT.
*INCLUDE ZDeclaration.
*INCLUDE YBDC.
*INCLUDE YBUILD_ALV.
Types: Begin Of itab,
 EMP_CODE Type PERSNO,
 EMP_NAME Type PAD_CNAME,
 EMP_JOIN_DATE Type BEGDA,
 EMP_DEPT Type Y_DEPT,
 EMP_DESIGNATION Type Y_DESIG,
 SAL_HRA Type P Length 10,
 SAL_BASIC Type P Length 10,
 SAL_CNV Type P Length 10,
 TOTAL Type P Length 15,
End Of itab.
Data: IT_FINAL Type Standard Table Of itab,
 WA_FINAL Like Line Of IT_FINAL,
 RAWSTRUCT Type TRUXS_T_TEXT_DATA,
 IT_FCAT Type SLIS_T_FIELDCAT_ALV,
 WA_FCAT Like Line Of IT_FCAT.
SELECTION-Screen Begin Of Block B1 With Frame.
 Parameters: Loc_file Type rlgrap-filename.
SELECTION-Screen End Of Block B1.
At SELECTION-Screen On Value-REQUEST For loc_file.
Perform UPLOAD.
Perform Convert.
Perform Create.
Perform ALV.
*&---------------------------------------------------------------------*
*& Form UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
Form UPLOAD .
 Call Function 'F4_FILENAME'
 EXPORTING
 PROGRAM_NAME = SYST-CPROG
 DYNPRO_NUMBER = SYST-DYNNR
 FIELD_NAME = ' '
 Importing
 FILE_NAME = loc_file
 .
Endform. " UPLOAD
*&---------------------------------------------------------------------*
*& Form CREATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
Form Create .
Break-Point.
 Loop At IT_FINAL Into WA_FINAL.
 Call Function 'YBDC_PROJECT2'
 Exporting
 CTU = 'X'
 Mode = 'N'
 Update = 'L'
* GROUP =
* USER =
* KEEP =
* HOLDDATE =
 NODATA = '/'
 TBMA_001 = 'X'
 TBMA_VAL_002 = 'YIT_EMP_MASTER'
 VIMA_VAL_003 = 'YIT_EMP_MASTER'
 EMP_CODE_004 = WA_FINAL-EMP_CODE "'9'
 EMP_NAME_005 = WA_FINAL-EMP_NAME "'USER TEST 9'
 EMP_JOIN_DATE_006 = WA_FINAL-EMP_JOIN_DATE "'03.08.2010'
 EMP_DEPT_007 = WA_FINAL-EMP_DEPT "'IT DEPARTMENT'
 EMP_DESIGNATION_008 = WA_FINAL-EMP_DESIGNATION "'TRAINEE'
* IMPORTING
* SUBRC =
* TABLES
* MESSTAB =
 .
 ENDLOOP.
ENDFORM. " CREATE
*&---------------------------------------------------------------------*
*& Form CONVERT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
Form Convert .
 Call Function 'TEXT_CONVERT_XLS_TO_SAP'
 Exporting
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
 I_TAB_RAW_DATA = RAWSTRUCT
 I_FILENAME = LOC_FILE
 Tables
 I_TAB_CONVERTED_DATA = IT_FINAL
 Exceptions
 CONVERSION_FAILED = 1
 Others = 2
 .
 Delete IT_FINAL Index 1.
Endform. " CONVERT
FORM ALV.
Perform BUILD_FCAT Using 'X' 'EMP_CODE' 'Employee Code' '1' 'IT_FINAL' '20' ''.
Perform BUILD_FCAT Using 'X' 'EMP_NAME' 'Employee Name' '2' 'IT_FINAL' '20' ''.
Perform BUILD_FCAT Using 'X' 'EMP_JOIN_DATE' 'Joining Date' '3' 'IT_FINAL' '15' ''.
Perform BUILD_FCAT Using 'X' 'EMP_DEPT' 'Department' '4' 'IT_FINAL' '15' ''.
Perform BUILD_FCAT Using 'X' 'EMP_DESIGNATION' 'Designation' '5' 'IT_FINAL' '15' ''.
Perform BUILD_FCAT Using 'X' 'SAL_HRA' 'House Rent Allowance' '6' 'IT_FINAL' '25' 'X'.
Perform BUILD_FCAT Using 'X' 'SAL_BASIC' 'Basic Salary' '7' 'IT_FINAL' '10' 'X'.
Perform BUILD_FCAT Using 'X' 'SAL_CNV' 'Conveyance Allowance' '8' 'IT_FINAL' '25' 'X'.
Perform BUILD_FCAT Using '' 'TOTAL' 'Total' '9' 'IT_FINAL' '15' ''.
 Call Function 'REUSE_ALV_GRID_DISPLAY'
 Exporting
 IT_FIELDCAT = IT_FCAT
 Tables
 T_OUTTAB = IT_FINAL
 .
ENDFORM.
Form BUILD_FCAT Using CHECKBOX
 FIELDNAME
 SELTEXT_M
 COL_POS
 TABNAME
 outputlen
 Edit.
 WA_FCAT-CHECKBOX = CHECKBOX.
 WA_FCAT-FIELDNAME = FIELDNAME.
 WA_FCAT-SELTEXT_M = SELTEXT_M.
 WA_FCAT-COL_POS = COL_POS.
 WA_FCAT-TABNAME = TABNAME.
 WA_FCAT-outputlen = outputlen.
 WA_FCAT-edit = edit.
 Append WA_FCAT To IT_FCAT.
 Clear WA_FCAT.
Endform. " BUILD_FCAT
1 ACCEPTED SOLUTION

yusufoner
Participant
783

Hi Shashank

* Date format is wrong in your file.

* if your file have header line, you should put your code.

I_LINE_HEADER = 'X' for FM TEXT_CONVERT_XLS_TO_SAP

* dont use this code " WA_FCAT-CHECKBOX = CHECKBOX for all fields.

if you want to use a checkbox in your ALV,your field should be 1 length char.

like : flag type c

Best Regards


*INCLUDE ZDeclaration.
*INCLUDE YBDC.
*INCLUDE YBUILD_ALV.
Types: Begin Of itab,
EMP_CODE Type PERSNO,
EMP_NAME Type PAD_CNAME,
EMP_JOIN_DATE Type BEGDA,
EMP_DEPT Type char20,
EMP_DESIGNATION Type char20,
SAL_HRA Type P Length 10,
SAL_BASIC Type P Length 10,
SAL_CNV Type P Length 10,
TOTAL Type P Length 15,
End Of itab.
Data: IT_FINAL Type Standard Table Of itab,
WA_FINAL Like Line Of IT_FINAL,
RAWSTRUCT Type TRUXS_T_TEXT_DATA,
IT_FCAT Type SLIS_T_FIELDCAT_ALV,
WA_FCAT Like Line Of IT_FCAT.
SELECTION-Screen Begin Of Block B1 With Frame.
Parameters: Loc_file Type rlgrap-filename.
SELECTION-Screen End Of Block B1.
At SELECTION-Screen On Value-REQUEST For loc_file.
Perform UPLOAD.
Perform Convert.
Perform Create.
Perform ALV.
*&---------------------------------------------------------------------*
*& Form UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
Form UPLOAD .
Call Function 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
Importing
FILE_NAME = loc_file
.
Endform. " UPLOAD
*&---------------------------------------------------------------------*
*& Form CREATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
Form Create .
Break-Point.
* Loop At IT_FINAL Into WA_FINAL.
* Call Function 'YBDC_PROJECT2'
* Exporting
* CTU = 'X'
* Mode = 'N'
* Update = 'L'
** GROUP =
** USER =
** KEEP =
** HOLDDATE =
* NODATA = '/'
* TBMA_001 = 'X'
* TBMA_VAL_002 = 'YIT_EMP_MASTER'
* VIMA_VAL_003 = 'YIT_EMP_MASTER'
* EMP_CODE_004 = WA_FINAL-EMP_CODE "'9'
* EMP_NAME_005 = WA_FINAL-EMP_NAME "'USER TEST 9'
* EMP_JOIN_DATE_006 = WA_FINAL-EMP_JOIN_DATE "'03.08.2010'
* EMP_DEPT_007 = WA_FINAL-EMP_DEPT "'IT DEPARTMENT'
* EMP_DESIGNATION_008 = WA_FINAL-EMP_DESIGNATION "'TRAINEE'
** IMPORTING
** SUBRC =
** TABLES
** MESSTAB =
* .
* ENDLOOP.
ENDFORM. " CREATE
*&---------------------------------------------------------------------*
*& Form CONVERT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
Form Convert .
Call Function 'TEXT_CONVERT_XLS_TO_SAP'
Exporting
* I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = RAWSTRUCT
I_FILENAME = LOC_FILE
Tables
I_TAB_CONVERTED_DATA = IT_FINAL
Exceptions
CONVERSION_FAILED = 1
Others = 2

.
Endform. " CONVERT
FORM ALV.
Perform BUILD_FCAT Using 'X' 'EMP_CODE' 'Employee Code' '1' 'IT_FINAL' '20' ''.
Perform BUILD_FCAT Using 'X' 'EMP_NAME' 'Employee Name' '2' 'IT_FINAL' '20' ''.
Perform BUILD_FCAT Using 'X' 'EMP_JOIN_DATE' 'Joining Date' '3' 'IT_FINAL' '15' ''.
Perform BUILD_FCAT Using 'X' 'EMP_DEPT' 'Department' '4' 'IT_FINAL' '15' ''.
Perform BUILD_FCAT Using 'X' 'EMP_DESIGNATION' 'Designation' '5' 'IT_FINAL' '15' ''.
Perform BUILD_FCAT Using 'X' 'SAL_HRA' 'House Rent Allowance' '6' 'IT_FINAL' '25' 'X'.
Perform BUILD_FCAT Using 'X' 'SAL_BASIC' 'Basic Salary' '7' 'IT_FINAL' '10' 'X'.
Perform BUILD_FCAT Using 'X' 'SAL_CNV' 'Conveyance Allowance' '8' 'IT_FINAL' '25' 'X'.
Perform BUILD_FCAT Using '' 'TOTAL' 'Total' '9' 'IT_FINAL' '15' ''.
Call Function 'REUSE_ALV_GRID_DISPLAY'
Exporting
IT_FIELDCAT = IT_FCAT
Tables
T_OUTTAB = IT_FINAL
.
ENDFORM.
Form BUILD_FCAT Using CHECKBOX
FIELDNAME
SELTEXT_M
COL_POS
TABNAME
outputlen
Edit.
" WA_FCAT-CHECKBOX = CHECKBOX.
WA_FCAT-FIELDNAME = FIELDNAME.
WA_FCAT-SELTEXT_M = SELTEXT_M.
WA_FCAT-COL_POS = COL_POS.
WA_FCAT-TABNAME = TABNAME.
WA_FCAT-outputlen = outputlen.
WA_FCAT-edit = edit.
Append WA_FCAT To IT_FCAT.
Clear WA_FCAT.
Endform. " BUILD_FCAT

19 REPLIES 19

0 Kudos
783

@frdric.girod Help.

FredericGirod
Active Contributor
783

I was waiting the feedback of Matthew 🙂

So, what isyour problem? Did you try to debug it ?

SimoneMilesi
Active Contributor
0 Kudos
783

First of all, which is the issue you are facing?
Second, it looks like a custom table, why using a BDC?

You are doing something without a reason imho.

Sandra_Rossi
Active Contributor
783

I don't know what your question is, but I can already say that it's not a good idea to "BDC the data browser" (SE11/SE16) to insert rows in a database table, unless you have a very good reason to do so, that you should explain to us!

0 Kudos
783

frdric.girod Debugging shows IT_FINAL is empty (I don't know why) hence the output shows a blank ALV.

0 Kudos
783

I'm trying to add rows in a custom table through an excel sheet using BDC in IDES(still learning).

But while running the above code IT_FINAL(internal table) is not populating hence shows a blank ALV.

FredericGirod
Active Contributor
783

In debug, check your function module TEXT_CONVERT_XLS_TO_SAP is not returning a SY-SUBRC <> 0

0 Kudos
783

frdric.girod Sy-Subrc was 0 throughout the debugging process 😞

FredericGirod
Active Contributor
783

So,

First,

At SELECTION-Screen On Value-REQUEST For loc_file.
Perform UPLOAD.
Perform Convert.
Perform Create.
Perform ALV.

replace with

At SELECTION-Screen On Value-REQUEST For loc_file.
Perform UPLOAD.



start-of-selection
Perform Convert.
Perform Create.
Perform ALV.

Second, your function is getting error in debug : CONVERSION_FAILED

When I read an external file, I read the content in string or CHAR and after I try to convert the data to the right format.

I think it is your date with the wrong format

0 Kudos
783

Hey frdric.girod,

I have removed the date field from the internal table, to check if it was the format mismatch issue, made changes accordingly.

But still, it gives me a blank ALV 😞

Please check my new BDC recording.

bdc-recordingf.txt

0 Kudos
783

Did you check the SY-SUBRC after the function module ?

Did you check the content of the internal table IT_FINAL before the usage of 'REUSE_ALV_GRID_DISPLAY'?

0 Kudos
783

SHASHANK SENGAR Is it solved? If so, can you explain?

0 Kudos
783
sandra.rossi No, it's not solved yet but I'm trying.

0 Kudos
783

Help matthew.billingham

783

matthew.billingham I just want to say that I did not report any comment, just wanted you to expand on the points and I was okay with your reply.

Atleast help me out here.

yusufoner
Participant
784

Hi Shashank

* Date format is wrong in your file.

* if your file have header line, you should put your code.

I_LINE_HEADER = 'X' for FM TEXT_CONVERT_XLS_TO_SAP

* dont use this code " WA_FCAT-CHECKBOX = CHECKBOX for all fields.

if you want to use a checkbox in your ALV,your field should be 1 length char.

like : flag type c

Best Regards


*INCLUDE ZDeclaration.
*INCLUDE YBDC.
*INCLUDE YBUILD_ALV.
Types: Begin Of itab,
EMP_CODE Type PERSNO,
EMP_NAME Type PAD_CNAME,
EMP_JOIN_DATE Type BEGDA,
EMP_DEPT Type char20,
EMP_DESIGNATION Type char20,
SAL_HRA Type P Length 10,
SAL_BASIC Type P Length 10,
SAL_CNV Type P Length 10,
TOTAL Type P Length 15,
End Of itab.
Data: IT_FINAL Type Standard Table Of itab,
WA_FINAL Like Line Of IT_FINAL,
RAWSTRUCT Type TRUXS_T_TEXT_DATA,
IT_FCAT Type SLIS_T_FIELDCAT_ALV,
WA_FCAT Like Line Of IT_FCAT.
SELECTION-Screen Begin Of Block B1 With Frame.
Parameters: Loc_file Type rlgrap-filename.
SELECTION-Screen End Of Block B1.
At SELECTION-Screen On Value-REQUEST For loc_file.
Perform UPLOAD.
Perform Convert.
Perform Create.
Perform ALV.
*&---------------------------------------------------------------------*
*& Form UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
Form UPLOAD .
Call Function 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
Importing
FILE_NAME = loc_file
.
Endform. " UPLOAD
*&---------------------------------------------------------------------*
*& Form CREATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
Form Create .
Break-Point.
* Loop At IT_FINAL Into WA_FINAL.
* Call Function 'YBDC_PROJECT2'
* Exporting
* CTU = 'X'
* Mode = 'N'
* Update = 'L'
** GROUP =
** USER =
** KEEP =
** HOLDDATE =
* NODATA = '/'
* TBMA_001 = 'X'
* TBMA_VAL_002 = 'YIT_EMP_MASTER'
* VIMA_VAL_003 = 'YIT_EMP_MASTER'
* EMP_CODE_004 = WA_FINAL-EMP_CODE "'9'
* EMP_NAME_005 = WA_FINAL-EMP_NAME "'USER TEST 9'
* EMP_JOIN_DATE_006 = WA_FINAL-EMP_JOIN_DATE "'03.08.2010'
* EMP_DEPT_007 = WA_FINAL-EMP_DEPT "'IT DEPARTMENT'
* EMP_DESIGNATION_008 = WA_FINAL-EMP_DESIGNATION "'TRAINEE'
** IMPORTING
** SUBRC =
** TABLES
** MESSTAB =
* .
* ENDLOOP.
ENDFORM. " CREATE
*&---------------------------------------------------------------------*
*& Form CONVERT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
Form Convert .
Call Function 'TEXT_CONVERT_XLS_TO_SAP'
Exporting
* I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = RAWSTRUCT
I_FILENAME = LOC_FILE
Tables
I_TAB_CONVERTED_DATA = IT_FINAL
Exceptions
CONVERSION_FAILED = 1
Others = 2

.
Endform. " CONVERT
FORM ALV.
Perform BUILD_FCAT Using 'X' 'EMP_CODE' 'Employee Code' '1' 'IT_FINAL' '20' ''.
Perform BUILD_FCAT Using 'X' 'EMP_NAME' 'Employee Name' '2' 'IT_FINAL' '20' ''.
Perform BUILD_FCAT Using 'X' 'EMP_JOIN_DATE' 'Joining Date' '3' 'IT_FINAL' '15' ''.
Perform BUILD_FCAT Using 'X' 'EMP_DEPT' 'Department' '4' 'IT_FINAL' '15' ''.
Perform BUILD_FCAT Using 'X' 'EMP_DESIGNATION' 'Designation' '5' 'IT_FINAL' '15' ''.
Perform BUILD_FCAT Using 'X' 'SAL_HRA' 'House Rent Allowance' '6' 'IT_FINAL' '25' 'X'.
Perform BUILD_FCAT Using 'X' 'SAL_BASIC' 'Basic Salary' '7' 'IT_FINAL' '10' 'X'.
Perform BUILD_FCAT Using 'X' 'SAL_CNV' 'Conveyance Allowance' '8' 'IT_FINAL' '25' 'X'.
Perform BUILD_FCAT Using '' 'TOTAL' 'Total' '9' 'IT_FINAL' '15' ''.
Call Function 'REUSE_ALV_GRID_DISPLAY'
Exporting
IT_FIELDCAT = IT_FCAT
Tables
T_OUTTAB = IT_FINAL
.
ENDFORM.
Form BUILD_FCAT Using CHECKBOX
FIELDNAME
SELTEXT_M
COL_POS
TABNAME
outputlen
Edit.
" WA_FCAT-CHECKBOX = CHECKBOX.
WA_FCAT-FIELDNAME = FIELDNAME.
WA_FCAT-SELTEXT_M = SELTEXT_M.
WA_FCAT-COL_POS = COL_POS.
WA_FCAT-TABNAME = TABNAME.
WA_FCAT-outputlen = outputlen.
WA_FCAT-edit = edit.
Append WA_FCAT To IT_FCAT.
Clear WA_FCAT.
Endform. " BUILD_FCAT

783

I think it's important to comment your answer to help the OP. I'm not sure the OP can understand what the issue was, why you changed the code as you did and why it should solve the issue, only by reading the code.

matt
Active Contributor
783

If you're wanting to learn BDC, I suggest that you try a different transaction than SE11/SE16.

I think the information given here so far is helpful, I've nothing to add.