FM code for extracting data from 10 tables
Hi All,
I have a requirement, where i need to extract the data from 10 tables using FM which is further used to create a data source in SAP R3.
The fields are almost similar in all the tables but yet i have to fetch the data from all the tables.
My approach:
1. I have created a structure with all the fields in it from all the tables that comes to 35 fields.
2. create a structure of each table and loop it into an internal table and work area.
3. writing a read statement based on a key value from all the work areas and populate the same into my final structure.
Note: there is a key field that need to be considered when updating the data into final stucture.
All help on the code / logic would be appreciated.
Thanks
Moderator message : Spec/requirements dumping not allowed, show the work you have already done. Thread locked.
Edited by: Vinod Kumar on Feb 28, 2012 8:35 PM
Hi All,
I have a requirement, where i need to extract the data from 10 tables using FM which is further used to create a data source in SAP R3.
The fields are almost similar in all the tables but yet i have to fetch the data from all the tables.
My approach:
1. I have created a structure with all the fields in it from all the tables that comes to 35 fields.
2. create a structure of each table and loop it into an internal table and work area.
3. writing a read statement based on a key value from all the work areas and populate the same into my final structure.
Note: there is a key field that need to be considered when updating the data into final stucture.
All help on the code / logic would be appreciated.
Thanks
Moderator message : Spec/requirements dumping not allowed, show the work you have already done. Thread locked.
Edited by: Vinod Kumar on Feb 28, 2012 8:35 PM
Similar Messages
-
Time Out Dump while extracting data from table CKIS
Dear Friends,
I am getting TIme Out dump for the below code, while extracting data from table CKIS.
Table CKIS doesn't have any Indexes. Please guide me to resolve this.
Regards,
Viji.
form get_keko_ckis.
SELECT kalnr kalka kadky tvers bwvar matnr werks kokrs
FROM keko
INTO TABLE i_keko1
FOR ALL ENTRIES IN i_final_modify
WHERE matnr = i_final_modify-main_f
AND werks = p_werks
AND kokrs = p_kokrs
AND kadat = p_kadat
AND bidat = p_bidat
AND bwdat = p_bwdat.
IF sy-subrc = 0.
SORT i_keko1 BY kalnr kalka kadky tvers bwvar.
SELECT kalnr kalka kadky tvers bwvar posnr typps kstar
matnr menge gpreis
FROM ckis
INTO TABLE i_ckis_temp
FOR ALL ENTRIES IN i_keko1
WHERE kalnr = i_keko1-kalnr
AND kalka = i_keko1-kalka
AND kadky = i_keko1-kadky
AND tvers = i_keko1-tvers
AND bwvar = i_keko1-bwvar.
IF sy-subrc = 0.
SORT i_ckis_temp BY kalnr kalka kadky tvers bwvar.
LOOP AT i_ckis_temp INTO wa_ckis_temp.
wa_ckis-kalnr = wa_ckis_temp-kalnr.
wa_ckis-kadky = wa_ckis_temp-kadky.
wa_ckis-posnr = wa_ckis_temp-posnr.
wa_ckis-typps = wa_ckis_temp-typps.
wa_ckis-kstar = wa_ckis_temp-kstar.
wa_ckis-matnr1 = wa_ckis_temp-matnr1.
wa_ckis-menge = wa_ckis_temp-menge.
wa_ckis-gpreis = wa_ckis_temp-gpreis.
CLEAR wa_keko1.
READ TABLE i_keko1 INTO wa_keko1
WITH KEY kalnr = wa_ckis_temp-kalnr
kalka = wa_ckis_temp-kalka
kadky = wa_ckis_temp-kadky
tvers = wa_ckis_temp-tvers
bwvar = wa_ckis_temp-bwvar
BINARY SEARCH.
IF sy-subrc = 0.
wa_ckis-matnr = wa_keko1-matnr.
wa_ckis-werks = wa_keko1-werks.
ENDIF.
APPEND wa_ckis TO i_ckis.
CLEAR: wa_ckis_temp, wa_ckis.
ENDLOOP.
ENDIF.
REFRESH: i_keko1, i_ckis_temp.
ENDIF.
endform. " get_keko_ckisHi Try minimising the conditions in where clause
SELECT fields..... FROM CKIS
WHERE KALNR = KEKO-KALNR AND
KADKY = KEKO-KADKY AND
TVERS = KEKO-TVERS AND
TYPPS = 'M'.
after this, deleting unwanted records from internal table as per pending conditions...
Regds,
Anil -
BO DI for extracting data from legacy system to SAP BW 7.0
Hi,
Has anyone worked on scenario where BO Data Integrator is being used as ETL tool for extracting data from legacy systems to SAP BW 7.0 ?
Please share your experience on such a landscpae or related documents any of you had come across.
Regards,
PriteshThere are couple of them - Lawson ERP, Kalido, AS/400. ECC 5.0 might be there as well.
Regards,
Pritesh.
Edited by: pritesh prakash on Jun 14, 2010 2:00 PM -
BO DI for extracting data from legacy to SAP BW 7.0
Hi,
Has anyone worked on scenario where BO Data Integrator is being used as ETL tool for extracting data from legacy systems to SAP BW 7.0 ?
Please share your experience on such a landscpae or related documents any of you had come across.
Regards,
PriteshHi,
BO Integrator connects with other system (Database) and you will be creating your reports on the top of that DB or system. It never saw it being used to pull data from legacy to BW.
Regards,
Bashir Awan -
Generate Insert Statement Script to Extract Data from Table in Oracle 7i
Hi all, I have an old Oracle legacy system that is running for over 15 years.Every now and then we need to extract data from this table@ ORacle 7i to be imported back to Oracle 10G.
My thoughts are to create a script of Insert statements in oracle 7 and that to be deployed back to Oracle 10G.
I found this scripts in Google and not sure how exactly this works.Any explanation on thsi scripts , would be greatly appreciated.I find this scripst may help to generate a set of insert statements from that table to the latest table at 10G.
<pre>
-- Step 1: Create this procedure:
create or replace Function ExtractData(v_table_name varchar2) return varchar2 As
b_found boolean:=false;
v_tempa varchar2(8000);
v_tempb varchar2(8000);
v_tempc varchar2(255);
begin
for tab_rec in (select table_name from user_tables where table_name=upper(v_table_name))
loop
b_found:=true;
v_tempa:='select ''insert into '||tab_rec.table_name||' (';
for col_rec in (select * from user_tab_columns
where
table_name=tab_rec.table_name
order by
column_id)
loop
if col_rec.column_id=1 then
v_tempa:=v_tempa||'''||chr(10)||''';
else
v_tempa:=v_tempa||',''||chr(10)||''';
v_tempb:=v_tempb||',''||chr(10)||''';
end if;
v_tempa:=v_tempa||col_rec.column_name;
if instr(col_rec.data_type,'CHAR') > 0 then
v_tempc:='''''''''||'||col_rec.column_name||'||''''''''';
elsif instr(col_rec.data_type,'DATE') > 0 then
v_tempc:='''to_date(''''''||to_char('||col_rec.column_name||',''mm/dd/yyyy hh24:mi'')||'''''',''''mm/dd/yyyy hh24:mi'''')''';
else
v_tempc:=col_rec.column_name;
end if;
v_tempb:=v_tempb||'''||decode('||col_rec.column_name||',Null,''Null'','||v_tempc||')||''';
end loop;
v_tempa:=v_tempa||') values ('||v_tempb||');'' from '||tab_rec.table_name||';';
end loop;
if Not b_found then
v_tempa:='-- Table '||v_table_name||' not found';
else
v_tempa:=v_tempa||chr(10)||'select ''-- commit;'' from dual;';
end if;
return v_tempa;
end;
show errors
-- STEP 2: Run the following code to extract the data.
set head off
set pages 0
set trims on
set lines 2000
set feed off
set echo off
var retline varchar2(4000)
spool c:\t1.sql
select 'set echo off' from dual;
select 'spool c:\recreatedata.sql' from dual;
select 'select ''-- This data was extracted on ''||to_char(sysdate,''mm/dd/yyyy hh24:mi'') from dual;' from dual;
-- Repeat the following two lines as many times as tables you want to extract
exec :retline:=ExtractData('dept');
print :retline;
exec :retline:=ExtractData('emp');
print :retline;
select 'spool off' from dual;
spool off
@c:\t1
-- STEP3: Run the spooled output c:\recreatedata.sql to recreate data.
Source:http://www.idevelopment.info/data/Oracle/DBA_tips/PL_SQL/PLSQL_5.shtml
</pre>Thanks Justin.
I get what you are saying,i really wanted to see the output of the codes, because the furtherst i could get from that code is
SELECT EXTRACTDATA('MYTABLE') FROM MYTABLE;
and it generated this:
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
"select 'insert into MYTABLE ('||chr(10)||'DATE1,'||chr(10)||'TIME1,'||chr(10)||'COUNTS) values ('||decode(DATE1,Null,'Null','to_date('''||to_char(DATE1,'mm/dd/yyyy hh24:mi')||''',''mm/dd/yyyy hh24:mi'')')||','||chr(10)||''||decode(TIME1,Null,'Null',TIME1)||','||chr(10)||''||decode(COUNTS,Null,'Null',COUNTS)||');' from MYTABLE;
select '-- commit;' from dual;"
I was expecting a string of
insert into mytable values (19/1/2009,1,1);
insert into mytable values (19/10/2008,5,10);
Thanks for the explanation . -
Sample pgm for moving data from table control to internal table
Hi Experts,
I am newbi to ABAP. I don't have good material for Table control . Appreciate if you direct me to some good source of knowledge on Table control.
The problem at hand : I am trying to move info/data from table control (in screen painter/ input and output mode ) to ITAB but couldn't . Sample pgm if possible.
<b>Modify ITAB index TC-Current_Line .</b>
The above statement is not inserting new lines to ITAB . Help me!
Thanks for your timehi,
do like this...
<b>PROCESS AFTER INPUT.</b>
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TAB1'
LOOP AT itab_det.
CHAIN.
FIELD itab_det-comp_code.
FIELD itab_det-bill_no.
FIELD itab_det-bill_date.
FIELD itab_det-vend_cust_code.
FIELD itab_det-bill_amt.
MODULE <b>tab1_modify</b> ON CHAIN-REQUEST.
ENDCHAIN.
FIELD itab_det-mark
MODULE tab1_mark ON REQUEST.
ENDLOOP.
<b>MODULE tab1_modify INPUT.</b>
APPEND itab_det.
<b>ENDMODULE. "TAB1_MODIFY INPUT</b> -
How to extract data from table for huge volume
Hi,
I have around 200000 material doc number for which need to get material number from MSEG table but while using SE16 it gives dump , i have even tried breaking it into batches of 20000 records but still SAP gives dump on executing SE16 for MSEG. Please advise if there is any alternate way to get data from SE16 table for such a large volume.
Note: In our system SE16N does not work, only SE16 is there for our SAP version.
Thanks,
VihaanHi Jurgen,
Thanks for your reply.
I am getting Dump when i enter more than 5000 records as input parameter in MSEG, if I put more than that then it gives dump as "ABAP runtime errors SAPSQL_STMNT_TOO_LARGE ".
I understand that I can extract data restrciting 5000 every time but I have around 250000 material docs so that means if we consider batches of 5000 I need to run the step more 50 times--> 50 excel files. I wanted to avoid that as that is going to take lots of my time.
Any suggestion, please help.
Also wanted to highlight that apart from Material Doc number I am entering Plant (8 plants) and Mvt type (14 mvt type) also as input parameter.
Regards,
Vihaan
Edited by: Vihaan on Mar 25, 2010 12:30 AM -
Code Challange - Code for extracting content from a file in KM
Hi,
I want to extract content from a file which is in KM Repository using the Webdynpro View. I wrote the following code for the extraction. But it is throwing some exception.
Code Written:
<b>
URLConnection conn = null;
DataInputStream data = null;
String line;
StringBuffer buf = new StringBuffer();
wdContext.currentContextElement().setTextdisp("Hello");
try {
URL theURL = new URL("http://ctssap1:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/News/New%20text.txt");
conn = theURL.openConnection();
// conn.connect();
wdContext.currentContextElement().setTextdisp("Inside Try");
data = new DataInputStream(new BufferedInputStream(
conn.getInputStream()));
while ((line = data.readLine()) != null) {
buf.append(line + "\n");
data.close();
String buffer = new String(buf);
wdContext.currentContextElement().setTextdisp(buffer);
catch (IOException e) {
wdContext.currentContextElement().setTextdisp("IO Error:" + e.getMessage());
}</b>
Exception Got:
<b>IO Error:Server returned HTTP response code: 401 for URL: http://ctssap1:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/News/New%20text.txt</b>
Can anyone help me out in this process... or please suggest some other way to extract the content.
Thanks in Advance.
Regards,
Srinivas.Hi Srinivas,
VaPath will have the path of ur document.
Check this modified code snippet which will answer ur questions and solve ur problem.
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
IUser sapUser = wdClientUser. getSAPUser();
com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
IResourceContext context = new ResourceContext(ep5User);
/Specify the path of ur document here./
RID pathRID = RID.getRID("/documents/file2");
IResource resource = ResourceFactory.getInstance()
.getResource(context);
InputStream in = resource.getContent().getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int bytesread = 0;
while ((bytesread = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesread);
String myData = out.toString();
/*myFile will containS the content of the document./
wdComponentAPI.getMessageManager().reportSuccess(myData);
Hope this solves ur problem.
Regards,
Sowjanya. -
hi friends,
i need to extract complete material master data from 4.7 and upload to ecc 6.0.
to extract the material master data, which is the best way, how do i do that
is query a good way of extracting this data, are there any disadvantages.
thanks & rgds.When extracting the data take the groups as your starting point. Make a report where on the selection screen the user can enter the material group. Create a job for this report (SM36) and schedule it in background, since it will probably be running for quite some time, especially when you have loads and loads of materials.
You can extract the data from several database tables in ONE report and put them together in ONE internal table using an INNER JOIN select. But depending on the data it could (again) take some time for the report to be done. Another option would be to do several selects from different database tables and put them into separate internal tables. After selecting all the data you can collect them in ONE internal table again, and download the data to application server.
You can also download all internal tables separately to application server. For linking the files together for upload again use an identifier in the file name. This has the disadvantage that when uploading them other system, you will have to link all records together (like you would do when collecting them from database at first). So all the data that you download must have some fields with which can identify that row 1 from internal table A, belongs to row x from internal table B.
There are many ways which lead to the correct result, now it is up to you to select one. And maybe other people have other (better) suggestions, which will only make it harder for you.
So I wish you all the best for this. -
Extracting date from table, format problems
Hi
I am working on scm side, where i need to get the creation date of material from table /sapapo/matkey .
The problem is the field has a time stamp .
intially i was using fm : CONVERSION_EXIT_TSTLC_OUTPUT
to get the date , but the problem is this fm is not correct , as it depends upon the user date format , and gets date from display
of the table rather than the server . This is giving me an error
as the date format can be different everytime , it can be yyyymmdd or yyyyddmm.
Which is the way of firstly getting creation date from the time stamp , and in the format stored by databse.Hi thanks for ur replies.
My exact requirement is , that i need to pass the to a bapi which takes the date in the format : yyyymmdd.
So finally whatever be the user date format , i should use the time stamp and get the date , in one standard format always.
It can either be yyyymmdd or YYYYddmm , so that i can set the input for bapi accordingly. -
How to extract data from table in PDF document
Can somebody let me know that how to read tables from a PDF document as I need to process this data further and I want it to be saved as a database.
Google around; you might find a couple of sourceforge project.
Rich. -
Help to correct to codes to move data from tables! please help!
HI,
There is a internal table t and t1. I used loop to move the data which zuonr has no value from t to t1.
BSID TABLE:
KUNNR ZUONR
0000052984 no value           0000052984 no value 00052984 2007/06決算
00052984 no value
000052984  2007/07振当
0000052984 MSFT047/07
0000052984 MSFT061/07
*what I need to do is that to move all the data belonge to the same kunnr whenever zuonr = space happend. *.
The problem is that the data which zuonr = space is moved to t1 successful, but the other data which belong to the same kunnr has zuonr valune still remain.
-Question_ : How to move all the data belong to the same kunnr whenever zuonr = space happend.
DATA: BEGIN OF t OCCURS 0,
bukrs LIKE knb1-bukrs,
zuonr Like bsid-zuonr, "sort key "CR01
belnr LIKE bsid-belnr,
kunnr LIKE kna1-kunnr,
bldat LIKE bsid-bldat,
budat LIKE bsid-budat,
netdt LIKE bsega-netdt,
waers LIKE bsid-waers,
wrbtr LIKE bsid-wrbtr,
shkzg LIKE bsid-shkzg,
xblnr LIKE bsid-xblnr, "WD041005a
sgtxt LIKE bsid-sgtxt,
dmbtr LIKE bsid-dmbtr,
END OF t.
DATA : t1 LIKE STANDARD TABLE OF t WITH HEADER LINE.
*LOOP AT t WHERE zuonr EQ space.
MOVE-CORRESPONDING t TO t1.
APPEND t1.
ENDLOOP.*
How can I write the loop statement to mention the KUNNR
Please help, thank you!!Hi,
Try this.
data : wa_t like line of table t.
field-symbols : <f_t> like line of table t.
sort t by kunnr.
Loop at t where zuonr eq space.
read table t1 with key kunnr = t-kunnr.
if sy-subrc = 0.
continue.
endif.
read table t into wa_t with key kunnr = t-kunnr.
if sy-subrc = 0.
loop at t assigning <f_t> from sy-tabix..
if <f_t>-kunnr = wa_t-kunnr.
move-corresponding <f_t> to t1.
append t1.
else.
exit.
endif.
endloop.
endif.
endloop.
Regards,
Mohaiyuddin -
How to extract data from table
Hi
I want to export all the data present in the table to an excel sheet.
I know that we can export from
menu bar
system> List> save>Local file> spread sheet to local system
But by doing that only some data is being downloaded but i want the whole data present in that table. I had extended the width to maximum but the total entries are more than the width i want that data also to be downloaded into the local system
Points will be rewarded surely
Regards
LaxmanHave tried option
Menu Path Edit-> download -> spreadshet
and
have you removed value in maximum no. hits field, by default it value is 200
Message was edited by:
Saida Rao Devarasetty -
Extracting data from HR tables
Hi All,
I have to extract data from table in HR with is containes one field with different subtype . how to get the data in to BW. where to apply filters , best way to do it.
harryHi,
Is this transactional or master data you want to extract?
HR works on Infotypes you need to check whether or not there is standard extractor if not then you need to find a table which this data is stored on. Once you have found the table then create a generic datasource in the source system. Then within BW replicate this datasource, create Infosource/ Transfer rules and load into ODS/Cube/InfoObject.
Also depending on which version of BW you are using you can create a DTP. -
How to create a RFC destination for extracting data to HANA
Hello All,
Could someone help me in providing a document or note on how to create a RFC destination for extracting data from SAP data source to HANA using SAP LT replication server ?
I am able to create a data base connection while transforming data from non SAP data source,but wasnt able to transform data which is from SAP abap tables .Hi Venkatesh,
In SM59 t.code we create RFC destinations.
Go thru the video link for creating RFC destinations step by step
How to setup a trusted RFC connection between SAP systems: a step-by-step guide - YouTube
Maybe you are looking for
-
My iPod touch suddenly stopped working. It was fine earlier, but when I went back a few hours later, the screen had gone black and I was unable to turn it on. It is now unresponsive and my computer does not recognize it when it is plugged in. I thoug
-
Is there any way to know when an app is going to be discontinued?
I purchased an app around eight months ago for $13. I forgot about it until I was reloading apps onto my new IPad. When I went to find it, it was no longer in the app store at all. I contacted the support people who told me that since it was "so long
-
In a very long Document such as SO or PO how to search for say an ITEM?
Hi Forum, Sometimes documents such as quotations, Sales Orders, Purchase Orders could be very long over say over 300 items. How can we search for something within that document while staying in the document - For example specific item in the document
-
Getting exception whil calling an oracle stored procedure from java program
Dear All, I encounter this error in my application when I call only the stored procedure but the view is executing fine from the application and my environment is as follow: Java 1.4 oracle 10g oracle jdbc driver:9.2.0.8.0 websphere portal 6.0.0.1 th
-
Slideshow with multiple images on the screen at once
I'm trying to create a graduation slideshow in Premiere Elements 11 that mixes both still photos and video. I can handle the video portion just fine (I think!), but I'm struggling to get the photos to do what I want. I would like five photos (and a