Shared Top Border

Enterprise Resource
Planning Portal

 

Advertise | Founder BLOG

ERPGenie.COM ABAP Tips and Tricks Database

THE ultimate
ERP website

 

Forums | Vote for us |

Google    Other Search Options

Login

Login to view more content!!!





Lost Password?
No account yet? Register

Registered Access

Poll

What area of ABAP are you interested in?
 
Home arrow Sample Code arrow ABAP Reports arrow Creating a dynamic structure
Creating a dynamic structure PDF Print E-mail
User Rating: / 2
PoorBest 
Written by Anon.   
Saturday, 20 January 2007
Question : Subject : Dynamic structure
 
does anyone know if it's possible to declare a dynamic structure?
 my program receives a record-field of 1000, and I need to overlay this record with a structure that needs to
 be dynamic.
 
 Reply : Subject : Dynamic structure
 
if your structure changes from one defined structure to another one, you can try this:
 ASSIGN yourfield CASTING TYPE yourstructure
 or CREATE DATA yourdata TYPE yourstructure.
 If your structure has to be really dynamic - like ALV - you can use the class CL_ALV_TABLE_CREATE. try this example:
 =====================================
 REPORT zmaschl_create_data_dynamic .
 
 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.
 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.
 
< Prev   Next >

Google Search

Statistics

Contribution Activity
Utilities: 38
Tips and Tricks: 334
Sample Code: 166
Total Contributions: 553

Member Activity
Members: 6305 since 2/1/2007!
New: 0 since yesterday!
Visitors: 1167691
We have 1 guest online

Newest Members

Welcome our newest members:

Google Ads

Shared Bottom Border

Contact Us | Polls | Add URL | Contribute | Privacy | Terms | Feedback

Discussion Forum | BLOG | Consultants: Post your resume | Companies: Advertise on ERPGenie.COM | Post Job
Financials Consultant | Consultant Review | Gallia Consulting | Supply Chain Project | SAP Financials Forum
GenieHoldings.COM, Inc. | Genie Press | WorkflowGenie | ESAGenie | ERPTopSites | ABAP Tips and Tricks | SAP Solutions Database

EDIGenie | Searching Survivor