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

Dynamic internal table

Former Member
0 Likes
1,018

Hi All,

here my requirement is to add a column to the dynamic internal table(<itab>) as first column(enchancement).Is it possible to do so?

if so ..kindly helpme out.Points will be rewarded for helpful answers.

Thanks in Advance,

Padmasri.

5 REPLIES 5
Read only

Former Member
0 Likes
728

Hi,

Check these posts

Regards,

Satish

Read only

Former Member
0 Likes
728

You can look at www.saptechnical.com for an article on dynamic internal table and a scenario in ALV.

See the below links for some programs:-

http://searchsap.techtarget.com/tip/1,289483,sid21_gci912390,00.html

http://www.saptechnical.com/articles/ABAP/DynamicInternaltable/DynamicInternalTable.htm

http://www.sap-img.com/ab030.htm

Award points if found helpful...

Cheers,

Chandra Sekhar.

Read only

Former Member
0 Likes
728

Hi,

Check the code below:

DATA: d_ref TYPE REF TO data,

i_alv_cat TYPE TABLE OF lvc_s_fcat,

ls_alv_cat LIKE LINE OF i_alv_cat,

fname TYPE fieldname,

ncomp(9) TYPE n,

rcount(9) TYPE n,

fcount(3) TYPE n.

TYPES: BEGIN OF itab1,

message(50) TYPE c,

END OF itab1.

DATA: g_itab1 TYPE STANDARD TABLE OF itab1.

DATA: wa_itab1 TYPE itab1.

ncomp = 1.

rcount = 0.

TYPES: tabname LIKE dcobjdef-name,

fieldname LIKE dcobjdef-name.

PARAMETER: p_tablen TYPE tabname. "Input table field

DATA: BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE dntab.

DATA: END OF itab.

FIELD-SYMBOLS : <f_fs> TYPE table,

<f_fs2> TYPE ANY,

<f_fs3> TYPE ANY,

<f_fs4> TYPE ANY.

REFRESH itab.

CALL FUNCTION 'NAMETAB_GET' "Fetches the fields

EXPORTING

langu = sy-langu

tabname = p_tablen

TABLES

nametab = itab

EXCEPTIONS

no_texts_found = 1.

ls_alv_cat-fieldname = fieldname. " For the first column

ls_alv_cat-ref_table = reftable.

ls_alv_cat-ref_field = reffield.

ls_alv_cat-seltext = fieldtext.

ls_alv_cat-reptext = fieldtext.

ls_alv_cat-col = 1.

LOOP AT itab .

ls_alv_cat-fieldname = itab-fieldname.

ls_alv_cat-ref_table = p_tablen.

ls_alv_cat-ref_field = itab-fieldname.

ls_alv_cat-seltext = itab-fieldtext.

ls_alv_cat-reptext = itab-fieldtext.

APPEND ls_alv_cat TO i_alv_cat.

ENDLOOP.

  • internal table build

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_alv_cat

IMPORTING

ep_table = d_ref.

ASSIGN d_ref->* TO <f_fs>. " Dynamic table creation with fields of the

*table

DATA: l_field TYPE fieldname,

l_field1 TYPE fieldname.

SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <f_fs>.

"Fetching of the data from the table

rcount = 0.

LOOP AT <f_fs> ASSIGNING <f_fs2>.

"Here u can check the validations and process

ASSIGN COMPONENT ncomp OF STRUCTURE <f_fs2> TO <f_fs4>.

IF NOT <f_fs4> IS INITIAL.

MOVE <f_fs4> TO l_field1.

ncomp = ncomp + 1.

ELSE.

CONCATENATE 'IN ROW' rcount 'COLUMN' ncomp 'IS BLANK' INTO wa_itab1.

APPEND wa_itab1 TO g_itab1.

ENDIF.

ENDDO.

ENDLOOP.

LOOP AT g_itab1 INTO wa_itab1.

WRITE:/ wa_itab1 'is blank'.

ENDLOOP.

Regards

Kannaiah

Read only

Former Member
0 Likes
728

Hi

Hi

Try like this

* The dynamic internal table stucture
DATA: BEGIN OF STRUCT OCCURS 10,
FILDNAME(8) TYPE C,
ABPTYPE TYPE C,
LENGTH TYPE I,
END OF STRUCT.

* The dynamic program source table
DATA: BEGIN OF INCTABL OCCURS 10,
LINE(72),
END OF INCTABL.

DATA: LNG TYPE I, TYPESRTING(6).

* Sample dynamic internal table stucture
STRUCT-FILDNAME = 'field1'. STRUCT-ABPTYPE = 'c'. STRUCT-LENGTH = '6'.
APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field2'. STRUCT-ABPTYPE = 'd'.
APPEND STRUCT. CLEAR STRUCT.

STRUCT-FILDNAME = 'field3'. STRUCT-ABPTYPE = 'i'.
APPEND STRUCT. CLEAR STRUCT.

* Create the dynamic internal table definition in the dyn. program
INCTABL-LINE = 'program zdynpro.'. APPEND INCTABL.
INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.

LOOP AT STRUCT.
INCTABL-LINE = STRUCT-FILDNAME.
LNG = STRLEN( STRUCT-FILDNAME ).

IF NOT STRUCT-LENGTH IS INITIAL .
TYPESRTING(1) = '('.
TYPESRTING+1 = STRUCT-LENGTH.
TYPESRTING+5 = ')'.
CONDENSE TYPESRTING NO-GAPS.
INCTABL-LINE+LNG = TYPESRTING.
ENDIF.

INCTABL-LINE+15 = 'type '.
INCTABL-LINE+21 = STRUCT-ABPTYPE.
INCTABL-LINE+22 = ','.
APPEND INCTABL.
ENDLOOP.
INCTABL-LINE = 'end of dyntab. '.
APPEND INCTABL.

* Create the code processes the dynamic internal table
INCTABL-LINE = ' '. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = ''aaaaaa''.'. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = ''19970814''.'. APPEND INCTABL.
INCTABL-LINE = 'dyntab-field1 = 1.'. APPEND INCTABL.
INCTABL-LINE = 'append dyntab.'. APPEND INCTABL.
INCTABL-LINE = ' '. APPEND INCTABL.
INCTABL-LINE = 'loop at dyntab.'. APPEND INCTABL.
INCTABL-LINE = 'write: / dyntab.'. APPEND INCTABL.
INCTABL-LINE = 'endloop.'. APPEND INCTABL.

* Create and run the dynamic program
INSERT REPORT 'zdynpro'(001) FROM INCTABL.
SUBMIT ZDYNPRO.

or Just try out this simpler dynamic internal tables

DATA: itab TYPE STANDARD TABLE OF spfli,
wa LIKE LINE OF itab.

DATA: line(72) TYPE c,
list LIKE TABLE OF line(72).

START-OF-SELECTION.
*line = ' CITYFROM CITYTO '.
line = ' AIRPTO '.
APPEND line TO list.

SELECT DISTINCT (list)
INTO CORRESPONDING FIELDS OF TABLE itab
FROM spfli.

IF sy-subrc EQ 0.
LOOP AT itab INTO wa.
* WRITE: / wa-cityfrom, wa-cityto.
WRITE :/ wa-airpto.
ENDLOOP.
ENDIF.

Check this links

Regards

Pavan

Read only

Former Member
0 Likes
728

Hi,

pls go through this program.

report z_dynamic.

type-pools : abap.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

data: dy_table type ref to data,

dy_line type ref to data,

xfc type lvc_s_fcat,

ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.

parameters: p_table(30) type c default 'T001'.

selection-screen end of block b1.

start-of-selection.

perform get_structure.

perform create_dynamic_itab.

perform get_data.

perform write_out.

form create_dynamic_itab.

Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = ifc

importing

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

endform.

Regards,

Gowri sankar

if it is usful reward points