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

cl_alv_table_create=>create_dynamic_table

dieterzenger
Participant
0 Likes
3,450

Hello all,

I'm using method

cl_alv_table_create=>create_dynamic_table

to create an internal table (depending on the entered operation concern). Im' assigning the table to a field symbol. The data can be selected into this table reference (works fine). Unfortunately I'm not able to read the value fields (Type P) anymore. I guess they are packed. I tried to use the unpack command, but it doesn't work.

Can someone help me

Thank you

Dieter

Dieter

9 REPLIES 9
Read only

FredericGirod
Active Contributor
0 Likes
1,814

Hello Dieter,

First you create a dyn table :

call method .. 
assign it_dyn_table->* to <it_dyn_table>

Second you assign a structure :

create data is_tmp like line of <it_dyn_table>.
assign is_tmp->* to <is_dyn_table>.

Now, you have : a structure, an internal table and a fieldcatalog.

So you could play :

loop at <it_dyn_table> into <is_dyn_table>.
  loop at it_fieldcat into is_fieldcat.
    assign component is_fieldcat-fielname 
           of structure <is_dyn_table>
           to <field>.
* Now <field> contain the good value. (field is type any)
  endloop.
endloop.

I hope that will help for your problem.

Regards

Frédéric

Read only

0 Likes
1,814

Hello Frederic,

I tried your coding, the loop and the assignment works fine. But I'm still not able to process the Packed value

The compoent 'ABSMG' of my structur contains the value

' 5720=000000000000000<000'

Assigning this component to a fied symbol of type any it contains: ' 5720=000000000000000<000'. When i try to use the unpack command on this field i receive the value

'33333333333333333333333333303'.

Any idea ?

Thank you

Dieter

Read only

0 Likes
1,814

try this.

  
field-symbols: <outtab> type any table,
  <l_line>  type any,
  <l_field> type any.
data: new_table type ref to data.
data: new_line  type ref to data.

call method cl_alv_table_create=>create_dynamic_table
        exporting
          it_fieldcatalog = it_fieldcat
        importing
          ep_table        = new_table.
      assign new_table->* to <outtab>.
      create data new_line like line of <outtab>.
      assign new_line->* to <l_line> .

 loop at <outtab> assigning <l_line>.
        write:/ <l_line> .
      endloop .

if you go into debugging and see, even if <outtab> has a type p field ,the <l_line> which is like line of <outtab>, all the type p fields are converted to type c fields . looks like this is how SAP handles it internally.

Regards

Raja

Read only

0 Likes
1,814

Hi Dieter,

your problem looks strange, when you debug this program, the internal table contain good values ?

Maybe your problem is the type of the data that contain ABSMG. How did you set the type in the fieldcatalog ?

Read only

0 Likes
1,814

Hi Dieter,

you've to convert all p-fields to c-fields .

dynamically you can try that :

data charfield type string.
describe field <fs> type t.

if t = 'P'.
 write <fs> to charfield.
...

regards Andreas

Read only

0 Likes
1,814

Hi Frederic,

The fieldcatalog is set up by using FM 'REUSE_ALV_FIELDCATALOG_MERGE'. Here I pass the CE1XXXX(operating concern) table. Result: I receive a fieldcatalog of type SLIS_T_FIELDCAT_ALV.

Now I convert the fieldcatalog to another table of type

LVC_T_FCAT, by using a statement like

"move-corresponding gs_fcat to gs_fieldcat."
"append gs_fieldcat to gt_fieldcat"

.

After this I create the table by using method

cl_alv_table_create=>create_dynamic_table.

Now I assign the table to a field-symbol of type ref to data.( assign gt_ce1->* to <fs_1table>)

The select statement looks as follows

select * from (gv_tabnam)

into table <fs_1table>.

Checking <fs_1table> in the debugger, it contains the records, but all value fields (type p) are packed.

I tried to change the data type to type c, before building the fieldcatalogue,-> dump in FM

I also tried to use write to character field ... but it doesn't work.

Read only

0 Likes
1,814

After you field catalog is built, loop thru it and overwrite the "TYPE P" fields with type "C" also increase the field length a little.

Or if you problem is that you are accessing the entire record containing a type P, you can access just the fields one by one. This will allow your TYPE P field to look as it should. Check out the sample program below. Pay close attention to the loop after the form BUILD_REPORT.



report zrich_0003
       no standard page heading.

type-pools: slis.

field-symbols: <dyn_table> type standard table,
               <dyn_wa>,
               <dyn_field>.

data: alv_fldcat type slis_t_fieldcat_alv,
      it_fldcat type lvc_t_fcat.


selection-screen begin of block b1 with frame title text-001.
parameters: p_check type c.
selection-screen end of block b1.

start-of-selection.

  perform build_dyn_itab.
  perform build_report.

* Write out your dynamic internal table - one field at a time.
<b>  loop at <dyn_table> into <dyn_wa>.
    do.
      assign component  sy-index  of structure <dyn_wa> to <dyn_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      write:/ <dyn_field>.
    enddo.
  endloop.</b>


************************************************************************
*  Build_dyn_itab
************************************************************************
form build_dyn_itab.

  data: index(3) type c.

  data: new_table type ref to data,
        new_line  type ref to data,
        wa_it_fldcat type lvc_s_fcat.

* Create fields
  clear index.
  do 5 times.
    index = sy-index.
    clear wa_it_fldcat.
    concatenate 'Field' index into
             wa_it_fldcat-fieldname .
    condense  wa_it_fldcat-fieldname no-gaps.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 5.
    append wa_it_fldcat to it_fldcat .
  enddo.

* Add a field that is TYPE P
  clear wa_it_fldcat.
  wa_it_fldcat-fieldname = 'FIELDP' .
  wa_it_fldcat-datatype = 'CURR'.
  wa_it_fldcat-intlen = 10.
  append wa_it_fldcat to it_fldcat .

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
               exporting
                  it_fieldcatalog = it_fldcat
               importing
                  ep_table        = new_table.

  assign new_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data new_line like line of <dyn_table>.
  assign new_line->* to <dyn_wa>.

endform.

*********************************************************************
*      Form  build_report
*********************************************************************
form build_report.

  data: fieldname(20) type c.
  data: fieldvalue(5) type c.
  data: index(3) type c.
  field-symbols: <fs1>.

* Create a record to add to table
  do 5 times.
    index = sy-index.
* Set up fieldname
    concatenate 'FIELD' index into
             fieldname .
    condense   fieldname  no-gaps.
* Set up fieldvalue
    concatenate 'FLD' index into
             fieldvalue.
    condense   fieldvalue no-gaps.
    assign component  fieldname  of structure <dyn_wa> to <fs1>.
    <fs1> =  fieldvalue.
  enddo.
  assign component  'FIELDP'  of structure <dyn_wa> to <fs1>.
  <fs1> =  '1234.75'.

* Append to the dynamic internal table
  append <dyn_wa> to <dyn_table>.

endform.

Regards.

Rich Heilman

Message was edited by: Rich Heilman

Read only

NikiScaglione
Product and Topic Expert
Product and Topic Expert
0 Likes
1,814

Hi,

I'm using your source code for creating and managing a dynamic table, but i have a problem:

I made differents fields with different length, but when my <dyn_table> is built, it has always fields type C and length 10 fixed.

Can i change this?

Thanks

Read only

Former Member
0 Likes
1,814

Hi Dieter,

This has a code snippet:

http://sap.ittoolbox.com/code/d.asp?a=s&d=3038

Regards,

Anjali