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

Column headers will be dynamic based on given input

Former Member
0 Likes
2,021

Hi Experts,

I have created custom structure with 10 fields in a program, last three fields in the structure will be dynamic based on the input. Consider input as days, from this if I give days as 2 it has to display from current date to 2 days as A-20130719 B-20130719 C-20130719 and A-20130720 B-20130720 C-20130720 as column header based on the number of days in input.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,214

Hi,

Can you please specify how you are displaying the records - using ALV or write statement? If its ALV, you can append in field catalog.

you can set a flag...

if for example it is 2 days...

you can use while...endwhile or do..enddo and increment the counter.

while n < p_days.

if n  = 1.

lv_date = sy-datum.

else.

lv_date = sy-datum + 1.

endif.

first 3 columns would be A-lv_date B-lv_date C-lv_date " Concatenate and build field catalog

n = n + 1

endwhile.

Is this what you wanted?

8 REPLIES 8
Read only

Former Member
0 Likes
1,215

Hi,

Can you please specify how you are displaying the records - using ALV or write statement? If its ALV, you can append in field catalog.

you can set a flag...

if for example it is 2 days...

you can use while...endwhile or do..enddo and increment the counter.

while n < p_days.

if n  = 1.

lv_date = sy-datum.

else.

lv_date = sy-datum + 1.

endif.

first 3 columns would be A-lv_date B-lv_date C-lv_date " Concatenate and build field catalog

n = n + 1

endwhile.

Is this what you wanted?

Read only

Former Member
0 Likes
1,214

Hello your requirement is not clear.

Do you want to assign dynamic texts to heading???

Case 1. Are your number of columns are fixed?

Case 2. Number of columns are variable.

As per my understanding your requirement is as follows

Suppose your internal table has 15 fields from your custom structure

and you want further columns as per your input.

Ex. if input is 5 then you want more 5 X 3 = 15 columns..... (5 for Each for A, B and C)

If i am correct then you want you create dynamic internal table first.

Following code will help you....

DATA: BEGIN OF it_dntab OCCURS 10.

        INCLUDE STRUCTURE dntab.

DATA: END OF it_dntab.

FIELD-SYMBOLS: <f_tab> TYPE STANDARD TABLE.

DATA: gd_tabfield TYPE lvc_t_fcat,

      wa_tabfield TYPE lvc_s_fcat,

      it_tab      TYPE REF TO data,

      gd_fieldcat   TYPE slis_t_fieldcat_alv,

wa_fieldcat   TYPE slis_fieldcat_alv.

  CALL FUNCTION 'NAMETAB_GET'

   EXPORTING

     langu                     = sy-langu

*    ONLY                      = ' '

     tabname                   = p_table

*  IMPORTING

*    HEADER                    =

*    RC                        =

   TABLES

     nametab                   = it_dntab

   EXCEPTIONS

     internal_error            = 1

     table_has_no_fields       = 2

     table_not_activ           = 3

     no_texts_found            = 4

     OTHERS                    = 5.

  IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

  CHECK: it_dntab[] IS NOT INITIAL.

  LOOP AT it_dntab.

    CLEAR: wa_tabfield.

    wa_tabfield-fieldname = it_dntab-fieldname.

    wa_tabfield-datatype  = it_dntab-datatype.

    wa_tabfield-outputlen = it_dntab-ddlen.

    APPEND wa_tabfield TO gd_tabfield.

    CLEAR: wa_fieldcat.

    wa_fieldcat-fieldname = it_dntab-fieldname.

    IF p_fname EQ 'X'.

      wa_fieldcat-seltext_l = it_dntab-fieldname.

      wa_fieldcat-seltext_m = it_dntab-fieldname.

      wa_fieldcat-seltext_s = it_dntab-fieldname.

    ELSEIF p_ftext EQ 'X'..

      wa_fieldcat-seltext_l = it_dntab-fieldtext.

      wa_fieldcat-seltext_m = it_dntab-fieldtext.

      wa_fieldcat-seltext_s = it_dntab-fieldtext.

    ENDIF.

    wa_fieldcat-ddictxt = 'M'.

    APPEND wa_fieldcat TO gd_fieldcat.

  ENDLOOP.

* create dynamic internal table from field catalog

  CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

      it_fieldcatalog           = gd_tabfield

    IMPORTING

      ep_table                  = it_tab

    EXCEPTIONS

      generate_subpool_dir_full = 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.

  ASSIGN it_tab->* TO <f_tab>.

Read only

Former Member
0 Likes
1,214

Hi,

If you are using standard ALV function modules/methods to display the report, generate the field catalog for those 3 fields dynamically based on condition.

If you are displaying using write statement, use the same condition before 'WRITE'.

Regards,

Koushik

Read only

0 Likes
1,214

Hi Koushik,

Can you explain how to generate field catalog for only three fields dynamically?

Read only

0 Likes
1,214

You can build field catalog  as:

data: var type char25,d1 type sy-datum

  fc_str-tabname = 'ITAB'.     "Your internal table name

  fc_str-fieldname = 'FIELD1'.   "Field name of your column

  fc_str-outputlen = 10.

concatenate 'A-' sy-datum into var.

condense var.

  fc_str-seltext_m = var.

  APPEND fc_str TO fieldcat.

clear var.

  fc_str-tabname = 'ITAB'.     "Your internal table name

  fc_str-fieldname = 'FIELD2'.   "Field name of your column

  fc_str-outputlen = 10.

concatenate 'B-' sy-datum into var.

condense var.

  fc_str-seltext_m = var.

  APPEND fc_str TO fieldcat.

clear var.

  fc_str-tabname = 'ITAB'.     "Your internal table name

  fc_str-fieldname = 'FIELD3'.   "Field name of your column

  fc_str-outputlen = 10.

concatenate 'C-' sy-datum into var.

condense var.

  fc_str-seltext_m = var.

  APPEND fc_str TO fieldcat.

clear var.

d1 = sy-datum + 1.

  fc_str-tabname = 'ITAB'.     "Your internal table name

  fc_str-fieldname = 'FIELD4'.   "Field name of your column

  fc_str-outputlen = 10.

concatenate 'A-' d1 into var.

condense var.

  fc_str-seltext_m = var.

  APPEND fc_str TO fieldcat.

clear var.

....

Regards

Read only

0 Likes
1,214

First of all your requirement is not clear. But based on my understanding i believe you just want to change the column labels in an ALV report.

This you can do using a case and endcase statement while you are creating your fieldcat.

Case 'A'.

Fieldcat-seltext_l = ' test1'.

Case 'B'.

Fieldcat-seltext_l = ' test2'.

Endcase.

I hope this will solve your purpose.

Read only

0 Likes
1,214

Hi,

If you want to set the column name of last 3 columns based on entry date it can be achieved by concatenating the date and the static text into a variable and passing it on to the seltext_l field.

But if something else, please explain in details.

Regards,

Koushik

Read only

venkateswaran_k
Active Contributor
0 Likes
1,214

In the Field Catalog defention, you have to formulate the label text and use them.

CONCATENATE 'A' 'your date field in char' INTO labelfield SEPARATED BY '-'.

      wa_fieldcat-seltext_l =  your label field

      wa_fieldcat-seltext_m = your label field

      wa_fieldcat-seltext_s =  your label field

Regards,

Venkat