‎2007 Jul 25 8:26 AM
Developing a Sales report where all the pricing conditions of a bill need to be displayed in output list in diffrent columns. Trying to use dynamic internal table otherwise every time program has to be modified for a new condition defined and the same to be hardcoded.
Various bills can have different conditions. For example one bill can have freight while this condition could be missing from other bill. Further, for all conditions table KONV has to be read number of times. How this can be handled using dynamic internal table.
Can any one help in this regard.
thanks
anu
‎2007 Jul 25 8:31 AM
Hi,
You cannot dynamically add fields in internal table.
You take supposition of maximum columns in table.
Then at the time of display, display only those columns that are having data in alv grid. You can set flag no-display or you dont make field-catalog of the fields that dont have data.
Hope this works out.
Regards,
Reward if helpful.
Navin
‎2007 Jul 25 8:35 AM
Hi Anu,
You can create dynamic internal tables using the Class "cl_alv_table_create" Method "create_dynamic_table"
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = fp_t_fieldcat
IMPORTING
ep_table = fp_t_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
Using this you can create dynamic internal table that you can use in your program as per requirement.
<u><b>Reward points for informatory answers.</b></u>
Best Regards,
Ram.
‎2007 Jul 25 8:38 AM
Hi,
Use the following code
TYPE-POOLS: slis.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
is_fcat LIKE LINE OF it_fcat.
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
DATA: new_table TYPE REF TO data,
new_line TYPE REF TO data.
FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
Build fieldcat
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SYST'
CHANGING
ct_fieldcat = it_fcat[].
LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.
MOVE-CORRESPONDING is_fcat TO is_fieldcat.
is_fieldcat-fieldname = is_fcat-fieldname.
is_fieldcat-ref_field = is_fcat-fieldname.
is_fieldcat-ref_table = is_fcat-ref_tabname.
APPEND is_fieldcat TO it_fieldcat.
ENDLOOP.
Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
Create a new Line with the same structure of the table.
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
Test it...
DO 30 TIMES.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = sy-index.
INSERT <l_line> INTO TABLE <l_table>.
ENDDO.
LOOP AT <l_table> ASSIGNING <l_line>.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
WRITE <l_field>.
ENDLOOP.
<b>Reward if helpful</b>