Create a Dynamic Internal Table from any Field Catalog created for an ALV Report

AdobeStock_98307620.jpeg

Business Requirements/Scenario

It’s a quite frequent requirement where we need to create ALV report - requirement in which we need to create the output dynamically w.r.t the Selection screen:
For example:  If the details of efforts booked by an employee needs to be checked, based on any date range given in the selection screen.
The ALV final table can be regenerated and created w.r.t the field catalog prepared and passed in the method.

 We need to follow below explained Coding Tips in order to get the desired result:    

1.    The Method that we are going to use here is: create_dynamic_table which is a static method in the class cl_alv_table_create

2.     The code declaration procedure is given as follows:

  Data:  fp_fieldcat type lvc_t_fcat,

               l_t_data type ref to data,

               l_fname type lvc_fname.

                Based on the above declaration, by preparing the field catalog data in fp_fieldcat an internal table of similar type will be created with the below method.

               CALL METHOD cl_alv_table_create=>create_dynamic_table

               EXPORTING  

           it_fieldcatalog           = fp_fieldcat

               IMPORTING  

         ep_table                      = l_t_data

        e_style_fname             = l_fname

               EXCEPTIONS

                      generate_subpool_dir_full = 1

               OTHERS                    = 2.

              IF sy-subrc <> 0.

                < Exception Handling>

              ENDIF.

            Now, after the internal table creation, in order to process data on the same, we create a structure as a work area as shown below :

 

               Data : wa_data  type ref to data .

             field-symbols : <fs_data>  type standard table .

  

TRY .

      

ASSIGN l_t_data->* TO <fs_data>.

  

           CATCH cx_sy_assign_cast_illegal_cast   

        

         cx_sy_assign_cast_unknown_type

                                         cx_sy_assign_out_of_range.

                                      < MESSAGE Check>.

                ENDTRY.

                TRY .

                       CREATE DATA l_data LIKE LINE OF <fs_data>.

                          CATCH cx_sy_create_data_error.

                        <MESSAGE  Check>.

                 ENDTRY.

So, now we have a dynamic Internal table and its work area ready to process and populate the data for our Current Report program .

Note: We cannot directly assign the data to the fields in the work Area, rather we need to populate the same with the Dynamic programming technique.

Author: Vivek Kumar

SAP ABAP Technical Consultant/Vistex Technical/CRM Technical Consultant More than 5 years of total IT industry experience encompassing skill set, roles and industry verticals. Experience involved with requirement designing in ERP domain as a technical consultant. Currently Working as ABAP team member. The functional module where provided technical solutions are Order to cash ( OTC/ Sales & Distribution), Procure to Plant ( PTP/Material Management and Production Planning ), Plant to Distribution (PTD/ Production Planning). Knowledge of ABAP Programming Techniques with different modules like Vistex and different functional module. Worked on Social CRM platform as CRM technical consultant and BRF+ Consultant for 1.5 years. Worked on DDIC, Report, Enhancement,screen design, Conversion, Function Module, Interface, Transaction Variant etc. Analyses of Functional Specification, Technical Specification and Unit Test Plan preparation. Experience of 1 implementation, 2 post implementation support, 1 Upgrade project and 2 continuous Enhancement Projects.

Module(s): ABAP, Basis, CRM