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: 

Reading data from dynamic internal table.

Former Member
0 Kudos

Hello all,

I have created a dynamic internal table, the structure of which will be something like this during runtime (this structure varies according to user input):

VKORG VTWEG SPART FROMDATE TODATE

  0001      0001         01       04/04/2011   04/04/2012

I came across a piece of code where you get the components name of the dynamic table structure <dyn_table> :

 

DATA: r_struct TYPE REF TO cl_abap_structdescr,
             table_fields TYPE abap_component_tab.

FIELD-SYMBOLS: <field> TYPE ANY,

                                <value> TYPE ANY.

           r_struct ?= cl_abap_typedescr=>describe_by_data( <dyn_wa> ).

           table_fields = r_struct->get_components( ).

LOOP AT <dyn_table> INTO <dyn_wa>.
   LOOP AT table_fields ASSIGNING <field>.
       ASSIGN COMPONENT <field> OF STRUCTURE <dyn_wa> TO <value>.

   ENDLOOP.

ENDLOOP.

I'm getting a dump with this code.

My requirement is to get the values of VKORG, VTWEG and SPART and validate these using AUTHORITY-CHECK OBJECT, but unable to understand how to proceed. Please help. Thanks!

3 REPLIES 3

Former Member

Hi,

Generally you create the dynamic internal table using field catalog and then convert the field catalog to strecture.

it you vhave done this loop youe field catalog usins where clause fieldname = VKORG.

you will get VKORG as the first record in the field catalog table.

store this sy-tabix in some variable.

now

ASSIGN COMPONENT sy-tabix OF STRUCTURE <your dynamic work area> TO <temporary field lable>.

then the <temporary field lable> will store the value of VKORG.

Revert in case you have any doubts.

HOPE THIS HELPS.

Former Member
0 Kudos

Hi,

  Do like this.

DATA: r_struct TYPE REF TO cl_abap_structdescr,

      table_fields TYPE abap_component_tab.

r_struct ?= cl_abap_typedescr=>describe_by_data( <dyn_wa> ).

table_fields = r_struct->get_components( ).   "here you have components name of dynamic table

field-symbols: <field>, <value>.

LOOP AT <dyn_table> INTO <dyn_wa>.

   LOOP AT table_fields ASSIGNING <field>.

   ASSIGN COMPONENT <field>-name OF STRUCTURE <dyn_wa> to <value>.

   if sy-subr = 0.

      <value> = ...  "here you have value for particular field i.e. kokrs, so it is similar to <dyn_wa>-korks etc

    endif.

endif.

ENDLOOP.

ENDLOOP.

Procedure for  Authority-Check Object:

If want to see the the authorization fields             Tcode : SU20.

If want to see the the authorization calsses         Tcode : SU21.

Each class contain so many objects .

Each object contain 10 fields.

CHECK statement for all values of selection tables. The AUTHORITY-CHECK statement is supported by a statement pattern.

Only if the user has all authorizations, is the return value sy-subrc of the AUTHORITY-CHECK statement set to 0. The most important return values are:

·    0: The user has an authorization for all specified values.
·    4: The user does not have the authorization.
·    8: The number of specified fields is incorrect.
·    12: The specified authorization object does not exist.
  24 . Field names listed in this check doesn't match the fields of the object.
     28,32,36 . System Error

IT is for checking whether the user has authorization to check the data

            for example

authority-check object 'z:cust'

                 ID 'ACTVT' field '01' .
                  only display,
                 ID 'ACTVT' field '02'
                      display with edit .

all these fields are maintained in su20 and su21.

former_member525851
Participant
0 Kudos

Hi Abeer,

In order to add a component to the dynamic itab components, check the below code:

** Adding new field name to components **

*  lt_comp  = lf_details->get_components( ).

*  APPEND LINES OF lt_comp TO lt_com.

*  ls_com-name = 'SELECT'.

*  ls_com-type = cl_abap_elemdescr=>get_c( 1 ).

*  INSERT ls_com INTO lt_com INDEX 1.


Instead of adding a component to existing components try to create fieldcatelog, check below code:

" Build Field Catelog for Dynamic Table Creation

   ls_fcatdet-fieldname = 'COMPANY_CODE'.

   APPEND ls_fcatdet TO lt_fcatdet.

   LOOP AT gt_flat INTO gs_flat.

     CLEAR ls_fcatdet.

     ls_fcatdet-fieldname = gs_flat-tabname.

     APPEND ls_fcatdet TO lt_fcatdet.

     CLEAR gs_flat.

   ENDLOOP.

   " Create Dynamic Internal

   CALL METHOD cl_alv_table_create=>create_dynamic_table

     EXPORTING

       it_fieldcatalog           = lt_fcatdet

     IMPORTING

       ep_table                  = lf_ep_table

     EXCEPTIONS

       generate_subpool_dir_full = 1

       OTHERS                    = 2.


Hope you find my reply helpful.