4 Replies Latest reply on Feb 13, 2019 8:04 AM by wucis

    dynamic column name in Report

    wucis

      I got a table with columns like

      J0 NUMBER,

      J1 NUMBER,

      J2 NUMBER,

      J3 NUMBER,

      J4 NUMBER,

       

      and would like to have a report on this table with the column heading depending on the actual year:

      in 2019

      J0 should have the heading 2019

      J1 should have the heading 2018

      J2 should have the heading 2017  ...

       

      in 2020

      J0 should have the heading 2020

      J1 should have the heading 2019

      J2 should have the heading 2018  ...

        • 1. Re: dynamic column name in Report
          fac586

          wucis wrote:

           

          I got a table with columns like

          J0 NUMBER,

          J1 NUMBER,

          J2 NUMBER,

          J3 NUMBER,

          J4 NUMBER,

           

          and would like to have a report on this table with the column heading depending on the actual year:

          in 2019

          J0 should have the heading 2019

          J1 should have the heading 2018

          J2 should have the heading 2017 ...

           

          in 2020

          J0 should have the heading 2020

          J1 should have the heading 2019

          J2 should have the heading 2018 ...

          APEX version?

           

          What type of "report" are we discussing?

          • 2. Re: dynamic column name in Report
            wucis

            Actually I'm on apex 5.1.3 and as report would be best an IG.

            • 3. Re: dynamic column name in Report
              mskamene

              It's not super elegant, but I am not sure how you could resolve this without the use of a page item per column, and have these items populated with your logic.

               

              So your column headings would look like: &PX_J01. , &PX_J02., &PX_J03.,&PX_J04. etc..

               

              And you would have a Before Header Page Process that sets the values of these items, something like:

               

              begin

              : PX_J01:=to_char(sysdate,'YYYY');

              : PX_J02 :=to_char(sysdate,'YYYY')+1;

              : PX_J03:=to_char(sysdate,'YYYY')+2;

              ...

              end;

              • 4. Re: dynamic column name in Report
                wucis

                Thx mskamene, nice idea and it works fine.

                For calculating the column headings I used something like:

                DECLARE

                 

                BEGIN

                 

                SELECT TO_CHAR(SYSDATE, 'YYYY') - Z0, TO_CHAR(SYSDATE, 'YYYY') -Z1, TO_CHAR(SYSDATE, 'YYYY')- Z2 , TO_CHAR(SYSDATE, 'YYYY')- Z3 , TO_CHAR(SYSDATE, 'YYYY')- Z4

                INTO :P12_J0 , :P12_J1 , :P12_J2  , :P12_J3  , :P12_J4

                FROM (

                SELECT

                'J0'

                ,SUBSTR('J0', 2) Z0

                ,'J1'

                ,SUBSTR('J1', 2) Z1

                ,'J2'

                ,SUBSTR('J2', 2) Z2

                ,'J3'

                ,SUBSTR('J3', 2) Z3

                ,'J4'

                ,SUBSTR('J4', 2) Z4

                 

                 

                , TO_CHAR(SYSDATE, 'YYYY')

                FROM DUAL

                 

                );

                 

                END;

                 

                with J0, J1, J2, J3, J4 as the original column names in the subjacent table.