on ‎2021 Mar 16 9:23 AM
Hi, friends!
I have a global internal table gt_file_data. The structure of gt_file_data you can see below.
As you can see there're several fields with string_table type.
I need to insert the values of these fields to new internal tables and I have to use a nested loop for doing this.
I know it's not good and too resource-intensive.
Can anybody advise me on the way to get around a nested loop?
TYPES: BEGIN OF stt_file_data,
code TYPE guid,
name TYPE string,
actions TYPE string_table,
product_id TYPE comt_product_id,
comp TYPE string_table,
status TYPE abap_bool,
property TYPE string_table,
END OF stt_file_data.
DATA: gt_file_data TYPE TABLE OF stt_file_data,
ls_file_data LIKE LINE OF gt_file_data.
LOOP AT gt_file_data ASSIGNING FIELD-SYMBOL(<fs_file_data>).
" Some operations with other fields ...
LOOP AT <fs_file_data>-actions ASSIGNING FIELD-SYMBOL(<fs_action>).
" Insert data into another new itab ...
ENDLOOP.
LOOP AT <fs_file_data>-comp ASSIGNING FIELD-SYMBOL(<fs_comp>).
" Insert data into another new itab ...
ENDLOOP.
LOOP AT <fs_file_data>-property ASSIGNING FIELD-SYMBOL(<fs_property>).
" Insert data into another new itab ...
ENDLOOP.
ENDLOOP.
Request clarification before answering.
It will depend on what the "Insert data into another new itab"-part really comes down to, but you could look at the MOVE-CORRESPONDING or VALUE statements (or if both internal tables are identical you can go for APPEND LINES OF). Then again, if you have to convert the string-values to structures, it will be come more complicated..
But like I said it all depends on what needs to be done exactly. And keep in mind that writing it differently doesn't necessarily mean it is more performant. A VALUE statement containing a LET is still a loop.
And on the "not-good" and "resource intensive" part, do you have performance issues at the moment?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
pvnierop, Thanks a lot for your feedback!
1. Data from gt_file_date-actions will be transferred to database table ztd_actions-action which type is char(40).
2. Data from gt_file_date-comp will be transferred to database table ztd_comps-comp which type is char(40).
3. Data from gt_file_date-property will be transferred to database table ztd_properties-property which type is char(20).
4. At the moment I don't have any performance issues. It's just my fear about nested loop.
Have you considered something like this then:
actions = file_date-actions
or if you need to collect all the actions
APPEND LINES OF file_date-actions TO actions
(and I know I haven't used your variables, but I hope this describes it enough for you to implement)
If you get warnings that the types are different, I guess a CONV statement could help out there
I want to supplement the previous comment!
gt_file_date-actions data I wanna save into lt_actions-action.
gt_file_date-comp data I wanna save into lt_comps-comp.
gt_file_date-property data I wanna save into lt_properties-property.
Then I'll transfer data from lt_actions, lt_comps, lt_properties to the database tables ztd_actions, ztd_comps, ztd_properties, respectively.TYPES: BEGIN OF stt_action,
act_code TYPE guid,
action(40) TYPE c,
END OF stt_action,
BEGIN OF stt_comp,
comp_code TYPE guid,
comp(40) TYPE c,
END OF stt_comp,
BEGIN OF stt_property,
prop_code TYPE guid,
property(20) TYPE c,
END OF stt_property.
DATA: lt_actions TYPE TABLE OF stt_action,
ls_actions LIKE LINE OF lt_actions,
lt_comps TYPE TABLE OF stt_comp,
ls_comp LIKE LINE OF lt_comps,
lt_properties TYPE TABLE OF stt_property,
ls_property LIKE LINE OF lt_properties.| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.