Reputation: 205
I have a combination of 2 DataStore, lds_header and lds_detail which is fetching data in 1 DataWindow. I've set the columns of the DataWindow based on the columns of the header.
lds_header has 10 columns to export for header segment - holds in first row only
lds_detail has 5 columns to export for detail segment - holds in second row and so on.
DataWindow has 10 columns.
When the .TXT (Tab Delimited) File was generated. the detail segment carry over the another 5 columns. Now my question is, how to remove the unnecessary columns for the detail segment when using a DataWindow Save AS method?
Actually, I was able to deliver the expected output in using FileOpen method then used a string concatenation but FileOpen method has a limitation in terms of holding a string value that's why I want to do the exportation in a DataWindow SaveAs method.
Upvotes: 2
Views: 4728
Reputation: 2706
The easiest way to export only some of the columns in a DataWindow is to set up the data source so that the columns you want are the first N columns. I'll call the DataWindow with all of the columns dw_all. Next save dw_all as dw_some, then delete the columns after N from the data source. Then, assuming dw_all is in ds_all and has your data, and dw_some is in ds_some and empty:
ll_rows = ds_all.rowcount()
ds_some.object.data[1, 1,ll_rows,N] = ds_all.object.data[1,1,ll_rows,N]
You can change the start and end columns for ds_all to copy a block of columns out of the middle, or the last N columns, but then you have to be careful about the type and size of the columns when you make dw_some, whereas doing a save as and deleting the columns after N is almost foolproof.
Finaly, you can use DataWindows that don't match and copy columns and blocks of column one at a time. I hope the example below shows why making the DataWindows the way I recommend is better. The only way you can tell if this is correct is to carefully check the data sources in both DataWindows:
dw_excel.Object.Data[1,1,il_rows,1] = dw_report.Object.Data[1,1,il_rows,1]
dw_excel.Object.Data[1,2,il_rows,3] = dw_report.Object.Data[1,3,il_rows,4]
dw_excel.Object.Data[1,4,il_rows,12] = dw_report.Object.Data[1,5,il_rows,13]
dw_excel.Object.Data[1,13,il_rows,13] = dw_report.Object.Data[1,15,il_rows,15]
dw_excel.Object.Data[1,14,il_rows,14] = dw_report.Object.Data[1,25,il_rows,25]
dw_excel.Object.Data[1,15,il_rows,20] = dw_report.Object.Data[1,17,il_rows,22]
Note: Make sure the rowcount is > 0 before attempting to use data expressions like these.
Upvotes: 2
Reputation: 205
I'm trying to figure out on how to do the above question. This line of script, dw_Outbound.Modify("DESTROY i")
returns an incorrect syntax. How to delete the column without deleting the data?
FOR ll_outbound = 2 TO dw_Outbound.RowCount()
IF dw_Outbound.Object.A[ll_outbound] = 'D' THEN
ls_column = dw_Outbound.Object.DataWindow.Column.Count
FOR li_column = 9 TO Integer(ls_Column)
dw_Outbound.Modify("DESTROY i")
dw_Outbound.Modify("DESTROY j")
dw_Outbound.Modify("DESTROY k")
dw_Outbound.Modify("DESTROY l")
dw_Outbound.Modify("DESTROY m")
dw_Outbound.Modify("DESTROY n")
dw_Outbound.Modify("DESTROY o")
dw_Outbound.Modify("DESTROY p")
dw_Outbound.Modify("DESTROY q")
dw_Outbound.Modify("DESTROY r")
dw_Outbound.Modify("DESTROY s")
dw_Outbound.Modify("DESTROY t")
NEXT
END IF
NEXT
Upvotes: 2
Reputation: 640
I think that if you use SaveAs Method than all columns will be exported, that are in the select list. No matter that wether it is visible or not. With the destroy and create you only creates a control for the column in the select list. If you do not want to export several columns or you want to rename the "labels" of the columns I think you need a separate datawindow with the columns you want to export and you need to copy the data from the original datawindow to the "export" datawindow. Was this your issue?
Br. Gábor
Upvotes: 0