Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Nested FOR statement ABAP

amit_khedekar
Discoverer
0 Likes
1,775

Hi Everyone.

I want to replace the below old style loop logic with new FOR statement.

The final table p_gt_sales_area should contain data merging 3 internal tables

Example::

so_vkorg is having values VK1

so_vtweg is having values VT1 , VT2 and VT3

so_spart is having values SP1 and SP2

then the final table p_gt_sales_area should have below values

VK1 VT1 SP1

VK1 VT1 SP2

VK1 VT2 SP1

VK1 VT2 SP2

VK1 VT3 SP1

VK1 VT3 SP2

Old logic ::-

LOOP AT so_vkorg ASSIGNING FIELD-SYMBOL(<lfs_vkorg>).
CLEAR : ls_sales_area.
ls_sales_area-vkorg = <lfs_vkorg>-low. ""Sales Org

LOOP AT so_vtweg ASSIGNING FIELD-SYMBOL(<lfs_vtweg>).
ls_sales_area-vtweg = <lfs_vtweg>-low. ""Dist Channel

LOOP AT so_spart ASSIGNING FIELD-SYMBOL(<lfs_spart>).
ls_sales_area-spart = <lfs_spart>-low. ""Division

APPEND ls_sales_area TO p_gt_sales_area.

ENDLOOP.

ENDLOOP.

ENDLOOP.

6 REPLIES 6
Read only

ChrisSolomon
Active Contributor
1,637

Soooo can you show what you tried or are you really wanting someone to do the work for you?

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,637

To help you, here is the starting point (replace ... with some contents):

p_gt_sales_area = VALUE #(
    FOR ... 
    FOR ... 
    ...
    ).
Read only

amit_khedekar
Discoverer
0 Likes
1,637

Hi christopher.solomon

I was trying as below but its not working, it would be appreciating if you can assist

p_gt_sales_area = VALUE #(
BASE p_gt_sales_area
(
vkorg = REDUCE vkorg( INIT vkorg TYPE vkorg
FOR <lfs_vkorg> IN so_vkorg
NEXT vkorg = <lfs_vkorg>-low

vtweg = REDUCE vtweg( INIT vtweg TYPE vtweg
FOR <lfs_vtweg> IN so_vtweg
NEXT vtweg = <lfs_vtweg>-low

spart = REDUCE spart( INIT spart TYPE spart
FOR <lfs_spart> IN so_spart
NEXT spart = <lfs_spart>-low
)

)

)
)
).

Read only

Sandra_Rossi
Active Contributor
1,637

You don't need reduce, all you need is VALUE #( FOR ... FOR ... FOR ... ( ... ) ).

Read only

amit_khedekar
Discoverer
0 Likes
1,637

Thanks Sandra for assistance. It helped me.

Read only

former_member598787
Participant
1,637

hello

pls post the final solution