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

Modify internal table

former_member298409
Participant
0 Likes
2,997

Hi ,

I am facing problem while modifying of my internal table from work area.

source code:

modify table <fs> from <fs1>.

Both the field symbols are having same structure. It was not giving any syntax error. But not modifying the internal table <fs>.

Please help on this ...

*Note: My internal table was Dynamically created*

Thanks In Advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,773

Hi,

As Clemens says, there is no use of the MODIFY statement within a LOOP if you are working with field-symbols.

If you are not in a LOOP and have to work with field-symbol, you'd better read the entry you need to modify and assign it to your fs first.


READ TABLE <fs> WITH KEY... ASSIGNING <fs1>.
IF sy-subrc NE 0.       
  APPEND INITIAL LINE TO <fs> ASSIGNING <fs1>. "or INSERT INTO
ENDIF.

<fsf1>-fld1 = ...
<fsf1>-fld2 = ...

Cheers,

m.

9 REPLIES 9
Read only

Former Member
0 Likes
1,773

Hi,

Why dont you use the TRANSPORTING suffix addition for the MODIFY

LOOP AT i_cust into wa_cust.

IFwa_cust-name = 'John' and (wa_cust-discount = '40' and wa_cust-type = 'HIGH LEVEL').

wa_cust-discount = wa_cust-discount + 10.

MODIFY i_cust FROM wa_cust TRANSPORTING discount.

ENDIF.

ENDLOOP.

Just the ASSIGNING and the allocation of structure is different in case of Field Symbols nothing else changes

Thanks

Sri

Edited by: SRIKANTH P on Oct 8, 2011 11:41 PM

Read only

0 Likes
1,773

Hi Sri,

Thanks for reply

I have to modify all the fields .. not for a specific field

Read only

Clemenss
Active Contributor
0 Likes
1,773

Hi kandulaws,

if you use field-symbols, you can forget the modify statement.

loop at itab assigning <fs>.
  <fs> = <fs1>.
endloop.

precondition is that <fs> is of itab structure type or type any and <fs1> is assigned to a data object of itab structure.

In this case, all existing records of table itab will have the same value as the data object <fs1> is assigned to.

This does not make too much sense - just as your single code line won't make sense.

Regards,

Clemens

Read only

Former Member
0 Likes
1,774

Hi,

As Clemens says, there is no use of the MODIFY statement within a LOOP if you are working with field-symbols.

If you are not in a LOOP and have to work with field-symbol, you'd better read the entry you need to modify and assign it to your fs first.


READ TABLE <fs> WITH KEY... ASSIGNING <fs1>.
IF sy-subrc NE 0.       
  APPEND INITIAL LINE TO <fs> ASSIGNING <fs1>. "or INSERT INTO
ENDIF.

<fsf1>-fld1 = ...
<fsf1>-fld2 = ...

Cheers,

m.

Read only

0 Likes
1,773

Hi Thanks for ur Reply.

My Requirement was different i will give you the scenario.

1. I have to Download my Internal table data into XL sheet

But Internal table was not fixed fields it is a dynamic ( Based On the inputRange It was varies )

2. My selectionscreen was Productio order number ( Ranges )

Suppose user enters 1-20 in th select otions my internal table has to fetch those many production orders and downloaded into same xl.

output format.

example: production order range 1 to 5

ORD1 ORD2 ORD3 ORD4 ORD5 (first Row Number of Production Orders

MAT1 MAT2 MAT3 MAT4 MAT5 ( second row Header Materials of corresponding Production Order

QUA1 QUA2 QUA3 QUA4 QUA5 (third Row Quantity

child child child child child (4th Row child components

child child child child child (4th Row child components

child child child child child (4th Row child components

child child child child child (4th Row child components

...

For achiving of this i am using Dynamic internal table creation concept.

Now i am able to get all the three ORD and MAT and QUA in differnt rows .

But how to get the child components some times one production order we are having more than 50 child materials

How to achive this ?

Please help me on this scenario ?

Thanksin Advance

Read only

0 Likes
1,773

Hi

If you fill those dynamic internal tablem you should know how you fill them, so you need to managed a key fields in order to link father and child.

Max

Read only

0 Likes
1,773

Hi,

I suppose you have the transposed version of that expected result in another table.

In my opinion you shoud have a table defined with a row type like:


TYPES: BEGIN OF ty_main,
        ord  TYPE ...,
        mat  TYPE ...,
        qty  TYPE ...,
        comp TYPE ...,
       END OF ty_main,

so e.g.

ORD1 MAT1 QUA1 CHILD1

ORD1 MAT1 QUA1 CHILD2

ORD1 MAT1 QUA1 CHILD3

ORD1 MAT2 QUA2 CHILD4

ORD1 MAT2 QUA2 CHILD5

ORD2 MAT3 QUA3 CHILD6

...

Then if you sort that one on all fields, by looping and using AT NEW statement you should be able to easily build your new table in that custom format...

How do you actually build the ORD and MAT and QUA rows ?

Kr,

m.

Read only

0 Likes
1,773

Hi,

As per my last thread, herewith a small example:

First create a macro that will take care of the maintenace of your final table:


DEFINE _update_row.
* &1: Column index | &2: Row index | &3: value
  if &2 > g_cnt.
    insert <gs_final> into table <gt_final> assigning <row>.  "Add new row
  else.
    loop at <gt_final> assigning <row>.                       "Update existing row
      check sy-tabix = &2.
      exit.
    endloop.
  endif.
  assign component &1 of structure <row> to <fs>.
  if sy-subrc = 0.
    <fs> = &3.
  endif.
END-OF-DEFINITION.

Then, loop on your main table (that contains all combinations), and maintain your final table at each break:



  DATA: l_ord TYPE syindex,                     "Order column index
        l_mat TYPE syindex,                     "Material row index
        l_qty TYPE syindex,                     "Quantity row index
        l_com TYPE syindex,                     "Component row index
        l_num_com TYPE i.                       "Components counter

  FIELD-SYMBOLS: <main> TYPE ty_main.

  SORT gt_main BY ord mat qty com.

  LOOP AT gt_main ASSIGNING <main>.
    AT NEW ord.
      DESCRIBE TABLE <gt_final> LINES g_cnt.    "Get number of rows
      l_ord = l_ord + 1.                        "Set Order column index
      l_mat = l_qty = l_com = 1.                "Reset row indexes
      _update_row l_ord 1 <main>-ord.           "Update order row
    ENDAT.

    AT NEW mat.
      l_mat = l_com + 1.                        "New material following components or order
      l_num_com = 0.                            "Reset component counter
      _update_row l_ord l_mat <main>-mat.       "Update material row
    ENDAT.

    AT NEW qty.
      l_qty = l_mat + 1.                        "New quantity following material
      _update_row l_ord l_qty <main>-qty.       "Update quantity row
    ENDAT.

    AT NEW com.
      l_com = l_qty + l_num_com + 1.            "New component following Qty or component
      l_num_com = l_num_com + 1.                "Increase material component counter
      _update_row l_ord l_com <main>-com.       "Update component row
    ENDAT.
  ENDLOOP.

If your main table is like:


O1 M1 Q1 C1
O1 M1 Q1 C2
O1 M1 Q1 C3
O2 M2 Q2 C1
O2 M2 Q2 C2
O3 M3 Q3 C1
O4 M4 Q4 C1
O4 M4 Q4 C2
O4 M4 Q4 C3
O4 M4 Q4 C4

Your final table will be:


O1 O2 O3 O4
M1 M2 M3 M4
Q1 Q2 Q3 Q4
C1 C1 C1 C1
C2 C2    C2
C3       C3
         C4

However, there should be plenty of ways of doing that...not sure this solution is the best one

Cheers,

m.

Read only

Subhankar
Active Contributor
0 Likes
1,773

HI

please check code..

FIELD-SYMBOLS: <Tab> TYPE STANDARD TABLE,

<wa> TYPE any.

MODIFY <Tab> FROM <wa> .