‎2022 Sep 23 11:07 AM
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.
‎2022 Sep 23 11:17 AM
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 0And in csks there are two lines
datab datbi func_area
20220101 20220531 FM
20220601 20221231 FRThe 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
‎2022 Sep 23 1:14 PM
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.
‎2022 Sep 23 2:31 PM
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