UNIQUE Problem in pulling DATA from DATA base table to internal table
Dear Experts,
I am new to ABAP. I have a very basic question but looks a quite puzzling one to me. Hemnce I am posting it here.
I am facing an unique problem in pulling data from database table and populating that data into internal table for further use.
The data in the database table "Zlt_mita" with fields M1 (Employee Name, Type: Char20) and M2 (Employee Code, Type Char7) are:
Plz refer the screenshot in the attached file:
My Code:
1) When I try to pull data from Dbase table by taking M2 as parameter.
This code is succcessful and I am able to populate data in internal table it_dat.
TYPES: Begin Of ty_DAT,
M1 TYPE Zlt_mita-M1,
M2 TYPE ZLT_mita-M2,
END OF ty_DAT.
DATA: it_dat TYPE STANDARD TABLE OF ty_dat with header line,
wa_dat TYPE ty_dat.
PARAMETERS: p_mitar TYPE Zlt_Mita-M2.
SELECT M1
M2
FROM ZLt_mita
INTO TABLE it_dat
Where M2 = p_mitar.
Loop at it_dat into wa_dat.
WRITE:/2 wa_dat-M1,
10 wa_dat-M2.
ENDLOOP.
2) When I try to pull data from Dbase table by taking M1 as parameter.
This code is NOT succcessful and I am NOT able to populate data in internal table it_dat.
TYPES: Begin Of ty_DAT,
M1 TYPE Zlt_mita-M1,
M2 TYPE ZLT_mita-M2,
END OF ty_DAT.
DATA: it_dat TYPE STANDARD TABLE OF ty_dat with header line,
wa_dat TYPE ty_dat.
PARAMETERS: P_Mita TYPE ZLT_Mita-M1.
SELECT M1
M2
FROM ZLt_mita
INTO TABLE it_dat
Where M1 = P_Mita.
Loop at it_dat into wa_dat.
WRITE:/2 wa_dat-M1,
10 wa_dat-M2.
ENDLOOP.
Why is this happening when both M1 and M2 are Type Character fields.
Looking forward for your replies.
Regards
Chandan Kumar
Hi Chandan ,
Database fetch is case sensitive ,So u need to give exact format in where condition.
Make your parameter and database in same case so that you need not worry about case sensitivity .
Check the lowecase check box in the domain .
Then declare your parameter
PARAMETERS:
P_Mita
TYPE ZLT_Mita-M1 LOWER CASE .
You can do the vice versa also by unchecking lowercase and giving Upper case instead of lower in parameter declartion .
Regards ,
Juneed Manha
Similar Messages
-
How to extract data from info cube into an internal table using ABAP code
HI
Can Anyone plz suggest me
How to extract data from info cube into an internal table using ABAP code like BAPI's or function modules.
Thankx in advance
regds
AJAYHI Dinesh,
Thankq for ur reply
but i ahve already tried to use the function module.
When I try to Use the function module RSDRI_INFOPOV_READ
I get an information message "ERROR GENERATION TEST FRAME".
can U plz tell me what could be the problem
Bye
AJAY -
Join data from a file with an internal table
Hi to everybody!!
I need help, I don't know how to join two differents data, one of them is internal...
This select fill my itab
SELECT PERNR PERID VORNA NACHN FROM PA0002 APPENDING TABLE itab_tabla
WHERE
PA0002~BEGDA <= SY-DATUM AND
PA0002~ENDDA >= SY-DATUM AND
PERID = G_PERID.
ENDLOOP.
Now I have to insert inside the table more data that pass from a file...but I don't know how to join this... can anybody help me?
Thanks a lot
Regards,
RebecaHI,
you will need to upload the file by Using the FM GUI_UPLOAD.
this will take the data from the file to an internal table that you will have to declare.
once you get the data in to your table,you can merge both the tables in to another final table or in the 1st internal table if all the fields are there and modify the table.so the table will have the records of both the tables.
after you get the data in your second table"
loop at itab2.
move: <field 1> to itab1.
<field 2> to itab1.
modify itab1.
endloop. -
How to fetch data from bseg based on 2 internal tables in 1 select query?
hi,
i have bukrs and belnr in one internal table and bukrs and vbeln in another internal table..now if i select from bseg twice using for all entries for fields bukrs vbeln and bukrs belnr twice in 2 select statements its fine..but since bseg is a huge table i want to use select only once..but the problem is that none of the belnrs in the one internal table will have vbeln in another internal table....ie if vbeln is selected from bseg based on belnr in 1 internal table non eof those vbeln will be equal to vbeln on another internal tables..in this scenario even if i take all data from two internal tables into 1 single internal table and then use for all entries on vbeln and belnr of that table ..but i think this will not work because and AND operator will not work because no record will satisfy both vbeln and belnr conditions..even if i use OR operator if the 1st condition satisfies the select clause will not enter into the second clause and all the records will not be fetched...Please help how should i tackle this..Hi vijaya,
no simple select statement solution so far.
As BSEG is a huge table you should try to get the full key values into another internal table first.
SAP avoids direct selections from BSEG.
Pleas consider the use of one of the secondary index tables first:
BSAD : Accounting: Secondary Index for Customers (Cleared Items)
BSAK : Accounting: Secondary Index for Vendors (Cleared Items)
BSAS : Accounting: Secondary Index for G/L Accounts (Cleared Item
BSEC : One-Time Account Data Document Segment
BSEG : Accounting Document Segment
BSID : Accounting: Secondary Index for Customers
BSIK : Accounting: Secondary Index for Vendors
BSIS : Accounting: Secondary Index for G/L Accounts
you may include
BKPF : Accounting Document Header
for restrictions about time and document type.
The last step is a FOR ALL ENTRIES selection from BSEG providing the full key values.
Although you may have even more selects, the overall performance will be much better.
Regards,
Clemens -
Read data from xml files and populate internal table
Hi.
How to read data from xml files into internal tables?
Can u tell me the classes and methods to read xml data..
Can u explain it with a sample program...<pre>DATA itab_accontextdir TYPE TABLE OF ACCONTEXTDIR.
DATA struct_accontextdir LIKE LINE OF itab_accontextdir.
DATA l_o_error TYPE REF TO cx_root.
DATA: filename type string ,
xmldata type xstring .
DATA: mr TYPE REF TO if_mr_api.
mr = cl_mime_repository_api=>get_api( ).
mr->get( EXPORTING i_url = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
IMPORTING e_content = xmldata ).
WRITE xmldata.
TRY.
CALL TRANSFORMATION id
SOURCE XML xmldata
RESULT shiva = itab_accontextdir.
CATCH cx_root INTO l_o_error.
ENDTRY.
LOOP AT itab_accontextdir INTO struct_accontextdir.
WRITE: / struct_accontextdir-context_id,
struct_accontextdir-context_name,
struct_accontextdir-context_type.
NEW-LINE.
ENDLOOP.</pre>
<br/>
Description:
In the above code snippet I am storing the data in an xml file(you know xml is used to store and transport data ) called 'xml_accontextdir.xml' that is uploaded into the MIME repository at path 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'.
The below API is used to read a file in MIME repo and convert it into a string that is stored in ' xmldata'. (This is just a raw data that is got by appending the each line of xml file).
mr = cl_mime_repository_api=>get_api( ).
mr->get( EXPORTING i_url = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
IMPORTING e_content = xmldata ).
Once the 'xmldata' string is available we use the tranformation to parse the xml string that we have got from the above API and convert it into the internal table.
<pre>TRY.
CALL TRANSFORMATION id
SOURCE XML xmldata
RESULT shiva = itab_accontextdir.
CATCH cx_root INTO l_o_error.
ENDTRY.</pre>
Here the trasnsformation 'id ' is used to conververt the source xml 'xmldata' to resulting internal table itab_accontextdir, that have same structure as our xml file 'xml_accontextdir.xml'. In the RESULT root of the xml file has to be specified. (In my the root is 'shiva').
Things to be taken care:
One of the major problem that occurs when reading the xml file is 'format not compatible with the internal table' that you are reading into internal table. Iin order to get rid of this issue use one more tranformation to convert the data from the internal table into the xml file.
<pre>TRY.
CALL TRANSFORMATION id
SOURCE shiv = t_internal_tab
RESULT XML xml.
CATCH cx_root INTO l_o_error.
ENDTRY.
WRITE xml.
NEW-LINE.</pre>
<br/>
This is the same transformation that we used above but the differnce is that the SOURCE and RESULT parameters are changed the source is now the internal table and result is *xml *string. Use xml browser that is available with the ABAP workbench to read the xml string displayed with proper indentation. In this way we get the format of xml file to be used that is compatable with the given internal table.
Thank you, Hope this will help you!!!
Edited by: Shiva Prasad L on Jun 15, 2009 7:30 AM
Edited by: Shiva Prasad L on Jun 15, 2009 11:56 AM
Edited by: Shiva Prasad L on Jun 15, 2009 12:06 PM -
How to Copy data from field symbol to Dynamic Internal Table
Hi,
I want to copy the data between two dynamic Internal tables . Following is the code were I have data in the field symbol wanted to transfer it to the other Internal table :
REPORT ztest.
DATA:
gd_dref TYPE REF TO data,
gd_dref1 TYPE REF TO data.
FIELD-SYMBOLS: <fs1> TYPE any,
<fs_wa> TYPE any,
<field> TYPE any,
<fs_wa1> TYPE ANY TABLE. * Contains data from p_src
*Copy data from p_src to p_dest*
PARAMETERS: p_src LIKE dd02l-tabname . * Name of Dynamic Internal table *
p_dest LIKE dd02l-tabname . * Name of Dynamic Internal table*
*DATA : lt_csks LIKE p_dest WITH HEADER LINE.
START-OF-SELECTION.
CREATE DATA gd_dref TYPE (p_src).
CREATE DATA gd_dref1 TYPE TABLE OF (p_src).
ASSIGN gd_dref->* TO <fs_wa>.
ASSIGN gd_dref1->* TO <fs_wa1>.
SELECT * FROM (p_src) INTO TABLE <fs_wa1>.
*Write out data from FIELD SYMBOLS TO Table.
loop at <fs_wa1> into <fs_wa>.
do.
assign component sy-index
of structure <fs_wa> to <field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <field>.
else.
write: / <field>.
endif.
enddo.
endloop.
*Need Logic To Copy the Data to p_dest table from <fs_wa1>.
*p_dest is a table having a similar structure to table p_src .
*Need Logic To Copy the Data to p_dest table from <fs_wa1>.
EXIT.
Thanks in Advance.try this...
I have extended your source code and just used vbak/vbap as an example as they have some common fields like vbeln/erdat etc which corresponds with your requirement of 'similar structure' i.e. shared/common fields in both.
Cheers...
report ztest.
data:
gd_dref type ref to data,
gd_dref1 type ref to data,
gd_dref_str type ref to data,
gd_dref_tab type ref to data.
field-symbols:
<fs1> type any,
<fs_wa> type any,
<fs1_dest_str> type any,
<fs_dest_tab> type any table,
<field> type any,
<fs_wa1> type any table.
* contains data from p_src
*Copy data from p_src to p_dest*
parameters: p_src like dd02l-tabname default 'vbak',
* name of dynamic internal table *
p_dest like dd02l-tabname default 'vbap'.
* name of dynamic internal table*
*data : lt_csks like p_dest with header line.
start-of-selection.
create data gd_dref type (p_src).
create data gd_dref1 type table of (p_src).
assign gd_dref->* to <fs_wa>.
assign gd_dref1->* to <fs_wa1>.
select * from (p_src) into corresponding fields of table <fs_wa1>
up to 3 rows
where vbeln ne space.
create data gd_dref_str type (p_dest).
create data gd_dref_tab type standard table of (p_dest).
assign gd_dref_str->* to <fs1_dest_str>.
assign gd_dref_tab->* to <fs_dest_tab>.
*write out data from field symbols to table.
loop at <fs_wa1> into <fs_wa>.
" break-point here - can see vbeln/waers/create date/ etc move over to new structure
" the 'common' fields of your structures - the same will happen. if they not the same name you will have to do an
" explicit move i.e. if fieldname = xyz ....move fieldxyz to new field123....after the move-corre
break-point.
move-corresponding <fs_wa> to <fs1_dest_str>.
insert <fs1_dest_str> into table <fs_dest_tab>.
** do.
** assign component sy-index
** of structure <fs_wa> to <field>.
** if sy-subrc <> 0.
** exit.
** endif.
** if sy-index = 1.
** write:/ <field>.
** else.
** write: / <field>.
** endif.
** enddo.
endloop.
" write out some dest data from the dest table build from previous loop
loop at <fs_dest_tab> assigning <fs1_dest_str>.
do.
assign component sy-index of structure <fs_wa> to <field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <field>.
else.
write: / <field>.
endif.
enddo.
endloop. -
Data from field symbol into an internal table or workarea
Hi Experts,
I have field symbol in which i get the data. I want to get this data into an internal table of type any or into an work area. How is this possible.
My declaration for field symbol is as follow:
FIELD-SYMBOLS: <l_t_data> TYPE any.
DATA l_r_data TYPE REF TO data.
CREATE DATA l_r_data type STANDARD TABLE OF (l_local_tab).
ASSIGN l_r_data->* TO <l_t_data>.
I get the data in this field symbol <l_t_data>. by passing into a funtion module. and I get the data into it. Now i have to assign the values of this field symbol to any internal table or to a work are how do i do it. Please help.
Regards,
Prashant.Not exactly sure what you need here, but.....
FIELD-SYMBOLS: <l_t_data> TYPE TABLE. "<<-- Change this
FIELD-SYMBOLS: <l_s_data> TYPE ANY. "<<---Add This
DATA l_r_data TYPE REF TO data.
CREATE DATA l_r_data type STANDARD TABLE OF (l_local_tab).
ASSIGN l_r_data->* TO <l_t_data>.
Loop at <l_t_data> assigning <l_s_data>.
* Do what ever using <l_s_data>
Endloop.
Regards,
Rich Heilman
Edited by: Rich Heilman on Feb 28, 2008 2:42 PM -
Transfer data from XI message interafce to internal table
my code is like this..
TYPES: BEGIN OF xxx,
vbeln TYPE vbrk-vbeln,
END OF xxx.
Data yyy TYPE TABLE OF xxx.
i have an XI mesage interface where i have an internal table which holds 10 numbers(itab). i want those to be transferref to my internal table in the proxy class. how do i do that. i am done upto this part..
LOOP AT itab into cstr
where cstr is a string to hold the individual values of itab for transfer
ENDLOOPresolved
-
Get data in editable ALV back to internal table without data_changed ev?
Hi,
I have an editable ALV using classes to whch I have users the option to edit directly on the screen or upload data from an excel. The event data_changed gets triggered when users edit the table on the screen.
However when EXCEL is uploaded, I refresh the table display. So, I need a way to get the data from the ALV into a internal table to check which rows were update using the excel and save them into the db table.
PrakashHi!
For more information, inspect programs suiting the mask "BCALVEDIT*" and the thread with header "How to make a row of ALV editable " (I know this is some more steps further from your demand but it may be useful) at URL " How to make a row of ALV editable " .
If you want to study more BC412 "EnjoySAP Controls" may help you.
*--Serdar -
When to refresh Servlet data from Data Base
Hello all,
I have a servlet that retrive few hundreds thousands records from data base table.
The data in data base table being updated once or twice in every week.
Since same servlet instance serve all users, that access the servlet many times a day.
I would like to avoid retriving the data from data base on each servlet access.
and make the users use same data already retrieved and kept in servlet members.
First, what is the best way to avoid data retrive from data base on each servlet access?
and how could I have some kind of trigger that will refresh servlet data from data base every few days?
Thanks in advance for every idea.
AmiJava_A wrote:
Thanks Saish for your reply.
I'm not using DAO in my application but retrive the data from BI data base using a web service. response time querying the BI data base is not quick enuogh.
Since, I wouldn't want to query the BI server on each servlet access.
Because the data I retrived at the begining using the web service contains all required data for all servlet requests, I thought to store the data (~200K rows) once in the servlet which will be using for all requests.
Why not store the results locally in your own database after you fetch them?
This still leave me with the questions: in which event should I query the BI data, and also when or in which event should I update the data again from BI server?
Query at startup, an user demand, when data becomes stale. It depends on your requirements.
>
Thanks
Ami- Saish -
Problems While Extracting Hours From Date Field
Hi Guys,
Hope you are doing well.
I am facing some problems while extracting hours from date field. Below is an example of my orders table:-
select * from orders;
Order_NO Arrival Time Product Name
1 20-NOV-10 10:10:00 AM Desktop
2 21-NOV-10 17:26:34 PM Laptop
3 22-JAN-11 08:10:00 AM Printer
Earlier there was a requirement that daily how many orders are taking place in the order's table, In that I used to write a query
arrival_time>=trunc((sysdate-1),'DD')
and arrival_time<trunc((sysdate),'DD')
The above query gives me yesterday how many orders have been taken place.
Now I have new requirement to generate a report on every 4 hours how many orders will take place. For an example if current time is 8.00 AM IST then the query should fetch from 4.00 AM till 8 AM how many orders taken place. The report will run next at 12.00 PM IST which will give me order took place from 8.00 AM till 12.00 PM.
The report will run at every 4 hours a day and generate report of orders taken place of last 4 hours. I have a scheduler which will run this query every hours, but how to make the query understand to fetch order details which arrived last 4 hours. I am not able to achieve this using trunc.
Can you please assist me how to make this happen. I have checked "Extract" also but I am not satisfied.
Please help.
Thanks In Advance
Arijityou may try something like
with testdata as (
select sysdate - level/24 t from dual
connect by level <11
select
to_char(sysdate, 'DD-MM-YYYY HH24:MI:SS') s
, to_char(t, 'DD-MM-YYYY HH24:MI:SS') t from testdata
where
t >= trunc(sysdate, 'HH') - numtodsinterval(4, 'HOUR')
S T
19-06-2012 16:08:21 19-06-2012 15:08:21
19-06-2012 16:08:21 19-06-2012 14:08:21
19-06-2012 16:08:21 19-06-2012 13:08:21
19-06-2012 16:08:21 19-06-2012 12:08:21trunc ( ,'HH') truncates the minutes and seconds from the date.
Extract hour works only on timestamps
regards
Edited by: chris227 on 19.06.2012 14:13 -
Unable to access the data from Data Management Gateway: Query timeout expired
Hi,
Since 2-3 days the data refresh is failing on our PowerBI site. I checked below:
1. The gateway is in running status.
2. Data source is also in ready status and test connection worked fine too.
3. Below is the error in System Health -
Failed to refresh the data source. An internal service error has occurred. Retry the operation at a later time. If the problem persists, contact Microsoft support for further assistance.
Error code: 4025
4. Below is the error in Event Viewer.
Unable to access the data from Data Management Gateway: Query timeout expired. Please check 1) whether the data source is available 2) whether the gateway on-premises service is running using Windows Event Logs.
5. This is the correlational id for latest refresh failure
is
f9030dd8-af4c-4225-8674-50ce85a770d0
6.
Refresh History error is –
Errors in the high-level relational engine. The following exception occurred while the managed IDataReader interface was being used: The operation has timed out. Errors in the high-level relational engine. The following exception occurred while the
managed IDataReader interface was being used: Query timeout expired.
Any idea what could have went wrong suddenly, everything was working fine from last 1 month.
Thanks,
RichaNever mind, figured out there was a lock on SQL table which caused all the problems. Once I released the lock it PowerPivot refresh started working fine.
Thanks. -
Error while extracting data from data source 0RT_PA_TRAN_CONTROL, in RSA7
Hi Gurs,
I'm getting the below error while extracting data from data source 0RT_PA_TRAN_CONTROL, in RSA7. (Actullly this is IS Retail datasource used to push POSDM data into BI cubes)
The error is:
Update mode "Full Upload" is not supported by the extraction API
Message no. R3011
Diagnosis
The application program for the extraction of the data was called using update mode "Full Upload". However, this is not supported by the InfoSource.
System Response
The data extraction is terminated.
Procedure
Check for relevant OSS Notes, or send a problem message of your own.
Your help in this regd. would be highly appreciated.
Thanks,
David.Hi David,
I have no experience with IS Retail data sources. But as message clearly say this DS is not suppose to be ran in Full mode.
Try to switch you DTPs/Infopackages to Delta mode.
While to checking extraction in source system, within TA RSA3 = Extractor checker, kindly switch Update mode field to Delta.
BR
m./ -
Runtime error when Transfering data from data object to a file
Hi everybody,
I'm having a problem when I transfer data from data object to file. The codes like following :
data : full_path(128).
OPEN DATASET full_path FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
and transfer data from flat structure to this file full_path
move: tab to c_output-tab_5,
tab to c_output-tab_4,
tab to c_output-tab_3.
transfer c_output to full_path. // Error Line
The detail error like the following:
For the statement
"TRANSFER f TO ..."
only character-type data objects are supported at the argument position
"f".
In this case. the operand "f" has the non-character-type "u". The
current program is a Unicode program. In the Unicode context, the type
'X' or structures containing not only character-type components are
regarded as non-character-type.
transfer c_output to full_path. " Line error
Please help me to fix this issue !
Thank you in advance !
Edited by: Hai Nguyen on Mar 4, 2009 10:55 AMHi Mickey,
Thanks for your answer,
I found out that the structure c_output have the field with data type X. I know that the cause of the issue.
begin of c_output,
vbeln(10),
tab_5 like tab,
posnr(6),
tab_4 like tab,
topmat(18),
tab_3 like tab,
end of c_output.
data : tab type X value 9.
Could you tell me how to fix it ? What I have to do in this situation ?
Thank you very much ! -
DATA BASE TABLE AND INTERNAL TABLE
Dear Friends,
please help me out in getting complete information about database table and internal table.
you can email me at < Removed by moderator - please maintain e-mail iDs in Business Card>
Message was edited by:
Arun VaradarajanHi Hazi,
<b>DATABASE Tables :</b>
This are the tables which are stored in the database (eg Oracle , informix , DB2 etc..) Physically. u can view it from T-codes SE11 or SE16. here in SE11 u can create ur own Transparent table.
for more information...
http://www.sapbrainsonline.com/TUTORIALS/TECHNICAL/dictionary_tutorial.html
<b>Internal Tables.</b>
While generating reports or other objects we are not modifying the database tables directly first we are selecting the data of the database table into the internal tables... so that we can reduce the database access time and network traffic .. which is highly needed in R/3 system..
internal tables are not exist phyiscally in the system. its like a array. the existance of the internal tables is upto the program execution in which u r declaring nd using it...
for more information..
http://www.sapbrainsonline.com/TUTORIALS/TECHNICAL/internaltables_tutorial.html
Hope it will solve ur problem..
<b>Reward points if useful..</b>
Thanks & Regards
ilesh 24x7
Maybe you are looking for
-
Image in a JDesktopPane background
Is it possible to paint an Image in a JDesktopPane background ?? how can I get it ?
-
Hi all, I'm looking to add a little bit of Swing eye-candy. I have a little pop-up window that informs the user that their file has saved after they hit "save" or Ctr-S. I need it to be noticeable (so that they are assured that their file did indeed
-
Last night my wife asked me when I had burned an audio CD. I popped it into the iMac and did a Get Info only to discover that its creation and modification dates were last night! I then tried it in Toast 11 under Disk Info and got no dates at all .
-
Export tables starting with same name format
Hi All, I need to export set of table below it_approvals it_attachments it_dev_schedule it_dev_schedule_log it_email it_email_group it_filetype it_group it_group_system it_manage_system it_menu it_page it_page_action it_parameter it_personal it_relea
-
X205-S9810 Computer just stopped working No beeps just black screen
Yesterday my laptop which was running just fine, went to sleep and I couldn't revive it. When I turn it on the fans start, the hard drive initializes then stops, the DVD starts and stops then the fans turn off and that's it. Black screen the entire