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

Using corresponding in FOR, THEN and UNTIL|WHILE

ShivaKona
Product and Topic Expert
Product and Topic Expert
0 Likes
1,603

Hi Experts,

DATA(lv_len) = lines( poitem ).
poitem[] = VALUE #( FOR i = 10 THEN i + 10 UNTIL i GT lv_len * 10
( po_item = i acctasscat = ‘W’ ) ) .

In the above syntax i have tried to embed corresponding so that only two fields of table poitem gets filled but was encountered with errors

DATA(lv_len) = lines( poitem ).
poitem[] = VALUE #( FOR i = 10 THEN i + 10 UNTIL i GT lines( poitem ) * 10
( po_item = i acctasscat = ‘W’ ) ) .

And also i have tried giving length regex so that it runs for number of table rows but not successful

So please can you help me in this two points

Regards,

Shiva

5 REPLIES 5
Read only

Domi
Active Contributor
0 Likes
1,415

Hi

ad 1) You are using the constructor expression VALUE to greate a new internal table with only po_item and acctasscat filled.

Wich errors have you encountered? Coding works fine!


ad 2) There is no regex! this will add only 1 row to the table!


If you try to change the table poitem - I assume you want to do this... - you need to use some other coding and commands!


regards Domi

Read only

DoanManhQuynh
Active Contributor
0 Likes
1,415

i see no error in both of your code. what error you got?

Read only

ShivaKona
Product and Topic Expert
Product and Topic Expert
0 Likes
1,415

poitem[] has already 6 lines in it.

poitem[] = VALUE #( FOR i = 10 THEN i + 10 UNTIL i GT lines( poitem ) * 10

( po_item = i acctasscat = ‘W’ ) ) .

1)In this syntax, there was no error but ideally it should run for 6 iterations considering UNTIL i GT lines( poitem ) * 10 but it was only running for single iteration

2)Imagine there are already some fields filled in the table so they are getting wiped out and only two fields po_item and acctasscat are getting filled

So how to handle this situation

Read only

srikanthnalluri
Active Participant
0 Likes
1,415

Hi Shiva, If i understand correctly, you wanted to loop the poitem based on number of line items in it and move only two fields to another poitem table.

Then you can directly loop poitem and moved what ever fields you wanted to different internal table using CORRESPONDING. Please check example.

types:
  begin of ty_tab1,
    matnr type matnr,
    mbrsh type mbrsh,
  end of ty_tab1,
  tt_tab1 type standard table of ty_tab1 with default key.

data: lt_tab1 type tt_tab1.

select * from mara into table @data(lt_mara) up to 100 rows.

lt_tab1 = value tt_tab1( for wa in lt_mara ( corresponding #( wa ) ) ).
cl_demo_output=>display( lt_tab1 ).
Read only

ShivaKona
Product and Topic Expert
Product and Topic Expert
0 Likes
1,415

Hi SN,

You are correct but i don't want to construct new table, but update two fields in the existing poitem table which already has records in it, one field with constant value and other with an incrementing value.

( po_item = i acctasscat = ‘W’ )

Regards,

Shiva