• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 671
  • Last Modified:

Dynamic column creation at runtime

I want to make an report in power builder.
I want to produce statistical information for each company. I will pass the company code as retrieval argument. Each company can have any number of  branchs. i want to make the report with branch name as column, based on the number of branchs retrieved the number of columns for the report will change. Below each branch name i want display their statistical information also i need the total summary for those informations.without using crosstab
0
batchakamal
Asked:
batchakamal
1 Solution
 
buasuwanCommented:
Hi batchakamal,

     The easiest way is using 'N-up' datawindow.  In this type of report, it cans diplay the brach names as columns. And you can display statistical information of these branches below.

     But you need to set 'Number of rows per detail band' to the maximum values.  And then you need some codes to hide the unused texts at the header band above brach names like this if you have.

long  rowcount, index
rowcount = dw_1.rowcount()

long  max_branches = 500

for index = rowcount + 1 to max_branches
    dw_1.modify("branchname_t_" + string(index) + ".visible = '0'")
next


Hope this help,
0
 
tr1l0b1tCommented:
Hi,

I think easiest way is not to create fields but hide/show them. In this case
you could use nested reports. Imagine you put 10 nested reports vertically
(the needed to fit page width) in Summary band, all of them invisible,
all with the same dataobject which receives one argument, the branch code
(which will be supplied by script).

In the retrieve process we loop throught company branchs and make visible
the needed nested reports :

Long ll_row, ll_rows
Long ll_max_branchs = 10
String ls_branch
String ls_nobranch = '0'

// Retrieve company branchs ...
DataStore lds_branchs
lds_branchs.DataObject = 'd_ds_branchs'
lds_branchs.SetTransObject(SQLCA)
lds_branchs.Retrieve(ls_company)

ll_rows = lds_branchs.RowCount()
For ll_row = 1 to ll_max_branchs
      If ll_row <= ll_rows Then
            // Assign a nested and make it visible
            ls_branch = lds_branchs.GetItemString(ll_row, "branchID")
            dw_report.Modify("nested" + String(ll_row) + ".Nest_Arguments=((~"'" + ls_branch + "'~"))")
            dw_report.Modify("nested" + String(ll_row) + ".Visible = '1'")
      Else
            // Hide
            dw_report.Modify("nested" + String(ll_row) + ".Nest_Arguments=((~"'" + ls_nobranch + "'~"))")
            dw_report.Modify("nested" + String(ll_row) + ".Visible = '0'")
      End If
Next

DESTROY lds_branchs

dw_report.Retrieve(ls_company)

Well, just an idea ...i've tested and works.
At end, you'll have to get values from each nested to calculate totals.
Let me know if you have any question about it.
Regards
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now