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

ABAP Loop Question for next record

Former Member
0 Likes
2,023

Hello All, I am new to ABAP so please forgive this basic question. The below is a snippet of code I have in a ABAP Proxy.

Here is a snippet of my code:

DATA: ls_item TYPE ZSHOPPING_CART_IN_BBP_PDS_SC_I.

DATA: i_item TYPE TABLE OF bbp_pds_sc_item_icu.

DATA: w_item TYPE bbp_pds_sc_item_icu.

....

LOOP AT input-I_ITEM-item INTO ls_item.

CLEAR w_item.

w_item-guid = v_item_guid.

w_item-parent = v_header_guid.

w_item-description = ls_item-description.

w_item-number_int = ls_item-number_int.

w_item-category = ls_item-category.

w_item-category_id = ls_item-category_id.

w_item-product_type = ls_item-product_type.

APPEND w_item TO i_item.

ENDLOOP.

-


The structure input-I_ITEM-item is an input from a ABAP Proxy. This all works great if I feed in only 1 line item to proxy, but if I send in two line items the result is i_item has line item 1 twice, and I get nothing for line item2. It is almost like the the loop runs twice but the ls_item stays on line 1. I am sure I am missing something simple.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,600

You sure this is correct? These values are not coming from LS_ITEM?

w_item-guid = v_item_guid.
w_item-parent = v_header_guid.

REgards,

Rich Heilman

12 REPLIES 12
Read only

suresh_datti
Active Contributor
0 Likes
1,601

CLEAR ls_item after the APPEND statement.

~Suresh

Read only

0 Likes
1,601

Hi Suresh,

I added the CLEAR ls_item. after the Append but I still get record 1 twice.

Cheers,

J

Read only

0 Likes
1,601

I_ITEM seems to be a structure and NOT LINE TYPE.

Rajesh - You are right. CLEAR clears header area.

Thanks,

SKJ

Read only

Former Member
0 Likes
1,601

Try clearing like this:

LOOP AT input-I_ITEM-item INTO ls_item.

CLEAR w_item.

w_item-guid = v_item_guid.

w_item-parent = v_header_guid.

w_item-description = ls_item-description.

w_item-number_int = ls_item-number_int.

w_item-category = ls_item-category.

w_item-category_id = ls_item-category_id.

w_item-product_type = ls_item-product_type.

APPEND w_item TO i_item.

<b>CLEAR i_item.</b>

ENDLOOP.

Thanks,

SKJ

Read only

0 Likes
1,601

Hi SKJ,

If we clear an internal table with out header line(i_item) then the contents of the table will get deleted. Correct me if I'm wrong.

Read only

0 Likes
1,601

Hi SKJ,

When I add CLEAR i_item. I get no lines outputted.

Cheers,

J

Read only

Former Member
0 Likes
1,601

Hi,

Check if the internal table <b>input-I_ITEM-item</b> has two different rows..

Thanks,

Naren

Read only

0 Likes
1,601

Here is a snippet of the XML I am sending to ABAP proxy:

<I_ITEM>

<item>

<GUID>00000000000000000000000000055556</GUID>

<PARENT>00000000000000000000000000055555</PARENT>

<NUMBER_INT>0000000001</NUMBER_INT>

<DESCRIPTION>Proxy Test Line</DESCRIPTION>

<CATEGORY>268CA1C5BB9965449BED8C9B49484999</CATEGORY>

<CATEGORY_ID>03000</CATEGORY_ID>

<PRODUCT_TYPE>01</PRODUCT_TYPE>

</item>

<item>

<GUID>00000000000000000000000000055557</GUID>

<PARENT>00000000000000000000000000055555</PARENT>

<NUMBER_INT>0000000002</NUMBER_INT>

<DESCRIPTION>Proxy Test Line 2</DESCRIPTION>

<CATEGORY>268CA1C5BB9965449BED8C9B49484999</CATEGORY>

<CATEGORY_ID>03000</CATEGORY_ID>

<PRODUCT_TYPE>01</PRODUCT_TYPE>

</item>

</I_ITEM>

Read only

Former Member
0 Likes
1,601

Hi Joe,

check the values of the fields

ls_item-description,

ls_item-number_int,

ls_item-category,

ls_item-category_id,

ls_item-product_type in debugging,

ensure that they are different for the 2 line items.

Read only

0 Likes
1,601

Hi All, Maybe this will help. When I remove all clear statements and move the APPEND w_item TO i_item outside the ENDLOOP, it writes only the second line from input-I_ITEM-item. So this shows I have two lines but seems to be a problem with my routine moving to next line. Not sure hope this helps.

Cheers,

j

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,601

You sure this is correct? These values are not coming from LS_ITEM?

w_item-guid = v_item_guid.
w_item-parent = v_header_guid.

REgards,

Rich Heilman

Read only

0 Likes
1,601

Hi Rich,

Looks like you are correct in that because I am not passing the item-guid as a unique value both records are using the same guid resulting in the record showing as duplicates. I will work through the logical and determine what is wrong, but it looks like it is not an issue with moving through the loop.

Thanks Everyone,

J