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
Similar Messages
-
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 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 -
How to pass data from one internal session to another internal session
hi all sap experts ,
How to pass data from one internal session to another internal session and from oneExternal session to another external session.
Except : Import and Export parameters and SPA/GPA parameters.
Tell me the otherWay to pass data ..
Plz
Thanks in advancehi,
abap memory management u will understand about this concept.
the import /export parameter will help u that passing data between two internal sessions by using abap memory.
for syntax
Passing Data Between Programs
There are two ways of passing data to a called program:
Passing Data Using Internal Memory Areas
There are two cross-program memory areas to which ABAP programs have access (refer to the diagram in Memory Structures of an ABAP Program) that you can use to pass data between programs.
SAP Memory
SAP memory is a memory area to which all main sessions within a SAPgui have access. You can use SAP memory either to pass data from one program to another within a session, or to pass data from one session to another. Application programs that use SAP memory must do so using SPA/GPA parameters (also known as SET/GET parameters). These parameters can be set either for a particular user or for a particular program using the SET PARAMETER statement. Other ABAP programs can then retrieve the set parameters using the GET PARAMETER statement. The most frequent use of SPA/GPA parameters is to fill input fields on screens (see below).
ABAP Memory
ABAP memory is a memory area that all ABAP programs within the same internal session can access using the EXPORT and IMPORT statements. Data within this area remains intact during a whole sequence of program calls. To pass data to a program which you are calling, the data needs to be placed in ABAP memory before the call is made. The internal session of the called program then replaces that of the calling program. The program called can then read from the ABAP memory. If control is then returned to the program which made the initial call, the same process operates in reverse. For further information, refer to Data Clusters in ABAP Memory.
Filling Input Fields on an Initial Screen
Most programs that you call from other programs have their own initial screen that the user must fill with values. For an executable program, this is normally the selection screen. The SUBMIT statement has a series of additions that you can use to fill the input fields of the called program:
Filling the Selection Screen of a Called Program
You cannot fill the input fields of a screen using additions in the calling statement. Instead, you can use SPA/GPA parameters. For further information, refer to Filling an Initial Screen Using SPA/GPA Parameters.
Message was edited by:
sunil kumar
Message was edited by:
sunil kumar -
How to pass data from one internal session to another
Hi SAP Experts,
How to pass data from one internal session to another and from One external session to another external session. I used import and export parmeter and SPA/GPA parameters. What is the other way to pass data?
Please tel me urgently
Thank you
BasuMemory Structures of an ABAP Program
In the Overview of the R/3 Basis System you have seen that each user can open up to six R/3 windows in a single SAPgui session. Each of these windows corresponds to a session on the application server with its own area of shared memory.
The first application program that you start in a session opens an internal session within the main session. The internal session has a memory area that contains the ABAP program and its associated data. When the program calls external routines (methods, subroutines or function modules) their main program and working data are also loaded into the memory area of the internal session.
Only one internal session is ever active. If the active application program calls a further application program, the system opens another internal session. Here, there are two possible cases: If the second program does not return control to the calling program when it has finished running, the called program replaces the calling program in the internal session. The contents of the memory of the calling program are deleted. If the second program does return control to the calling program when it has finished running, the session of the called program is not deleted. Instead, it becomes inactive, and its memory contents are placed on a stack.
The memory area of each session contains an area called ABAP memory. ABAP memory is available to all internal sessions. ABAP programs can use the EXPORT and IMPORT statements to access it. Data within this area remains intact during a whole sequence of program calls. To pass data to a program which you are calling, the data needs to be placed in ABAP memory before the call is made. The internal session of the called program then replaces that of the calling program. The program called can then read from the ABAP memory. If control is then returned to the program which made the initial call, the same process operates in reverse.
All ABAP programs can also access the SAP memory. This is a memory area to which all sessions within a SAPgui have access. You can use SAP memory either to pass data from one program to another within a session, or to pass data from one session to another. Application programs that use SAP memory must do so using SPA/GPA parameters (also known as SET/GET parameters). These parameters are often used to preassign values to input fields. You can set them individually for users, or globally according to the flow of an application program. SAP memory is the only connection between the different sessions within a SAPgui.
The following diagram shows how an application program accesses the different areas within shared memory:
In the diagram, an ABAP program is active in the second internal session of the first main session. It can access the memory of its own internal session, ABAP memory and SAP memory. The program in the first internal session has called the program which is currently active, and its own data is currently inactive on the stack. If the program currently active calls another program but will itself carry on once that program has finished running, the new program will be activated in a third internal session.
Data Clusters in ABAP Memory
You can store data clusters in ABAP memory. ABAP memory is a memory area within the internal session (roll area) of an ABAP program and any other program called from it using CALL TRANSACTION or SUBMIT.
ABAP memory is independent of the ABAP program or program module from which it was generated. In other words, an object saved in ABAP memory can be read from any other ABAP program in the same call chain. ABAP memory is not the same as the cross-transaction global SAP memory. For further information, refer to Passing Data Between Programs.
This allows you to pass data from one module to another over several levels of the program hierarchy. For example, you can pass data
From an executable program (report) to another executable program called using SUBMIT.
From a transaction to an executable program (report).
Between dialog modules.
From a program to a function module.
and so on.
The contents of the memory are released when you leave the transaction.
To save data objects in ABAP memory, use the statement EXPORT TO MEMORY.
Saving Data Objects in Memory
To read data objects from memory, use the statement IMPORT FROM MEMORY.
Reading Data Objects from Memory
To delete data clusters from memory, use the statement FREE MEMORY.
Deleting Data Clusters from Memory
please read this which provide more idea about memory
Message was edited by:
sunil kumar -
Moving data from one internal table to another
Hi,
I have one internal table populated with a list of material codes and another with all the material numbers.
ITAB1: MCODE KSCHL KNUMH MATNR
ITAB2: MCODE MATNR
The matnr field in itab1 is blank initially. It needs to be populated with all the material numbers from itab2. How can I achieve this?
Thanks,
apHi
Lets say that there is only one record in itab1 and for that there is correspondingly 10 records in itab2.
that means that the one record in itab1 should be changed to the first material number in itab2 and there should be nine more records created in itab1 according to the values in itab2.
Hope this is what you mean.
If this is the logic then the following code should work
then lets have a third internal table the same type as itab1
Loop at itab1 into wa_itab1
*readt table itab2 into wa_itab2 with key mcode = wa_itab1-mcode.
*IF sy-subrc eq 0.
loop at itab2 into wa_itab2 where mcode = wa_itab1-mcode.
wa_itab1-matnr = wa_itab2-matnr
append wa_itab1 to itab3.
endloop.
*ENDIF.
*modify itab1 from wa_itab1.
endloop.
itab3 will contain all the values that you require -
Transferring data from one internal table to another
Hi,
I have two internal tables it_acct and it_acct1 as below.
data: begin of it_acct occurs 0,
belnr like bkpf-belnr,
bldat like bkpf-bldat,
augcp like bseg-augcp,
vbeln like bseg-vbeln,
end of it_acct.
data: begin of it_acct1 occurs 0,
belnr like bkpf-belnr,
cpudt like bsad-cpudt,
vbeln like bseg-vbeln,
end of it_acct1.
select belnr cpudt vbeln into corresponding fields of table it_acct1
from bsad where cpudt in s_cpudt.
Now I want to move the data from it_acct1 to it_acct . I have no data in it_acct now.
i want to move it_acct1-belnr to it_acct-belnr,
move it_acct1-cpudt to it_acct-augcp,
move it_acct1-vbeln to it_acct-vbeln.
Can someone help me how to code to move the data from it_acct1 to it_acct.
Regards,
DHi Dev,
Just add an additional line in Naren's code to get proper results at any time.
LOOP AT IT_ACCT1.
IT_ACCT-BELNR = IT_ACCT1-BELNR.
IT_ACCT-VBELN = IT_ACCT1-VBELN.
it_acct-augcp = it_acct1-cpudt.
APPEND IT_ACCT.
<b>CLEAR IT_ACCT.</b>
ENDLOOP.
If you didnt include CLEAR statement, even if IT_ACCT1 doesnt have any values for all fields or few fields in the next record, it will take values of previous one and it may lead to improper results.So it is a good practise to have CLEAR statement after APPEND statement in LOOP...ENDLOOP.
Thanks,
Vinay -
How to transfer Data of One internal table to another
Dear Guru,
I have an internal table
DATA: BEGIN OF t_cust OCCURS 0,
kschl LIKE rv13a-kschl,
werks LIKE komg-werks,
matnr LIKE komg-matnr,
kbetr LIKE konp-kbetr,
datab LIKE rv13a-datab,
datbi LIKE rv13a-datbi,
END OF t_cust.
I want to tranfer all the contents of internal table "t_cust" into another internal table "t_cust2" after converting kbetr, datab, datbi fields into char type.
How i will do it??
pls hlp..Hi Saifur,
if the structure is same then you can simply do
itab1[] = itab2[].
if you are changing the data type then.
data: wa1 like itab1,
wa2 like itab2.
loop at itab1 into wa.
wa2-field1 = wa1-field1.
wa2-field2 = wa1-field2.
Append wa2 to itab2.
endloop. -
How do i transfer data from one internal tabe to another.
Hi All,
How do i transfer data from one internal tabe to another.
Can i do it ebven if he tables are different in structure.
Please Advice.
Thanks in advance.Hi Saket Tiwari,
I hope the earlier post by kashyap is good enough an answer. anywas in addition to it let me give a detailed
explanation of how you can populate an internal table.
1) Append data line by line.
Syntax : APPEND [<wa> TO / INITIAL LINE TO] <itab>.
this appends new line to internal table <itab>.
2) Using COLLECT statement.
COLLECT is another form of statement used for populating the internal tables. Generally COLLECT is used while inserting lines into an internal table with unique standard key. The syntax for COLLECT statement is as shown
Syntax : COLLECT [<wa> INTO] <itab>.
3) Using INSERT statement
Syntax INSERT [<wa> INTO / INITIAL LINE INTO] <itab> [index <idx>].
INSERT statement adds a line/work area to the internal table. You can specify the position at which the new line is to be added by using the INDEX clause with the INSERT statement.
Now coming to your request..
To append part or all of an internal table
Syntax
APPEND LINES OF <itab1> [FROM <n1>] [TO <n2>] TO <itab2>.
* Note:
Without the FROM and TO options, this statement appends the entire table <itab1> to <itab2>.*
b) To insert part or all of an internal table into another internal table
Syntax
INSERT LINES OF <itab1> [FROM <n1>] [TO <n2>]
INTO <itab2> [INDEX <idx>].
c) Using Move statement.
To copy entire contents of one table into another in one execution
Syntax MOVE <itab1> To <itab2>.
OR
<itab1> = <itab2>.
but u hav to be careful because he contents of itab2 will eb overwritten on the execution of this statement.
These copy the contents of ITAB1 to ITAB2. Incase of internal tables with header line we have to use [] inorder to distinguish from work area. So, to copy contents of internal tables with header line the syntax becomes,
ITAB1[] = ITAB2[].
Coming to the letter part of your question, Yes, we can copy values between tables having different structures.
for this we use
MOVE-CORRESPONDING <itab1> TO <itab2>
this executes the statement for their header lines. Searches for the sub-fields which occur both in itab1 and itab2 and then generates, for all relevant field pairs which correspond to the
sub-fields ni , statements of the form MOVE itab1-ni TO itab2-ni. The other fields remain unchanged.
I hope the information provided has been of your help.
Reward if useful.
Regards,
Jose -
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 insert select columns from one internal table to another
Hi,
How to insert select columns from one internal table to another based on condition as we do from a standart table to internal table.
regards,
SriramHi,
If your question is for copying data from 1 int table to other ;
we can use
APPEND LINES OF it_1 TO it_2.
or if they have different columns then:
loop at it_1 into wa_it1.
move wa_it1-data to wa_it2-d1.
apped wa_it2 to it_2.
clear wa_it2.
endloop.
thnxz -
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 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 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 -
How to get data from an internal table in some other program
I would like to get data from the internal table in the other program. When I using FM "LIST_FROM_MEMORY" to get the data, it doesn't work and the exception is not fount.
If any special code need in the other program, like write data to memory .
Many thx .
From Ross WangHi
<li>You need to have interaction if you want to use EXPORT/IMPORT statments.
<li>The internal tables in both programs must be same
<li>Program one ..Calling program
REPORT ZTEST_NOTEPAD.
DATA: BEGIN OF it_t001 OCCURS 0,
bukrs TYPE t001-bukrs,
butxt TYPE t001-butxt,
END OF it_t001.
START-OF-SELECTION.
SUBMIT ztest_notepad1 AND RETURN.
IMPORT it_t001 FROM MEMORY ID 'ZTEST_T100'.
LOOP AT it_t001.
WRITE:/ it_t001.
ENDLOOP.
<li>Program two ...Called program
REPORT ztest_notepad1.
DATA: BEGIN OF it_t001 OCCURS 0,
bukrs TYPE t001-bukrs,
butxt TYPE t001-butxt,
END OF it_t001.
START-OF-SELECTION.
SELECT * FROM t001 INTO CORRESPONDING FIELDS OF TABLE it_t001 UP TO 10 ROWS.
IF sy-dbcnt > 1.
EXPORT it_t001 TO MEMORY ID 'ZTEST_T100'.
ENDIF.
I hope that it gets you some idea.
Thanks
Venkat.O
Maybe you are looking for
-
EDN not available throws runtimeFault - Fault Policy Framework unable to catch it
Hi Team, I have been working on some error handling scenarios for EDN . From my observation if BPEL is used to publish the event, BPEL Fault policy cannot catch EDN errors (e.g., EDN unavailable) but BPEL catch activity can catch it. Steps performed
-
Was checking on my MBP's Security> Firewall settings which I had set to "Set access for specific services and applications". Noticed that Safari and System Preferences have been added. I don't remember adding them. So I checked the log and found mayb
-
Error in Custom Rule EVALUATE_AGENT_VIA_RULE
Hi, I am working on a workflow and have created a custom rule for a workflow. When I simulate this rule, it returns 1 users but when workflow is triggered, Possible agents and Actual agents are blank. i am getting error in Rule EVALUATE_AGENT_VIA_RUL
-
Adobe PDFMAker was not able to mail merge the document?
Has anyone ever ran into this issue? I'm trying to evaluate a trial verion of Pro Extended 9.0, but hit that error when trying to complete the merge with the Adobe add-ins. I'm using Word 2007, Outlook 2007 and Win XP sp3. Thx - Would love to buy t
-
This is my first time building the kernel myself. Following this wiki page: https://wiki.archlinux.org/index.php/Ke - ild_System makepkg or makepkg -i fails with this output: Hunk #1 succeeded at 56 with fuzz 2 (offset -2 lines). ==> Starting build()