Dynamic column creation at runtime

Posted on 2006-05-28
Last Modified: 2013-12-26
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
Question by:batchakamal
    LVL 5

    Expert Comment

    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'")

    Hope this help,
    LVL 6

    Accepted Solution


    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'

    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'")
                // Hide
                dw_report.Modify("nested" + String(ll_row) + ".Nest_Arguments=((~"'" + ls_nobranch + "'~"))")
                dw_report.Modify("nested" + String(ll_row) + ".Visible = '0'")
          End If

    DESTROY lds_branchs


    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.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    how to become programmer? 12 13
    eclipse debug jspwriter output 3 129
    Visual Studio 2015 -- ONLINE benefits ? 2 81
    Java eclipse error 2 60
    Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now