2

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.

Terry
  • 6,160
  • 17
  • 16
RedHat
  • 205
  • 2
  • 12
  • 24
  • 1
    Assuming you're referring to FileOpen and FileWrite, the constraint that FileWrite only takes a string shouldn't be a constraint, since you can String() the value of any column, even string data type columns. – Terry Jun 06 '13 at 14:46

3 Answers3

2

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
Seki
  • 11,135
  • 7
  • 46
  • 70
RedHat
  • 205
  • 2
  • 12
  • 24
  • 1
    The syntax is `destroy column #n` (with the sharp sign) or `destroy column_name` – Seki Jun 06 '13 at 08:11
  • 1
    @Seki, i'm using the syntax destroy column_name. the column_name is i but its not working. DataWindow.Modify("destroy i"), is this correct? – RedHat Jun 06 '13 at 08:59
  • 1
    I missed the fact that you `destroy` the columns inside a loop on the rows... The column exists for all the rows, and once you destroy it in the first row, the `destroy` of the same column in the second row will fail, because the column had already vanished. That's the origin of the `incorrect syntax`: deleting a column that does not exist (anymore) – Seki Jun 06 '13 at 09:15
  • 1
    Unfortunately, there's a mix of syntax in the first comment. The syntax is: DESTROY [COLUMN] control, where if the keyword COLUMN is added, the data set column is destroyed as well as the column control; skipping that keyword just destroys the control. Since SaveAs() works against the data set, you want the "DESTROY COLUMN control" syntax. And as Seki said, there's no point doing this inside of loops: this affects all rows at once, there is no row-by-row column destruction, if that's what you're after. – Terry Jun 06 '13 at 14:44
  • 1
    @Terry, Thank you for the added inputs. What I'm really after for is to remove the remaining tabs from column 9 to 20 in the Detail segment. – RedHat Jun 07 '13 at 04:54
  • @Alex: Seki has answered you're question, addressing a stand-alone DataStore or DataWindow, unless there's something we're missing, which might be how the "detail" is related to everything else. You reference header and detail being "in 1 DataWindow". Are you saying these are two report objects in one DataWindow object? If so, is this parent object Composite (in the export, "datawindow (... processing=5 ...)") or Nested? This factor could make a world of difference in the viable answers to your question. – Terry Jun 07 '13 at 14:10
2

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.

Hugh Brackett
  • 2,706
  • 14
  • 21
0

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

DARKinVADER
  • 640
  • 3
  • 11