How to fetch data from an internal table by comparing the a value in loop
i have an internale table with two fields like parvw and vtext.
acc to valuue in parvw in loop we sholud fetch the corresponding value of vtext.
we should not use loop in loop .
ex code
select parvw vtext from tpart into table i_vtext where spras = sy-langu.
LOOP AT I_OUTPUT.
CASE I_OUTPUT-tabname.
WHEN 'VBPA'.
IF I_OUTPUT-fname = 'KUNNR' OR
I_OUTPUT-fname IS INITIAL.
MOVE I_OUTPUT-tabkey TO vbpa.
READ TABLE i_vtext WITH table KEY parvw = vbpa-*parvw .
IF sy-subrc = 0.
REPLACE '&' WITH i_vtext-vtext INTO I_OUTPUT-indtext.
ENDIF.
ENDIF.
WHEN 'VBAP'.
IF I_OUTPUT-fname IS INITIAL.
REPLACE '&' WITH 'item' INTO I_OUTPUT-indtext.
ENDIF.
ENDCASE.
IF I_OUTPUT-indtext(1) EQ '&'.
REPLACE '&' WITH I_OUTPUT-ftext(40) INTO I_OUTPUT-indtext.
ENDIF.
Loop the main ITAB
and then use READ TABLE to fetch a row from the 2nd ITAB.
sort the main itab abd use binary search option in READ to improve the performance
Narendra
Similar Messages
-
How to fetch data from nested internal table
Hi,
Im using FM CRM_PRODUCT_GETDETAIL_API which is returning me work area (ES_PRODUCT_DATA) of type
COMT_PRODUCT_MAINTAIN_API. This work area contains a table SHORT_TEXTS of type COMT_PR_SHTEXT_MAINTAIN_TAB
whcih in turn contain a line type DATA of type COMT_PRSHTEXT_X. I need to fetch fields lying inside DATA. Can anybody please
let me know how to achieve this. I would like to do this by not using nested loop structure.
Rgds
Sudhanshu SharmaHi,
Use field ES_PRODUCT_DATA-short_texts like any other internal table (without header line).
E.g.:
field-symbols: <text> type COMT_PRSHTEXT_X.
loop at ES_PRODUCT_DATA-short_texts assigning <text>.
write: <text>-short_text
endloop.
Regards, Gerd Rother -
How to Fetch Data From an Internal table to a field in Modulepool Screen ??
In my Modulepool Screen i have two fields ,
Based on the data of the First field ,the second field will display the data.
For ex- first field - I choosed the data -" MARUTI",
then in the second field , all d CARs ( 800,zen,waganor.....)related to MARUTI shd be displayed.
without using POV module hw to use dis ? and also using POV ,what are the function modules to be used ..
pls explore in details...
Thnks to all d contributors for their Time.....see if u have a limited values to display in Listbox, den we will go for vrm_set_values.
but here as per the requirement
thr is no limited Values in d second dropdown box.
Let me Clear abt the requirement.
First field - issue no.
2nd field- Item no.
when u select a particular issue no, den in item it shd display the corresponding item nos related to that issueno. And both Fields r Primary keys in d table( customised Table.)
this is wwht exactly my requirement.
as i created The search help for issueNo, its displaying all the issueno Dat are in DB.
But Itemno Field is nt behaving as per That.
Pls Suggest me.. in details -
How to read data from an internal table into a real table?
Hello experts,
I'm relatively new to ABAP and I'm trying to figure out how to read data from an internal table into a table that I created. I'm trying to use the RRW3_GET_QUERY_VIEW_DATA function module to read data from a multiprovider. I'm trying to read data from the e_cell_data and e_axis_data tables into a table that I've already created. Please see code below.
TABLES MULTITAB.
DATA:
query_name TYPE RSZCOMPID,
s_cubename TYPE RSINFOPROV,
t_cell_data TYPE RRWS_T_CELL,
t_axis_data TYPE RRWS_THX_AXIS_DATA,
t_axis_info TYPE RRWS_THX_AXIS_INFO,
wa_t_cell_data like line of t_cell_data,
wa_t_axis_data like line of t_axis_data,
w_corp_tab like line of t_cell_data.
s_cubename = 'CORP_MPO1'.
query_name = 'Z_corp_test'.
CALL FUNCTION 'RRW3_GET_QUERY_VIEW_DATA'
EXPORTING
i_infoprovider = s_cubename
i_query = query_name
i_t_parameter = query_string_tab
IMPORTING
e_cell_data = t_cell_data
e_axis_data = t_axis_data
e_axis_info = t_axis_info.
If anyone has any information to help me, I would greatly appreciate it. Thanks.Hi,
<li>Once you call the function module RRW3_GET_QUERY_VIEW_DATA, lets say data is available in the corresponding tables e_cell_data e_axis_data which you have mentioned.
<li>Modify your internal table defined for other purpose, with data from e_cell_data e_axis_data like below.
LOOP AT t_cell_data INTO wa_t_cell_data.
"Get the required data from t_cell_data.
MOVE-CORRESPONDING wa_t_cell_data TO it_ur_tab.
"Modify your internal table wih data
MODIFY it_ur_tab TRANSPORTING <field1> <field2> <field3>.
ENDLOOP.
LOOP AT t_axis_data INTO wa_t_axis_data.
"Get the required data from t_cell_data.
MOVE-CORRESPONDING wa_t_axis_data TO it_ur_tab.
"Modify your internal table wih data
MODIFY it_ur_tab TRANSPORTING <field1> <field2> <field3>.
ENDLOOP.
Thanks
Venkat.O -
How to move data from 2 internal table to 1 internal table
Can any body send me code that how to move data from 2 internal table into one internal table.
Moderator message : Read ABAP documentation. Thread locked.
Edited by: Vinod Kumar on Jun 13, 2011 11:45 AMHi Mohdarif92;
I don't know your full needs. But general method should be as below code.
Please check exam below code.
Best regards.
data : begin of gt_result.
... like mkpf-...
... like mkpf-...
... like mseg-...
... like mseg-...
end of gt_result
select *
into table gt_mkpf
from mkpf where ...
select *
into table mseg
from mseg where ...
loop at gt_mkpf.
loop at gt_mseg where ... = mkpf-...
move-corresponding gt_mkpf to gt_result.
move-corresponding gt_mseg to gt_result.
append gt_result
endloop.
endloop. -
How to fetch data from single database table using 2 internal tables.
Hi friends,
i am a new user of ABAP and also SDN.
i need a help.
i want to fetch data from one database table based on primary keys of 2 internal tables. how to put in where clause.
Thanks in advance.hii
refer to following code ..i hope it will help you
SELECT matnr " Material Number
FROM mara
INTO TABLE i_mara
WHERE matnr IN s_matnr.
IF i_mara[] IS NOT INITIAL.
SELECT matnr " Material Number
werks " Plants
prctr " Profit Center
FROM marc
INTO TABLE i_marc
FOR ALL ENTRIES IN i_mara
WHERE matnr = i_mara-matnr
AND werks IN s_werks.
ENDIF. " IF i_mara[] IS NOT INITIAL
i_output = i_marc.
IF i_marc[] IS NOT INITIAL.
SELECT matnr " Material Number
werks " Plants
lgort " Storage Location
FROM mard
INTO TABLE i_mard
FOR ALL ENTRIES IN i_marc
WHERE matnr EQ i_marc-matnr
AND werks EQ i_marc-werks
AND lgort IN s_lgort.
ENDIF. " IF i_mara[] IS NOT INITIAL
regards
twinkal -
How to insert data from different internal table into a data base table
hi all,
I want to insert a particular field in an internal table to a field in a data base table.Note that the fields in the internal table and database table are not of the same name since i need to insert data from different internal tables.can some one tell me how to do this?
in short i want to do something like the foll:
INSERT INTO ZMIS_CODES-CODE VALUE '1'.
*INSERT INTO ZMIS_CODES-COL1 VALUE DATA_MTD-AUFNR .(zmis_codes is the db table and data_mtd is the int.table)REPORT ZINSERT.
tables kna1.
data: itab LIKE KNA1.
data lv_kUNAG LIKE KNA1-KUNNR.
lv_kuNAG = '0000010223'.
ITAB-kuNNR = lv_kuNAG.
ITAB-name1 = 'XYZ'.
INSERT INTO KNA1 VALUES ITAB.
IF SY-SUBRC = 0.
WRITE:/ 'SUCCESS'.
ELSE.
WRITE:/ 'FAILED'.
ENDIF.
Here lv_kunag is ref to kna1 kunnr passed in different name
In internal table .
Try and let me know if this logic dint work. -
How to scan data from one internal table to another
Hi All,
let me know how to scan all from one internal table to another internal table. Pls provide me the syntax and code.
i am very thankful to you all in advance.
Thanks & Regards,
Nagarjuna.if u want to copy data from itab1 to itab2 then use
itab2[] = itab1[].
if u want to compare whether both itab1 and itab2 are same or not,use
if itab1[] = itab2[].
*--same
else.
*--not same
endif.
if u want to compare itabs based on primary key....
loop at itab1.
read table itab2 with key f1 = itab1-f1.
if sy-subrc <> 0.
*--not same....
endif.
endloop.
if u want to copy only few lines(say from 1 to 3) of itab1 to itab2 then use...
append lines of itab1 from 1 to 3 to itab2.
if internal tables don't have same structure,
say only fields f1 and f2 are common,then
loop at itab1.
itab2-f1 = itab1-f1.
itab2-f2 = itab1-f2.
append itab2.
clear itab2.
endloop.
if there are many common fields then...
loop at itab1.
move-corresponding itab1 to itab2.
append itab2.
clear itab2.
endloop.
Please don't forget to reward points....!!!
Regards
vasu -
How to download data from an internal table to a text
Hi All,
I want to download data from an internal table to a text file.
The fields should be pipe(|) separated. I have tried GUI_DOWNLOAD but it is not taking the field separator.
The sample of the desired data that i require should be this way:-
13456TR|M|COUP|MATERIAL|KGS
Thanks in advance.
Regards
Satish.Hi,
Try this..
REPORT zc1download message-id zc1dwnmsg.
*& Declaration Section for the Tables *
TABLES: makt.
*& Declaration Section for the Internal Tables
DATA: intab TYPE TABLE OF makt,
wa_intab LIKE LINE OF intab,
no_of_rec TYPE i,
count TYPE i.
DATA: BEGIN OF f_intab,
str(255) TYPE c,
END OF f_intab.
DATA: t_intab LIKE TABLE OF f_intab,
w_intab LIKE LINE OF t_intab,
temp(255) TYPE c.
FIELD-SYMBOLS: <f> TYPE ANY.
*& Selection ScreenSection for the file download
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: file TYPE rlgrap-filename MEMORY ID file,
tab RADIOBUTTON GROUP rad1 DEFAULT 'X',
others RADIOBUTTON GROUP rad1,
delimit TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
IF file IS INITIAL. " check to ensure file.
MESSAGE i001.
EXIT.
ENDIF.
IF others = 'X'. " check to ensure delimiter.
IF delimit = ' '.
MESSAGE i002.
EXIT.
ENDIF.
ENDIF.
SELECT * FROM makt INTO TABLE intab.
IF tab = 'X'. " default delimiter tab is used
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = file
filetype = 'DAT'
mode = 'A'
TABLES
data_tab = intab
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ELSE. " If user defind delimiter is to be used
Counts the number of fields *
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.
IF sy-subrc <> 0.
EXIT.
ELSE.
count = count + 1.
ENDIF.
ENDDO.
LOOP AT intab INTO wa_intab.
DO count TIMES. " Adding the delimiter in required places
ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.
CONCATENATE temp delimit <f> INTO temp.
ENDDO.
SHIFT temp.
APPEND temp TO t_intab.
CLEAR temp.
ENDLOOP.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = file
filetype = 'ASC'
mode = 'A'
TABLES
data_tab = t_intab
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
WRITE:/ 'The Data has been tranfered to :', file.
Cheers
Kathir!~ -
How to copy data from one internal table to another
i am using some function module to get some data for my function module
and the retrieved data is not getting populated in mu fumctional module
i am sucessful in getting the data to an internal table in my function module but dont know how to pass it to my table parameter
thanks in advanceHi Naval,
Declare an internal table of type table parameter structure and pass it the table parameters of the Function module.
Check the code for this function module.
DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.
SELECT * FROM MARA UP TO 10 ROWS INTO TABLE IT_MARA.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\TEST.TXT'. FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
<b> TABLES
DATA_TAB = IT_MARA</b>
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Thanks,
Vinay -
How to append data from an internal table to an external table.
HI everyone,
I am trying to update an DB table type 'c'from the data captured in my internal table. can any one tell me as to how to do this.the contents of the DB table needs to be erased completly before i send in new data.
Regards,
VjAssuming that you table has 1 character field(?) besides the MANDT field
MANDT
FIELD
you need to update this db table with values from ITAB which I assume has one field of type c.
To first delete all of the data from DB table.
* Yes there are other ways of doing this.
tables: ztable.
select * from ztable.
delete ztable.
endselect.
Then simply LOOP your internal table and update the table.
loop at itab.
ztable-field = itab-field.
insert ztable.
endloop.
Regards,
Rich Heilman -
How to select data from an internal table
material norm date last modified
B2-SP HEAT 50.000 20090420
BF COKE 575.000 20090419
GROSS COKE 200.000 20090419
B2-SP HEAT 100.000 20090419
TWT 33.000 20090330
B7-SP HEAT 2.000 20090310
B1-SP HEAT 1.000 20090309
B7-SP HEAT 615.000 20090308
B2-SP HEAT 585.000 20090308
B1-SP HEAT 100.000 20090308
B3-SP HEAT 610.000 20090308
BF COKE 68.500 20090308
GROSS COKE 72.600 20090308
B8-SP HEAT 600.000 20090308
B9-SP HEAT 625.000 20090308
BX-SP HEAT 615.000 20090308
B9-SP HEAT 58.000 20090307
B1-SP HEAT 100.000 20090307
B6-SP HEAT 350.000 20090306
B2-SP HEAT 888.000 20090306
Like above there r numerous data in a table :
how will i select data into another internal table where material above is not repeated with latest modified date.please help.Hi Sonu,
The main task is to move the contents of the one internal table to another with some condition.
First sort and delete the duplicate entries from the First Internal table like below :
sort it_tab by material ascending date_modified descending.
delete adjacent duplicates from it_tab.
Then move that Internal table contents to another internal table.
Define another internal table with the same structure as you have first internal table and then
Second Step :
it_itab1 = it_itab.
If you are using seperate Header line and Body then you can do like below :
it_itab1[] = it_itab[].
This will fix the issue.
Please let me know if you need any further explonation.
Regards,
Kittu
Edited by: Kittu on Apr 24, 2009 12:21 PM -
Fetching data from one internal table and populating into other table
hi
i am working on a report program.
here,i have my data in a internal table(having only one field) i.e. only one column in the table.
now i want to populate this data into other internal internal table that has 13fields i.e. 13 columns.
so could anyone let me know how can i work on this.
i am looping the internal table with one field into a work area from there i am not able to proceed ahead.
thanks in advancehi
i would like to clear one point here i.e. my internal table into which i want to populate data is a dynamic internal table....so i cant give the fieldnames here..
here i am pasting the code..so that u may get some idea...
"generating dynamic internal table :
ref_descr ?= cl_abap_typedescr=>describe_by_data( it_itab ).
it_details[] = ref_descr->components[].
loop at it_details into wa_comp.
cnt = cnt + 1.
wa_fcat-col_pos = cnt.
wa_fcat-fieldname = wa_comp-name.
append wa_fcat to t_fcat.
endloop.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
I_STYLE_TABLE =
IT_FIELDCATALOG = t_fcat
I_LENGTH_IN_BYTE =
IMPORTING
EP_TABLE = lo_table
E_STYLE_FNAME =
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
others = 2
so lo_table is my dynamic internal table.
ASSIGN lo_table->* TO <f_tab>.
using the GUI_UPLOAD i have uploaded the data file(separated by semicolon) from presentation server and its in the table itab.
with the following logic i am capturing the data in between the semicolon's.
LOOP AT itab INTO wa_itab.
find all occurrences of c_semicolon in wsg_string results result_tab.
loop at result_tab into wa_reslt.
if sy-tabix = 1.
str1 = wsg_string+0(wa_reslt-offset).
wa_prev_offset = wa_reslt-offset.
wa_prev_offset = wa_prev_offset + 1.
clear str1.
else.
count = wa_reslt-offset - wa_prev_offset.
count = count.
str2 = wsg_string+wa_prev_offset(count).
clear str2.
wa_prev_offset = wa_reslt-offset.
wa_prev_offset = wa_prev_offset + 1.
enddo.
endif.
endloop.
data is there in the fields str1 and str2.now i want to populate this data into dynamic internal table row-wise.
could anyone suggest me how can i do this -
How to delete data from dynamic internal table
Hi,
I have dynamic internal table and I have some slection screen fields , using these selection screen fields
(select -options), I have to filter the data? assigning will work with READ , but I have select options not the parametre,
and also delete will not work for dynamic table..
as we cannot use assigning with delete..
So how to do this?
and one more thing is , I cannot filter the data while selection( in select, I cannot filter the data-> as it's not coming directly from table, it's coming from buffer),
so now after selection of data, I need to filter the data from dynamic table.
Is there any way to do this?
Regards,
MrunalHi matt,
I tried with below code as you said. But I am getting dump. can you help?
here is my piece of code.
FIELD-SYMBOLS: <LS_DATA> type any,
<LT_DATA> TYPE table,
<L_FIELD> type any.
ASSIGN <l_buffer_entry>-dataptr->* TO <LS_DATA>.
ASSIGN <l_buffer_entry>-dataptr->* TO <LT_DATA>.
LOOP AT <LT_DATA> ASSIGNING <LS_DATA>.
ASSIGN COMPONENT 'BUKRS' OF STRUCTURE <LS_DATA> TO <L_FIELD>.
IF <L_FIELD> NOT IN SO_BUKRS.
DELETE <LT_DATA>.
ENDIF.
UNASSIGN <L_FIELD>.
ASSIGN COMPONENT 'BELNR' OF STRUCTURE <LS_DATA> TO <L_FIELD>.
IF <L_FIELD> NOT IN SO_BELNR.
DELETE <LT_DATA>.
ENDIF.
UNASSIGN <L_FIELD>.
ENDLOOP.
and here is the description of my dump:->>>
You attempted to access an unassigned field symbol
(data segment 32772).
This error may occur for any of the following reasons:
- You address a typed field symbol before it is set using ASSIGN
- You address a field symbol that points to a line in an internal table
that has been deleted
- You address a field symbol that had previously been reset using
UNASSIGN, or that pointed to a local field that no longer exists
- You address a global function interface parameter, even
though the relevant function module is not active,
that is it is not in the list of active calls. You can get the list
of active calls from the this short dump. -
HOW TO TRANSFER DATA FROM ONE INTERNAL TABLE TO ANOTHER
FOR PERTICULAR OBJECT ID ONE INT TABLE JTAB CONTAINS ONE RECORD(ROW) AND ANOTHER INT TABLE KTAB CONTAINS 3 RECORDS(ROWS). THEN HOW I SHOULD TRANSFER DATA FROM KTAB TO JTAB? WHAT R THE VARIOUS WAYS TO DO THAT. PLS HELP ME OUT. THANKS IN ADVANCE
Try something like
If you want one record per ktab :
LOOP AT jtab.
MOVE-CORRESPONDING jtab TO itab.
LOOP AT ktab WHERE id = jtab-id.
MOVE-CORRESPONDING ktab TO itab.
APPEND itab.
ENDLOOP.
ENDLOOP.
or
LOOP AT ktab.
READ TABLE jtab WITH KEY id = ktab-id. " binary implicit if sorted type
MOVE-CORRESPONDING jtab TO itab.
MOVE-CORRESPONDING ktab TO itab.
APPEND itab.
ENDLOOP.
If you want to sum ktab ratio into itab for each jtab
LOOP AT jtab.
MOVE-CORRESPONDING jtab TO itab.
LOOP AT ktab WHERE id = jtab-id.
ADD-CORRESPONDING ktab TO itab.
APPEND itab.
ENDLOOP.
ENDLOOP.
Use sorted type table when LOOP AT WHERE, else SORT table is enough.
Regards
Maybe you are looking for
-
Highligh current row not working for classic report in 4.1
Hello experts, One of our customers is migrating applications from APEX 3.0 to 4.1. All their applications use classic reports because interactive reports didn't exist in 3.0. The end users of the applications like the row color changing when they ho
-
Lost mail after upgrading to Mountain Lion
Hi, new to this forum, but I upgraded to Mountain Lion from the previous version and seem to have lost the last six months mail (Mar 2012 to the date I upgraded in Nov 2012). I have found all the old mail folders, notes, etc, and imported them based
-
I have a macbook pro what virus protection should i install?
I have a macbook pro, what virus protection should I install?
-
hi, Can anyone help me to determine how I can know if a html document has been displayed in a JEditorPane?
-
How to refresh pictures in iWeb
so I edited a picture in photoshop and instead of importing the new picture on each single page, deleting the old one and lining it all back up I just went to the published folder and replaced the image with the new one in each pages folder. now when