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 syntax for SAP_APPL 605

former_member214084
Participant
0 Kudos

Hi

I am on SAP_APPL 605, trying to convert columns into rows with field symbols..though having no syntax errors in code it is thorwing dump.

Below is my sample code :

Looping table (it_grp_display_tmp) has 2 columns :

1.  Column mrgamt  has     12 records which I want to convert it into row 1 with type GPRVAL, with rowtxt-field as 'Amount'

2.  Column Netwr    has     12 records which I want to convert it into row 2 with type GPRVAL  with rowtxt-field as 'Margin'

So I am trying to convert 1st column into row, but with no syntax error it is giving dump & debugger sy-subrc is 4.

Is there is something missing in code or I have to use different syntax because of older version. ???

Please guide me to field-symbol syntax link for 605 or correct me if I missing some logic ...

1 ACCEPTED SOLUTION

former_member289261
Active Contributor
0 Kudos

Hi,

So you want to place amount field of 12 records to a single row with 12 columns ?

Regards,

Ashish

9 REPLIES 9

former_member289261
Active Contributor
0 Kudos

Hi,

So you want to place amount field of 12 records to a single row with 12 columns ?

Regards,

Ashish

0 Kudos

Ashish,

Yes , I want my internal data to be moved in below structure.

0 Kudos

Hi,

Try this code :

data : it_values         type table of gprval,

          wa_values      type gprval,

          wa_values2     type gprval,

          lv_comp          type sy-tabix.

field-symbols : <field> type simple.

wa_values-rowtxt = Ámount'.

wa_values2-rowtxt = 'Margin'.

loop at it_grp_display_tmp into wa_grp_display_tmp.

     lv_comp = sy-tabix + 1.

    

     assign component lv_comp of structure wa_values to <field>.

          if <field> is assigned.

               <field> = wa_grp_display_tmp-mrgamt.

               unassign <field>.

          endif.

     assign component lv_comp of structure wa_values2 to <field>.

          if <field> is assigned.

               <field> = wa_grp_display_tmp-netwr.

               unassign <field>.

          endif.

endloop.

append wa_values to it_values.

append wa_values2 to it_values.

Regards,

Ashish

Former Member
0 Kudos

what is the dump error reporting? That may help understand the fault better.

regarding the field symbols - you can work with them in several ways.

but it looks like you are trying to assign a literal. This is incorrect.

Check the field symbol is assigned, then move the value...

if <wor> is assigned.

move 'amount' to <wor>. "will move text to field symbol

...

if <wor> is assigned.

move var_value to <wor>. " will move a variable of var_value to field symbol

if <wor> is assigned and <amount> is assigned.

move <amount> to <wor>. " will move a field symbol with your value to <wor>

looking at your code though - it looks incorrectly written.

You have loops etc but you don't seem to be even working with the right values in your processing

0 Kudos

Steve,

I was modifying the code & fortunately dump is not coming now..Below is my revised code but Getting data inside it_table but not moving in proper fields because of the  "AMOUNT" field . Below is updated code which has little bit of issue

Besides My source data table has 2 columns only. So each need to convert into rows.

Target Table  it_values structure is like below, & every new row I have to insert hard coded char text, i.e. row1 --> amount   1000 1000   1000  1000 ...............

             row2-->  margin     500    500    500  500.....

0 Kudos

Hi,

as far as i can see, you have only one primary issue left.

Since you assign according to sy-tabix, your rowtext column will be overwritten in the first pass.

So skip the assignment for the first pass by checking sy-tabix gt 1.

Then you should get your desired result.

BR - Jörg

custodio_deoliveira
Active Contributor
0 Kudos

Hi,

There are quite a few things wrong here. I don't have my system now, so I can't give you 100% answer, but I'll try to point out what seems obvious (to me at least)


assign component sy-tabix of structure <tab> to <wor>

this is wrong for 2 reasons: 1st, sy-tabix will be 3 in the 3rd loop, but I believe the table you want has only 2 fields, so there's no component 3. Also, you first need to assign something to <tab>, then you can assign component of <tab> to <wor>.

After each assign, it's good practice to check IF <field-symbol> IS ASSIGNED.

Regards,

Custodio

dibyajeeban_jena
Active Participant
0 Kudos

Hi,

If the  dump  is ' field symbol not assigned yet' , then check your code... i can see  field-symbol <tab>  is not assigned before statement-

ASSIGN COMPONENT SY-INDEX  OF STRUCTURE <TAB>  TO <WOR> .

Again : i guess your logic is going wrong...

If you want to - tab1 ---  mrgamt     netwr             to           tab2 -   field       amt1   amt2   amt3   amt4

                                           1            10                                        Amount    10       15       20        25 

                                            2            15                                       Margine     1         2        3           4

                                             3           20

                                             4           25

if above is the requirement ,,  do as below

TYPES : BEGIN OF STR_TAB2,

               FIELD    TYPE  CHAR20,

               AMT1     TYPE  GPRVAL,

              AMT2     TYPE  GPRVAL,

               AMT3     TYPE  GPRVAL,

               AMT4     TYPE  GPRVAL,

               END OF STR_TAB2 .

DATA : IT_TAB2 TYPE TABLE OF STR_TAB2,

             WA_TAB2_1  TYPE STR_TAB2 ,

             WA_TAB2_2   TYPE STR_TAB2 .  .

FIELD-SYMBOL : <WA_TAB1>  TYPE ANY ,

                             <WA_VAL>  TYPE ANY .

LOOP AT TAB1 ASSIGNING <WA_TAB1> .

WA_TAB2_1-FIELD = 'AMOUNT' .

WA_TAB2_2-FIELD = 'MARGINE' .

DO .

ASSIGN COMPONENT SY-INDEX  OF STRUCTURE <WA_TAB1>  TO <WA_VAL> .

IF SY-SUBRC NE 0 .

EXIT .

ENDIF .

..............

..............

.............

put the logic to keep the values in above two workarea fields .

............

..........

ENDDO.

ENDLOOP .

Regards

DJ

former_member214084
Participant
0 Kudos

Thank you for all the replies.. I am learner in field symbols , this cleared many of my field symbol concepts.