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

How to improve loop inside loop?

former_member625844
Participant
0 Likes
1,298

I 'm writng a program. First I query fields WTGXXX and objnr from cosp_bak. Then for each line I search csks with same objnr and filled func_area field.

Suppose data in cosp_bak like below:

WTG001 WTG002 WTG003 WTG004 WTG005 WTG006 WTG007 WTG008 WTG009 WTG010 WTG011 WTG012

3 4 0 0 0 8 0 0 0 0 0 0

And in csks there are two lines

datab datbi func_area

20220101 20220531 FM

20220601 20221231 FR

The expected result will be two rows as below:

WTG001 WTG002 WTG003 WTG004 WTG005 WTG006 WTG007 WTG008 WTG009 WTG010 WTG011 WTG012

3 4 0 0 0 0 0 0 0 0 0 0 FM

3 4 0 0 0 8 0 0 0 0 0 0 FR

I wonder is there a better way to do it since loop inside loop is pretty consuming?Thx.

3 REPLIES 3
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,226

Please format better your question to make it legible e.g. as follows

Suppose data in cosp_bak like below:

WTG001 WTG002 WTG003 WTG004 WTG005 WTG006 WTG007 WTG008 WTG009 WTG010 WTG011 WTG012
3      4      0      0      0      8      0      0      0      0      0      0

And in csks there are two lines

datab    datbi    func_area
20220101 20220531 FM
20220601 20221231 FR

The expected result will be two rows as below:

WTG001 WTG002 WTG003 WTG004 WTG005 WTG006 WTG007 WTG008 WTG009 WTG010 WTG011 WTG012 func_area
3      4      0      0      0      0      0      0      0      0      0      0      FM
3      4      0      0      0      8      0      0      0      0      0      0      FR
Read only

prakashjasti
Contributor
0 Likes
1,226

Hi Ricky,

Loop at csks (table having two rows) and read the values from cosp_bak (One row) with key and populate values as required.

Thanks,

Prakash.

Prakash J
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,226

You could use a JOIN between COSP_BACK and CSKS but keep date from/to in the result table as there will be duplicate amounts to resolve:

Work on the result table in a single LOOP, clearing amount not relevant : if one record of CSKS was valid from january to march and another one from april. then clear amounts for april-december in the first record, clear amounts for january-march in the second record, delete any record with no non-null amount.

With your data you should get

WTG001 WTG002 WTG003 WTG004 WTG005 WTG006 WTG007 WTG008 WTG009 WTG010 WTG011 WTG012 datab    datbi    func_area
3      4      0      0      0      0      0      0      0      0      0      0      20220101 20220531 FM

0      0      0      0      0      8      0      0      0      0      0      0      20220601 20221231 FR