Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
242 views

SAP ABAP Central - Data Migration - Using A Single Program To Upload Any Database Table

Uploaded by

Amrita P p
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
242 views

SAP ABAP Central - Data Migration - Using A Single Program To Upload Any Database Table

Uploaded by

Amrita P p
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

More Create Blog Sign In

SAP ABAP Central


Home SAP ABAP Tutorials Interview Q&A Job Certifications Books

NIT Rourkela Certi cation

Get certi ed as a Big Data Engineer by NIT


Rourkela. Check scholarship eligibility now
www.edureka.co

Wednesday, 31 July 2019

Data Migration: Using a Single program to Upload any


database table
Introduction:

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.

CREATE DATA gt_data TYPE TABLE OF (p_table).

Since gt_data is a dynamic data, obviously we cannot declare gt_data by


specifying any database table name. We need to declare gt_data as generic data
like mentioned below:

DATA gt_data TYPE REF TO data.

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:

ASSIGN gt_data->* TO <ft_data>.

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.

Search This Blog


Steps for Upload:
Search
1. Enter the database table name and file path in the selection screen

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

*— Create dynamic work area ► June (19)


CREATE DATA gs_data TYPE (p_table).
► May (21)
ASSIGN gs_data->* TO <fs_data>.
► April (21)
*— Get Excel data in internal table ► March (14)
PERFORM f_convert_excel.
► February (5)
*— Upload data to database table ► January (14)
PERFORM f_upload_table.
► 2018 (156)
END-OF-SELECTION. ► 2017 (199)
► 2016 (71)
*— Create Factory ALV and display result
PERFORM f_show_result. ► 2015 (5)
► 2014 (2)
*&———————————————————————*
*& Form F4_FILE_NAME ► 2013 (4)
*&———————————————————————* ► 2012 (3)
* text
*———————————————————————-*
* –> p1 text
Popular Posts
* <– p2 text
*———————————————————————-* Sample: Custom CDS View
FORM f4_file_name . using predefined Virtual
CALL FUNCTION ‘KD_GET_FILENAME_ON_F4’ Data Model and Extend
* EXPORTING View in S/4HANA
* PROGRAM_NAME = SYST-REPID Purpose This blog intends
to encourage you to enjoy high
* DYNPRO_NUMBER = SYST-DYNNR productivity of custom object
* FIELD_NAME =‘‘ development by using predefined
* STATIC =‘‘ Virtual Data Mode...
* MASK =‘‘
Using ABAP2XLSX to send ALV table
* FILEOPERATION = ‘R’
output as Excel spreadsheet via
* PATH = internet email
CHANGING A recent discussion
file_name = p_file amongst the ABAP
developers at my site dealt
* LOCATION_FLAG = ‘P’
with the topic of how to
* EXCEPTIONS arrange for a customized
* MASK_TOO_LONG =1 ABAP program running as ...
* OTHERS =2
. Excel file (*.xlsx)
Export/Import
IF sy-subrc <> 0.
In this Blog-post I’d like to
give a few insights on how
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno we process XLSX file by
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. using latest ABAP, which might be
ENDIF. quite different than in ...

FOR expression in ABAP


ENDFORM. ” F4_FILE_NAME 7.40 – Best case scenarios
As we all know, the In-line
*&———————————————————————* declarations, operators
*& Form F_VALIDATE_TABLE and expressions available
*&———————————————————————* in 7.4 SP02 onward are taking the
* text abap world by storm for las...
*———————————————————————-* 5 Use Cases of GROUP BY
* –> p1 text for Internal Tables
* <– p2 text ABAP developers target a
*———————————————————————-* moving Netweaver
FORM F_VALIDATE_TABLE . platform (7.0, or 7.02 or
7.31 or 7.40 or 7.5x or the Cloud)
DATA LV_TABNAME TYPE DD02L-TABNAME.
where the state of the art method to...

*— Upload only Tables in customer namespace


IF p_table+0(1) NE ‘Z’ AND p_table+0(1) NE ‘Y’. Facebook
MESSAGE ‘Only tables in customer namespace can be uploaded’ TYPE ‘E’.
ENDIF.
SAP ABAP Central
*— Only transparent tables can be uploaded Like Page
SELECT SINGLE tabname
FROM DD02L
Be the first of your friends to like this
INTO lv_tabname
where tabname = p_table and
tabclass = ‘TRANSP’.
IF sy-subrc NE 0.
Twitter
MESSAGE ‘Only transparent tables can be uploaded’ TYPE ‘E’.
ENDIF.
Follow @Go_SAP_ABAP 513 followers
ENDFORM. ” F_VALIDATE_TABLE

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

CALL FUNCTION ‘TEXT_CONVERT_XLS_TO_SAP’


EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = ‘X’
i_tab_raw_data = lt_raw_data
i_filename = P_file
TABLES
i_tab_converted_data = <FT_DATA>

EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.

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

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. ” F_CONVERT_EXCEL

*&———————————————————————*
*& Form upload_data
*&———————————————————————*
* text
*———————————————————————-*
FORM f_upload_table.

SET UPDATE TASK LOCAL. ” Switch to local update

LOOP AT <ft_data> ASSIGNING <fs_data>.

MODIFY (P_TABLE) FROM <FS_DATA>.

IF SY-SUBRC = 0.

GV_SUCCESS = GV_SUCCESS + 1.

ELSE.

delete <ft_data> index sy-tabix.

GV_ERROR = GV_ERROR + 1.

ENDIF.

ENDLOOP.

ENDFORM. “upload_data

*&———————————————————————*
*& Form f_show_result
*&———————————————————————*
* text
*———————————————————————-*
FORM f_show_result.
*— Create Instance

CALL METHOD CL_SALV_TABLE=>FACTORY

IMPORTING

R_SALV_TABLE = GR_TABLE

CHANGING

T_TABLE = <FT_DATA>. ” Only entries which are updated successfully

*— Display ALV \Output


gr_table->display( ).

write: ‘No. of records successfully uploaded’,GV_SUCCESS.

write: ‘No. of records unable to upload’, GV_ERROR.


ENDFORM. “f_show_result

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.

Posted by Sabrina Pinto at 11:50

Labels: ABAP Development

8 comments:

high technologies solutions 16 August 2019 at 15:46


SAP course in Delhi
SAP course in Noida
SAP course in Gurgaon

Reply

high technologies solutions 16 August 2019 at 15:51


SAP course in Delhi
SAP course in Noida
SAP course in Gurgaon

Reply

high technologies solutions 17 August 2019 at 11:52


SAP course in Delhi
SAP course in Noida
SAP course in Gurgaon

Reply

chetan maini 17 August 2019 at 14:19


Looking for the Genuine Experience Certificate with 100% Complete
Verification So Contact Experienced Letter Solutions Consulting Firms
Which Provide Experienced Letter with100 % Guaranteed. Contact Now-
9599119376. Or Visit Website- https://experincedletter.blogspot.com/

Reply

high technologies solutions 18 August 2019 at 00:46

SAP course in Delhi


SAP course in Noida
SAP course in Gurgaon
Reply

Alfred Avina 29 October 2019 at 11:10


Though it is challenging to transform the data from one computer to
another, that is,data migration, but with the help of this program, I had
not felt any need to change the source code for uploading the several
database tables.
Reply

Jim 14 November 2019 at 15:58


Migration of data center is a truly difficult and risky process, thanks for the
guide!
Reply

teqtindia 30 November 2019 at 15:53


Data migration is not as easy as it seems to be. Companies invest hugely
in data migration services. That is a good piece of article that explains so
much around data migration and even with the program code to upload
the database table.
Reply

Enter your comment...

Comment as: amrita.suwalka Sign out

Publish Preview Notify me

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)


© 2016 sapabapcentral.com, All rights reserved. Simple template. Powered by Blogger.

You might also like