RE: New puzzle
Posted in 1997
I don't think the below example will quite handle the needs of the
problem. The below array will go accross instead of down. Example
Below output...
V1 V2 V3
V4 V5 V6
V7....
desired output...
V1 V4 V7
V2 V5 V8
V3 V6 V9
In order to do this without a using an array I think you would have to
do something like this.
main
define
st1,st2,st3 state.statename
l_size integer
l_counter,l_columns integer
l_columns = 3
/* get the number of rows for the report....(this is each data element
not rows)
select count(*) into l_size from state.......l_size = l_size / l_columns
declare curs1 cursor for select statename from state order by 1
declare curs2 cursor for select statename from state order by 1
declare curs3 cursor for select statename from state order by 1
let l_counter = 1
open curs1
open curs2
open curs3
while l_counter <= (l_size * 2)
if l_counter <= l_size then fetch curs2 into st2 end if
if l_counter <= (l_size *2) then fetch curs3 into st3 end if
let l_counter = l_counter + 1
end while
/* now these three cursors sould be lined up to each fetch the next
element in each column...
let l_counter = 1
while l_counter <= l_size
fetch curs1 into st1
fetch curs2 into st2
fetch curs3 into st3
display st1,st2,st3
let l_counter = l_counter + 1
end while
end main
}-----Original Message-----
}From: Sujit Pal [SMTP:spal@scotch.den.csci.csc.com]
}Sent: Tuesday, July 29, 1997 12:01 PM
}To: 'Paul Roberts'
}Cc: 'informix-list@rmy.emory.edu'
}Subject: RE: New puzzle
}
}Paul
}
}If this is a 4GL puzzle, the solution is quite simple. Heres a program
}without using arrays which will do this:
}
}DATABASE test
}MAIN
} DEFINE st1, st2, st3 LIKE states.statename
} DECLARE cStatename CURSOR FOR
} SELECT statename FROM states
} ORDER BY 1
} OPEN cStatename
} WHILE (1)
} FETCH cStatename INTO st1
} IF (sqlca.sqlcode = NOTFOUND) THEN
} LET st1 = NULL
} END IF
} FETCH cStatename INTO st2
} IF (sqlca.sqlcode = NOTFOUND) THEN
} LET st2 = NULL
} END IF
} FETCH cStatename INTO st3
} IF (sqlca.sqlcode = NOTFOUND) THEN
} LET st3 = NULL
} END IF
} DISPLAY st1, st2, st3
} IF (st1 IS NULL) OR (st2 IS NULL) OR (st3 IS NULL) THEN
} EXIT WHILE
} END IF
} END WHILE
}END MAIN
}
}Instead of a DISPLAY you could send the contents out to a report.
}
}Doing it with a single select would be tougher (or maybe impossible?).
}
}HTH
}
}Sujit
}----------
}OK, here's my 4GL reporting puzzle: how do I produce a report ordered
}like this:
}
}ALABAMA LOUISIANA OHIO
}ALASKA MAINE OKLAHOMA
}ARIZONA MARYLAND OREGON
}ARKANSAS MASSACHUSETTS PENNSYLVANIA
}CALIFORNIA MICHIGAN RHODE ISLAND
}COLORADO MINNESOTA SOUTH CAROLINA
}CONNECTICUT MISSISSIPPI SOUTH DAKOTA
}DELAWARE MISSOURI TENNESSEE
}FLORIDA MONTANA TEXAS
}GEORGIA NEBRASKA UTAH
}HAWAII NEVADA VERMONT
}IDAHO NEW HAMPSHIRE VIRGINIA
}ILLINOIS NEW JERSEY WASHINGTON
}INDIANA NEW MEXICO WEST VIRGINIA
}IOWA NEW YORK WISCONSIN
}KANSAS N CAROLINA WYOMING
}KENTUCKY NORTH DAKOTA
}
}One way would be load up an array, but that would set a limit on the number
}of elements we would handle (since the array has to be declared as of being
}of some finite size). Is there a better way to do it?
}
} - Paul
}
}
}