cancel
Showing results for 
Search instead for 
Did you mean: 

logic required

Former Member
0 Kudos

Hi all,

My requirement is to create a dynamic internal table based on a internal table and period value.

For ex:

I have an internal table with following data.


MATNR       MENGE        GLTRP        AUART   
13319705    20000       26.0.2005     production order
13319705    25000       01.12.2005    planned order
13319705    25000       01.02.2006    planned order
13319705    20000       10.02.2006    planned order

I got the above data based on selection of date 09.02.2006

and period value '3'.

And this period value is dynamic it changes according to selection but maximum upto 12.

now i have to split the above internal table into 3 time slots like 09.02.2006, 10.02.2006, and 11.02.2006(bcoz the period value is 3 and selection date is 09.02.2006) if it is 2 then 09.02.2006, 10.02.2006 like that changes according to user selection.

now i should get new internal table like this :

date(as field name)09.02.2006 10.02.2006 11.02.2006

menge 0 20000 0-->this should be result

and i have to get remaining all fields also from the above internal table except the date and menge fields.

I hope it is clear.

Any help will be appreciated.

Thanks and Regards

Chandu

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi sai,

Check out this blog for creation of dynamic internal tables:

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

Regards,

sudheer.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Sai,

First try calculating the time slots based on the date and period given by the user. I think u can maintain the dates and MENGE corresponding to that date in one more inernal table by populating the data from your first internal table. Then u can use forall entries key word

to get the remaining fields from your first internal table.

Regards,

Sudheer.

FredericGirod
Active Contributor
0 Kudos

Hi,

first create a table make the link between the column name and the date.

Date_1 -> 09.02.2006

Date_2 -> 10.02.2006

Create a field catalog with the column name, and in the description the real date.

and make a loop on the first table, use the assigning component of to set the value.

Easy, isn't it ?

Frédéric

Former Member
0 Kudos

Hi,

And the colums are not fixed like date 1 or date 2.

it depends on user selection for period value if it is 1 then column1 if it is 10 then i should get 10 columns like that max 12.

Please give me some sample code.

Message was edited by: Sai Chand Pullepu

FredericGirod
Active Contributor
0 Kudos

Ok,

If you have a dynamic table, you have a fieldcatalog, I hope you have a field type date (like sydatum data element).

Imagine the field name is datum.

it_key is an internal table with two column : field contain date_1, date_2 ... and value contain the date.



read table it_fieldcatalog
     into is_fieldcatalog
     where fieldname eq 'DATUM'.

loop at it_key_date.
  move : it_key_date-field to is_fieldcatalog-fieldname ,
         it_key_date-value to is_fieldcatalog-srctext_s , 
         ...
  append is_fieldcatalog to it_fieldcatalog.
endloop.

after you can loop to your data table and make an assign component of (the fieldname is in the is_fieldcatalog-fieldname).

I hope it's more clear now.

Rgd

Frédéric

Former Member
0 Kudos

Hi Frederic,

Thanks for ur help.

It helped me alot.

MY code is like this:


 data:
    lv_counter(2)   type n,
    lv_datum        type text10.

  loop at gt_datelist into lv_datum.
    locl_felder-col_pos      = '14' + sy-tabix.
    write sy-tabix to locl_felder-fieldname.
    condense locl_felder-fieldname no-gaps.
    concatenate 'MENGE' locl_felder-fieldname
           into locl_felder-fieldname.
    locl_felder-reptext_ddic = lv_datum.
    locl_felder-seltext_l    = lv_datum.
    locl_felder-datatype     =  'INT4'.
    locl_felder-round        = 0.
    locl_felder-decimals_out = '0'.
    locl_felder-no_zero      = 'X'.
*  locl_felder-ref_tabname = ''.
*   locl_felder-no_out    = ''.
    locl_felder-outputlen     = 0.
*  locl_felder-do_sum        = ' '.
    append locl_felder to feldkatalog.

    add 1 to lv_counter.
    if lv_counter > p_perio.
      exit.
    endif.
  endloop.

Its working fine.

I followed ur logic only with slight difference.

But iam struck in getting values into internal table.


FORM time_division.

  help = 1.

  LOOP AT datum.--> similar to gt_datelist

    CONCATENATE 'itab-datum' help INTO feld_datum.
    CONCATENATE 'itab-menge' help INTO feld_menge.
    ASSIGN:
        (feld_datum) TO <field1>,
        (feld_menge) TO <field2>.


    READ TABLE b_tab WITH KEY gltrp = datum-low BINARY SEARCH.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING b_tab TO itab.
      <field1> = datum-low.
      <field2> = b_tab-menge.
*      MOVE datum-low TO itab-datum1.
*      MOVE b_tab-menge TO itab-menge1.
      collect itab.
      clear itab.
      endif.
    help = help + 1.
  ENDLOOP.
  clear itab.

Before this code I have already values in itab.

So what i want here is in itab iwant to modify existing records with the new values datum1 and menge1 so on....

But its appending.

I used modify also its not working(bcoz iam getting values from b_tab).

So anybody please suggest me a work around.

Thanks once again.

Chandu