‎2016 Mar 30 4:17 AM
Hi All,
i have one field symbol and one internal table.
Filed symbol is pointing to the other table which is active table of DSO. Now i want to pass whole data of table via field symbol to the mentain intrenal table withhout loop statement.
Can it possible.?
i want to replace below loop code and pass whole filed symbol data to internal table
DATA:
FIELD-SYMBOLS:
<lfs_one> TYPE ANY TABLE,<lfs_view> TYPE ANY.
CONCATENATE 'GT_' iv_view INTO lv_txt.
ASSIGN (lv_txt) TO <lfs_one>.
CONCATENATE 'GS_' iv_view INTO lv_txt.
ASSIGN (lv_txt) TO <lfs_view>.
LOOP AT <lfs_one> INTO <lfs_view>.
MOVE-CORRESPONDING <lfs_view> to gs_one-d1.
APPEND gs_one to gty_one.
ENDLOOP.
Request you to please help me on this.
regards,
disha
‎2016 Mar 30 5:13 AM
‎2016 Mar 30 5:22 AM
You can use MOVE-CORRESPONDING for internal tables if you are on or above 7.4 SP05.
Have a look at
http://scn.sap.com/community/abap/blog/2014/02/06/abap-news-for-release-740-sp05
‎2016 Mar 30 7:19 AM
Thanks for your reply. but this is too complex and i am beginner in ABAP so,i dont know all this is required or not as i am alredy using move corresponding in my program, but move corresponding required loop as it will read row by row from the table.
I want some idea on how to append whole table x, which is pointing or holded by filed symbole <lfs_one> to gty_one. I dont want loop statement but want to append whole data in one single shot.
just required some clear idea wheather it is possible or not.
Thanks and Regards,
Disha
‎2016 Mar 30 7:31 AM
Yes, it is possible and Former Member already give you the hint therefore.
‎2016 Mar 30 7:40 AM
To be clear. In ABAP, from 7.4 onwards, MOVE-CORRESPONDING works with internal tables. This is very simple - even if you are a newbie.
If you are before 7.4, you must loop.
‎2016 Mar 30 10:04 AM
Hi,
If structures of both table are not same use as follow:
MOVE-CORRESPONDING <fs_one> TO gty_one KEEPING TARGET LINES.
But if structure is same for both table you can try as follow:
APPEND LINES OF <fs_one> TO gty_one.
Thanks,
Hardik.
‎2016 Mar 30 12:52 PM
INSERT LINES OF <fs_one> INTO TABLE gty_one
is safer than APPEND.
‎2016 Mar 30 1:04 PM
Your code suggests that the assigned table should completely end up in field d1 (which has a table type) of a new line for gty_one.
Maybe you can add the types of your variables (gty_one, gs_one) to the question, to make this clear.
Hardik is right in distinguishing the two cases.
If the types are not the same, you have to use what you currently have. You can only improve this if you are on 7.4 SP 05 as stated above, it would look like this instead of your loop:
MOVE-CORRESPONDING <lfs_one> to gs_one-d1.
APPEND gs_one to gty_one.
Or in my favorite syntax for this case:
APPEND VALUE #( d1 = CORRESPONDING #( <lfs_one> ) ) TO gty_one.
If the types ARE the same, you can simply use:
gs_one-d1 = <lfs_one>.
APPEND gs_one TO gty_one.
Other ways to write this in new syntax:
APPEND VALUE #( d1 = <lfs_one> ) TO gty_one.
Or
gty_one = VALUE #( BASE gty_one ( d1 = <lfs_one> ) ).
‎2016 Mar 30 4:11 PM
Hi Hardik,
the structure of internal table and field symbol is different. so have to use below code.
MOVE-CORRESPONDING <fs_one> TO gty_one KEEPING TARGET LINES.
But here problem is that its not assigning any value to the structure of gty_one-d1 . i want to assign the value to the d1 field of the gty_one internal table.
so here, i want to use:
MOVE-CORRESPONDING <fs_one> TO gty_one-d1 KEEPING TARGET LINES.
where gty_one is a internal table without headder.
regards,
Disha
‎2016 Mar 30 4:22 PM
‎2016 Mar 31 7:59 AM
Thank you for reply.
i did as you suggested in my code.
MOVE-CORRESPONDING <lfs_one> to gs_one-d1.
APPEND gs_one to gty_one.
But throwing an error both: must be the structure or both should be the internal table.
Any solution for such an issue?
Thanks and regards,
Disha
‎2016 Mar 31 8:03 AM
moreover, i have 7.4 SP 11 version. still not working as you suggested. But i checked few sample code for without loop in system and they ran also.
‎2016 Mar 31 8:11 AM
Hi Disha,
As you are moving to table, you might get error stating that component "d1" does not exist. In such case, better you loop on table append data to target table.
Thanks,
Hardik
‎2016 Mar 31 10:51 AM
Disha Patel wrote:
...
But throwing an error both: must be the structure or both should be the internal table.
...
Yes, ensure both are structures or both are internal tables.
‎2016 Mar 31 11:16 AM
Oh, my bad, i got that wrong with the d1 field. It seems to be structured, and your goal is to have a new line in gty_one FOR EACH line of <lfs_one>, with the content of the line of <lfs_one> ending up in the fields of d1?
That would be (if the type of d1 and the line type of <lfs_one> are the same):
gty_one = VALUE #( FOR <wa> in <lfs_one> ( d1 = <wa> ) ).
If not:
gty_one = VALUE #( FOR <wa> IN <lfs_one> ( d1 = CORRESPONDING #( <wa> ) ) ).
(This overwrites any content previously in gty_one, if you need to keep entries, use BASE addition).
By the way, do you have any specific reason to avoid the loop? Internally, this statement is resolved into some sort of loop too, you won't gain performance here.
edit: Matthews approach also seems promising, if the d1 = table_line works for you.
gs_one = corresponding #( <fs_one> mapping d1 = table_line )regards,
Thomas
‎2016 Mar 31 11:03 AM
You have been quite vague on your data structures and what you are trying to achieve. If you had been more clear, you probably would have had a resolution by now. As an IT worker you should be used to being specific and exact.
Please confirm the following.
1. You have an internal table of unknown structure <fs_one>.
2. You have an internal table gs_one
3. gs_one has a field d1
4. You wish to put every record in <fs_one> into each d1 field of table gs_one.
Possibly you need something like gs_one = corresponding #( <fs_one> mapping d1 = table_line )
‎2016 Mar 31 11:36 AM
Hello Matthew,
Please find the details as per below:
1. You have an internal table of unknown structure <fs_one>. : Assigning this field pointer to DSO's active table.
2. You have an internal table gt_one : internal table is gt_one and as i am unable to remove the loop in my shared code, so i used gs_one as a work area.
3. gs_one has a field d1 : gt_one having d1 field. More over this d1 having same structure as the <fs_one>.
4. You wish to put every record in <fs_one> into each d1 field of table gs_one.:i want to push all the records of <fs_one> to gt_one-d1 field.
Hope you can share some solution
Regards,
Disha
‎2016 Mar 31 1:11 PM
If gt_one already contains data (which seems likely), then you must loop, I think.
LOOP AT <fs_one> ASSIGNING FIELD-SYMBOL( <record> ).
READ TABLE gt_one ASSIGNING FIELD-SYMBOL( <gs_one> ) INDEX sy-tabix.
<gs_one>-d1 = <record>.
ENDLOOP.
This will be quite efficient.