How add only required fields from table to dynamic temp table? - PROGRESS 4GL - openedge

I am new to progress 4gl and below is the query used to add all fields from a table to dynamic temp table except few fields but I am not sure how to add only required fields to dynamic temp table. Please help to modify the query I shared.
/* p-ttdyn2.p - a join of 2 tables */
DEFINE VARIABLE tth4 AS HANDLE.
DEFINE VARIABLE btth4 AS HANDLE.
DEFINE VARIABLE qh4 AS HANDLE.
DEFINE VARIABLE bCust AS HANDLE.
DEFINE VARIABLE bOrder AS HANDLE.
DEFINE VARIABLE i AS INTEGER.
DEFINE VARIABLE fldh AS HANDLE EXTENT 15.
bCust = BUFFER customer:HANDLE.
bOrder = BUFFER order:HANDLE.
CREATE TEMP-TABLE tth4.
tth4:ADD-FIELDS-FROM(bCust,"address,address2,phone,city,comments").
tth4:ADD-FIELDS-FROM(bOrder,"cust-num,carrier,instructions,PO,terms").
tth4:TEMP-TABLE-PREPARE("CustOrdJoinTT").
btth4 = tth4:DEFAULT-BUFFER-HANDLE.
FOR EACH customer WHERE cust.cust-num < 6, EACH order OF customer:
btth4:BUFFER-CREATE.
btth4:BUFFER-COPY(bCust).
btth4:BUFFER-COPY(bOrder).
END.
/* Create Query */
CREATE QUERY qh4.
qh4:SET-BUFFERS(btth4).
qh4:QUERY-PREPARE("for each CustOrdJoinTT").
qh4:QUERY-OPEN.
REPEAT WITH FRAME zz DOWN:
qh4:GET-NEXT.
IF qh4:QUERY-OFF-END THEN LEAVE.
REPEAT i = 1 TO 15:
fldh[i] = btth4:BUFFER-FIELD(i).
DISPLAY fldh[i]:NAME FORMAT "x(15)"
fldh[i]:BUFFER-VALUE FORMAT "x(20)".
END.
END.
btth4:BUFFER-RELEASE.
DELETE OBJECT tth4.
DELETE OBJECT qh4.

ADD-FIELDS-FROM only supports excluding fields that are not needed. Instead you can use ADD-LIKE-FIELD multiple times:
CREATE TEMP-TABLE tth4.
tth4:ADD-LIKE-FIELD("address", "customer.address").
tth4:ADD-LIKE-FIELD("address2", "customer.address2").
tth4:ADD-LIKE-FIELD("phone", customer.phone").
...
tth4:ADD-LIKE-FIELD("cust-num", "Order.cust-num").
...
tth4:TEMP-TABLE-PREPARE("CustOrdJoinTT").
btth4 = tth4:DEFAULT-BUFFER-HANDLE.

Depending on your use case, you can also invert the required field list to an except field list:
var handle ht,hb.
var longchar lcjson.
function invertFields returns character (
i_hb as handle,
i_crequired as char
):
var char cexcept,cfield.
var int ic.
do ic = 1 to i_hb:num-fields:
cfield = i_hb:buffer-field( ic ):name.
if lookup( cfield, i_crequired ) = 0 then
cexcept = cexcept + ',' + cfield.
end.
return substring( cexcept, 2 ).
end function.
create temp-table ht.
ht:add-fields-from(
buffer customer:handle,
invertFields( buffer customer:handle, "CustNum,Name" )
).
ht:temp-table-prepare( 'tt' ).
hb = ht:default-buffer-handle.
hb:buffer-create().
assign
hb::CustNum = 1
hb::Name = 'test'
.
hb:write-json( 'longchar', lcjson, true ).
message string( lcjson ).
https://abldojo.services.progress.com/?shareId=624993253fb02369b25437c4

Related

What is the easiest way to simulate an SQL "IN" statement

What is the easiest way to achieve the "IN" SQL functionality in Progress? Here is my code block, and I want to limit this query to 5 different pin numbers for my test. I'd rather not use a string of "OR"s if I can avoid that.
//using the "IN" way with specific pin numbers
FOR EACH names NO-LOCK WHERE names.m-date GE 1/1/1900: //AND names.pin IN (179,198,200,201,210)
FOR EACH nacminfo NO-LOCK WHERE nacminfo.pin = names.pin:
FIND FIRST nacmtype WHERE nacmtype.contact_type_num EQ nacminfo.contact_type_num
AND nacmtype.descr MATCHES ("~*" + "email") NO-LOCK NO-ERROR.
IF AVAILABLE nacmtype THEN DO:
DISPLAY
nacmtype.type_val
nacmtype.descr.
END.
END.
END.
As Stefan says, you can use LOOKUP but performance may suffer since you will need to compare every record with the list.
Using a series of OR comparisons can be very efficient and if the list is short and static (like your example) not at all hard to do.
If the list is longer or changes frequently or if it is held in a variable then you might consider iterating over the list outside the FOR EACH.
Something like this:
define variable i as integer no-undo.
define variable j as integer no-undo.
define variable n as integer no-undo.
define variable myList as character no-undo.
myList = "179,198,200,201,210".
n = num-entries( myList ).
do j = 1 to n:
FOR EACH names NO-LOCK WHERE names.m-date GE 1/1/1900 AND names.pin = entry( j, myList ):
FOR EACH nacminfo NO-LOCK WHERE nacminfo.pin = names.pin:
FIND FIRST nacmtype NO-LOCK
WHERE nacmtype.contact_type_num EQ nacminfo.contact_type_num
AND nacmtype.descr MATCHES ("~*" + "email") NO-ERROR.
IF AVAILABLE nacmtype THEN DO:
DISPLAY
nacmtype.type_val
nacmtype.descr.
END.
END.
END.
end.
Or, finally, transform the list into a temp-table. Something like this:
define temp-table tt_myList no-undo
  field namePIN as character
  index namePIN-idx is unique primary namePIN.
.
define variable i as integer no-undo.
define variable n as integer no-undo.
define variable myList as character no-undo.
myList = "179,198,200,201,210".
/* build a TT */
n = num-entries( myList ).
do i = 1 to n:
  create tt_myList.
  tt_myList.namePIN = entry( i, myList ).
end.
for each tt_myList:
FOR EACH names NO-LOCK WHERE names.m-date GE 1/1/1900 AND names.pin = tt_myList.repName:
FOR EACH nacminfo NO-LOCK WHERE nacminfo.pin = names.pin:
FIND FIRST nacmtype NO-LOCK
WHERE nacmtype.contact_type_num EQ nacminfo.contact_type_num
AND nacmtype.descr MATCHES ("~*" + "email") NO-ERROR.
IF AVAILABLE nacmtype THEN DO:
DISPLAY
nacmtype.type_val
nacmtype.descr.
END.
END.
END.
end.
You could join the TT in the FOR EACH but it won't really make any difference and, personally, I find the nested FOR EACH syntax more natural.
Do you really need that FIRST? Can there ever be more than one record in the result of that FIND?
Lastly, MATCHES isn't doing you any performance favors. Hopefully the other parts of the WHERE clause are narrowing the result set enough that its impact is minimal.
Beware of the performance, since a function on the left side generally cannot use an index, but you can use the lookup function:
for each names
where names.m-date ge 1/1/1990
and lookup( string( names.pin ), '179,198,200,201,210' ) ) > 0
no-lock:
// do something
end.
I'd rather not use a string of "OR"s if I can avoid that.
As Stefan notes, using a function in the WHERE clause means that you will not use any indexes. That will impact performance, possibly very badly.
Look into using dynamic queries to build a WHERE clause with a a bunch of OR names.pin = 179 phrases.
You will need to tweak the building of the where string to make sure that it uses the best indexes available (and that's a huge topic by itself). You can see what indexes are used via the LOG-MANAGER - see https://docs.progress.com/bundle/openedge-abl-troubleshoot-applications-122/page/Query-information-logged.html for some info on this.
define variable pins as integet extent 5 initial [179,198,200,201,210] no-undo.
define variable loop as integer no-undo.
define variable cnt as integer no-undo.
define variable whereString as character no-undo.
define query q1 for names.
whereString = ' for each names no-lock where names.m-date GE 1/1/1900'.
cnt = extent(pins).
do loop = 1 to cnt:
whereSTring = whereSTring + substitute(' OR names.pin = &1', pins[loop]).
end.
query q1:query-prepare(whereString).
query q1:query-open().
query q1:get-first().
do while available names:
// do something with the names
query q1:get-next().
end.
finally:
query q1:query-close().
end finally.

How to add html tables in progress 4gl?

I created a temp table in Progress4gl and I need to email the data from temp table using html syntax. Which means I need to link all the fields in temp table to html table and email.
The fields in temp table are:
Part_ID, CustomerPartID, customer
Please help me with this.
Well you could just output the HTML. Something like this:
define temp-table tt_test
field f1 as integer
field f2 as character
field f3 as date
.
create tt_test.
assign
f1 = 1
f2 = "abc"
f3 = today
.
create tt_test.
assign
f1 = 2
f2 = "xyz"
f3 = today + 30
.
output to value( "mytable.html" ).
put unformatted "<table>" skip.
for each tt_test:
put unformatted substitute( " <tr><td>&1</td><td>&2</td><td>&3</td></tr>", f1, f2, f3 ) skip.
end.
put unformatted "</table>" skip.
output close.
For creating an html table you can (ab)use the power of datasets combined with serialize-name:
/* Write some awesome ABL code here, or load an existing snippet! */
define temp-table ttparts serialize-name "tr"
field part_id as char serialize-name "td"
field customerPartID as char serialize-name "td"
field customer as char serialize-name "td"
.
define dataset ds serialize-name "table" for ttparts .
define buffer bupart for ttparts.
create bupart.
assign
bupart.part_id = "one"
bupart.customer = "A"
.
create bupart.
assign
bupart.part_id = "two"
bupart.customer = "B"
.
def var lcc as longchar no-undo.
dataset ds:write-xml( "longchar", lcc, true ).
message string( lcc ).
https://abldojo.services.progress.com:443/#/?shareId=5d1618c14b1a0f40c34b8bc8
An updated version which accepts any temp-table handle and will return a longchar containing the HTML table:
function createHtmlTable returns longchar (
i_ht as handle
):
def var lcc as longchar.
def var hds as handle.
def var hb as handle.
def var ic as int.
create dataset hds.
hds:serialize-name = "table". // not needed if stripped below
create buffer hb for table i_ht.
hb:serialize-name = "tr".
hds:add-buffer( hb ).
do ic = 1 to hb:num-fields:
hb:buffer-field( ic ):serialize-name = "td".
end.
hds:write-xml( "longchar", lcc, true ).
// remove xml declaration
lcc = substring( lcc, index( lcc, "<", 2 ) ).
entry( 1, lcc, ">" ) = "<table". // see comment above
return lcc.
finally:
delete object hds.
end finally.
end function.
define temp-table ttparts
field part_id as char
field customerPartID as char
field customer as char
.
define buffer bupart for ttparts.
create bupart.
assign
bupart.part_id = "one"
bupart.customer = "A"
.
create bupart.
assign
bupart.part_id = "two"
bupart.customer = "B"
.
message string( createHtmlTable( temp-table ttparts:handle ) ).
https://abldojo.services.progress.com/#/?shareId=5d1760d84b1a0f40c34b8bcd
There is no built-in method to do this. One way that I could think of is converting the temp table to json and then json to HTML. I believe there are several utilities to convert json to html table. You can convert temp table to json in ABL using WRITE-JSON method.
An example from Progress documentation:
DEFINE VARIABLE cTargetType AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE lFormatted AS LOGICAL NO-UNDO.
DEFINE VARIABLE lRetOK AS LOGICAL NO-UNDO.
DEFINE TEMP-TABLE ttCust NO-UNDO LIKE Customer.
/* Code to populate the temp-table */
ASSIGN
cTargetType = "file"
cFile = "ttCust.json"
lFormatted = TRUE.
lRetOK = TEMP-TABLE ttCust:WRITE-JSON(cTargetType, cFile, lFormatted).

Display dynamic number of fields

I'm new to progress and I'm trying to learn dynamic queries. As a Task I gave to myself I want to read a csv file and create a table based on the contents of said file. So far everything works but I can't really seem to find a way to display the contents properly.
I have a temp-table created based on a csv input with the first line being the columns or fields of the table and everything after being the records.
Field1,Field2,Field3,Field4,Fieldn...
Value1.1,Value2.1,Value3.1,Value4.1,Valuen.1...
Value1.2,Value2.2,Value3.2,Value4.2,Valuen.1...
Value1.3,Value2.3,Value3.3,Value4.3,Valuen.1...
Value1.4,Value2.4,Value3.4,Value4.4,Valuen.1...
etc...
How can I display a dynamic number of fields and their names properly?
The following things are unknown:
Number of fields
Name of fields
Values of records
The following works and shows the data in the desired format (but it's hard coded):
DO WHILE qMyTable:GET-NEXT():
DISPLAY
bMyTable:BUFFER-FIELD(1):BUFFER-VALUE LABEL 'PK'
bMyTable:BUFFER-FIELD(2):BUFFER-VALUE LABEL 'Field1'
bMyTable:BUFFER-FIELD(3):BUFFER-VALUE LABEL 'Field2'
bMyTable:BUFFER-FIELD(4):BUFFER-VALUE LABEL 'Field3'
bMyTable:BUFFER-FIELD(5):BUFFER-VALUE LABEL 'Field4'
WITH FRAME f DOWN.
DOWN WITH FRAME f.
END.
I'm trying to loop over the buffer fields but I can't find a way to do it without redefining the DISPLAY command every iteration. Also I don't know how to display the labels of the fields in as a header row.
I'm looking for something like this :
/*
This doesn't work
*/
DO WHILE qMyTable:GET-NEXT():
DO i = 1 to iNumFields:
DISPLAY bMyTable:BUFFER-FIELD(i):BUFFER-VALUE LABEL cTitlerow[i].
END.
END.
This would be the full code:
/*
Variables
*/
DEF VAR i AS INTEGER INITIAL 0 NO-UNDO. //Counter
DEF VAR iEntry AS INTEGER INITIAL 0 NO-UNDO. //Counter2
DEF VAR cTitleRow AS CHARACTER NO-UNDO. //Fields csv
DEF VAR cDataRow AS CHARACTER NO-UNDO. //Entries csv
DEF VAR cFieldName AS CHARACTER NO-UNDO. //Field
DEF VAR iNumFields AS INTEGER NO-UNDO. //Amount of Fields
DEF VAR iNumLines AS INTEGER NO-UNDO. //Amount of records
DEF VAR cTitleArray AS CHARACTER EXTENT NO-UNDO. //Fields Array
/*
Handles
*/
DEF VAR ttMyTable AS HANDLE NO-UNDO. //Temp table
DEF VAR bMyTable AS HANDLE NO-UNDO. //Buffer
DEF VAR qMyTable AS HANDLE NO-UNDO. //Query
INPUT FROM 'C:\Path\To\CSV\mycsv.csv'.
/*
Get first row for fields and field names
*/
IMPORT UNFORMATTED cTitleRow.
iNumFields = NUM-ENTRIES(cTitleRow) + 1. //Additional field for PK
EXTENT(cTitleArray) = iNumFields.
/*
Dynamic table creation
*/
CREATE TEMP-TABLE ttMyTable.
ttMyTable:ADD-NEW-FIELD('PK', 'integer').
cTitleArray[1] = 'PK'.
DO i = 2 to iNumFields:
iEntry = i - 1.
cFieldName = ENTRY(iEntry,cTitleRow).
ttMyTable:ADD-NEW-FIELD(cFieldName, 'character').
cTitleArray[i] = cFieldName.
END.
/*
Adding and defining indexes
*/
ttMyTable:ADD-NEW-INDEX('idx', TRUE, TRUE).
ttMyTable:ADD-INDEX-FIELD('idx', 'PK', 'asc').
ttMyTable:TEMP-TABLE-PREPARE('myTable').
/*
Creating buffer
*/
bMyTable = ttMyTable:DEFAULT-BUFFER-HANDLE.
/*
Populating data
*/
REPEAT:
IMPORT UNFORMATTED cDataRow.
bMyTable:BUFFER-CREATE.
bMyTable::pk = iNumLines.
DO i = 2 to iNumFields:
iEntry = i - 1.
bMyTable:BUFFER-FIELD(i):BUFFER-VALUE = ENTRY(iEntry,cDataRow).
bMyTable:BUFFER-FIELD(i):COLUMN-LABEL = cTitleArray[i].
bMyTable:BUFFER-FIELD(i):LABEL = cTitleArray[i].
END.
iNumLines = iNumLines + 1.
END.
/*
Creating query
*/
CREATE QUERY qMyTable.
qMyTable:SET-BUFFERS(bMyTable).
qMyTable:QUERY-PREPARE('for each myTable').
qMyTable:QUERY-OPEN().
/*
/*
This doesn't work
*/
DO WHILE qMyTable:GET-NEXT():
DO i = 1 to iNumFields:
DISPLAY bMyTable:BUFFER-FIELD(i):BUFFER-VALUE.
END.
END.
*/
DO WHILE qMyTable:GET-NEXT():
DISPLAY
bMyTable:BUFFER-FIELD(1):BUFFER-VALUE LABEL 'PK'
bMyTable:BUFFER-FIELD(2):BUFFER-VALUE LABEL 'Field1'
bMyTable:BUFFER-FIELD(3):BUFFER-VALUE LABEL 'Field2'
bMyTable:BUFFER-FIELD(4):BUFFER-VALUE LABEL 'Field3'
bMyTable:BUFFER-FIELD(5):BUFFER-VALUE LABEL 'Field4'
WITH FRAME f DOWN.
DOWN WITH FRAME f.
END.
qMyTable:QUERY-CLOSE().
DELETE OBJECT qMyTable.
I think you only might have some frame issues. Your code should basically work.
This minor change with display your data but for it will display them all in one column.
DO WHILE qMyTable:GET-NEXT():
DO i = 1 to iNumFields:
DISPLAY bMyTable:BUFFER-FIELD(i):BUFFER-VALUE WITH FRAME f2 DOWN TITLE "Dynamic" .
DOWN WITH FRAME f2 .
END.
END.
So output will basically be
row1column1
row1column2
row1column3
...
row1columnN
row2column1
row2column2
row2column3
...
row2columnN
etc
Instead of
row1column1 row1column2 row1column3 ... row1columnN
row2column1 row2column2 row2column3 ... row2columnN
One idea to get the same result is to create a frame widget dynamically as well...
I'd do it this way. It would show the field value next to its name, and one record at a time. I hope this helps:
DO WHILE qMyTable:GET-NEXT():
DO i = 1 to iNumFields:
DISPLAY bMyTable:BUFFER-FIELD(i):NAME
bMyTable:BUFFER-FIELD(i):BUFFER-VALUE LABEL cTitlerow[i] WITH FRAME f DOWN.
DOWN WITH FRAME f.
END.
CLEAR FRAME f ALL.
END.
This should get you started on creating a frame and a "text" widgets dynamically:
define variable f as handle no-undo.
define variable t as handle no-undo.
define variable r as integer no-undo initial 1.
define variable c as integer no-undo initial 1.
create frame f.
assign
f:row = 4
f:column = 1
f:width-chars = 132
f:box = no
f:top-only = false
f:overlay = true
f:name = "something"
no-error.
create text t.
assign
t:frame = f
t:name = "text1"
t:format = substitute( "x(&1)", max( 1, 20, length( t:name )))
t:row = r
t:col = c
t:screen-value = "value1"
f:height-chars = max( r, f:height-chars )
.
f:visible = yes.
In your case you would probably want to create the frame just once at the top and then create 2 text widgets for each field - one for the label and one for the data values.

Select Top 1 From a Table For Each row in another Table

I am just starting to work with openedge and I need to join information from two tables but I just need the first row from the second one.
Basically I need to do a typical SQL Cross Apply but in progress. I look in the documentation and the Statement FETCH FIRST 10 ROWS ONLY only in OpenEdge 11.
My query is:
SELECT * FROM la_of PUB.la_ofart ON la_of.empr_cod = la_ofart.empr_cod
AND la_of.Cod_Ordf = la_ofart.Cod_Ordf
AND la_of.Num_ordex = la_ofart.Num_ordex AND la_of.Num_partida = la_ofart.Num_partida
CROSS APPLY (
SELECT TOP 1 ofart.Cod_Ordf AS Cod_Ordf_ofart ,
ofart.Num_ordex AS Num_ordex_ofart
FROM la_ofart AS ofart
WHERE ofart.empr_cod = la_ofart.empr_cod
AND ofart.Num_partida = la_ofart.Num_partida
AND la_ofart.doc1_num = ofart.doc1_num
AND la_ofart.doc2_linha = ofart.doc2_linha
ORDER BY ofart.Cod_Ordf DESC) ofart
I am using SSMS to extract data from OE10 using an ODBC connector and querying to OE using OpenQuery.
Thanks for all help.
If I correctly understood your question, maybe you can use something like this. Maybe this isn't the best solution for your problem, but may suit your needs.
DEF BUFFER ofart FOR la_ofart.
DEF TEMP-TABLE tt-ofart NO-UNDO LIKE ofart
FIELD seq AS INT
INDEX ch-seq
seq.
DEF VAR i-count AS INT NO-UNDO.
EMPTY TEMP-TABLE tt-ofart.
blk:
FOR EACH la_ofart NO-LOCK,
EACH la_of NO-LOCK
WHERE la_of.empr_cod = la_ofart.empr_cod
AND la_of.Cod_Ordf = la_ofart.Cod_Ordf
AND la_of.Num_ordex = la_ofart.Num_ordex
AND la_of.Num_partida = la_ofart.Num_partida,
EACH ofart NO-LOCK
WHERE ofart.empr_cod = la_ofart.empr_cod
AND ofart.Num_partida = la_ofart.Num_partida
AND ofart.doc1_num = la_ofart.doc1_num
AND ofart.doc2_linha = la_ofart.doc2_linha
BREAK BY ofart.Cod_Ordf DESCENDING:
ASSIGN i-count = i-count + 1.
CREATE tt-ofart.
BUFFER-COPY ofart TO tt-ofart
ASSIGN ofart.seq = i-count.
IF i-count >= 10 THEN
LEAVE blk.
END.
FOR EACH tt-ofart USE-INDEX seq:
DISP tt-ofart WITH SCROLLABLE 1 COL 1 DOWN NO-ERROR.
END.

u-sql script can not obtain scalar value from dataset

In u-sql script I must extract a variable from file to a dataset and then use it to form a name of output file. How can I get the variable from the dataset?
In details.
I have 2 input files: csv file with a set of fields and a dictionary file. The 1st file has file name like ****ClintCode*****.csv. The 2nd file-dictionary has 2 fields with mapping: ClientCode - ClintCode2. My task is extract ClientCode value from the file name, get ClientCode2 from the dictionary, insert it as a field to output file (implemented), and, moreover, form the name of output file as ****ClientCode2****.csv.
Dictionary csv file has the content:
OldCode NewCode
6HAA Alfa
CCVV Beta
CVXX gamma
? Davis
The question is how to get ClientCode2 into scalar variable to write an expression for the output file?
DECLARE #inputFile string = "D:/DFS_SSC_Automation/Tasks/FundInfo/ESP_FAD_GL_6HAA_20170930.txt"; // '6HAA' is ClientCode here that mapped to other code in ClientCode_KVP.csv
DECLARE #outputFile string = "D:/DFS_SSC_Automation/Tasks/FundInfo/ClientCode_sftp_" + // 'ClientCode' should be replaced with ClientCode from mapping in ClientCode_KVP.csv
DateTime.Now.ToString("yyyymmdd") + "_" +
DateTime.Now.ToString("HHmmss") + ".csv";
DECLARE #dictionaryFile string = "D:/DFS_SSC_Automation/ClientCode_KVP.csv";
#dict =
EXTRACT [OldCode] string,
[NewCode] string
FROM #dictionaryFile
USING Extractors.Text(skipFirstNRows : 1, delimiter : ',');
#theCode =
SELECT Path.GetFileNameWithoutExtension(#inputFile).IndexOf([OldCode]) >= 0 ? 1 : 3 AS [CodeExists],
[NewCode]
FROM #dict
UNION
SELECT *
FROM(
VALUES
(
2,
""
)) AS t([CodeExists],[NewCode]);
#code =
SELECT [NewCode]
FROM #theCode
ORDER BY [CodeExists]
FETCH 1 ROWS;
#GLdata =
EXTRACT [ASAT] string,
[ASOF] string,
[BASIS_INDICATOR] string,
[CALENDAR_DATE] string,
[CR_EOP_AMOUNT] string,
[DR_EOP_AMOUNT] string,
[FUND_ID] string,
[GL_ACCT_TYPE_IND] string,
[TRANS_CLIENT_FUND_NUM] string
FROM #inputFile
USING Extractors.Text(delimiter : '|', skipFirstNRows : 1);
// Prepare output dataset
#FundInfoGL =
SELECT "" AS [AccountPeriodEnd],
"" AS [ClientCode],
[FUND_ID] AS [FundCode],
SUM(GL_ACCT_TYPE_IND == "A"? System.Convert.ToDecimal(DR_EOP_AMOUNT) : 0) AS [NetValueOtherAssets],
SUM(GL_ACCT_TYPE_IND == "L"? System.Convert.ToDecimal(CR_EOP_AMOUNT) : 0) AS [NetValueOtherLiabilities],
0.0000 AS [NetAssetsOfSeries]
FROM #GLdata
GROUP BY FUND_ID;
// NetAssetsOfSeries calculation
#FundInfoGLOut =
SELECT [AccountPeriodEnd],
[NewCode] AS [ClientCode],
[FundCode],
Convert.ToString([NetValueOtherAssets]) AS [NetValueOtherAssets],
Convert.ToString([NetValueOtherLiabilities]) AS [NetValueOtherLiabilities],
Convert.ToString([NetValueOtherAssets] - [NetValueOtherLiabilities]) AS [NetAssetsOfSeries]
FROM #FundInfoGL
CROSS JOIN #code;
// Output
OUTPUT #FundInfoGLOut
TO #outputFile
USING Outputters.Text(outputHeader : true, delimiter : '|', quoting : false);
As David points out: You cannot assign query results to scalar variables.
However, we have a dynamic partitioned output feature in private preview right now that will give you the ability to generate file names based on column values. Please contact me if you want to try it out.
You can't. Please see Convert Rowset variables to scalar value.
You may still be able to achieve your ultimate goal in a different manner. Please consider re-writing your post with clear & concise language, small dataset, expected output, and a very minimal amount of code needed to repro - remove all details and nuances that aren't necessary to create a test case.

Resources