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: 

Dynamic internal table

Former Member
0 Kudos

HI,

Can anybody please tell me the functional requirment, where the dynamic internal table is being used.

Regards

Prasanth

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Check this blog..

[https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2071] [original link is broken] [original link is broken] [original link is broken];

Regards,

Priya.

7 REPLIES 7

Former Member
0 Kudos

Please give me reward points..

p291102
Active Contributor
0 Kudos

Hi,

go through that following sample report.

REPORT YMS_DYNAMICALV.

TYPE-POOLS: SLIS.

FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,

<DYN_WA>.

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_FLDS(5) TYPE C.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

  • build the dynamic internal table

PERFORM BUILD_DYN_ITAB.

  • write 5 records to the alv grid

DO 5 TIMES.

PERFORM BUILD_REPORT.

ENDDO.

  • call the alv grid.

PERFORM CALL_ALV.

************************************************************************

  • Build_dyn_itab

************************************************************************

FORM BUILD_DYN_ITAB.

DATA: NEW_TABLE TYPE REF TO DATA,

NEW_LINE TYPE REF TO DATA,

WA_IT_FLDCAT TYPE LVC_S_FCAT.

  • Create fields .

DO P_FLDS TIMES.

CLEAR WA_IT_FLDCAT.

WA_IT_FLDCAT-FIELDNAME = SY-INDEX.

WA_IT_FLDCAT-DATATYPE = 'CHAR'.

WA_IT_FLDCAT-INTLEN = 5.

APPEND WA_IT_FLDCAT TO IT_FLDCAT .

ENDDO.

  • 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. "build_dyn_itab

*********************************************************************

  • Form build_report

*********************************************************************

FORM BUILD_REPORT.

DATA: FIELDNAME(20) TYPE C.

DATA: FIELDVALUE(5) TYPE C.

DATA: INDEX(3) TYPE C.

FIELD-SYMBOLS: <FS1>.

DO P_FLDS TIMES.

INDEX = SY-INDEX.

  • Set up fieldvalue

CONCATENATE 'FLD' INDEX INTO

FIELDVALUE.

CONDENSE FIELDVALUE NO-GAPS.

  • <b> assign component index of structure <dyn_wa> to <fs1>.

  • <fs1> = fieldvalue.</b>

ENDDO.

  • Append to the dynamic internal table

APPEND <DYN_WA> TO <DYN_TABLE>.

ENDFORM. "build_report

************************************************************************

  • CALL_ALV

************************************************************************

FORM CALL_ALV.

DATA: WA_CAT LIKE LINE OF ALV_FLDCAT.

DO P_FLDS TIMES.

CLEAR WA_CAT.

WA_CAT-FIELDNAME = SY-INDEX.

WA_CAT-SELTEXT_S = SY-INDEX.

WA_CAT-OUTPUTLEN = '5'.

APPEND WA_CAT TO ALV_FLDCAT.

ENDDO.

  • Call ABAP List Viewer (ALV)

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IT_FIELDCAT = ALV_FLDCAT

TABLES

T_OUTTAB = <DYN_TABLE>.

ENDFORM. "call_alv

Thanks,

Sankar M

Former Member
0 Kudos

Hi,

Check this blog..

[https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2071] [original link is broken] [original link is broken] [original link is broken];

Regards,

Priya.

0 Kudos

Hi Priya,

Thanks for your reply. i know how to create dynamic internal table stuff. I just want a scenario where i can implement this. Hope you understood my requirment. Expecting reply.

Regards

Prassanth

0 Kudos

Hi,

Check this scenario!

I need to enter a database table name in Selection Screen and it has to create an internal table based on

the given table name structure in Selection screen.

Then, i need to populate the data from a Database table to this internal table.

In this scenario, we need dynamic internal table.I guess u know how to create and use it!

Reward if helpful!

Regards,

Ramya

0 Kudos

Hi Ramya,

Thanks for your useful information. can you be more precise.

Regards

Prasanth

0 Kudos

Hi ,

Consider this scenario in seed industry where in the enduser wants to know the qty of the crop for a particular season and year eg : Wheat 2007 , Rice2006 ... the database might have lot of records depending on the date u enter on selection screen in that case to dynamically determine the no of columns of (season+year) we can use dynamic internal table and pass that to o/p.

Regards ,

Priya Kota.