Application Development and Automation 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: 
Read only

Field Symbol assignment

Former Member
0 Likes
18,573

Hi all ,

I am working on Field symbols and have the foll doubt .

my internal table structure depends on my field catalog which itself is dynamic .

however , the problem is while assigning the values to the internal table.

I have a final internal table which has all the columns however my field catalog contains 5 columns .. field A , B , C , D and E .

I have managed to create the internal table dynamically (here 5 colums ) by using cl_alv_table_create=>create_dynamic_table .

*******************

LOOP AT it_fieldcatalog INTO wa_fieldcatalog .

wa_xfc-fieldname = wa_fieldcatalog-fieldname .

APPEND wa_xfc TO it_ifc .

CLEAR wa_xfc .

ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_ifc

i_length_in_byte = 'X'

IMPORTING

ep_table = dy_table.

ASSIGN dy_table->* TO <fs_table>.

  • Create dynamic work area and assign to FS

CREATE DATA dy_line LIKE LINE OF <fs_table>.

ASSIGN dy_line->* TO <fs_tab>.

*******************

I am handling the dynamic field catalog in the foll way :

ASSIGN it_finalvari TO <fs_table1>. " final itab

ASSIGN wa_finalvari TO <fs_tab1> . " final wa

LOOP AT <fs_table1> INTO <fs_tab1>.

LOOP AT it_fieldcatalog INTO wa_fieldcatalog.

g_i = sy-tabix .

ASSIGN COMPONENT wa_fieldcatalog-fieldname OF STRUCTURE <fs_tab1> TO <fs>.

IF sy-subrc EQ 0.

        • WHAT TO DO HERE *****

ENDIF.

ENDLOOP.

ENDLOOP .

now in the first pass , I am getting the valie of col A in <fs> .

But how should I pass this value of A to the first column of <fs_table> and subsequently the other column values too ?

Pls help ...

Supriya ...

Hi all ,

I am working on Field symbols and have the foll doubt .

my internal table structure depends on my field catalog which itself is dynamic .

however , the problem is while assigning the values to the internal table.

I have a final internal table which has all the columns however my field catalog contains 5 columns .. field A , B , C , D and E .

I have managed to create the internal table dynamically (here 5 colums ) by using cl_alv_table_create=>create_dynamic_table .

*******************

LOOP AT it_fieldcatalog INTO wa_fieldcatalog .

wa_xfc-fieldname = wa_fieldcatalog-fieldname .

APPEND wa_xfc TO it_ifc .

CLEAR wa_xfc .

ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_ifc

i_length_in_byte = 'X'

IMPORTING

ep_table = dy_table.

ASSIGN dy_table->* TO <fs_table>.

  • Create dynamic work area and assign to FS

CREATE DATA dy_line LIKE LINE OF <fs_table>.

ASSIGN dy_line->* TO <fs_tab>.

*******************

I am handling the dynamic field catalog in the foll way :

ASSIGN it_finalvari TO <fs_table1>. " final itab

ASSIGN wa_finalvari TO <fs_tab1> . " final wa

LOOP AT <fs_table1> INTO <fs_tab1>.

LOOP AT it_fieldcatalog INTO wa_fieldcatalog.

g_i = sy-tabix .

ASSIGN COMPONENT wa_fieldcatalog-fieldname OF STRUCTURE <fs_tab1> TO <fs>.

IF sy-subrc EQ 0.

        • WHAT TO DO HERE *****

ENDIF.

ENDLOOP.

ENDLOOP .

now in the first pass , I am getting the valie of col A in <fs> .

But how should I pass this value of A to the first column of <fs_table> and subsequently the other column values too ?

Pls help ...

Supriya ...

8 REPLIES 8
Read only

Kiran_Valluru
Active Contributor
0 Likes
5,536

Hi supriya.,

refer this snippet., use assign component..

DATA:   i_gp_table             TYPE REF TO data,
      wa_gp_line             TYPE REF TO data.
*&------------------------------------------------------------------------------------------*
*& Data Declaration for field symbols to store dynamic internal table and dynamic components
*&---------------re----------------------------------------------------------------------------*

FIELD-SYMBOLS: <gt_table>      TYPE STANDARD TABLE,
               <gwa_table>     TYPE ANY,        
               <l_received>    TYPE any,
               <l_date>        TYPE ANY,
               <l_matnr>       TYPE ANY,
               <l_matdesc>     TYPE ANY,
               <l_color>       TYPE ANY,
               <l_processtype> TYPE ANY.

**============Create table dynamically====================

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = i_fieldcat_cl
    IMPORTING
      ep_table        = i_gp_table.

  ASSIGN i_gp_table->* TO <gt_table>.

*--Create Work Area Dynamically
  CREATE DATA wa_gp_line LIKE LINE OF <gt_table>.
  ASSIGN wa_gp_line->* TO <gwa_table>.

*** now loop at interna ltable and assign to final internal table 

 ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gwa_table>  " here matnr is the field name in field catalog to which u want              
                                                    TO <l_matnr>.                            "  to assign
                                     

    IF <l_matnr> is ASSIGNED.
      <l_matnr> =  ls_vals-matnr .
    ENDIF.


    ASSIGN COMPONENT 'MATDES' OF STRUCTURE <gwa_table>
                                       TO <l_matdesc>.

    IF <l_matdesc> is ASSIGNED.

      <l_matdesc> =  ls_vals-maktx .

    ENDIF.

    ASSIGN COMPONENT 'PTYPE' OF STRUCTURE <gwa_table>
                                      TO <l_processtype>.

    IF <l_processtype> is ASSIGNED.

      <l_processtype> =  ls_vals-ptype .

    ENDIF.


    APPEND <gwa_table> to <gt_table>.
    CLEAR:  <gwa_table>.

*endloop.

* Display ALV
 CALL METHOD O_GRID->set_table_for_first_display   
    CHANGING
      it_fieldcatalog = i_fieldcat_cl
      it_outtab       = <gt_table>.

hope this helps u., reply if u need some more clarifications.,

Thanks & Regards

Kiran

Read only

0 Likes
5,536

Hi ,

Do i have to write this Assign Component for every column in thr Itab .

My Itab has over 600 columns (its n age old prog ...) ... not practical to write it for all columns ..

Thanks

Supriya

Read only

0 Likes
5,536

Hi,

You can also access fields dynamically without giving fields name.

Observer the below code change


data: lv_line type i.
describe table it_fieldcatalog lines lv_line.

do lv_line.
ASSIGN COMPONENT sy-tabix OF STRUCTURE <fs_tab1> TO <fs>.
IF sy-subrc ne 0.
exit.
else.
 * Write your processing logic for assign fields value to fields symbols
ENDIF.

ENDdo.

Read only

Former Member
0 Likes
5,536

Hi Supriya,

If understand you correctly, you have an itab let us say ITAB1 which has all the columns, and you have a field catalog which is dynamic, you build a dynamic ITAB (DYN_ITAB - 5 columns) as per the FC Now you want to assign the values to this DYN_ITAB, if i have understood you correclty then your code does everything except for an append statement i guess.

LOOP AT <fs_table1> INTO <fs_tab1>.

LOOP AT it_fieldcatalog INTO wa_fieldcatalog.

g_i = sy-tabix .

ASSIGN COMPONENT wa_fieldcatalog-fieldname OF STRUCTURE <fs_tab1> TO <fs>.

IF sy-subrc EQ 0.

        • WHAT TO DO HERE *****

ENDIF.

ENDLOOP.

          • This is what you have to do - APPEND <FS> to <FS_TABLE>.

ENDLOOP .

Regards,

Chen

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
5,536

try this


LOOP AT <fs_table1> assigning <fs_tab1>.
g_tabix = sy-tabix.
do.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_tab1> TO <fs>.
IF sy-subrc EQ 0.
<fs> = 'A'.  "Move your values here
else.
modify <fs_table1> index g_tabix from <fs_tab1>.
exit.
ENDIF.
enddo.
ENDLOOP .

Read only

0 Likes
5,536

Hi all ,

I have no issues in assignment .

I am facing problems in getting the value in the internal table (field symbol) .

From the Field catalog , i am getting the field name and I am getting the valu associated with this field from the internal table.

But now , i need to have them in my FINAL internal table whose structure is same as the Fieldcatalog as i need to download the final internal table using GUI_DOWNLOAD .

Pls help .

Supriya

Read only

0 Likes
5,536

field-symbols:<fs_s> type any,
                      <fs_t> type any.

LOOP AT <fs_table1> assigning <fs_tab1>.
LOOP AT it_fieldcatalog INTO wa_fieldcatalog.
ASSIGN COMPONENT  wa_fieldcatalog-fname OF STRUCTURE <fs_tab1> TO <fs_s>.
IF sy-subrc EQ 0.
ASSIGN COMPONENT wa_fieldcatalog-fname OF STRUCTURE <fs_final> TO <fs_t>.
if sy-subrc = 0.
<fs_t> = <fs_s>.
endif.
ENDIF.
endloop.
if sy-subrc = 0.
append <fs_final> to <fs_itfinal>.
endif.
ENDLOOP .
Read only

0 Likes
5,536

Hi ,

Issue hs been resolved ....

Use move corr as both the field symbols had the same name

Thanks for ur help .

Supriya