Application Development 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: 

dynamic columns display

Former Member
0 Kudos

Hi All...

can anybody help me....

my requirement is

if i have 3 records in internal table then i have to display them in 3 cols,

if i have 40 records in table i have to disply 40 cols in output....is it possible....

thanks and regards....

5 REPLIES 5

Former Member
0 Kudos

You can do this using cl_alv_table_create=>create_dynamic_table

Refer to the standard SAP example <b>BCALV_TABLE_CREATE</b>

Former Member
0 Kudos

Hi kamala,

if you mean normal output with write do this.

*

loop at itab.

write: itab.

endloop.

*

if you mean ALV you have to change the fieldcat.

*

regards, Dieter

Former Member
0 Kudos

Hi,

Check whether the below code helps for your scenario. Note that the below code depends on the Line Size...

report abc line-size 300.

data vLines type i.

parameters vv_ind like sy-index.

data: begin of itab occurs 0,

index like sy-index,

end of itab.

do vv_ind times.

itab-index = sy-index.

append itab.

enddo.

describe table itab lines vlines.

do vlines times.

read table itab index sy-index.

check sy-subrc = 0.

write: itab-index.

enddo.

Former Member
0 Kudos

Hi,

by using field symbols u can do.

this is not the exact code but just i am giving an idea how to do.

perform dynamic TABLES itab .

form dynamic p_itab like itab.

FIELD-SYMBOLS: <F>.

DO.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE p_itab TO <F>.

IF SY-SUBRC <> 0. EXIT. ENDIF.

if sy-index = 1. write / ' '. endif.

if sy-index = 25. exit. endif.

WRITE : <F>, sy-vline.

ENDDO.

ENDForm.

(or) check this link regarding ALV using oops concept

http://help.sap.com/saphelp_erp2005/helpdata/en/b5/ac884118aa1709e10000000a155106/content.htm

Former Member
0 Kudos

*&-----Local Data Declarations

DATA : l_ref TYPE REF TO data. "Reference

*&-----Generate Internal Table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_fieldtab

IMPORTING

ep_table = l_ref.

ASSIGN l_ref->* TO <f_fs>.

Here the field tab is of type :

t_fieldtab TYPE TABLE OF lvc_s_fcat. "Internal Table

<f_fs> is ur dynamic table of type as in ur fieldtab.

Field Tab:

*&-----Macro to populate field tab

DEFINE field_tab.

st_fieldtab-fieldname = &1.

st_fieldtab-ref_table = &2.

st_fieldtab-ref_field = &3.

append st_fieldtab to t_fieldtab.

clear st_fieldtab.

END-OF-DEFINITION.

My requirement was to display columns based on the posting date on selection screen. Am populating the field catalog and field tab as follows.

&----


*& Form set_field_catalog

&----


  • Generate Field Catalog

----


FORM set_field_catalog .

*&-----Local Data Declarations

DATA : l_text(20) TYPE c, "To Store Field Headers

l_lin_cnt TYPE i. "Line Count

*&-----Generate Header for Retailer

field_tab c_kunnr c_s850 c_kunnr.

field_cat c_kunnr c_final 'Retailer No.'(016) c_x.

*&-----Generate Header for Reatilor Name

field_tab c_name c_kna1 c_name.

field_cat c_name c_final 'Retailer Name'(017) c_x.

*&-----Generate Header for Field Description

field_tab c_descr c_kna1 c_name.

field_cat c_descr c_final 'Description'(018) c_x.

*Line Color

field_tab c_color c_marav c_maktx .

field_cat c_color c_final c_color space.

*&-----Sort by Year, Month, Posting Date and Posting Week

SORT t_t009b BY bdatj bumon butag poper.

*&-----Do No of Columns Times

DO w_lin_cnt TIMES.

*&-----Increament Line Count at each loop.

l_lin_cnt = l_lin_cnt + 1.

*&-----Read Periods Table to Get Posting Date

READ TABLE t_t009b INTO st_t009b

WITH KEY key_ix = l_lin_cnt

BINARY SEARCH.

IF sy-subrc EQ 0.

*&-----Clear Variables

CLEAR : l_text.

*&-----Generate Date in Words

PERFORM generate_header_text USING st_t009b

CHANGING l_text.

  • field_tab l_text c_s850 'ZZLOCKDMND'(015).

field_tab l_text c_s850 c_kunnr.

field_cat l_text c_s850 l_text space.

ENDIF.

ENDDO.

ENDFORM. " set_field_catalog

The table <f_fs> is your output table of type field_tab.

And since field strings are nothing but just link to memory areas, you frst have to fill the table with dummy values based on your requirement and then replacing your dummy values with your data.

follow these steps:

1. Determine your number of output lines.

2. Start a do loop for the number of lines from step 1.

3. For each line, Read the <f_fs> into some workarea <f_fs2> and store ur data values.

Try for it.

Regards,

Santosh.