Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to create column dynamically in run time

Former Member
0 Likes
2,122

Hi genius,

How are you friends....

I got one problem to develop a alv report. am just now only start a work .

My selection select-options : Fromdate  - Todate


this is my column and row output list type :

Column1
column2
column3   
fromdate   
fromdate+1 fromdate+2 ........ todate
Customer Order

Day


2

3

   4 .......

 
10

Month


(0+2) = 2

(2+3) = 5     

(5+4) = 9 ..........

( X +10 ) = Y

cumulation  

  100 

(100+2)= 102(102+3) = 108 (108+ 4) = 112 ..... ( XX+ 10 ) = YY
Dealer OrderDay
3



Month
( 0 + 3 ) = 3



Cumulation   20










This is urgend work, am new in develop dynamic column creation and row creation...

Hi genius,

How are you friends....

I got one problem to develop a alv report. am just now only start a work .

My selection select-options : Fromdate  - Todate


this is my column and row output list type :

Column1
column2
column3   
fromdate   
fromdate+1 fromdate+2 ........ todate
Customer Order

Day


2

3

   4 .......

 
10

Month


(0+2) = 2

(2+3) = 5     

(5+4) = 9 ..........

( X +10 ) = Y

cumulation  

  100 

(100+2)= 102(102+3) = 108 (108+ 4) = 112 ..... ( XX+ 10 ) = YY
Dealer OrderDay
3



Month
( 0 + 3 ) = 3



Cumulation   20










This is urgend work, am new in develop dynamic column creation and row creation...

13 REPLIES 13
Read only

vinoth_aruldass
Contributor
0 Likes
2,089

hi,

try to bring everything in a single internal table it is possible. identify customer and dealer order calculations separately in two different internal tables and copy the customer first and dealer second in your final internal table . its easier try.

hope it helps,

Vinoth.

Read only

0 Likes
2,089

Hi vinoth ,

i need dynamically increase the column based on my select option.

first three column only static , remaining column are dynamic.

for example : in select-option : 01.12.2012 to 28.12.2012

Column1   Column2    Column3     01.12.2012      02.12.2012     03.12.2012 ....... 28.12.2012

Read only

0 Likes
2,089

hi,

static and dynamic columns for customer order collect and put in customer internal table

static and dynamic columns fo dealer order collect and put in dealerinternal table

combine both internal table to get final internal table .

see even though the dynamic columns are incrementing according to selet options the column heading will be same so the above method will work out.

Hope it hellps,

Vinoth

Read only

0 Likes
2,089

Hi vinoth ,

  Understand my question,

i want know how to build column headling based on the select opeion.

Read only

0 Likes
2,089

in your field catelog ,

according to your select options give conditions for your column.

Read only

0 Likes
2,089

for ex 01012012     to 03012012 your select option (s_date)means

in your field catalog,

col1,

col2,

col3,

from date,

before this you have to calculate how many days.

do days times

s_date-low + 1 < s_date-high.

concatenate col days into colhead. " first time col4 2nd time col5

enddo.

hope it helps,

Vinoth.

Read only

0 Likes
2,089

gs_filedcat-fieldname = 'order type '   "  this is only for char type  and its passing within single quiet ( ' ') .

but date is store in some variable . how to pass ....

i try to do this way only , but i cant.

Read only

Former Member
0 Likes
2,089

Hi,

The best way is by using RTTS classes to build your final table... There are plenty of threads describing how to proceed... Give it a try and get back with some coding so we can help you further.

Kr,

Manu.

Read only

Former Member
0 Likes
2,089

Hi Subramani,

Kindly go through below code, hope it will work for ur requirement.

   DATA: git_final TYPE TABLE OF vbap,
      gwa_Final LIKE LINE OF git_final,
      git_fieldcat TYPE slis_t_fieldcat_alv,
      gwa_fieldcat LIKE LINE OF git_fieldcat.

DATA: lv_date TYPE i,
      s_no TYPE i.

START-OF-SELECTION.

  IF date IS NOT INITIAL.
    lv_date = date-high - date-low + 1.
    DO lv_date TIMES.
   s_no = s_no + 1.
      gwa_fieldcat-col_pos    = s_no.
      gwa_fieldcat-fieldname  = date-low.
      gwa_fieldcat-seltext_l  = date-low.
      APPEND gwa_fieldcat TO git_fieldcat.
    date-low = date-low + 1.
    ENDDO.
  SORT git_fieldcat by col_pos.
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = git_fieldcat
    TABLES
      t_outtab      = git_final
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

Regards,

Praveen Reddy

Read only

Former Member
0 Likes
2,089

Hi subramani,

Use the following code for generation of dynamic internal table.

data:   XFC TYPE LVC_S_FCAT,

           IFC TYPE LVC_T_FCAT.

DATA: DY_TABLE TYPE REF TO DATA,

    DY_LINE  TYPE REF TO DATA,

CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'

      EXPORTING

       BEGDA           = fromdate

        ENDDA           =  to_date

*       TAB_MODE        = ' '

     IMPORTING

       DAYS            = NO

*       C_WEEKS         =

*       C_MONTHS        =

*       C_YEARS         =

*       WEEKS           =

*       MONTHS          =

*       YEARS           =

*       D_MONTHS        =

*       MONTH_TAB       =

              .

XFC-FIELDNAME = 'column1'.
  XFC-INTTYPE = 'C'.
  XFC-INTLEN = 80.
  APPEND XFC TO IFC.
  CLEAR XFC.

  XFC-FIELDNAME = 'column2' .
  XFC-INTTYPE = 'C'.
  XFC-INTLEN = 80.
  APPEND XFC TO IFC.
  CLEAR XFC.

  XFC-FIELDNAME = 'column3' .
  XFC-INTTYPE = 'C'.
  XFC-INTLEN = 80.
  APPEND XFC TO IFC.
  CLEAR XFC.

DO no TIMES.
    CLEAR XFC.
    DURATION-DURDD = SY-INDEX - 1.
    CALL FUNCTION 'HR_99S_DATE_ADD_SUB_DURATION'
      EXPORTING
        IM_DATE     = fromdate
        IM_OPERATOR = '+'
        IM_DURATION = DURATION
      IMPORTING
        EX_DATE     = DT.

*    CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
*     EXPORTING
*       DATE_INTERNAL                  = DT
*     IMPORTING
*       DATE_EXTERNAL                  = p_output
*     EXCEPTIONS
*       DATE_INTERNAL_IS_INVALID       = 1
*       OTHERS                         = 2
*              .
*    IF SY-SUBRC <> 0.
*          MESSAGE 'Internal Date is invalid' type 'E'.
*    ENDIF.


    CONCATENATE 'D' DT INTO DT_S SEPARATED BY '_'.
    CONDENSE DT_S.
    XFC-FIELDNAME = DT_S.
    XFC-INTTYPE = 'C'.
    XFC-INTLEN = 20.
    APPEND XFC TO IFC.
  ENDDO.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

    EXPORTING

      IT_FIELDCATALOG  = IFC

      I_LENGTH_IN_BYTE = 'X'

    IMPORTING

      EP_TABLE         = DY_TABLE.

  ASSIGN DY_TABLE->* TO <DYN_TABLE>.

* Create dynamic work area and assign to FS

  CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE>.

  ASSIGN DY_LINE->* TO <DYN_WA>.

Hope this helps

Regards

Gaurav Ahluwalia

Read only

Former Member
0 Likes
2,089

Hi all ,

Now am clear about column heading...

but my body how to populate. 

for example :

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = GT_FIELDCAT
    TABLES
      t_outtab      = GT_FINAL

now am clear about GT_FIELDCAT .

then how to build GT_FINAL

am try to declare following way : ( Please tell this is correct way )

TYPES : BEGIN OF TY_FINAL,
           ORD(20) TYPE C,
           DAY(20) TYPE C,
           STOCK   TYPE P DECIMALS 0,
           D1     TYPE P DECIMALS 0,
           D2     TYPE P DECIMALS 0,
           D3     TYPE P DECIMALS 0,
           D4     TYPE P DECIMALS 0,
           D5     TYPE P DECIMALS 0,
           D6     TYPE P DECIMALS 0,
           D7     TYPE P DECIMALS 0,
           D8     TYPE P DECIMALS 0,
           D9     TYPE P DECIMALS 0,
           D10    TYPE P DECIMALS 0,
           D11    TYPE P DECIMALS 0,
           D12    TYPE P DECIMALS 0,
           D13    TYPE P DECIMALS 0,
           D14    TYPE P DECIMALS 0,
           D15    TYPE P DECIMALS 0,
           D16    TYPE P DECIMALS 0,
           D17    TYPE P DECIMALS 0,
           D18    TYPE P DECIMALS 0,
           D19    TYPE P DECIMALS 0,
           D20    TYPE P DECIMALS 0,
           D21    TYPE P DECIMALS 0,
           D22    TYPE P DECIMALS 0,
           D23    TYPE P DECIMALS 0,
           D24    TYPE P DECIMALS 0,
           D25    TYPE P DECIMALS 0,
           D26    TYPE P DECIMALS 0,
           D27    TYPE P DECIMALS 0,
           D28    TYPE P DECIMALS 0,
           D29    TYPE P DECIMALS 0,
           D30    TYPE P DECIMALS 0,
           D31    TYPE P DECIMALS 0,
         END OF TY_FINAL.

DATA : GT_FINAL TYPE TABLE OF TY_FINAL,

             GS_FINAL TYPE TY_FINAL.

suppose the user given more than 31 days in select option , wt i do?


Read only

0 Likes
2,089

Hi Subramani,

As i mentioned above, we created dynamic fieldcatalog based on selection screen field date.

Now create dynamic internal table based on your fieldcatalog as mentioned below.

Pass the field catalog to method, based on it your internal table will be created. Once created, update your data into internal table.

For reference go through below code.

*Data Declaration:

TYPE-POOLS: slis.

FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,  “ Dynamic internal table name

                             <fs_dyntable>,                     “ Field symbol to create work area

                             fs_fldval> TYPE ANY.              “ Field symbol to assign values 

DATA:  t_fldcat   TYPE lvc_t_fcat,  

           wa_it_fldcat TYPE lvc_s_fcat,

* Create dynamic internal table and assign to field symbol

  CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

      it_fieldcatalog = t_fldcat

    IMPORTING

      ep_table        = t_newtable. 

  ASSIGN t_newtable->* TO <t_dyntable>. 

* Create dynamic work area and assign to FS

  CREATE DATA t_newline LIKE LINE OF <t_dyntable>.

  ASSIGN t_newline->* TO <fs_dyntable>.

Thanks,

Regards,

Praveen Reddy

Read only

0 Likes
2,089

Hi ,

Pls check following code

TYPE-POOLS : SLIS.

TABLES : ZFDRBOOKING.

TYPES : BEGIN OF TY_BOOK,
         EXTWG          TYPE ZFDRBOOKING-EXTWG,
         KUNNR          TYPE ZFDRBOOKING-KUNNR,
         BOOKNO         TYPE ZFDRBOOKING-BOOKNO,
         CUSTOMERNAME   TYPE ZFDRBOOKING-CUSTOMERNAME,
         CUSTOMERMOBILE TYPE ZFDRBOOKING-CUSTOMERMOBILE,
         MJAHR          TYPE ZFDRBOOKING-MJAHR,
         BOOKDATE       TYPE ZFDRBOOKING-BOOKDATE,
         BOOKQTY        TYPE ZFDRBOOKING-BOOKQTY,
         BOOKSTATUS     TYPE ZFDRBOOKING-BOOKSTATUS,
        END OF TY_BOOK.



DATA : GT_BOOK    TYPE TABLE OF TY_BOOK.


DATA : GS_BOOK    TYPE TY_BOOK.

DATA : GT_FIELDCAT TYPE LVC_T_FCAT,                                          "slis_t_fieldcat_alv,
            GS_FIELDCAT TYPE LVC_S_FCAT.                                         "LIKE LINE OF gt_fieldcat.

FIELD-SYMBOLS: <GT_DYNTABLE> TYPE TABLE,    " Dynamic internal table name

                <FS_DYNTABLE>,                       " Field symbol to create work area

                 <FS_FLDVAL> TYPE ANY.


DATA : GT_FINAL TYPE REF TO DATA,
        GS_final  LIKE GT_FINAL.                    "“ Field symbol to assign values


DATA: LV_DATE TYPE I,
       S_NO TYPE I.

SELECT-OPTIONS : S_BUDAT FOR ZFDRBOOKING-BOOKDATE.

START-OF-SELECTION.

   IF S_BUDAT IS NOT INITIAL.
     LV_DATE = S_BUDAT-HIGH - S_BUDAT-LOW + 3.

     DO LV_DATE TIMES.
       S_NO = S_NO + 4.
       CASE: S_NO.
         WHEN '1'.
           GS_FIELDCAT-COL_POS    = S_NO.
           GS_FIELDCAT-FIELDNAME  = 'Order_Type'.
           GS_FIELDCAT-SELTEXT    = 'Order Type'.
           APPEND GS_FIELDCAT TO GT_FIELDCAT.
           CLEAR GS_FIELDCAT.
         WHEN '2'.
           GS_FIELDCAT-COL_POS    = S_NO.
           GS_FIELDCAT-FIELDNAME  = 'Detail'.
           GS_FIELDCAT-SELTEXT    = 'Detail'.
           APPEND GS_FIELDCAT TO GT_FIELDCAT.
           CLEAR GS_FIELDCAT.
         WHEN '3'.
           GS_FIELDCAT-COL_POS    = S_NO.
           GS_FIELDCAT-FIELDNAME  = 'Stock'.
           GS_FIELDCAT-SELTEXT   = 'Stock'.
           APPEND GS_FIELDCAT TO GT_FIELDCAT.
           CLEAR GS_FIELDCAT.
         WHEN '4'.
           GS_FIELDCAT-COL_POS    = S_NO.
           GS_FIELDCAT-FIELDNAME  = 'EXTWG'.
           GS_FIELDCAT-SELTEXT   =  'GROUP'.
           APPEND GS_FIELDCAT TO GT_FIELDCAT.
           CLEAR GS_FIELDCAT.
         WHEN OTHERS.
           GS_FIELDCAT-COL_POS    = S_NO.
           GS_FIELDCAT-FIELDNAME  = S_BUDAT-LOW.
           GS_FIELDCAT-SELTEXT    = S_BUDAT-LOW.
           APPEND GS_FIELDCAT TO GT_FIELDCAT.
           S_BUDAT-LOW = S_BUDAT-LOW + 1.
       ENDCASE.
     ENDDO.
     SORT GT_FIELDCAT BY COL_POS.
   ENDIF.

   DATA : GT_TABLE TYPE REF TO DATA.

   CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
     EXPORTING
       IT_FIELDCATALOG = GT_FIELDCAT[]
     IMPORTING
       EP_TABLE        = GT_TABLE.

   GT_FINAL = GT_TABLE.

   ASSIGN GT_FINAL->* TO <GT_DYNTABLE>.

* Create dynamic work area and assign to FS

   CREATE DATA :  GS_FINAL LIKE LINE OF <GT_DYNTABLE>.

   ASSIGN GS_final->* TO <FS_DYNTABLE>.


   SELECT EXTWG KUNNR BOOKNO CUSTOMERNAME CUSTOMERMOBILE
           MJAHR BOOKDATE BOOKQTY BOOKSTATUS
      FROM ZFDRBOOKING
      INTO TABLE GT_BOOK
     WHERE BOOKDATE IN S_BUDAT
       AND EXTWG = '00010'.

     LOOP AT GT_BOOK INTO GS_BOOK.

     Here how to move my gt_book data into gt_final table based on the column heading.

     ENDLOOP.

Pls anyone help to me...