SAP ABAP Central - Data Migration - Using A Single Program To Upload Any Database Table
SAP ABAP Central - Data Migration - Using A Single Program To Upload Any Database Table
We often come across situations where we would like to directly upload data in
the custom database tables (Transparent tables) which we create. The main
intention of such kind of a direct update is primarily based on the fact that these
tables only hold relevant data and there are no complex validations which needs
to be taken care during the upload process.
Moreover we also may not have sufficient time to create a module pool
application or a table maintenance generator for the data input, and then create
an upload program or use a BDC program finally for data upload. In such
situations you can go for a generic program like the one I have discussed below,
for the data upload. The highlight of this program is that you don’t have to
change the program source code to upload several database tables. Well you can
use the same single program to upload data in any database table (Only
transparent tables, since they are the only tables which have one-to-one
relationship of fields between dictionary and database).
Concept:
Now speaking about the realization, it is obvious that there are many ways you
may create a data upload program that could achieve the functionality. But I am
sharing the source code of the program which I had developed, which I think is
more simple, highly re-usable and more easy to understand. The main concept
behind this program is dynamic creation of data via the CREATE DATA statement
in ABAP. This powerful statement is used in my program to create a dynamic
internal table and the corresponding work area, which forms the main part of this
program. This is how it works:
In the selection screen, user enters the table name which needs to be uploaded.
Now for the table name entered by the user, an internal table of same type is
created via the statement CREATE DATA as mentioned below.
Now once you have created the dynamic internal table through via CREATE DATA
statement as mentioned above, all you have to do in order to use this internal
table is to assign this dynamic data (gt_data) to a field symbol as mentioned
below:
Once this assignment is done, the field symbol now points to the dynamic internal
table gt_data and the internal table can now be processed just like a normal
internal table using the field symbol <ft_data>. The same approach is used for
creating the work area as well. Finally the data from the excel sheet is
transferred to the table <ft_data> by calling the function module
TEXT_CONVERT_XLS_TO_SAP. I preferred to use this function module since lot of
validations are done by this FM itself. For example, invalid cell value, incorrect
date format etc will be taken care by the function module itself. The FM will even
give the exact cell which is causing the error. However you may use other
function modules as well, but the concept will remain the same. You may even
use a text file for the data upload and use FM like GUI_UPLOAD.
Finally the data is uploaded in the database table row by row using MODIFY
statement. And the upload results are displayed by calling the factory ALV. Those
records which are successfully uploaded will be displayed in the ALV. You can also
see the number of records that were successfully uploaded and number of
records which gave error while uploading.
Blog Archive
► 2020 (4)
2. Click on execute button. The data upload takes place and you can see the ▼ 2019 (183)
result in ALV format. ► December (14)
► November (14)
► October (16)
► September (17)
► August (12)
▼ July (16)
Data Migration: Using a
Single program to
Upload a...
3. Click on BACK button and you can see the update count. Steps to create a data
connection between a
SAP on...
Break point for SELECT
statement with Table
Filter...
How to use
Source Code: BAPI_PRICES_CONDITIO
NS to mass upload p...
REPORT ZISU_DATA_MIGRATION. Building connected UI5
apps using Fiori
*— Selection Screen Elements
PARAMETERS: p_table TYPE dd02l-tabname OBLIGATORY. Gateway – OData Post
PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY MEMORY ID ysm. using Postman
ABAP on SAP Cloud
*— Declarations for dynamic data
platform – ABAP RESTful
DATA gt_data TYPE REF TO data. Programm...
DATA GS_DATA TYPE REF TO data.
S/4 HANA Embedded
Analytics KPI Tile:
FIELD-SYMBOLS: <ft_data> TYPE STANDARD TABLE, Configuring ...
<FS_DATA> TYPE ANY.
Currency and Unit
conversion in ABAP CDS
*— Declarations for Result Count
views
DATA: GV_SUCCESS TYPE I,
GV_ERROR TYPE I. How to create an openApi
Rest Service from an
oDat...
*— Declaration for factory ALV
data: gr_table type ref to cl_salv_table. Step-by-Step Archiving of
Material Documents
*— File Open Dialog Read COMM port using
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. ABAP w/o third party
PERFORM f4_file_name. software...
How to create OData for
*— Validate table name GET operation in SAP
AT SELECTION-SCREEN ON p_table. Cloud...
Excel Data to Internal table
PERFORM f_validate_table. using
ALSM_EXCEL_TO_I...
START-OF-SELECTION. ST Transformations: XML 2
ABAP, a working example
*— Create dynamic internal table
Comparative Analysis with
CREATE DATA gt_data TYPE TABLE OF (p_table).
S/4 HANA Embedded
ASSIGN gt_data->* TO <ft_data>. Analyt...
*&———————————————————————*
*& Form F_CONVERT_EXCEL Total Pageviews
*&———————————————————————*
* text
*———————————————————————-* 384,195
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM f_convert_excel .
DATA lt_raw_data TYPE truxs_t_text_data.
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. ” F_CONVERT_EXCEL
*&———————————————————————*
*& Form upload_data
*&———————————————————————*
* text
*———————————————————————-*
FORM f_upload_table.
IF SY-SUBRC = 0.
GV_SUCCESS = GV_SUCCESS + 1.
ELSE.
GV_ERROR = GV_ERROR + 1.
ENDIF.
ENDLOOP.
ENDFORM. “upload_data
*&———————————————————————*
*& Form f_show_result
*&———————————————————————*
* text
*———————————————————————-*
FORM f_show_result.
*— Create Instance
IMPORTING
R_SALV_TABLE = GR_TABLE
CHANGING
Note:
1. Even though I have created an executable type program for data upload, it is
better if we create an update function module with the above source code and
call it in update task for huge data upload.
2. If you wish to validate individual records of the file, you can use the ASSIGN
COMPONENT OF STRUCTURE statement to check for a particular field and then do
validations.
3. It is not mandatory that you should use only excel file for data transfer when
using this program, you can use text files or other file types also. You need to call
relevant function module accordingly in order to get data in your internal table
<FT_DATA>.
4. The excel file should contain all fields of the database table in the exactly same
order, including the MANDT field. Upload of partial fields is not possible through
this program.
8 comments:
Reply
Reply
Reply
Reply