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: 

Assign Field-Symbols Data into Workarea

Former Member
0 Kudos

Dear Team,

     Can anybody tell me, How to assign Field-Symbols data into my work area.

Actually the problem is i have a program of display dynamic table, so my requirement is that, I have to display my data in scramble format so at the run time user can enter any table so how can i assign field symbols data into my work area separately.

I am using HTTP_SCRAMBLE FM.

Below is my code:-

FIELD-SYMBOLS : <gv_tab> TYPE STANDARD TABLE,
                            <wa_tab> TYPE any.

ASSIGN <all_table> TO <gv_tab>.


DATA : w_dref TYPE REF TO data.

Create data w_dref type table of <gv_tab>.

assign w_dref->* to <gv_tab>.

6 REPLIES 6

Former Member
0 Kudos

Hi

Once <gv_tab> have value,

IF <gv_tab> is assigned.

Loop at <gv_tab> assigning <wa_tab>.

endloop.

ENDIF.

regards,

Archer

Former Member
0 Kudos

Hi Rishabh,

You can use field-symbol as work area. Is there specific need behind passing field-symbol values to work area?

Regards,

Sid

venuarun
Active Participant
0 Kudos

Hi Rishabh,

You can assign structure to field symbol like this

ASSIGN COMPONENT gv_fname OF STRUCTURE wa_output TO <fs>.

With Regards

Arun VS

Former Member
0 Kudos

Hi Rishab,

find the below code for your reference for dynamic table.

Create a dynamic internal table with the specified number of columns. 

Creating Dynamic internal table

TYPE-POOLS: slis.

FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,  “ Dynamic internal table name

               <fs_dyntable>,                     “ Field symbol to create work area

               <fs_fldval> type any.              “ Field symbol to assign values 

PARAMETERS: p_cols(5) TYPE c.                     “ Input number of columns

DATA:   t_newtable TYPE REF TO data,

        t_newline  TYPE REF TO data,

        t_fldcat   TYPE slis_t_fldcat_alv,

        t_fldcat   TYPE lvc_t_fcat,

        wa_it_fldcat TYPE lvc_s_fcat,

        wa_colno(2) TYPE n,

        wa_flname(5) TYPE c. 

* Create fields .

  DO p_cols TIMES.

    CLEAR wa_it_fldcat.

    move sy-index to wa_colno.

    concatenate 'COL'

                wa_colno

           into wa_flname.

    wa_it_fldcat-fieldname = wa_flname.

    wa_it_fldcat-datatype = 'CHAR'.

    wa_it_fldcat-intlen = 10.

    APPEND wa_it_fldcat TO t_fldcat.

  ENDDO. 

* Create dynamic internal table and assign to FS

  CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

      it_fieldcatalog = t_fldcat

    IMPORTING

      ep_table        = t_newtable. 

  ASSIGN t_newtable->* TO <t_dyntable>. 

* Create dynamic work area and assign to FS

  CREATE DATA t_newline LIKE LINE OF <t_dyntable>.

  ASSIGN t_newline->* TO <fs_dyntable>.

Populating Dynamic internal table 

  DATA: fieldname(20) TYPE c.

  DATA: fieldvalue(10) TYPE c.

  DATA: index(3) TYPE c. 

  DO p_cols TIMES. 

    index = sy-index.

    MOVE sy-index TO wa_colno.

    CONCATENATE 'COL'

                wa_colno

           INTO wa_flname. 

* Set up fieldvalue

    CONCATENATE 'VALUE' index INTO

                fieldvalue.

    CONDENSE    fieldvalue NO-GAPS. 

    ASSIGN COMPONENT  wa_flname

        OF STRUCTURE <fs_dyntable> TO <fs_fldval>.

   <fs_fldval> =  fieldvalue. 

  ENDDO. 

* Append to the dynamic internal table

  APPEND <fs_dyntable> TO <t_dyntable>.

Displaying dynamic internal table using Grid. 

DATA: wa_cat LIKE LINE OF fs_fldcat. 

  DO p_cols TIMES.

    CLEAR wa_cat.

    MOVE sy-index TO wa_colno.

    CONCATENATE 'COL'

                wa_colno

           INTO wa_flname. 

    wa_cat-fieldname = wa_flname.

    wa_cat-seltext_s = wa_flname.

    wa_cat-outputlen = '10'.

    APPEND wa_cat TO fs_fldcat.

  ENDDO. 

* Call ABAP List Viewer (ALV)

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

      it_fieldcat = fs_fldcat

    TABLES

      t_outtab    = <t_dyntable>.

Thanks,

Marimuthu.K

rajkumarnarasimman
Active Contributor

Hi Rishabh,

Getting the value from Field symbol to Work area, we can do it.

Work Area -> Work Area

  Here both the structure we know, only we are going to pass the value, that we can do it, using move, move-corresponding statements etc.,

Field-symbol -> Work Area

In Field-symbol concept, we are getting the structure at runtime and also getting the value during runtime only.


In Work area concept, the structure is previously assigned and only the value we use to get at runtime.

In order to move the value from Field-symbol to work area, we have to get the field value from Fieldsymbol one by one and have to assign the same to work area as shown below.

"Data Declarations
FIELD-SYMBOLS : <gv_tab> TYPE STANDARD TABLE,
                                <wa_tab>
TYPE ANY.

DATA : w_dref TYPE REF TO data.

ASSIGN <all_table> TO <gv_tab>.


CREATE DATA w_dref TYPE TABLE OF <gv_tab>.

ASSIGN w_dref->* TO <gv_tab>.


"Get Field1 value from Field symbol and assign to Workarea


ASSIGN COMPONENT 'FIELD1' OF  STRUCTURE <gv_tab> TO <wa_tab>.

IF <wa_tab> IS ASSIGNED.
  wa_final-field1
<wa_tab>.
ENDIF.


"Get Field2 value from Field symbol and assign to Workarea


ASSIGN COMPONENT 'FIELD2' OF  STRUCTURE <gv_tab> TO <wa_tab>.

IF <wa_tab> IS ASSIGNED.
  wa_final-field2
<wa_tab>.
ENDIF.


"Get Field3 value from Field symbol and assign to Workarea


ASSIGN COMPONENT 'FIELD3' OF  STRUCTURE <gv_tab> TO <wa_tab>.

IF <wa_tab> IS ASSIGNED.
  wa_final-field3
<wa_tab>.
ENDIF.


"Append the Internal Table
APPEND wa_final TO it_final.


"Clear the Work Area
CLEAR wa_final.


Hope it helps.. Let me know if you have any clarification.


If I am wrong, kindly correct me..


Regards


Rajkumar Narasimman

0 Kudos

Dear All,

   Thanks to you all.

Specially thanks to Rajkumar and Marimuthu and Arun also.

Done by below Code.

LOOP AT <t_itab> ASSIGNING <wa_itab>.
      ASSIGN COMPONENT sy-tabix OF STRUCTURE <wa_itab> TO <fs_val>.
      IF <fs_val> IS ASSIGNED.
         t_line = <fs_val>.
      ENDIF.

ENDLOOP.