Reading table struc
Hi,
I have a function that returns me table Struc. I am trying to create another table by going through this table. The new table would contain the ObjectID and the ObjectID of its parent.
In order to find the parent first we have to look at the PUP column corresponding to the Object. This PUP is then matched with another column in the same table SQNR. If PUP = SQNR then we grab the ObjectID corresponding to that SQNR and this is the parent.
What would be an efficient way of achieving this? I would really appreciate the help!!
Thanks.
Hi Stephan,
Thanks for your reply. I am actually very new to ABAP programing. Could you please explain it a bit more. The function that I am calling is
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = otype
act_objid = objid
act_plvar = plvar
act_wegid = pathid
TABLES
result_struc = result_struc
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
RAISE no_roots_found.
ENDIF.
I am trying to make a new table with only two fields. The employeeID and the parentID. The table result_struc which is a type STRUC has a lot more fields that I do not require.
I would really appreciate your help.
Regards,
Mark
Similar Messages
-
Sy-tabix in relation to LOOP AT and READ TABLE
Hi All,
As per SAP documentation,
1) While looping through an internal table (LOOP AT), sy-tabix contains the index number of current row(for standard and sorted tables)
2)When successfully reading from an internal table(READ TABLE), sy-tabix is set to the index of the result row.
But what happens when READ TABLE is used while looping through another internal table?
i.e. Loop at TAB1...
write sy-tabix.
READ TABLE TAB2...
write sy-tabix.
endloop.
If we are looping through 1st row of TAB1 and the result of read statement is found in 3rd row of TAB2, I expected that sy-tabix before READ would be 1 and after the READ be 3.
But, I found that sy-tabix remains unchanged at 1. Can someone expalin why?
Thanks,
JaganHi
If after reading the table TAB2 the system variable SY-TABIX has still the previous value, that menas the READ TABLE fails or it was read the first record of TAB2.
After READ TABLE TAB2 try to check the SY-SUBRC:
LOOP AT TAB1.
WRITE: / 'TAB1 index:', SY-TABIX.
READ TABLE TAB2 .........
IF SY-SUBRC = 0.
WRITE: 'TAB2 index:', SY-TABIX.
Try this:
DATA: BEGIN OF ITAB OCCURS 0,
FIELD1,
END OF ITAB.
DATA: BEGIN OF ITAB2 OCCURS 0,
FIELD1,
END OF ITAB2.
DATA: INDEX TYPE I.
DO 10 TIMES.
APPEND ITAB.
ENDDO.
DO 10 TIMES.
APPEND ITAB2.
ENDDO.
LOOP AT ITAB.
WRITE: / 'ITAB:', SY-TABIX.
INDEX = SY-TABIX + 2.
READ TABLE ITAB2 INDEX INDEX.
IF SY-SUBRC = 0.
WRITE: 'ITAB2:', SY-TABIX.
ENDIF.
ENDLOOP.
Max -
Conflict: READ TABLE itab2 INDEX 1 vs Modify itab1 from index sy-tabix
The below simple code is for each itab1 line, create a new itab2 by using select statement, and then grab the max value of field f in itab2 and fill it into a corresponding field in itab1.
However the statement:
READ TABLE itab2 into gs_itab1 INDEX 1.
causes the conflict with our another statement in the end of itab1 loop:
Modify itab1 from gs_itab1 index sy-tabix.
that the below Modify statement always modify itab1 at 1st row and also causes an unlimited loop that the program is hung up. Our code looks as the following:
Loop AT itab1 into gs_itab1.
use Select statement to fill in itab2...
SORT itab2 BY f DESCENDING. "f is a field of itab2
READ TABLE itab2 into gs_itab1 INDEX 1.
Modify itab1 from gs_itab1 index sy-tabix.
EndLoop.
However the last two lines of statements in the itab1 loop causes the program hang!
Any solution?
Thanks in advance!Hi,
I got confused while going thru the code...
according to code
first u loop itab1 and get tht in gs_itab1 and then a select query to get data from some table and store in itab2.
Here are u using any where condition, if yes u may probably check aganst gs_itab1 rite? if yes
first suggestion...why cant u put the select statement above the loop and get all the values to an internal table and then read the internal table in the loop stmt. Yes i can see u r sorting it based on some 'f'..just a suggestion
Now here can u follow this code...
Loop AT itab1 ASSIGNING <fs_itab1>,
use Select statement to fill in itab2...
SORT itab2 BY f DESCENDING. "f is a field of itab2
READ TABLE itab2 into <fs_itab1> index 1.
EndLoop.
Please let me know if its not ok
<REMOVED BY MODERATOR>
Regards,
ABAPer007
Edited by: Alvaro Tejada Galindo on Apr 11, 2008 12:26 PM -
How to get the number of hits ("returned rows") in read table statement
Hi Experts
I have the statement shown below, which seems not to work as I would like it to. My problem is that I would like to do two different things depending on weather or not a read table statement results in 0 hits or 1 (or more) hits.
READ TABLE g_ship_item
WITH KEY
l_ztknum = DATA_PACKAGE-/bic/ztknum
BINARY SEARCH.
IF sy-subrc is initial.
no hits found
DATA_PACKAGE-/BIC/ZSTAGEERR = 1.
ELSE.
hits where found and we will do something else...
DATA_PACKAGE-/BIC/ZSTAGEERR = 0.
Hope someone can help me out of my problem...
Thanks in advance, regards
TorbenHi,
As you are using READ statement with Binary search, check whether the internal table g_ship_item is sorted with field /bic/ztknum or not. If it is not sorted then the result of this READ statement is not correct.
Below is the correct code.
sort g_ship_item by /bic/ztknum.
READ table g_ship_item with key g_ship_item = xxx.
Thanks,
Satya -
Dear All,
Please let me know which one of the two should I use to improve the performance, for tables containing a lot of data ?
Regards,
Thanks in anticipation.
Alok.Hi,
Follow below steps.
In se30 transaction you can look for
Tip&TRicks button on application toolbar
apart from below conventions
Follow below steps
1) Remove corresponding from select satement
2) Remove * from select
3) Select field in sequence as defined in database
4) Avoid unnecessary selects
i.e check for internal table not initial
5) Use all entries and sort table by key fields
6) Remove selects ferom loop and use binary search
7) Try to use secondary index when you don't have
full key.
8) Modify internal table use transporting option
9) Avoid nested loop . Use read table and loop at itab
from sy-tabix statement.
10) free intrenal table memory wnen table is not
required for further processing.
11)
Follow below logic.
FORM SUB_SELECTION_AUFKTAB.
if not it_plant[] is initial.
it_plant1[] = it_plant[].
sort it_plant1 by werks.
delete adjacent duplicates from it_plant1 comparing werks
SELECT AUFNR KTEXT USER4 OBJNR INTO CORRESPONDING FIELDS OF TABLE I_AUFKTAB
FROM AUFK
FOR ALL ENTRIES IN it_plant1
WHERE AUFNR IN S_AUFNR AND
KTEXT IN S_KTEXT AND
WERKS IN S_WERKS AND
AUART IN S_AUART AND
USER4 IN S_USER4 AND
werks eq it_plant1-werks.
free it_plant1.
Endif.
ENDFORM. "SUB_SELECTION_AUFKTAB
Regards
Amole -
Invalid Cursor when I want to modify itab with READ TABLE ?
Following code causes a core dump and says invalid cursor.
What should I do if I want to change gt_itab .?
REPORT ZEV_READ_TABLE.
data: begin of gt_itab occurs 0,
key like vbrk-vbeln,
name(10) type C,
amount type i,
end of gt_itab .
start-of-SELECTION.
gt_itab-key = 1.
gt_itab-name = 'erkan'.
gt_itab-amount = 10.
append gt_itab.
gt_itab-key = 2.
gt_itab-name = 'dilem'.
gt_itab-amount = 20.
append gt_itab.
LOOP AT gt_itab.
write:/ gt_itab-key,
gt_itab-name,
gt_itab-amount.
ENDLOOP.
Read table gt_itab with key Key = 1.
if sy-subrc = 0.
gt_itab-amount = 100.
modify gt_itab.
endif.
Kind Regards.
Erkan VAROLChange the code this way & try
modify gt_itab index sy-tabix.
a® -
Field symbols and READ TABLE with system code 4
Hi,
I have a hashed table and I am using field symbols to point to it to retrieve the field content. I then use it in the READ TABLE statement in the following way:
Loop at x_data assign <fs>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c1>.
ASSIGN COMPONENT 'xxx' OF STRUCTURE <fs> TO <c2>.
READ TABLE ZZZZ assign <fs> with table key a1 = <c1>
a2 = <c2>.
If sy-subrc = 0.
endif.
I ran the debugger and I keep getting a 4. I am not able to get the value from a1 and a2 to see what it is and why it is causing a 4 sy-subrc. I know the value from the hashed table and the values c1 and c2 are the same, so the sy-subrc should be 0.
How would I read a hashed table using field symbols? I know that usig a standard table, I have to sort the table on the key fields() before I actually can do the READ TABLE using the binary search.
Please advise. Thanks
RTHai Rob
Go through the following Code
Field-Symbols are place holders for existing fields.
A Field-Symbol does not physically reserve space for a field but points to a field, which is not known until run time of the program.
Field-Symbols are like Pointers in Programming language C .
Syntax check is not effective.
Syntax :
Data : v1(4) value abcd.
Field-symbols <fs>.
Assign v1 to <fs>.
Write:/ <fs>.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 100.
READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.
IF <FS> IS ASSIGNED.
WRITE '<FS> is assigned!'.
ENDIF.
LOOP AT ITAB ASSIGNING <FS>.
WRITE: / <FS>-COL1, <FS>-COL2.
ENDLOOP.
The output is:
1 1
2 100
4 16
Thanks & regards
Sreenivasulu P -
Hi EXpert,
I have an internal table say itab and I need to fetch a single record with some given conditions.
Hence I have used READ table statement ,
But on using this read table statement , I am unable to fetch the record :-(((( . It gives sy-subrc = 4.
And the same conditions when are put in Loop at itab statement, then I am able to fetch the data .
My requirement is only 1 record for the given conditions ( in where clause in case of loop at statement).
I think I am probably missing out on some minor thing..
<removed_by_moderator>
Warm Regards,
SUDHA
Edited by: Julius Bussche on Feb 7, 2009 2:48 PMHi,
Test the following Code hope it will solve out your problem,
PARAMETERS: key TYPE i .
TYPES: BEGIN OF t_test,
s_no TYPE i,
name(15),
END OF t_test.
DATA: it_test TYPE STANDARD TABLE OF t_test WITH HEADER LINE.
DO 10 TIMES.
it_test-s_no = sy-index.
it_test-name = 'SDN'.
APPEND it_test TO it_test.
ENDDO.
READ TABLE it_test INTO it_test WITH KEY key.
IF sy-subrc = 0.
WRITE: 'sy-subrc = ' , sy-subrc,
/1 it_test-s_no, 15 it_test-name.
ELSE.
WRITE: 'sy-subrc = ' , sy-subrc,
/ 'Sorry there is no Records with this Key'.
ENDIF.
Kind Regards,
Faisal
Edited by: Faisal Altaf on Feb 7, 2009 6:59 PM -
RFC and read table in another destination
HI
I search a complete code to read a table using the function 'RFC_GET_TABLE_ENTRIES '
I can acess to another server using RFC without problem.
I need to read table 'tmsbuftxt ' and data ' TRKORR '.
my program looks like
TABLES:
tmsbuftxt.
DATA:
i_tab512 TYPE tab512 OCCURS 0 WITH HEADER LINE,
i_tmsbuftxt TYPE table of tmsbuftxt,
st_tmsbuftxt type tmsbuftxt.
PARAMETERS p_dest LIKE rfcdes-rfcdest OBLIGATORY.
START-OF-SELECTION.
CLEAR i_tab512. REFRESH i_tab512.
CALL FUNCTION 'RFC_GET_TABLE_ENTRIES'
DESTINATION
p_dest
EXPORTING
" BYPASS_BUFFER = ' '
" FROM_KEY = ' '
" GEN_KEY = ' '
" MAX_ENTRIES = 0
table_name = 'tmsbuftxt'
" TO_KEY = ' '
" IMPORTING
"* NUMBER_OF_ENTRIES =
TABLES
entries = i_tab512
EXCEPTIONS
OTHERS = 1.
i_tmsbuftxt[] = i_tab512[].
LOOP AT i_tmsbuftxt INTO st_tmsbuftxt.
Write : st_tmsbuftxt-TRKORR.
ENDLOOP.
The problem is I dont know how to use the function correctly , I can choose the RFC I want but my programm return nothing.
Anyone can corect this?
I just start develop abap since 1 month.
I just want write st_tmsbuftxt-TRKORR. who is in another environnement using RFC.Hello Guillaume,
welcome in this forum.
I try RFC_GET_TABLE_ENTRIES, but I think it is better to use RFC_READ_TABLE. Try this to get the numbers of the transports from another system:
"-Begin-----------------------------------------------------------------
Program Z_TEST.
Data Fields Type Standard Table Of RFC_DB_FLD.
Data Field Type RFC_DB_FLD.
Data Data Type Standard Table Of TAB512.
Data Line Type TAB512.
Field-FIELDNAME = 'TRKORR'.
Append Field To Fields.
Call Function 'RFC_READ_TABLE' Destination 'NONE'
Exporting
QUERY_TABLE = 'TMSBUFTXT'
Tables
FIELDS = Fields
DATA = Data
Exceptions
TABLE_NOT_AVAILABLE = 1
TABLE_WITHOUT_DATA = 2
OPTION_NOT_VALID = 3
FIELD_NOT_VALID = 4
NOT_AUTHORIZED = 5
DATA_BUFFER_EXCEEDED = 6
Others = 7.
If sy-subrc <> 0.
Else.
Loop At Data Into Line.
Write: / Line.
EndLoop.
EndIf.
"-End-------------------------------------------------------------------
Let us know your results.
Cheers
Stefan -
Performance syntax loop at and read table
in the routine , for reading one line in a internal table , the syntaxe
loop at xxx where and read tabl exxx with key XXXX
has a great difference on performance or not?Loop at statement is used only for processing multiple records.Read table is used for reading a particluar record of an internal table.If you just need to check whether record exists in internal table, use can sort and use binary search with TRANSPORTING NO FIELDS addition. Also, try to use field symbols so that performance is increased.
-
Hi,
I would like to seek advice on this.
I have 2 internal table as below. The problem is although i have the same set of data in both internal table but
why sy-subrc still returns 4. I found out anln2 map to different ones. Why read table not able to pick the same anln2 even though it has the same value of anln2 in itab2.
LOOP AT it_itab1 INTO wa_itab1.
READ TABLE it_itab2 INTO wa_itab2
WITH KEY glla = wa_itab2-glia
cctrla = wa_itab2-cctria
anln1 = wa_itab2-anln1
anln2 = wa_itab2-anln2.
IF sy-subrc = 0.
ThanksDear Please check the below code
same as urs but small mofications
>
Ask_que wrote:
> Hi,
> I would like to seek advice on this.
> I have 2 internal table as below. The problem is although i have the same set of data in both internal table but
> why sy-subrc still returns 4. I found out anln2 map to different ones. Why read table not able to pick the same anln2 even though it has the same value of anln2 in itab2.
>
> LOOP AT it_itab1 INTO wa_itab1.
> READ TABLE it_itab2 INTO wa_itab2
> WITH KEY glla = wa_itab1-glia
> cctrla = wa_itab2-cctria
> anln1 = wa_itab2-anln1
> anln2 = wa_itab2-anln2.
> IF sy-subrc = 0.
>
>
> Thanks
LOOP AT it_itab1 INTO wa_itab1.
READ TABLE it_itab2 INTO wa_itab2
WITH KEY glla = wa_itab1-glia
IF sy-subrc = 0.
cctrla = wa_itab1-cctria
anln1 = wa_itab1-anln1
anln2 = wa_itab1-anln2.
ENDIF.
ENDLOOP.
Thanks
Surendra P -
Hi,
How can i read this table with where condition in OOPS? is it possible?
Give some idea how to proceed?
Inside method i have written like this.
ret is my return parameter.
code:
Loop at me->s001_raw[] assigning <arr_s001>.
read table ret[] with table key
vkorg in me->select_parameters->SO_VKORG[]
and ZZEMP in me->select_parameters->SO_empl[].
assigning <arr_return>.
ThanksRead will not work
May be you can try this way
Loop at me->s001_raw[] assigning <arr_s001>.
loop at ret[] assigning <arr_return> where vkorg in me->select_parameters->SO_VKORG[]
and zzemp in me->select_parameters->SO_empl[].
exit.
endloop.
endloop.
a® -
"Read table" and field symbols
Hello all,
I have a (hopefully simple) question. Let's suppose I want to do the following:
loop at itab1 assigning <fs1>.
read table itab2 assigning <fs2> with table key <fs1>-field1.
if sy-subrc eq 0.
move <fs2>-field1 to ls_out-field1.
endif.
read table itab3 assigning <fs3> with table key <fs1>-field2.
if sy-subrc eq 0.
move <fs3>-field1 to ls_out-field2.
endif.
endloop.
It's also possible to do the following instead:
loop at itab1 assigning <fs1>.
unassign: <fs2>,
<fs3>.
read table itab2 assigning <fs2> with table key <fs1>-field1.
read table itab3 assigning <fs3> with table key <fs1>-field2.
if <fs2> is assigned.
move <fs2>-field1 to ls_out-field1.
endif.
if <fs3> is assigned.
move <fs3>-field1 to ls_out-field2.
endif.
endloop.
My question is: is it "better" to check sy-subrc after each read, and then do a move statement within that if statement, or is it better to check whether the field symbol is assigned each time I want to fill in a field and read everything at the same time?
I'm only really concerned about the case where you don't want to drop out of the loop after the read (so if the read fails you just don't fill any data in). I'm also discounting potential human error (otherwise the sy-subrc method wins hands-down).Just to close this one (albeit somewhat belatedly). I asked Harry Dietz (the ABAP Performance blogging fella) what he would suggest, and he says sy-subrc all the way. Checking that an integer is zero is considerably faster than checking for the assignment, or otherwise, of a field symbol. Furthermore, whilst the field symbol method has the potential to be faster than the sy-subrc method given some compiler optimizations, unfortunately these optimizations don't exist in the ABAP compiler - they're there in the Java compiler though! Shame really. Apparently the ABAP compiler is a pretty simple beast.
Anyway - thanks Harry for clearing this one up! -
How to assigne multiple value in key of read table
Hi gurus,
I want read table xxxx with key field1 = ' xxx' or field1 = 'yyy'.
how to assign multiple value as key for the same field while reading internal table.
Regards
sagarHi ,
You can loop the internal table like
loop at <table xxxx> where field1 = ' xxx' or field1 = 'yyy'
or you can write two read statements to read the internal table in wrk area.
read table <table xxxx> with key field1 = ' xxx'.
if sy-subrc <>0
read table <table xxxx> with key field1 = 'yyy'.
if sy-subrc = 0
endif.
else.
do your data processing.
endif.
Thans. -
RFC-Error while reading table TFMCA003
Hello,
we have a running system with campus management an I'm doing the customizing for a separate system SLCM with EHP3. I created a RFC-Connection as in the Base IMG Configuration Settings for Pre-Configured SAP Student Lifecycle Management (ERP 6 - EHP 3) 31 October 2007 page 8+9 described.
On the old system it works without problems but on EHP3 I get the following error displayed while creating new students: Error - check RFC-Destination RFC_FICA_ACCT_CREATE
Looking into the rfc trace I read the following entry:
Trace file opened at 20090407 135656 W. Europe Daylight Time, SAP-REL 700,0,185 RFC-VER nU 3 1025200 MT-SL
======> Fehler beim Lesen in der Tabelle TFMCA003
ABAP Programm: SAPLHRPIQ00STUDENT_ACCOUNT (Transaction: PIQSTC)
Called function module: HRIQ_STUDENT_ACCTDATA_UPD_INT
User: RSEIDLER (Client: 100)
Destination: RFC_FICA_CREATE_100 (handle: 6, 10238413, {306B23DE-EF74-F186-BAA8-0022640496A6})
Error RFCIO_ERROR_MESSAGE in abrfcio.c : 1833
So there is an error reading table TFMCA003, but this one is empty, in both systems!
Although the error message is displayed I can not see any limitation working with the created student. So it seems everything is working normal. But the message is unacceptable in a live system, of course.
Any ideas?
RobertHi Nivdedita,
Check the rule which you have defined in the workflow.
Regards,
Sravanthi
Maybe you are looking for
-
Issue using the Eclipse report designer with Derby Client JDBC Driver
All I am trying to do is add a table to a blank report using the Crystal reports Eclipse plugin. The database is connected successfully in Eclipse using the Derby Client JDBC Driver, but when I try to drag a table from the database over to my blank r
-
IDVD can't find my Favorite Themes
I've defined several of my own themes, and iDVD 6 can't find them. By this I mean that it finds them okay when I want to apply a theme to a menu, and everything is fine until I save the project. But when I try to reopen the project, I consistently ge
-
Unable to connect java to mysql
I have installed mysql on my linux machine (i didnt modify any default configuration settings, just using the default settings). And in my lan, from another machine in windows from my java code i am trying to connect to mysql of linux, but donno why
-
Creating a String with repeated chars
Is there a way to create a String with N repeated chars without using a loop? I want to create something like "aaaaaaaaaa" without having to do: StringBuffer s = new StringBuffer(); for(int i = 0; i< 10; i++){ s.append("a"); }
-
How do i change the phone number associated with my ipad mini to a different number?
i gave my girlfriend and ipad mini for christmas, but in imessage, it automatically pulls up my phone number, and i would like to change it to hers. She has an iphone and is on my account. What do i do?