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: 

Field Symbol modifiying using row position

Former Member
0 Kudos

Hello,

I am stuck up with a requirement wherein I have a field symbol table and another field symbol work area.

FS Table:

Emts  Desc  Pr_3  Dseg  Pr_5  Dseg  Pr_7 Dseg

1        AAA   12     Acct            Clnr           Clk 

2        BBB     9     HKpr           Drvr            Md

I have ALVgrid display which is the output tabstrip. The values I enter in the output display are fetched in the Fieldsymbol table.

The requirement is the percentage that has been entered in the first percentage column in our example Pr_3 (12%)  is to be passed to all other percentage columns Pr_5, Pr_7 of the first row, similarly the same logic is to be applied to the second row (9%) to all other percentage columns. As the modification of field symbol table from <wa_fs> using index cannot be used in here I'm unable to fill the remaining rows of the field symbol table. Please suggest a measure for filling of the data in FS table ...

Regds,

Sreekanth

3 REPLIES 3

former_member184158
Active Contributor
0 Kudos

Hi Sreekanth,

it depends on field symbol , if your field symbol from type any, or known structure.

so I have provided this solution wit many options,

if your  structure is unknown (any) or known.

I hope it could help you, if you face any problem, just let us to know

REPORT zibo_pg_test99.

TYPES: BEGIN OF ty_test,
        emts 
TYPE i,
        pr_3 
TYPE i,
        desc3
TYPE c LENGTH 3,
        pr_5 
TYPE i,
        desc5
TYPE c LENGTH 3,
         pr_7
TYPE i,
        desc7
TYPE c LENGTH 3,
 
END OF ty_test.

DATA ls_test TYPE ty_test.
DATA: lt_test TYPE TABLE OF ty_test.

FIELD-SYMBOLS <lt_data> TYPE ANY TABLE.
FIELD-SYMBOLS <ls_data1> TYPE ty_test.
FIELD-SYMBOLS <ls_data2> TYPE any.
FIELD-SYMBOLS <lv_value1> TYPE any.

FIELD-SYMBOLS <lv_value2> TYPE any.
FIELD-SYMBOLS <lv_value3> TYPE any.

ls_test-emts
= 1.
ls_test-desc3
= 'AAA'.
ls_test-pr_3
= 12.
ls_test-desc5
= 'Clnr'.
ls_test-desc7
= 'Clk'.

APPEND ls_test TO lt_test.

ls_test-emts
= 2.
ls_test-desc3
= 'BBB'.
ls_test-pr_3
= 9.
ls_test-desc5
= 'HKpr'.
ls_test-desc7
= 'Md'.

APPEND ls_test TO lt_test.


START-OF-SELECTION.

 
ASSIGN lt_test TO <lt_data>.

 
" if you know the field names.
 
LOOP AT <lt_data> ASSIGNING <ls_data1>.
    <ls_data1>
-pr_5 = <ls_data1>-pr_7 = <ls_data1>-pr_3.
 
ENDLOOP.
 
" if you don't know the field names , it mean
 
"   FIELD SYMBOL from type any,
 
"   you can assign the field name, or index if you know the order of fields/ name...

 
LOOP AT <lt_data> ASSIGNING <ls_data2>.
   
ASSIGN COMPONENT 'PR_3' OF STRUCTURE <ls_data2> TO <lv_value1>.

   
ASSIGN COMPONENT 'PR_5' OF STRUCTURE <ls_data2> TO <lv_value2>.
    <lv_value2>
= <lv_value1>.
   
ASSIGN COMPONENT 'PR_7' OF STRUCTURE <ls_data2> TO <lv_value3>.
    <lv_value3>
= <lv_value1>.
 
ENDLOOP.


 
" if you don't want to use the assign,
 
" you can use the move corresponding

 
LOOP AT <lt_data> ASSIGNING <ls_data2>.

   
MOVE-CORRESPONDING <ls_data2> TO ls_test.
    ls_test-pr_5
= ls_test-pr_7 = ls_test-pr_3.
   
MOVE-CORRESPONDING ls_test to <ls_data2>.
 
ENDLOOP.


http://s14.postimg.org/h43bts59t/image.jpg


http://s15.postimg.org/p89z1i3dn/image.jpg


Regards

Ebrahim

0 Kudos

Hello Ebrahim,

Thank you for the nice illustration with the screenshots. But my issue is the table is fully dynamic and ascertaining the number of rows that would have to be filled is to be determined in runtime and so a predefined structure will not work... Cannot use an internal table structure for my case....

Just adding to that the column names are known but the table being fully dynamic there is no fixed number of rows or columns but the columns names are static with the last numeric numbers (pr_7, pr_9....) change every time for indicating the number of columns.....

Regds,

Sreekanth

0 Kudos

Hi Sreekanth,

it is not difficult as I think, you can just try this code, and it will meet your requirement.

as you have written that the field names are with  last numeric numbers (pr_7, pr_9....)

so I can maintian the ITAB as dynamich and I don't know what is the name of the fileld only last 4 letters.


REPORT zibo_pg_test99.
TYPES: BEGIN OF ty_test,
        emts 
TYPE i,
        ibo_pr_3 
TYPE i,
        desc3
TYPE c LENGTH 3,
        ibo_pr_5 
TYPE i,
        desc5
TYPE c LENGTH 3,
         ibo_pr_7
TYPE i,
        desc7
TYPE c LENGTH 3,
 
END OF ty_test.

DATA ls_test TYPE ty_test.
DATA: lt_test TYPE TABLE OF ty_test.

DATA: lr_str TYPE REF TO cl_abap_structdescr.
DATA: lt_comp TYPE abap_compdescr_tab.


 
DATA ls_comp LIKE LINE OF lt_comp.
 
DATA lv_name LIKE ls_comp-name.


 
DATA lv_pr5 LIKE ls_comp-name.
 
DATA lv_pr7 LIKE ls_comp-name.

DATA lv_pr3 LIKE ls_comp-name.

 
DATA len TYPE i.

FIELD-SYMBOLS <lt_data> TYPE STANDARD  TABLE.
FIELD-SYMBOLS <ls_data1> TYPE ty_test.
FIELD-SYMBOLS <ls_data2> TYPE any.
FIELD-SYMBOLS <lv_value1> TYPE any.

FIELD-SYMBOLS <lv_value2> TYPE any.
FIELD-SYMBOLS <lv_value3> TYPE any.

ls_test-emts
= 1.
ls_test-desc3
= 'AAA'.
ls_test-ibo_pr_3
= 12.
ls_test-desc5
= 'Clnr'.
ls_test-desc7
= 'Clk'.

APPEND ls_test TO lt_test.

ls_test-emts
= 2.
ls_test-desc3
= 'BBB'.
ls_test-ibo_pr_3
= 9.
ls_test-desc5
= 'HKpr'.
ls_test-desc7
= 'Md'.

APPEND ls_test TO lt_test.


START-OF-SELECTION.

 
ASSIGN lt_test TO <lt_data>.
 
READ TABLE <lt_data> ASSIGNING <ls_data2> INDEX 1.

  lr_str ?= cl_abap_structdescr
=>describe_by_data( <ls_data2> ).

  lt_comp[]
= lr_str->components[].

 
LOOP AT lt_comp INTO ls_comp.
   
check strlen( ls_comp-name ) > 4.
    len
= strlen( ls_comp-name ) - 4.
    lv_name
= ls_comp-name+len(4).

   
IF lv_name = 'PR_5'.
      lv_pr5
= ls_comp-name.
   
ELSEIF lv_name = 'PR_7'.
      lv_pr7
= ls_comp-name.

   
ELSEIF lv_name = 'PR_3'.
      lv_pr3
= ls_comp-name.

   
ENDIF.
 
ENDLOOP.


 
LOOP AT <lt_data> ASSIGNING <ls_data2>.
 
ASSIGN COMPONENT lv_pr3 OF STRUCTURE <ls_data2> TO <lv_value1>.

 
ASSIGN COMPONENT lv_pr5 OF STRUCTURE <ls_data2> TO <lv_value2>.
 
ASSIGN COMPONENT lv_pr7 OF STRUCTURE <ls_data2> TO <lv_value3>.
   
<lv_value2> = <lv_value1>.
    <lv_value3>
= <lv_value1>.

 
ENDLOOP.

Regards

Ebrahim