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: 

save field symbol into dynamic itab.

former_member183924
Active Participant
0 Kudos
104

Hi experts,

I ve read this:

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

And now I want to save my field-symbol which has the structure of the dynamic internal table into the dynamic itab. I thought after my declaration and assignings the itab should be filled automaticly but i don't works.

Short: I need this:

APPEND <my_field_symbold> TO <itab>. Ofcourse we cannot do this with fieldsymbols...

here is my code:



DATA:

      gt_stxl_ext TYPE TABLE OF gs_stxl_ext,
      wa_stxl_ext TYPE          gs_stxl_ext,

      gt_text     TYPE TABLE OF tline,
      wa_text     TYPE tline,

      g_tdlines_max_loc   TYPE i,
      g_tdlines_max_all   TYPE i,

      gs_fcat_tdlines TYPE lvc_s_fcat,
      gt_fcat_tdlines TYPE lvc_t_fcat,

      gt_dyn_tdlines TYPE REF TO data,
      wa_dyn_table   TYPE REF TO data
      .

FIELD-SYMBOLS: <fs_stxl>     TYPE stxl,
               <fs_stxl_ext> TYPE gs_stxl_ext,
               <fs_dyn_tdlines> TYPE REF TO data,
               <fs_dyn_table>   TYPE ANY TABLE,
               <fs_dyn_newline>,
               <fs_dynnewline_field>
               .

  ASSIGN gt_dyn_tdlines TO <fs_dyn_tdlines>.
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING it_fieldcatalog  = gt_fcat_tdlines
    IMPORTING ep_table         = <fs_dyn_tdlines>
    .

IF sy-subrc <> 0.
  EXIT.
ENDIF.


ASSIGN <fs_dyn_tdlines>->* TO <fs_dyn_table>.

CREATE DATA wa_dyn_table LIKE LINE OF <fs_dyn_table>.

LOOP AT gt_stxl_ext ASSIGNING <fs_stxl_ext>.

  CALL FUNCTION 'READ_TEXT'
  EXPORTING
    client           = sy-mandt
    id               = <fs_stxl_ext>-tdid
    language         = <fs_stxl_ext>-tdspras
    name             = <fs_stxl_ext>-tdname
    object           = <fs_stxl_ext>-tdobject
  TABLES    lines    = gt_text
  .

  IF sy-subrc = 0.
    CLEAR: l_gttext_string, g_tdlines_max_loc.
    UNASSIGN <fs_dyn_newline>.
    ASSIGN wa_dyn_table->* TO <fs_dyn_newline>.

    MOVE-CORRESPONDING <fs_stxl_ext> TO <fs_dyn_newline>.


    LOOP AT gt_text INTO wa_text.

      l_dynnewline_field = 'TDLINE'.
      l_tabix_component = sy-tabix.
      SHIFT l_tabix_component LEFT DELETING LEADING '0'.
      CONCATENATE l_dynnewline_field l_tabix_component INTO l_dynnewline_field.

      ASSIGN COMPONENT l_dynnewline_field OF STRUCTURE <fs_dyn_newline> TO <fs_dynnewline_field>.
      <fs_dynnewline_field> = wa_text-tdline.

    ENDLOOP.

* all this below doesn't works... (ofcourse)
*    ASSIGN <fs_dyn_newline> TO <fs_dyn_table>.
*    MOVE <fs_dyn_newline> TO <fs_dyn_table>.
*    APPEND INITIAL LINE TO <fs_dyn_table> ASSIGNING <fs_dyn_newline>.

  ENDIF.


ENDLOOP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
63

hi,

see this code.we can do like this.

REPORT ZDYN_ITAB.

PARAMETERS:DB_TABLE(30).

DATA FCAT1 TYPE LVC_T_FCAT.

DATA:DYN_ITAB TYPE REF TO DATA,

WA TYPE REF TO DATA.

FIELD-SYMBOLS: <DISP_TABLE> TYPE TABLE,

<WA> TYPE ANY.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = DB_TABLE

CHANGING

CT_FIELDCAT = FCAT1[].

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = FCAT1[]

IMPORTING

EP_TABLE = DYN_ITAB.

<b> ASSIGN DYN_ITAB->* TO <DISP_TABLE>.

CREATE DATA WA LIKE LINE OF <DISP_TABLE>.

ASSIGN WA->* TO <WA>.</b>

<b> SELECT * FROM (db_table) INTO <WA>.

APPEND <WA> TO <DISP_table>.

ENDSELECT.</b>

rgds,

bharat.

3 REPLIES 3

Former Member
0 Kudos
64

hi,

see this code.we can do like this.

REPORT ZDYN_ITAB.

PARAMETERS:DB_TABLE(30).

DATA FCAT1 TYPE LVC_T_FCAT.

DATA:DYN_ITAB TYPE REF TO DATA,

WA TYPE REF TO DATA.

FIELD-SYMBOLS: <DISP_TABLE> TYPE TABLE,

<WA> TYPE ANY.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = DB_TABLE

CHANGING

CT_FIELDCAT = FCAT1[].

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = FCAT1[]

IMPORTING

EP_TABLE = DYN_ITAB.

<b> ASSIGN DYN_ITAB->* TO <DISP_TABLE>.

CREATE DATA WA LIKE LINE OF <DISP_TABLE>.

ASSIGN WA->* TO <WA>.</b>

<b> SELECT * FROM (db_table) INTO <WA>.

APPEND <WA> TO <DISP_table>.

ENDSELECT.</b>

rgds,

bharat.

0 Kudos
63

Thanks a lot bharat. I declared my field-symbol-table wrong.

i did it like this: <table> TYPE ANY TABLE. But I have to do it without ANY like you.

Deepu:i didn't test your solution, but it looks good... thanks so much.

Regards, Steffen

Former Member
0 Kudos
63

Hello,

Check this :-


************************************************************************************************
*************************DYNAMIC INTERNAL TABLE FOR PLANT FIELD*********************************
************************************************************************************************

      DATA : gt_fcat_dyn TYPE lvc_t_fcat ,
             gwa_fcat TYPE  lvc_s_fcat,
             gwa_fcat_temp TYPE lvc_s_fcat.

      DATA : lv_colname(25) TYPE c.

*      DATA:  gwa_dynamic_line TYPE REF TO data.

      FIELD-SYMBOLS:
*            <fs_table> TYPE STANDARD TABLE, " ( declared above )
             <gwa_line>  TYPE ANY,
             <gwa_field> TYPE ANY.

      REFRESH gt_fcat_dyn.

* Field-catalog for the field Vendor
      CLEAR:   gwa_fcat.
      gwa_fcat-fieldname       =  'Vendor'.
      gwa_fcat-tabname         =  'GT_LAST'.
      gwa_fcat-coltext         =  'Vendor'.
      gwa_fcat-outputlen   = '10'.
      APPEND gwa_fcat TO gt_fcat_dyn.

* Field-catalog for the field Vendor Description
      CLEAR:   gwa_fcat.
      gwa_fcat-fieldname       =  'Description'.
      gwa_fcat-tabname         =  'GT_LAST'.
      gwa_fcat-coltext         =  'Description'.
      gwa_fcat-outputlen   = '40'.
      APPEND  gwa_fcat TO gt_fcat_dyn.

* Field-catalog for the field Vendor Description
      CLEAR:   gwa_fcat.
      gwa_fcat-fieldname       =  'City'.
      gwa_fcat-tabname         =  'GT_LAST'.
      gwa_fcat-coltext         =  'City'.
      gwa_fcat-outputlen   = '35'.
      APPEND  gwa_fcat TO gt_fcat_dyn.

* Field-catalog for the field Username
      CLEAR:   gwa_fcat.
      gwa_fcat-fieldname       =  'Username'.
      gwa_fcat-tabname         =  'GT_LAST'.
      gwa_fcat-coltext         =  'UserName'.
      gwa_fcat-outputlen   = '12'.
      APPEND gwa_fcat TO gt_fcat_dyn.

* Field-catalog for the field Last Logon Date of the user
      CLEAR:   gwa_fcat.
      gwa_fcat-fieldname       =  'Lastlogon'.
      gwa_fcat-tabname         =  'GT_LAST'.
      gwa_fcat-coltext         =  'Lastlogon'.
      gwa_fcat-outputlen   = '12'.
      APPEND gwa_fcat TO gt_fcat_dyn.

* Field-catalog for the field User-Lock Status
      CLEAR:   gwa_fcat.
      gwa_fcat-fieldname       =  'UserLock_Status'.
      gwa_fcat-tabname         =  'GT_LAST'.
      gwa_fcat-coltext         =  'UserLock'.
      gwa_fcat-outputlen   = '12'.
      APPEND gwa_fcat TO gt_fcat_dyn.

* Field-catalog for the field Plant (Dynamic Creation)
*      clear wa_temp_final.
      CLEAR wa_last.

      LOOP AT gt_last INTO wa_last.

        IF NOT wa_last-werks IS INITIAL.
          READ TABLE gt_fcat_dyn INTO gwa_fcat_temp
                        WITH KEY fieldname = wa_last-werks.
          IF sy-subrc = 0.
            CONTINUE.
          ENDIF.
*wa_last-name1 = 'bsh. dillingen'.
          CLEAR:   gwa_fcat.
          gwa_fcat-fieldname = wa_last-werks.
          gwa_fcat-reptext   = wa_last-werks.
          gwa_fcat-tabname   =  'GT_LAST'.
          gwa_fcat-outputlen   = '12'.
          APPEND gwa_fcat TO gt_fcat_dyn.
        ENDIF.
        CLEAR gwa_fcat.
      ENDLOOP.

* Field-catalog for the field Transaction Code
      CLEAR:   gwa_fcat.
      gwa_fcat-fieldname       =  'Transaction'.
      gwa_fcat-tabname         =  'GT_LAST'.
      gwa_fcat-coltext         =  'Transactions'.
      gwa_fcat-outputlen       =  '1000'.
      APPEND gwa_fcat TO gt_fcat_dyn.

* Field-catalog for the field Transaction Code
      CLEAR:   gwa_fcat.
      gwa_fcat-fieldname       =  'TRANSACTION_DESCRIPTION'.
      gwa_fcat-tabname         =  'GT_LAST'.
      gwa_fcat-coltext         =  'Description'.
      gwa_fcat-outputlen       =  '1000'.
      APPEND gwa_fcat TO gt_fcat_dyn.


* Create Dynamic Table Structure
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gt_fcat_dyn[]
        IMPORTING
          ep_table        = gt_dynamic_table.

      ASSIGN gt_dynamic_table->* TO <fs_table>.

* Create a Work Area
      CREATE DATA gwa_dynamic_line LIKE LINE OF <fs_table>.
      ASSIGN gwa_dynamic_line->* TO <gwa_line>.

      SORT gt_final_temp BY bname.
      SORT gt_last       BY username.


      LOOP AT gt_last INTO wa_last.

        ASSIGN COMPONENT 'USERNAME' OF STRUCTURE <gwa_line> TO <gwa_field>.
        <gwa_field> = wa_last-username.

        ASSIGN COMPONENT 'VENDOR' OF STRUCTURE <gwa_line> TO <gwa_field>.
        <gwa_field> = wa_last-vendor.

        ASSIGN COMPONENT 'DESCRIPTION' OF STRUCTURE <gwa_line> TO <gwa_field>.
        <gwa_field> = wa_last-description.

        ASSIGN COMPONENT 'CITY' OF STRUCTURE <gwa_line> TO <gwa_field>.
        <gwa_field> = wa_last-city.

        ASSIGN COMPONENT 'LASTLOGON' OF STRUCTURE <gwa_line> TO <gwa_field>.
        <gwa_field> = wa_last-lastlogon.

        ASSIGN COMPONENT 'USERLOCK_STATUS' OF STRUCTURE <gwa_line> TO <gwa_field>.
        <gwa_field> = wa_last-userlock_status.

        IF wa_last-werks IS NOT INITIAL.
          lv_colname = wa_last-werks.
          ASSIGN COMPONENT lv_colname OF STRUCTURE
                                      <gwa_line> TO <gwa_field>.

          <gwa_field> = 'X'.

        ENDIF.

        ASSIGN COMPONENT 'TRANSACTION' OF STRUCTURE <gwa_line> TO <gwa_field>.
        <gwa_field> = wa_last-transaction.

        ASSIGN COMPONENT 'TRANSACTION_DESCRIPTION' OF STRUCTURE <gwa_line> TO <gwa_field>.
        <gwa_field> = wa_last-transaction_description.

* Use the control-break commands to populate the final table with only one entry for each user
        AT END OF username.
          INSERT <gwa_line> INTO TABLE <fs_table>.
          CLEAR  : <gwa_field>, <gwa_line> .
        ENDAT.

      ENDLOOP.

Regards,

Deepu.K