Building Field-Catalog for dynamic internal tables

Hi All,
I  created a dynamic internal table(<fs_final>,<fs_final_line>)  and populated data into it.Now I want to provide field catalog to these dynamic internal table.
Can anyone suggest me the how to create a field catalog for existing dynamic internal table.Thanks in advance.
Regards,
Chakradhar.
Moderator message - Please use proper subject line in future.
Message was edited by: Suhas Saha

Use this code to get all components of internal table.
Then build fieldcatlog.
DATA: tab_return type abap_compdescr_tab,
          components like line of tab_return.
perform get_int_table_fields using    <fs_it> changing  tab_return.
loop at tab_return into components.
  wa_fldcat-fieldname  = components-name.               "Field Name
  wa_fldcat-scrtext_m  = components-name.              "Column Heading
  wa_fldcat-inttype    = components-type_kind.     "Data Type
  wa_fldcat-intlen      = components-length.          "Data Lenght
  wa_fldcat-decimals = components-decimals.     "Data Decimal Places
append wa_fldcat to it_fldcat.
endloop.
form get_int_table_fields  using    t_data type any table
                            changing t_return type abap_compdescr_tab.
   data:
   oref_table type ref to cl_abap_tabledescr,
   oref_struc type ref to cl_abap_structdescr,
   oref_error type ref to cx_root,
   text type string.
*Get the description of data object type
   try.
       oref_table ?=
       cl_abap_tabledescr=>describe_by_data( t_data ).
     catch cx_root into oref_error.
       text = oref_error->get_text( ).
       write: / text.
       exit.
   endtry.
*Get the line type
   try.
       oref_struc ?= oref_table->get_table_line_type( ).
     catch cx_root into oref_error.
       text = oref_error->get_text( ).
       write: / text.
       exit.
   endtry.
   append lines of oref_struc->components to t_return.
endform.
Regards
Sreekanth

Similar Messages

  • Build field catalog for dynamic data objects

    Hi
    Could you please tell me how to build a field catalog (ooops alv)  for an internal table which is a dynamic data object.
      TYPES: BEGIN OF t_addsubty,
             subty TYPE subty,
             pernr TYPE persno,
             END OF t_addsubty.
      TYPES: ty_addsubty type t_addsubty occurs 1.
    i have data object using these
            CREATE DATA dref3 TYPE (g_type1).
            ASSIGN dref3->* TO <fs_dp>.
    where g_type1 refers a data type which i defined in the program. g_type1 = ty_addsubty. 
    now <fs_dp> refers to an internal table.
    now i want to build a field catalog for this internal table.
    In my program <fs_dp> structure is not always the same. i.e now it is ty_addsubty but for some other conditions the structure is different.
    please help me out.
    regards
    badri

    Here some piece of code, which shows how it works:
    <SNIP>
    type-pools:
         abap.
    DATA:
      lr_tabledescr          TYPE REF TO cl_abap_tabledescr,
      lr_structdescr     TYPE REF TO cl_abap_structdescr.
    field-symbols:
      <lw_component>     type abap_compdescr_tab.
    TYPES:
         BEGIN OF t_addsubty,
              subty TYPE subty,
              pernr TYPE persno,
         END OF t_addsubty.
    TYPES:
         ty_addsubty type t_addsubty occurs 1.
    CREATE DATA dref3 TYPE (g_type1).
    ASSIGN dref3->* TO <fs_dp>.
    lr_tabledescr ?= cl_abap_tabledescr=>describe_by_data( <fs_dp> ).
    assert condition lr_tabledescr is bound.
    lr_structdescr ?= lr_tabledescr->get_table_line_type( ).
    loop at lr_structdescr->components assigning <lw_component>.
    *     do whatever you want with the information about
    *     the components of the structure
    endloop.
    </SNIP>
    Do not forget to reward points...

  • ALV display using dynamic field catalog and dynamic internal table

    hi ,
    please guide me for ALV display using dynamic field catalog and dynamic internal table.
    Thank you.

    Hi Rahul,
    maybe thread dynamic program for alv is helpful for you. More information about the [SAP List Viewer (ALV)|http://help.sap.com/saphelp_nw70/helpdata/EN/5e/88d440e14f8431e10000000a1550b0/frameset.htm]. Also have a look into the example programs SALV_DEMO_TABLE*.
    Regards Rudi

  • Field Texts for Dynamic Internal Tables

    Hi All,
    I want to know whether there is any way to get the field Headings (Not the field names)
    Below is my CODE
    For ex :
    CLASS lvl_met DEFINITION.
       PUBLIC SECTION.
         METHODS : l_met IMPORTING m_itab TYPE STANDARD TABLE.
    ENDCLASS.
    CLASS lvl_met IMPLEMENTATION.
    METHOD l_met.
    data : l_t_fields TYPE abap_compdescr_tab." WITH HEADER LINE.
    field-symbols:
        <p_data>      type any,
        <p_field>     type any,
        <p_component> type abap_compdescr.
    CREATE DATA MY_WA LIKE LINE OF m_itab.
    ASSIGN MY_WA->* TO <P_DATA>.
    DESC_STRUC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <P_DATA> ).
    *I want the field Headings(Field Text) - In this case i want some thing like Material Number and Plant
    I can read this texts if i know atleast the data element
    At this point i see <p_data> in degbug mode under absolute type column i see \TYPE=WERKS_D aganst werks field
    I don't know how to capture the \TYPE=WERKS_D this thing so atleast i can read field Text based on Data Element
    Is there any other way to find out the field text
    ENDCLASS.
    TABLES : marc.
    DATA : l_met TYPE REF TO lcl_met.
    types : BEGIN OF t_itab,
      matnr like marc-matnr,
      werks like marc-werks,
      end of t_itab.
    data  : itab type table of t_itab.
    START-OF-SELECTION.
      IF l_met IS INITIAL.
        CREATE OBJECT l_met.
      ENDIF.
    select matnr werks from marc into TABLE itab up to 10 rows.
    l_met->get_headertext( EXPORTING m_itab = itab ).
    Thanks
    David

    Hi  Naimesh,
    I tried exactly what you said
    lt_comp = desc_struc->get_components( ). "Get the fields of the structure
    loop at lt_comp into ls_comp.
    lo_elem_desc ?= cl_abap_elemdescr=>describe_by_name( ls_comp-name ).
    lf_dfies = lo_elem_desc->get_ddic_field( ).
    WRITE: / lf_dfies-scrtext_s,
           / lf_dfies-scrtext_m,
           / lf_dfies-scrtext_l.
    WRITE:/ ls_comp-name. " Write the column names
    endloop.
    It Works fine for Matnr because field name and data element are same but when it comes to werks it gives me a dump because the date element is different werks_d
    I just tried hard coding werks_d and it works fine
    lo_elem_desc ?= cl_abap_elemdescr=>describe_by_name( 'WERKS_D' ).
    lf_dfies = lo_elem_desc->get_ddic_field( ).
    WRITE: / lf_dfies-scrtext_s,
           / lf_dfies-scrtext_m,
           / lf_dfies-scrtext_l.
    Let me know how
    Thanks
    David
    Edited by: DAVID KITSO on Nov 23, 2009 10:09 PM

  • How to get the NameTab Structure(X031L) for Dynamic internal table?

    when we pass standard table to the FM 'DD_GET_NAMETAB' we will get the
    nametab structure(x031l), like this i want to get the same structure for
    dynamic internal  table . how can I achieve this
    please help me...

    Hi,
    try this method
    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.

  • Are field symbols and Dynamic internal tables consistant?

    Hi,
    Are field symbols and Dynamic internal tables
    always consistent?
    In my program I m creating a dynamic itab and assignig values to it using <FS>, sometimes the program fails to execute assign <Fs> statement...
    this happens once in 3 to 4 runs
    any solution...
    I have proper clear and refresh statements in program.
    Thanks,
    Hardik

    Anurag,
    Thanks for a quick reply. Here I am sending a small piece of my code.
    MOVE-CORRESPONDING OUTTAB TO DYNTAB.
          CLEAR IT_UDATE.
          CLEAR : T_KBETR .
          READ TABLE IT_UDATE WITH KEY UDATE = OUTTAB-UDATE.
          CONCATENATE 'DYNTAB-KBETR' IT_UDATE-CO_POS INTO T_KBETR.
          ASSIGN (T_KBETR) TO <FS> .
          SUBRC5 = SY-SUBRC .
          IF SUBRC5 = 0 .
              <FS> =  OUTTAB-KBETR .
          ENDIF .
    read statement will always return CO_POS .
    while debuging this code a few times
    <b>ASSIGN (T_KBETR) TO <FS> .</b>
    returns sy-subrc = 4
    and that was leading the program to short dump earlier.
    now, as I have a check DYNTAB-KBETR holds no value on display.
    this happens very few times. (most of the times report is displaying desired output)
    Thanks,
    Hardik

  • At end of field,  for dynamic internal table entries ?

    Dear All,
    I've data in my dynamic internal table.
    But, to understand in a better way I created a test program with static entries.
    Case 1 -->
    DATA: BEGIN OF itab OCCURS 0,
            year TYPE char4,
            name TYPE char10,
          END OF itab.
    DATA: BEGIN OF itab2 OCCURS 0 ,
            year TYPE char4,
            name TYPE char10,
            count TYPE i,
          END OF itab2.
    DATA: gv_count TYPE i,
          gv_flag TYPE char1.
    itab-name = 'AAAA'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAB'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAC'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAD'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBB'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBA'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBC'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBD'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCC'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCA'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCB'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCD'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCE'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCf'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDD'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDA'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDB'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDC'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDE'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    SORT itab BY year.
    LOOP AT itab.
    * Counter
      gv_count = gv_count + 1.
      AT END OF year.
        itab2-count = gv_count.
        MOVE-CORRESPONDING itab TO itab2.
        APPEND itab2.
        CLEAR gv_count.
        WRITE:/ itab2-name,
        itab2-year,
        itab2-count.
        CLEAR itab2.
        CLEAR gv_flag.
      ENDAT.
    ENDLOOP.
    Now for the above program the Output is :
    Name     Year          Count
    ********** 2005          5
    ********** 2006          6
    ********** 2007          4
    ********** 2008          4
    " Forget about the asterisk values as it's an example !
    The above output is correct, But in my real case the table structure is not like the above .
    The order of the field are in reverse.
    i.e. The internal table is like this :
    Case 2 -->
    DATA: BEGIN OF itab OCCURS 0,
            name TYPE char10,
            year TYPE char4,
          END OF itab.
    DATA: BEGIN OF itab2 OCCURS 0 ,
            name TYPE char10,
            year TYPE char4,
            count TYPE i,
          END OF itab2.
    In this case if I'm using at end of year the output is coming wrong.
    Even on change of is also not working.
    Request you guys to help me out so that I can achieve the same output as of case 1 with the table declaration as of CASE 2.
    Regards,
    Deepu.k

    Hello Rich Heilman,
    Again you came for my rescue ............
    My code for this scenario is like this :
    DATA: BEGIN OF itab OCCURS 0,
            name TYPE char10,
            year TYPE char4,
          END OF itab.
    DATA: BEGIN OF itab2 OCCURS 0 ,
            name TYPE char10,
            year TYPE char4,
            count TYPE i,
          END OF itab2.
    DATA: gv_count TYPE i,
          gv_flag TYPE char1.
    itab-name = 'AAAA'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAB'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAC'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAD'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBB'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBA'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBC'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBD'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCC'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCA'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCB'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCD'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCE'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCf'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDD'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDA'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDB'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDC'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDE'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    SORT itab BY year.
    LOOP AT itab.
    * Counter
      gv_count = gv_count + 1.
      IF sy-tabix GT 1.
        ON CHANGE OF itab-year.
          itab2-count = gv_count.
          MOVE-CORRESPONDING itab TO itab2.
          APPEND itab2.
          CLEAR gv_count.
          WRITE:/ itab2-name,
          itab2-year,
          itab2-count.
          CLEAR itab2.
          CLEAR gv_flag.
        ENDON.
      ENDIF.
    ENDLOOP.
    The Output is :
    DDDC       2005          2
    CCCf       2006          4
    BBBD       2007          6
    AAAD       2008          4
    The above output is wrong.
    Can u correct me where I'm doing wrong ?
    Regards,
    Deepu.K

  • To create a deep structure for dynamic internal table.

    Hello
    My ALV has fields which are defined dynamically during execution.
    so, i did it in the following way,
    Declared Field symbolds, DREF and fieldcatalog as,
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
                  <fs_dyntable>.
    DATA:   dref_dyntab    TYPE REF TO data,
            dref_dynwa     TYPE REF TO data.
    DATA: ts_fieldcatalog TYPE lvc_t_fcat.
    DATA: wa_fieldcatalog TYPE lvc_s_fcat.
    Updated Fieldcatalog dynamically as,
    *function module to read segment structure
        CALL FUNCTION 'SEGMENT_READ'
          EXPORTING
            segmenttyp           = v_segment_name
          TABLES
            segmentstructure     = ts_seg_structure
          EXCEPTIONS
            no_authority         = 1
            segment_not_existing = 2
            OTHERS               = 3.
        IF sy-subrc <> 0.
          CASE sy-subrc.
            WHEN '1'.
              MESSAGE e024.
              STOP.
            WHEN '2'.
              MESSAGE e025 WITH v_segment_name.
              STOP.
            WHEN OTHERS.
              MESSAGE e023.
          ENDCASE.
        ENDIF.
    *FETCH FIELDS FROM STRUCTURE OF SEGMENT AND CREATE FIELDCATALOG FOR
    EACH FIELD OF SEGMENT (DYNAMIC FIELD CATALOG)
        LOOP AT ts_seg_structure INTO wa_seg_structure.
          ADD 1 TO v_counter.
          wa_fieldcatalog-fieldname = wa_seg_structure-fieldname.
          wa_fieldcatalog-col_pos   = v_counter.
          wa_fieldcatalog-ref_table = wa_seg_structure-segtyp.
          APPEND wa_fieldcatalog TO ts_fieldcatalog.
          CLEAR wa_fieldcatalog.
        ENDLOOP.
    and generated dynamic internal table using fieldcatalog as,
    *--Method to get the structure of table using fieldcatalog.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ts_fieldcatalog
        IMPORTING
    *--Variable of type REF TO DATA.
          ep_table        = dref_dyntab.
      IF sy-subrc <> 0.
        MESSAGE e023.
      ENDIF.
    *--Dynamic internal tables required when show segments selected
      IF p_selseg IS NOT INITIAL.
        ASSIGN dref_dyntab->* TO <t_dyntable>.
    *--Create dynamic work area and assign to FS
      CREATE DATA dref_dynwa LIKE LINE OF <t_dyntable>.
        ASSIGN dref_dynwa->* TO <fs_dyntable>.
    And then i populated this <t_dyntable> which is being passed as data-table to method
    CL_GUI_ALV_GRID => SET_TABLE_FOR_FIRST_DISPLAY
    for ALV grid Display along with above used filedcatalog ts_fieldcatalog.
    Things are fine till here, but now i have the requirement to edit selected rows of the ALV display..
    As you might be aware, we need a field
            TS_STYLEROW  TYPE lvc_t_styl, (i.e, a field of type 'h' and we can say as an internal table inside an internal table or else as a deep structure)
    in the output internal table <t_dyntable> to meet our requirement.
    My issue is about declaring one such field of type 'h' in this dynamically created internal table ''<t_dyntable>".
    I tried in the following way by adding one such field to fieldcatalog :
    *Field for Styling
      ADD 1 TO v_counter.
      wa_fieldcatalog-fieldname   = 'TS_STYLEROW'.
      wa_fieldcatalog-tabname     = 'TS_STYLE'.
      wa_fieldcatalog-col_pos     = v_counter.
      wa_fieldcatalog-no_out      = 'X'.
      wa_fieldcatalog-inttype     = 'h'.      " I even mentioned this
      APPEND wa_fieldcatalog TO ts_fieldcatalog.
      CLEAR  wa_fieldcatalog.
    But this is creating a field of type 'C' in the table <t_dyntable> instead of what i was expecting
    Guyz and respected,
    Please advice me with the solution or ur ideas....
    Note : The overall requirement is create a deep structure for dynamically generated internal table.
    Your help is highly appreciated and unforgettable..!!!!!!!

    hi,
    Dynamic append
    Dynamic internal table
    Dynamic internal table
    dynamic columns in ALV
    Variant for dynamic selection
    thanks

  • Create a deep structure for dynamic internal table

    Hi All,
    I am creating a dynamic table using method cl_alv_table_create=>create_dynamic_table.
    The normal structure gets created. but now I want to creat a Deep structure for having information of colors also for each column. So I want to add a COLTAB type LVC_T_SCOL for colors information .
    How should I create this using above method?
    Rgds,
    Madhuri

    I created a zcelltab structure as below. But while creating dynamic internal table, I received the error  with
    'Type "ZCELLTAB" is unknown 68 ZCELLTAB-CELLTAB
    Here is the code.
    DATA: BEGIN OF ZCELLTAB,
             CELLTAB LIKE LVC_S_STYL,
         END OF ZCELLTAB.
    FIELD-SYMBOLS <T_CELLTAB> TYPE LVC_T_STYL.
    DATA : LT_CELLTAB TYPE LVC_T_STYL.
    DATA:  WA_CELLTAB TYPE LINE OF LVC_T_STYL.
    DATA: GT_FCAT1 TYPE LVC_T_FCAT,
               GW_FCAT1 TYPE LVC_S_FCAT,
                GT_FCAT2 TYPE LVC_T_FCAT,
                GW_FCAT2  TYPE LVC_S_FCAT.
    After filling the FCAT1, I added the field in FCAT2  like below
      GT_FCAT2[ ] = GT_FCAT1[ ].
      G_TABIX = G_TABIX + 1.
      GW_FCAT2-INTTYPE = 'C'.
      MOVE G_TABIX TO GW_FCAT2-COL_POS.
      GW_FCAT2-OUTPUTLEN = '10'.
      GW_FCAT2-FIELDNAME = 'T_CELLTAB'.
      GW_FCAT2-TABNAME = 'ZCELLTAB'.
      GW_FCAT2-REF_FIELD = 'CELLTAB'.
      GW_FCAT2-REF_TABLE = 'ZCELLTAB'.
      APPEND GW_FCAT2 TO GT_FCAT2
      CLEAR GW_FCAT2.
    While calling the below method, the error with
    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
         EXPORTING
          IT_FIELDCATALOG = GT_FCAT2
        IMPORTING
          EP_TABLE        = GT_REQ.
      ASSIGN GT_REQ->* TO <F_TAB>.
      CREATE DATA GWA_REQ LIKE LINE OF <F_TAB>.
      ASSIGN GWA_REQ->* TO <F_WA>.
    LOOP AT ITAB.
    ASSIGN COMPONENT 'MATNR'  OF STRUCTURE <F_WA> TO <F_VAL>
    <F_VAL> = ITAB-MATNR.
    IF ITAB-MATNR IS INITIAL.
    ASSIGN COMPONENT 'T_CELLTAB' OF STRUCTURE <F_WA> TO <T_CELLTAB>
            CLEAR WA_CELLTAB.
            WA_CELLTAB-FIELDNAME = 'MATNR'.
            WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
            INSERT WA_CELLTAB INTO TABLE <T_CELLTAB>.
    ENDIF.
    APPEND <F_WA> TO <F_TAB>
    ENDLOOP.
    CALL METHOD GR_GRID->SET_TABLE_FOR_FIRST_DISPLAY
            EXPORTING
              I_CONSISTENCY_CHECK  = G_CONSISTENCY_CHECK
              IT_TOOLBAR_EXCLUDING = G_EXCLUDE
              I_SAVE               = G_SAVE
           I_DEFAULT            = 'X'
              IS_LAYOUT            = G_LAYOUT
            CHANGING
              IT_OUTTAB            = <F_TAB>
              IT_FIELDCATALOG      = F_CAT1.
    Please let me know where I was wrong.
    Should I remove the T_CELLTAB as the field name is not mentioned in the structure 'ZCELLTAB'.
    Thanks,
    Kumar.
    Edited by: venn e on May 7, 2010 4:10 PM

  • Usage of 'Select for all entries' for dynamic internal tables..

    Hi all,
    I have a situation where I need to use select for all entries for a dynamic internal table.
    select * from /BIC/AZHSD_O1500 into i_table for all entries in <b>Dynamic_table</b> where doc_number = <dynamic_table????????>
    here iam not knowing how to match the <dynamic_table????????> doc_number ?
    the dynamic_table contains the doc_number as one field.
    here dynaimc_table is the internal table which is dynamic.
    I have tried various options but couldnot find the solution.
    Please resolve.
    Sidhartha.

    data : i_dyn_where type char72 occurs 0.
    field-symbols : <fs> type table.
    assign itab[] to <fs>.
    i_dyn_where = 'docno = <fs>-docno'.
    append i_dyn_where.
    select *
    from   vbak
    into   table t_vbak
    for    all entries in <fs>
    where  (I_dyn_where).   "Populate this where condition dynamically too
    Hope this will solve ur prob.

  • How to Copy data from field symbol to Dynamic Internal Table

    Hi,
    I want to copy the data between two dynamic Internal tables . Following is the code were I have data in the field symbol wanted to transfer it to the other Internal table :
    REPORT  ztest.
    DATA:
           gd_dref          TYPE REF TO data,
           gd_dref1          TYPE REF TO data.
    FIELD-SYMBOLS:  <fs1>   TYPE any,
                               <fs_wa> TYPE any,
                                <field>    TYPE any,                  
                                <fs_wa1> TYPE ANY TABLE.  * Contains data from p_src
    *Copy data from p_src to p_dest*
    PARAMETERS: p_src LIKE dd02l-tabname .    * Name of Dynamic Internal table *
                             p_dest LIKE dd02l-tabname .  * Name of Dynamic Internal table*
    *DATA : lt_csks LIKE p_dest WITH HEADER LINE.
    START-OF-SELECTION.
      CREATE DATA gd_dref TYPE (p_src).
      CREATE DATA gd_dref1 TYPE TABLE OF (p_src).
       ASSIGN gd_dref->* TO <fs_wa>.
       ASSIGN gd_dref1->* TO <fs_wa1>.
       SELECT * FROM (p_src) INTO TABLE <fs_wa1>.
    *Write out data from FIELD SYMBOLS TO Table.
       loop at <fs_wa1> into <fs_wa>.
         do.
           assign component  sy-index
              of structure <fs_wa> to <field>.
           if sy-subrc <> 0.
           exit.
           endif.
           if sy-index = 1.
             write:/ <field>.
           else.
           write: / <field>.
           endif.
         enddo.
       endloop.
    *Need Logic To Copy the Data to p_dest table from <fs_wa1>.
    *p_dest is a table having a similar structure to table p_src .
    *Need Logic To Copy the Data to p_dest table from <fs_wa1>.
    EXIT.
    Thanks in Advance.

    try this...
    I have extended your source code and just used vbak/vbap as an example as they have some common fields like vbeln/erdat etc which corresponds with your requirement of 'similar structure' i.e. shared/common fields in both.
    Cheers...
    report  ztest.
    data:
      gd_dref type ref to data,
      gd_dref1 type ref to data,
      gd_dref_str type ref to data,
      gd_dref_tab type ref to data.
    field-symbols:
      <fs1> type any,
      <fs_wa> type any,
      <fs1_dest_str> type any,
      <fs_dest_tab> type any table,
      <field> type any,
      <fs_wa1> type any table.
    * contains data from p_src
    *Copy data from p_src to p_dest*
    parameters: p_src like dd02l-tabname default 'vbak',
    * name of dynamic internal table *
                p_dest like dd02l-tabname default 'vbap'.
    * name of dynamic internal table*
    *data : lt_csks like p_dest with header line.
    start-of-selection.
      create data gd_dref type (p_src).
      create data gd_dref1 type table of (p_src).
      assign gd_dref->* to <fs_wa>.
      assign gd_dref1->* to <fs_wa1>.
      select * from (p_src) into corresponding fields of table <fs_wa1>
      up to 3 rows
      where vbeln ne space.
      create data gd_dref_str type (p_dest).
      create data gd_dref_tab type standard table of (p_dest).
      assign gd_dref_str->* to <fs1_dest_str>.
      assign gd_dref_tab->* to <fs_dest_tab>.
    *write out data from field symbols to table.
      loop at <fs_wa1> into <fs_wa>.
        " break-point here - can see vbeln/waers/create date/ etc move over to new structure
        " the 'common' fields of your structures - the same will happen. if they not the same name you will have to do an
        " explicit move i.e. if fieldname = xyz ....move fieldxyz to new field123....after the move-corre
        break-point.
        move-corresponding <fs_wa> to <fs1_dest_str>.
        insert <fs1_dest_str> into table <fs_dest_tab>.
    **    do.
    **      assign component  sy-index
    **         of structure <fs_wa> to <field>.
    **      if sy-subrc <> 0.
    **        exit.
    **      endif.
    **      if sy-index = 1.
    **        write:/ <field>.
    **      else.
    **        write: / <field>.
    **      endif.
    **    enddo.
      endloop.
      " write out some dest data from the dest table build from previous loop
      loop at <fs_dest_tab> assigning <fs1_dest_str>.
        do.
          assign component sy-index of structure <fs_wa> to <field>.
          if sy-subrc <> 0.
            exit.
          endif.
          if sy-index = 1.
            write:/ <field>.
          else.
            write: / <field>.
          endif.
        enddo.
      endloop.

  • How To Read Field Values Form Dynamic Internal Table

    Hi,
    I Created a dynamic internal table using.
    FIELD-SYMBOLS: <gt_table> TYPE STANDARD TABLE,
                   <wa_gt_table>,
                   <l_fvalue> TYPE ANY.
    This Interanl table is working well, and all values are populated to an ALV.
    Now I try to set a link
    for that I am using below code
          READ TABLE <gt_table> ASSIGNING <l_fvalue> index rs_selfield-tabindex.
          IF sy-subrc EQ 0.
            insplot = <l_fvalue>-prueflos.
    Now it is showing a syntax error :
    the data object <l_fvalue> has no structure and there for no component called prueflos
    Regards
    Nausal

    Hi,
    Refere following code
    Local Field Symbol
      FIELD-SYMBOLS: <lf_any> TYPE ANY.                     "Changed data
      LOOP AT <gf_dyna_table> ASSIGNING <gf_dyna>.
        DO.
          ASSIGN COMPONENT sy-index OF STRUCTURE <gf_dyna> TO <lf_any>.
          IF sy-subrc NE 0.
            EXIT.
          ENDIF.
          IF ls_attach-line IS INITIAL.
            ls_attach-line = <lf_any>.
          ELSE.
            CONCATENATE ls_attach-line <lf_any> INTO ls_attach-line
                                                SEPARATED BY lc_tab.
          ENDIF.
        ENDDO.
        CONCATENATE lc_cret ls_attach-line  INTO ls_attach-line.
      Append Changed Data to attachement table
        APPEND ls_attach TO gt_attach.
      Clear
        CLEAR : ls_attach.
      ENDLOOP.
    Regards,
    Prashant

  • Problem with grid display in ALV for dynamic internal tables

    Hi,
    I am using dynamic internal tables in my program. To display it in grid format after populating it, I have used the following class and method. Here Im getting sy-subrc = 0 but, the grid is not getting displayed. Can some one pls help me with this.,
    DATA: W_GRID TYPE REF TO CL_GUI_ALV_GRID.
    DATA: w_tabname TYPE w_tabname.
    CREATE OBJECT W_GRID
    EXPORTING I_PARENT = CL_GUI_CONTAINER=>SCREEN0.
    CALL METHOD W_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
       I_BUFFER_ACTIVE               =
       I_BYPASSING_BUFFER            =
       I_CONSISTENCY_CHECK           =
        I_STRUCTURE_NAME              = W_TABNAME
       IS_VARIANT                    =
       I_SAVE                        =
       I_DEFAULT                     = 'X'
       IS_LAYOUT                     =
       IS_PRINT                      =
       IT_SPECIAL_GROUPS             =
       IT_TOOLBAR_EXCLUDING          =
       IT_HYPERLINK                  =
       IT_ALV_GRAPHICS               =
       IT_EXCEPT_QINFO               =
       IR_SALV_ADAPTER               =
      CHANGING
        IT_OUTTAB                     = <FS_1>
        IT_FIELDCATALOG               = LT_FIELDCATALOG2
       IT_SORT                       =
       IT_FILTER                     =
      EXCEPTIONS
        INVALID_PARAMETER_COMBINATION = 1
        PROGRAM_ERROR                 = 2
        TOO_MANY_LINES                = 3
        others                        = 4
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Here, <FS_1> is the field symbol of table type and it holds all my data. and LT_FIELDCATALOG2  is the structure of my fieldcatalog
    Thanks and Regards,
    Avinash

    Hi Avinash,
    Either use parameter
    I_STRUCTURE_NAME = W_TABNAME
    or
    IT_FIELDCATALOG = LT_FIELDCATALOG2
    Both are not required.
    At the end of ur program simply use a write statement like below. Your program will work.
    IF SY-SUBRC 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Write /.      <----
    Thanks,
    Edited by: Sap Fan on Oct 6, 2009 7:17 AM

  • Dynamic Alv for Dynamic Internal Table

    Hi All,
    I am new for abap dynpro.
    How can i create a dynamic alv table in abap dynpro withoud ddic structure??
    My requirement is as follows:
    I have a table having some field e.g MATNR WERKS NETWR.
    I want to pivot data werks and to display in webdynpro alv.
    Thnx:
    N. N. Tiwari

    You can use the RTTI to build up a dynamic structure in memory:
    Something like this - where both the data and its structure and meta data all come from an external source (which happens to be MDM in this case):
    ****ALV
          data:
             rootnode_info type ref to if_wd_context_node_info,
             dyn_node type ref to if_wd_context_node,
             dyn_node_info type ref to if_wd_context_node_info,
             tabname_node type ref to if_wd_context_node,
             current_tablename type string,
             tablename type string,
             struct_type type ref to cl_abap_structdescr,
              table_type  type ref to cl_abap_tabledescr,
              comp_tab    type cl_abap_structdescr=>component_table,
              comp        like line of comp_tab,
              my_table    type ref to data,
              my_row      type ref to data.
          field-symbols: <table> type table,
                         <row> type data,
                         <f>   type any,
                         <wa_string>     type string,
                         <wa_date_time>  type mdm_cdt_date_time,
                         <wa_integer>    type mdm_gdt_integervalue.
          rootnode_info = wd_context->get_node_info( ).
    * create subnode_info
          try.
              rootnode_info->remove_child_node( 'MDM_DATA' ).
            catch cx_wd_context.
          endtry.
          field-symbols <wa_detail> like line of field_details.
          field-symbols <wa_result> like line of result_set.
          field-symbols <wa_pair>   type mdm_name_value_pair.
          read table result_set assigning <wa_result> index 1.
          loop at field_details assigning <wa_detail>.
    * build a structure description from the list of single fields
            if strlen( <wa_detail>-field_code ) > 30.
              comp-name = <wa_detail>-field_code+0(30).
            else.
              comp-name = <wa_detail>-field_code.
            endif.
            if <wa_result> is assigned.
              read table <wa_result>-name_value_pairs assigning <wa_pair>
                            with key code = <wa_detail>-field_code.
              if sy-subrc = 0.
                case <wa_pair>-type.
                  when `MDM_CDT_DATE_TIME`.
                    comp-type ?= cl_abap_datadescr=>describe_by_name( 'TZNTSTMPL' ).
                  when `MDM_GDT_INTEGERVALUE`.
                    if <wa_detail>-field_lookup_table is not initial.
                      comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
                    else.
                      comp-type ?= cl_abap_datadescr=>describe_by_name( 'INT4' ).
                    endif.
                  when others.
                    comp-type ?= cl_abap_datadescr=>describe_by_name( <wa_pair>-type ).
                endcase.
              else.
                comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
              endif.
            else.
              comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
            endif.
            append comp to comp_tab.
          endloop.
          struct_type = cl_abap_structdescr=>create( comp_tab ).
          dyn_node_info = rootnode_info->add_new_child_node(
             name                   = 'MDM_DATA'
             is_mandatory           = abap_false
             is_mandatory_selection = abap_false
             static_element_rtti    = struct_type
             is_multiple            = abap_true
             is_static              = abap_false ).
    *  get instance of new node
          dyn_node = wd_context->get_child_node( name = 'MDM_DATA' ).
    ****Process Table Data
          data content_string type string.
          data l_tabix type sytabix.
          table_type = cl_abap_tabledescr=>create( p_line_type = struct_type ).
          create data my_table type handle table_type.
          assign my_table->* to <table>.
          loop at result_set assigning <wa_result>.
            create data my_row type handle struct_type.
            assign my_row->* to <row>.
            loop at field_details assigning <wa_detail>.
              l_tabix = sy-tabix.
              read table <wa_result>-name_value_pairs assigning <wa_pair>
                                      with key code = <wa_detail>-field_code.
    *        loop at <wa_result>-name_value_pairs assigning <wa_pair>.
              if sy-subrc = 0 and <wa_pair>-value is not initial.
                assign component l_tabix of structure <row> to <f>.
    *            READ TABLE field_details ASSIGNING <wa_detail> INDEX sy-tabix.
                case <wa_pair>-type.
                  when 'STRING'.
                    assign <wa_pair>-value->* to <wa_string>.
                    if <wa_string> is assigned.
    *                DATA: int TYPE i VALUE 258.
    *                DATA: buffer TYPE xstring,
    *                      text_buffer TYPE string,
    *                      conv TYPE REF TO cl_abap_conv_out_ce.
    *                conv = cl_abap_conv_out_ce=>create(
    *                         encoding = 'UTF-8'
    *                         endian = 'L' ).
    *                CALL METHOD conv->write( data = <wa_string> ).
    *                buffer = conv->get_buffer( ).
    *                DATA: convin  TYPE REF TO cl_abap_conv_in_ce.
    *                CALL METHOD cl_abap_conv_in_ce=>create
    *                  EXPORTING
    *                    input = buffer
    *                  RECEIVING
    *                    conv  = convin.
    *                CALL METHOD convin->read
    *                  IMPORTING
    *                    data = text_buffer.
    *                MOVE text_buffer TO <f>.
                      move <wa_string> to <f>.
                    endif.
                  when 'MDM_CDT_DATE_TIME'.
                    assign <wa_pair>-value->* to <wa_date_time>.
                    if <wa_date_time> is assigned.
                      move <wa_date_time>-content to <f>.
                    endif.
                  when 'MDM_GDT_INTEGERVALUE'.
                    assign <wa_pair>-value->* to <wa_integer>.
                    if <wa_integer> is assigned.
                      if <wa_detail>-field_lookup_table is not initial.
                        content_string = wd_assist->perform_value_lookup(
                            i_lookup_table = <wa_detail>-field_lookup_table
                            i_lookup_key   = <wa_integer> ).
                        move content_string to <f>.
                      else.
                        move <wa_integer> to <f>.
                      endif.
                    endif.
                endcase.
              endif.
            endloop.
            append <row> to <table>.
          endloop.
          dyn_node->bind_table( <table> ).
    * Connect to the component Usage of the ALV
          data: l_ref_cmp_usage type ref to if_wd_component_usage.
          l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
          if l_ref_cmp_usage->has_active_component( ) is initial.
            l_ref_cmp_usage->create_component( ).
          endif.
    * Through the interface controller of the ALV Component set the DATA node dynamically
          data: l_ref_interfacecontroller type ref to iwci_salv_wd_table .
          l_ref_interfacecontroller =   wd_this->wd_cpifc_alv( ).
          l_ref_interfacecontroller->set_data(
            r_node_data = dyn_node  ).
          data alv_model type ref to cl_salv_wd_config_table.
          alv_model = l_ref_interfacecontroller->get_model( ).
          data columns type salv_wd_t_column_ref.
          field-symbols <wa_column> like line of columns.
          columns = alv_model->if_salv_wd_column_settings~get_columns( ).
          data column_id type string.
          data header type ref to cl_salv_wd_column_header.
          data l_text type string.
          loop at field_details assigning <wa_detail>.
    * build a structure description from the list of single fields
            if strlen( <wa_detail>-field_code ) > 30.
              column_id = <wa_detail>-field_code+0(30).
            else.
              column_id = <wa_detail>-field_code.
            endif.
            translate column_id to upper case.
            read table columns assigning <wa_column> with table key id = column_id.
            if sy-subrc = 0.
              header = <wa_column>-r_column->get_header( ).
              header->set_ddic_binding_field( if_salv_wd_c_column_settings=>ddic_bind_none ).
    *      if <wa_detail>-field_lookup_table is initial.
              header->set_text( <wa_detail>-field_name1 ).
    *      else.
    *        l_text = wd_assist->read_table_desc_for_lookup( <wa_detail>-field_lookup_table ).
    *        header->set_text( l_text ).
    *      endif.
            endif.
          endloop.
        catch cx_root into o_except.
          data: l_current_controller type ref to if_wd_controller,
                l_message_manager    type ref to if_wd_message_manager.
          l_current_controller ?= wd_this->wd_get_api( ).
          l_message_manager = l_current_controller->get_message_manager( ).
          l_message_manager->report_exception(
              message_object           = o_except ).
      endtry.

  • Need Help in Field Symbol for Dynamically passing  table field value

    Hi All,
    In my internal table I am having data.
    I am dynamically forming table field name and substitute for the another table field name to pass DATA.
    but I am getting the Variable name insted of Value ie Data.
    I am using Field Symbol for this.
    data:
    Field-symbols <TS> type any.
    field1 type string.
    LOOP AT TABLEFIELDS INTO WA_TABLEFIELDS.
                READ TABLE  TEST  WITH KEY NAME = WA_TABLEFIELDS-FIELDNAME.
                IF SY-SUBRC = 0.
                  CONCATENATE 'WA_' WA_TABLEFIELDS-TABNAME '-' WA_TABLEFIELDS-FIELDNAME INTO  Field1.
                  Assign Field1 to <TS>.
                    ALL_VAL-VALUE = <TS>
    "After substituting the <TS>  into ALL_VAL-VALUE  field I need a DATA to be passed but the variable name is appending"*    
             APPEND ALL_VAL.
                ENDIF.
              ENDLOOP.
    kindly how to pass the value into the table.
    Thanks in advance.
    San

    Hi,
    pls assign a break point in
    CONCATENATE 'WA_' WA_TABLEFIELDS-TABNAME '-' WA_TABLEFIELDS-FIELDNAME INTO Field1.
    Assign Field1 to <TS>.
    ALL_VAL-VALUE = <TS>
       " Put a break point here and check for the value in <TS>.
    if <TS> contains value then create a work area for ALL_VAL AND PASS the Field-Symbol to that and then  append thw wa into the table...
    Hope this works out!!
    thanks

Maybe you are looking for