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 tables

Former Member
0 Kudos
311

Hello guys!

I have a special requirement. I have to create dynamic internal tables based on another internla table.

Its like 'AT NEW externalid ' i ahve to create a table. preferably it_<externlaid> .

All the tables which will be created are of same type and have same number of fields.

I also want to have another internal table which stores the names of these tables which are created.

Can any one explain me how to do this?

Even if done, problem would be how can i loop at the dyanmic internal table <it_externalid> when this table name is created at run time and is stored in another internal table?

All suggestions would be rewarded.

Regards

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos
104

Hello Trivenn

If the dynamic itabs have the same line type then there is no need to create dynamic itabs. You could simplify your problem as following:


TYPES: BEGIN OF ty_s_itab.
TYPES: externalid     TYPE <datatype of external id>.
TYPES: data             TYPE STANDARD TABLE OF <line type>
                                WITH DEFAULT KEY.
TYPES: END OF ty_s_itab.
TYPES: ty_t_itab       TYPE STANDARD TABLE OF ty_s_itab
                                 WITH DEFAULT KEY.

DATA: 
  ls_record                 TYPE <line type>,
  lt_itab                     TYPE ty_t_itab,
  ls_itab                     TYPE ty_s_itab.

LOOP AT ...
  CLEAR: ls_itab.

  AT NEW externalid.
    ls_itab-externalid = <external id>.

    " Fill data
     LOOP AT ... INTO ls_record.
       APPEND ls_record TO ls_itab-data.
     ENDLOOP.
     
     APPEND ls_itab TO lt_itab.
  ENDAT.

ENDLOOP.

This way you get a complex itab where each record is identified by its external ID and it contains an itab for the data.

Regards

Uwe

8 REPLIES 8

former_member262988
Active Contributor
0 Kudos
104

hi,

Download the original attachment

*&----


*& Report Z_RPT_MM_CLSTK *

&----


REPORT Z_RPT_MM_CLSTK NO STANDARD PAGE HEADING

LINE-SIZE 350

LINE-COUNT 53.

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

*

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

&----


  • T A B L E S *

&----


TABLES: MARA, MARD, T001W,MARDH.

&----


  • T Y P E P O O L S *

&----


TYPE-POOLS : SLIS.

&----


  • S T R U C T U R E D E C L A R A T I O N S *

&----


TYPES: BEGIN OF T_MARA,

MATNR TYPE MATNR,

SPART TYPE SPART,

MEINS TYPE MEINS,

END OF T_MARA.

TYPES: BEGIN OF T_MARDH,

MATNR TYPE MATNR,

WERKS TYPE WERKS_D,

LFGJA TYPE LFGJA,

LFMON TYPE LFMON,

LABST TYPE LABST,

END OF T_MARDH.

TYPES: BEGIN OF T_MAKT,

MATNR TYPE MATNR,

MAKTX TYPE MAKTX,

END OF T_MAKT.

TYPES: BEGIN OF T_T001W,

WERKS TYPE WERKS_D,

NAME1 TYPE NAME1,

END OF T_T001W.

TYPES: BEGIN OF T_FINAL,

MATNR TYPE MATNR,

WERKS TYPE WERKS_D,

NAME1 TYPE NAME1,

MAKTX TYPE MAKTX,

LABST TYPE LABST,

MEINS TYPE MEINS,

END OF T_FINAL.

TYPES: BEGIN OF T_MATNR,

MATNR TYPE MATNR,

MAKTX TYPE MAKTX,

END OF T_MATNR.

&----


  • I N T E R N A L T A B L E D E C L A R A T I O N S *

&----


DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA,

IT_MARD TYPE STANDARD TABLE OF T_MARDH,

IT_MAKT TYPE STANDARD TABLE OF T_MAKT,

IT_T001W TYPE STANDARD TABLE OF T_T001W,

IT_FINAL TYPE STANDARD TABLE OF T_FINAL,

IT_MATNR TYPE STANDARD TABLE OF T_MATNR.

DATA: ALV_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,

IT_FLDCAT TYPE LVC_T_FCAT.

DATA: NEW_TABLE TYPE REF TO DATA,

NEW_LINE TYPE REF TO DATA,

WA_IT_FLDCAT TYPE LVC_S_FCAT,

I_EVENT TYPE SLIS_T_EVENT,

FS_EVENT LIKE LINE OF I_EVENT.

&----


  • F I E L D S Y M B O L S *

&----


FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,

<DYN_HEAD> TYPE STANDARD TABLE,

<DYN_WA>,

<DYN_FIELD>,

<FS>.

&----


  • W O R K A R E A D E C L A R A T I O N S *

&----


DATA: WA_MARA TYPE T_MARA,

WA_MARD TYPE T_MARDH,

WA_MAKT TYPE T_MAKT,

WA_T001W TYPE T_T001W,

WA_FINAL TYPE T_FINAL,

WA_MATNR TYPE T_MATNR.

&----


  • V A R I A B L E S D E C L A R A T I O N S *

&----


DATA: V_TEXT(255),

V_LABST(15),V_INT(4),

LABST TYPE LABST,

L_TITLE TYPE LVC_TITLE,

V_MATNR(255),

V_WERKS(255),

V_MTART(255),

V_SPART(255),

V_MATKL(255),

V_LFGJA(255),

V_LFMON(255),

V_LGORT(255).

&----


  • S E L E C T I O N S C R E E N *

&----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECTION-SCREEN: SKIP 2.

SELECT-OPTIONS: S_MATNR FOR MARA-MATNR,

S_WERKS FOR T001W-WERKS OBLIGATORY,

S_MTART FOR MARA-MTART,

S_SPART FOR MARA-SPART ,

S_MATKL FOR MARA-MATKL,

S_LGORT FOR MARD-LGORT,

S_LFGJA FOR MARDH-LFGJA OBLIGATORY,

S_LFMON FOR MARDH-LFMON.

SELECTION-SCREEN: SKIP 1.

SELECTION-SCREEN END OF BLOCK B1.

&----


  • A T S E L E C T I O N S C R E E N *

&----


AT SELECTION-SCREEN ON S_MATNR.

PERFORM VALIDATE_MATNR.

AT SELECTION-SCREEN ON S_WERKS.

PERFORM VALIDATE_WERKS.

AT SELECTION-SCREEN ON S_MTART.

PERFORM VALIDATE_MTART.

AT SELECTION-SCREEN ON S_SPART.

PERFORM VALIDATE_SPART.

AT SELECTION-SCREEN ON S_MATKL.

PERFORM VALIDATE_MATKL.

AT SELECTION-SCREEN ON S_LGORT.

PERFORM VALIDATE_LGORT.

AT SELECTION-SCREEN ON S_LFGJA.

PERFORM VALIDATE_LFGJA.

AT SELECTION-SCREEN ON S_LFMON.

PERFORM VALIDATE_LFMON.

&----


  • T O P O F P A G E *

&----


TOP-OF-PAGE.

&----


  • I N I T I A L I Z A T I O N *

&----


INITIALIZATION.

PERFORM TOP.

&----


  • S T A R T O F S E L E C T I O N *

&----


START-OF-SELECTION.

PERFORM GET_DATA.

PERFORM PROCESS_DATA.

PERFORM BUILD_DYN_ITAB.

PERFORM BUILD_REPORT.

PERFORM CALL_ALV.

&----


  • E N D O F S E L E C T I O N *

&----


END-OF-SELECTION.

&----


*& Form GET_DATA

&----


FORM GET_DATA .

SELECT MATNR

SPART

MEINS

FROM MARA

INTO TABLE IT_MARA

WHERE MATNR IN S_MATNR

AND MTART IN S_MTART

AND SPART IN S_SPART

AND MATKL IN S_MATKL.

IF NOT IT_MARA[] IS INITIAL.

IF S_LFMON[] IS INITIAL.

SELECT MATNR

WERKS

LFGJA

LFMON

LABST

FROM MARD

INTO TABLE IT_MARD

FOR ALL ENTRIES IN IT_MARA

WHERE MATNR EQ IT_MARA-MATNR

AND WERKS IN S_WERKS

AND LGORT IN S_LGORT

AND LFGJA IN S_LFGJA

AND LFMON IN S_LFMON.

ELSE.

SELECT MATNR

WERKS

LFGJA

LFMON

LABST

FROM MARDH

INTO TABLE IT_MARD

FOR ALL ENTRIES IN IT_MARA

WHERE MATNR EQ IT_MARA-MATNR

AND WERKS IN S_WERKS

AND LGORT IN S_LGORT

AND LFGJA IN S_LFGJA

AND LFMON IN S_LFMON.

ENDIF.

IF SY-SUBRC = 0.

SELECT MATNR

MAKTX

FROM MAKT

INTO TABLE IT_MAKT

FOR ALL ENTRIES IN IT_MARD

WHERE MATNR EQ IT_MARD-MATNR.

SELECT WERKS

NAME1

FROM T001W

INTO TABLE IT_T001W

FOR ALL ENTRIES IN IT_MARD

WHERE WERKS EQ IT_MARD-WERKS.

ENDIF.

ENDIF.

ENDFORM. " GET_DATA

&----


*& Form PROCESS_DATA

&----


FORM PROCESS_DATA .

IF S_WERKS-LOW+0(1) = 2.

LOOP AT IT_MARD INTO WA_MARD WHERE WERKS+0(1) = 3.

WA_MARD-WERKS+0(1) = 2.

MODIFY IT_MARD FROM WA_MARD.

ENDLOOP.

LOOP AT IT_T001W INTO WA_T001W WHERE WERKS+0(1) = 3.

WA_T001W-WERKS+0(1) = 2.

MODIFY IT_T001W FROM WA_T001W.

ENDLOOP.

SORT IT_T001W BY WERKS.

DELETE ADJACENT DUPLICATES FROM IT_T001W COMPARING WERKS.

ENDIF.

SORT IT_MARD BY MATNR WERKS LFGJA LFMON.

LOOP AT IT_MARD INTO WA_MARD.

READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_MARD-MATNR.

IF SY-SUBRC = 0.

WA_MATNR-MATNR = WA_MAKT-MATNR.

WA_MATNR-MAKTX = WA_MAKT-MAKTX.

WA_FINAL-MATNR = WA_MAKT-MATNR.

WA_FINAL-MAKTX = WA_MAKT-MAKTX.

READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = WA_MARD-MATNR.

IF SY-SUBRC = 0.

WA_FINAL-MEINS = WA_MARA-MEINS.

ENDIF.

READ TABLE IT_T001W INTO WA_T001W WITH KEY WERKS = WA_MARD-WERKS.

IF SY-SUBRC = 0.

WA_FINAL-WERKS = WA_T001W-WERKS.

WA_FINAL-NAME1 = WA_T001W-NAME1.

WA_FINAL-LABST = WA_FINAL-LABST + WA_MARD-LABST.

ENDIF.

ENDIF.

COLLECT WA_FINAL INTO IT_FINAL.

COLLECT WA_MATNR INTO IT_MATNR.

CLEAR: WA_MARD, WA_MAKT, WA_T001W,WA_FINAL, WA_MATNR, WA_MARA.

ENDLOOP.

ENDFORM. " PROCESS_DATA

&----


*& Form BUILD_DYN_ITAB

&----


FORM BUILD_DYN_ITAB .

CLEAR WA_IT_FLDCAT.

WA_IT_FLDCAT-FIELDNAME = 'MATNR'.

WA_IT_FLDCAT-DATATYPE = 'CHAR'.

WA_IT_FLDCAT-INTLEN = 18.

APPEND WA_IT_FLDCAT TO IT_FLDCAT .

CLEAR WA_IT_FLDCAT.

WA_IT_FLDCAT-FIELDNAME = 'MAKTX'.

WA_IT_FLDCAT-DATATYPE = 'CHAR'.

WA_IT_FLDCAT-INTLEN = 35.

APPEND WA_IT_FLDCAT TO IT_FLDCAT .

CLEAR WA_IT_FLDCAT.

WA_IT_FLDCAT-FIELDNAME = 'MEINS'.

WA_IT_FLDCAT-DATATYPE = 'CHAR'.

WA_IT_FLDCAT-INTLEN = 3.

APPEND WA_IT_FLDCAT TO IT_FLDCAT .

LOOP AT IT_T001W INTO WA_T001W.

V_INT = V_INT + 1.

CONDENSE V_INT NO-GAPS.

CONCATENATE 'LABST' V_INT INTO V_LABST.

CLEAR WA_IT_FLDCAT.

WA_IT_FLDCAT-FIELDNAME = V_LABST.

WA_IT_FLDCAT-DATATYPE = 'QUAN'.

WA_IT_FLDCAT-INTLEN = 15.

APPEND WA_IT_FLDCAT TO IT_FLDCAT.

ENDLOOP.

*-- 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>.

ASSIGN NEW_TABLE->* TO <DYN_HEAD>.

*-- Create dynamic work area and assign to FS

CREATE DATA NEW_LINE LIKE LINE OF <DYN_TABLE>.

CREATE DATA NEW_LINE LIKE LINE OF <DYN_HEAD>.

ASSIGN NEW_LINE->* TO <DYN_WA>.

ENDFORM. " BUILD_DYN_ITAB

&----


*& Form BUILD_REPORT

&----


FORM BUILD_REPORT .

SORT IT_FINAL BY WERKS MATNR.

SORT IT_MATNR BY MATNR.

LOOP AT IT_MATNR INTO WA_MATNR.

ASSIGN COMPONENT 'MATNR' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.

IF SY-SUBRC EQ 0.

<DYN_FIELD> = WA_MATNR-MATNR.

ENDIF.

ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.

IF SY-SUBRC EQ 0.

<DYN_FIELD> = WA_MATNR-MAKTX.

ENDIF.

READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = WA_MATNR-MATNR.

IF SY-SUBRC = 0.

ASSIGN COMPONENT 'MEINS' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.

IF SY-SUBRC EQ 0.

<DYN_FIELD> = WA_MARA-MEINS.

ENDIF.

ENDIF.

CLEAR V_INT.

LOOP AT IT_T001W INTO WA_T001W.

V_INT = V_INT + 1.

CONDENSE V_INT NO-GAPS.

CONCATENATE 'LABST' V_INT INTO V_LABST.

READ TABLE IT_FINAL INTO WA_FINAL WITH KEY MATNR = WA_MATNR-MATNR

WERKS = WA_T001W-WERKS.

IF SY-SUBRC EQ 0.

LABST = WA_FINAL-LABST.

ASSIGN COMPONENT V_LABST OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.

MOVE WA_FINAL-LABST TO <DYN_FIELD>.

ENDIF.

  • CLEAR: WA_FINAL, WA_MATNR, WA_T001W.

ENDLOOP.

*-- Append to the dynamic internal table

APPEND <DYN_WA> TO <DYN_TABLE>.

APPEND <DYN_WA> TO <DYN_HEAD>.

CLEAR <DYN_WA>.

ENDLOOP.

ENDFORM. " BUILD_REPORT

&----


*& Form CALL_ALV

&----


FORM CALL_ALV .

DATA: WA_CAT LIKE LINE OF ALV_FLDCAT.

DATA: GS_KEYINFO TYPE SLIS_KEYINFO_ALV.

CLEAR WA_IT_FLDCAT.

WA_CAT-FIELDNAME = 'MATNR'.

WA_CAT-DATATYPE = 'CHAR'.

WA_CAT-INTLEN = 18.

WA_CAT-SELTEXT_M = 'Material No'.

APPEND WA_CAT TO ALV_FLDCAT.

CLEAR WA_IT_FLDCAT.

WA_CAT-FIELDNAME = 'MAKTX'.

WA_CAT-DATATYPE = 'CHAR'.

WA_CAT-INTLEN = 35.

WA_CAT-SELTEXT_M = 'Material Description'.

APPEND WA_CAT TO ALV_FLDCAT .

CLEAR WA_IT_FLDCAT.

WA_CAT-FIELDNAME = 'MEINS'.

WA_CAT-DATATYPE = 'CHAR'.

WA_CAT-INTLEN = 3.

WA_CAT-SELTEXT_M = 'UOM'.

APPEND WA_CAT TO ALV_FLDCAT .

CLEAR V_INT.

LOOP AT IT_T001W INTO WA_T001W.

V_INT = V_INT + 1.

CONDENSE V_INT NO-GAPS.

CONCATENATE 'LABST' V_INT INTO V_LABST.

CLEAR WA_IT_FLDCAT.

WA_CAT-FIELDNAME = V_LABST.

WA_CAT-DATATYPE = 'QUAN'.

WA_CAT-INTLEN = 15.

WA_CAT-SELTEXT_M = WA_T001W-NAME1.

APPEND WA_CAT TO ALV_FLDCAT.

ENDLOOP.

GS_KEYINFO-HEADER01 = 'MATNR'..

GS_KEYINFO-ITEM01 = 'MATNR'.

DELETE ADJACENT DUPLICATES FROM <DYN_TABLE> COMPARING ALL FIELDS.

IF SY-MANDT = '045'.

L_TITLE = 'PARENTERAL DRUGS (INDIA) LTD'.

ELSEIF SY-MANDT = '040'.

L_TITLE = 'PUNJAB FORMULATIONS PVT LTD'.

ELSEIF SY-MANDT = '020'.

L_TITLE = 'GOA FORMULATIONS PVT LTD'.

ENDIF.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = ALV_FLDCAT

I_GRID_TITLE = L_TITLE

IT_EVENTS = I_EVENT

  • I_BACKGROUND_ID = 'ZEASY'

TABLES

T_OUTTAB = <DYN_TABLE>.

*CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

  • EXPORTING

  • I_CALLBACK_PROGRAM = SY-REPID

  • IT_FIELDCAT = ALV_FLDCAT

  • IT_EVENTS = I_EVENT

  • TABLES

  • T_OUTTAB = <DYN_TABLE>

  • .

*IF SY-SUBRC <> 0.

*ENDIF.

ENDFORM. " CALL_ALV

&----


*& Form TOPOFPAGE

&----


FORM TOPOFPAGE.

DATA: LS_LINE TYPE SLIS_LISTHEADER,

E04_LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

IF NOT S_MATNR-HIGH IS INITIAL.

CONCATENATE 'MATERIAL : ' S_MATNR-LOW 'TO'

S_MATNR-HIGH INTO V_MATNR SEPARATED BY SPACE.

ELSE.

CONCATENATE 'MATERIAL : ' S_MATNR-LOW

INTO V_MATNR SEPARATED BY SPACE.

ENDIF.

IF NOT S_MATNR-HIGH IS INITIAL.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-INFO = V_MATNR.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

ENDIF.

IF NOT S_WERKS-HIGH IS INITIAL.

CONCATENATE 'PLANT : ' S_WERKS-LOW 'TO'

S_WERKS-HIGH INTO V_WERKS SEPARATED BY SPACE.

ELSE.

CONCATENATE 'PLANT : ' S_WERKS-LOW

INTO V_WERKS SEPARATED BY SPACE.

ENDIF.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-INFO = V_WERKS.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

IF NOT S_MTART-HIGH IS INITIAL.

CONCATENATE 'MATERIAL TYPE : ' S_MTART-LOW 'TO'

S_MTART-HIGH INTO V_MTART SEPARATED BY SPACE.

ELSE.

CONCATENATE 'MATERIAL TYPE : ' S_MTART-LOW

INTO V_MTART SEPARATED BY SPACE.

ENDIF.

IF NOT S_MTART-LOW IS INITIAL.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-INFO = V_MTART.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

ENDIF.

IF NOT S_SPART-HIGH IS INITIAL.

CONCATENATE 'DIVISION : ' S_SPART-LOW 'TO'

S_SPART-HIGH INTO V_SPART SEPARATED BY SPACE.

ELSE.

CONCATENATE 'DIVISION : ' S_SPART-LOW

INTO V_SPART SEPARATED BY SPACE.

ENDIF.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-INFO = V_SPART.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

IF NOT S_MATKL-HIGH IS INITIAL.

CONCATENATE 'MATERIAL GROUP : ' '(' S_MATKL-OPTION ' ) '

S_MATKL-LOW 'TO'

S_MATKL-HIGH INTO V_MATKL SEPARATED BY SPACE.

ELSE.

CONCATENATE 'MATERIAL GROUP : ' '(' S_MATKL-OPTION ' ) '

S_MATKL-LOW INTO V_MATKL SEPARATED BY SPACE.

ENDIF.

IF NOT S_MATKL-LOW IS INITIAL.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-INFO = V_MATKL.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

ENDIF.

IF NOT S_LGORT-HIGH IS INITIAL.

CONCATENATE 'STORAGE LOCATION : ' S_LGORT-LOW 'TO'

S_LGORT-HIGH INTO V_LGORT SEPARATED BY SPACE.

ELSE.

CONCATENATE 'STORAGE LOCATION : ' S_MATKL-LOW

INTO V_MATKL SEPARATED BY SPACE.

ENDIF.

IF NOT S_LGORT-LOW IS INITIAL.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-INFO = V_LGORT.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

ENDIF.

IF NOT S_LFGJA-HIGH IS INITIAL.

CONCATENATE 'YEAR : ' S_LFGJA-LOW 'TO'

S_LFGJA-HIGH INTO V_LFGJA SEPARATED BY SPACE.

ELSE.

CONCATENATE 'YEAR : ' S_LFGJA-LOW

INTO V_LFGJA SEPARATED BY SPACE.

ENDIF.

IF NOT S_LFGJA-LOW IS INITIAL.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-INFO = V_LFGJA.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

ENDIF.

IF NOT S_LFMON-HIGH IS INITIAL.

CONCATENATE 'PERIOAD : ' S_LFMON-LOW 'TO'

S_LFMON-HIGH INTO V_LFMON SEPARATED BY SPACE.

ELSE.

CONCATENATE 'PERIOD : ' S_LFMON-LOW

INTO V_LFMON SEPARATED BY SPACE.

ENDIF.

IF NOT S_LFMON-LOW IS INITIAL.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-INFO = V_LFMON.

APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.

ENDIF.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = E04_LT_TOP_OF_PAGE.

ENDFORM. "TOPOFPAGE

&----


*& Form TOP

&----


FORM TOP .

FS_EVENT-NAME = 'TOP_OF_PAGE'.

FS_EVENT-FORM = 'TOPOFPAGE'.

APPEND FS_EVENT TO I_EVENT.

ENDFORM. " TOP

&----


*& Form VALIDATE_MATNR

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_MATNR .

IF NOT S_MATNR-LOW IS INITIAL.

SELECT SINGLE MATNR

INTO MARA-MATNR

FROM MARA

WHERE MATNR = S_MATNR-LOW.

IF SY-SUBRC <> 0.

MESSAGE 'MATERIAL DOES NOT EXIST' TYPE 'E'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_MATNR

&----


*& Form VALIDATE_WERKS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_WERKS .

IF NOT S_WERKS-LOW IS INITIAL.

SELECT SINGLE WERKS

INTO T001W-WERKS

FROM T001W

WHERE WERKS = S_WERKS-LOW.

IF SY-SUBRC <> 0.

MESSAGE 'PLANT DOES NOT EXIST' TYPE 'E'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_WERKS

&----


*& Form VALIDATE_MTART

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_MTART .

IF NOT S_MTART-LOW IS INITIAL.

SELECT SINGLE MTART

INTO MARA-MTART

FROM MARA

WHERE MTART = S_MTART-LOW.

IF SY-SUBRC <> 0.

MESSAGE 'MATERIAL TYPE DOES NOT EXIST' TYPE 'E'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_MTART

&----


*& Form VALIDATE_SPART

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_SPART .

IF NOT S_SPART-LOW IS INITIAL.

SELECT SINGLE SPART

INTO MARA-SPART

FROM MARA

WHERE SPART = S_SPART-LOW.

IF SY-SUBRC <> 0.

MESSAGE 'DIVISION DOES NOT EXIST' TYPE 'E'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_SPART

&----


*& Form VALIDATE_MATKL

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_MATKL .

IF NOT S_MATKL-LOW IS INITIAL.

SELECT SINGLE MATKL

INTO MARA-MATKL

FROM MARA

WHERE MATKL = S_MATKL-LOW.

IF SY-SUBRC <> 0.

MESSAGE 'MATERIAL GROUP DOES NOT EXIST' TYPE 'E'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_MATKL

&----


*& Form VALIDATE_LGORT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_LGORT .

*IF NOT S_LGORT-LOW IS INITIAL.

  • SELECT SINGLE LGORT

  • INTO MARD-LGORT

  • FROM MARD

  • WHERE LGORT = S_LGORT-LOW.

*IF SY-SUBRC <> 0.

*MESSAGE 'STORAGE LOCATION DIES NOT EXIST' TYPE 'E'.

*ENDIF.

*ENDIF.

ENDFORM. " VALIDATE_LGORT

&----


*& Form VALIDATE_LFGJA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_LFGJA .

IF NOT S_LFGJA-LOW IS INITIAL.

SELECT SINGLE LFGJA

INTO MARDH-LFGJA

FROM MARDH

WHERE LFGJA = S_LFGJA-LOW.

IF SY-SUBRC <> 0.

MESSAGE 'ENTER A VALID YEAR' TYPE 'E'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_LFGJA

&----


*& Form VALIDATE_LFMON

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_LFMON .

IF NOT S_LFMON-LOW IS INITIAL.

IF NOT ( S_LFMON-LOW GE 1 AND S_LFMON-LOW LE 12 ).

MESSAGE 'ENTER A VALID PERIOD' TYPE 'E'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_LFMON

Former Member
0 Kudos
104

Hi,

check this link it will help to create the dynamic internal table step by step.

http://saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm

bpawanchand
Active Contributor
0 Kudos
104

former_member188685
Active Contributor
0 Kudos
104

Example to create the Dynamic Tabeles.

First you need to populate what fields you want to be in Dynamic table and then call the method create_dynamic_table of class cl_alv_table_create. use the dat object and assign to <fs> to create the internal table .

REPORT  zdynamic.
 
FIELD-SYMBOLS: <l_table> TYPE table,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
 
DATA: is_lvc_cat TYPE lvc_s_fcat,
      it_lvc_cat TYPE lvc_t_fcat.
 
DATA: new_table TYPE REF TO data,
      new_line  TYPE REF TO data.
 
 
START-OF-SELECTION.
 
  is_lvc_cat-fieldname = 'KUNNR'.
  APPEND is_lvc_cat TO it_lvc_cat.
 
  is_lvc_cat-fieldname = 'NAME1'.
  APPEND is_lvc_cat TO it_lvc_cat.
 
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_lvc_cat
    IMPORTING
      ep_table        = new_table.
 
*Create a new Line with the same structure of the table.
  ASSIGN new_table->* TO <l_table>.
  CREATE DATA new_line LIKE LINE OF <l_table>.
  ASSIGN new_line->* TO <l_line>.
 
 
  DO 2 TIMES.
    ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <l_line> TO <l_field>.
    <l_field> = sy-index.
 
    ASSIGN COMPONENT 'NAME1' OF STRUCTURE <l_line> TO <l_field>.
    <l_field> = 'A'.
    INSERT <l_line> INTO TABLE <l_table>.
  ENDDO.
 
  LOOP AT <l_table> INTO <l_line>.
    WRITE:/ <l_line>.
  ENDLOOP.
 
  READ TABLE <l_table> INTO <l_line> INDEX 2.
  <l_line>+10(2) = 'B'.
  MODIFY <l_table> FROM <l_line> INDEX 2.
 
 
  LOOP AT <l_table> INTO <l_line>.
    WRITE:/ <l_line>.
  ENDLOOP.

Regards

Vijay babu Dudla

Former Member
0 Kudos
104

Hi,

Here is some information about creating dynamic internal table in ddifferent scenario...just go through this u may get some help...

Creating Dynamic internal table

PARAMETERS : p_table(10) TYPE C.

DATA: w_tabname TYPE w_tabname,

w_dref TYPE REF TO data,

w_grid TYPE REF TO cl_gui_alv_grid.

FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE.

w_tabname = p_table.

CREATE DATA w_dref TYPE TABLE OF (w_tabname).

ASSIGN w_dref->* TO <t_itab>.

Populating Dynamic internal table

SELECT *

FROM (w_tabname) UP TO 20 ROWS

INTO TABLE <t_itab>.

Displaying dynamic internal table using Grid.

CREATE OBJECT w_grid

EXPORTING i_parent = cl_gui_container=>screen0.

CALL METHOD w_grid->set_table_for_first_display

EXPORTING

i_structure_name = w_tabname

CHANGING

it_outtab = <t_itab>.

CALL SCREEN 100.

Scenario 2:

Create a dynamic internal table with the specified number of columns.

Creating Dynamic internal table

TYPE-POOLS: slis.

FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE, u201C Dynamic internal table name

<fs_dyntable>, u201C Field symbol to create work area

<fs_fldval> type any. u201C Field symbol to assign values

PARAMETERS: p_cols(5) TYPE c. u201C Input number of columns

DATA: t_newtable TYPE REF TO data,

t_newline TYPE REF TO data,

t_fldcat TYPE slis_t_fldcat_alv,

t_fldcat TYPE lvc_t_fcat,

wa_it_fldcat TYPE lvc_s_fcat,

wa_colno(2) TYPE n,

wa_flname(5) TYPE c.

  • Create fields .

DO p_cols TIMES.

CLEAR wa_it_fldcat.

move sy-index to wa_colno.

concatenate 'COL'

wa_colno

into wa_flname.

wa_it_fldcat-fieldname = wa_flname.

wa_it_fldcat-datatype = 'CHAR'.

wa_it_fldcat-intlen = 10.

APPEND wa_it_fldcat TO t_fldcat.

ENDDO.

  • Create dynamic internal table and assign to FS

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_fldcat

IMPORTING

ep_table = t_newtable.

ASSIGN t_newtable->* TO <t_dyntable>.

  • Create dynamic work area and assign to FS

CREATE DATA t_newline LIKE LINE OF <t_dyntable>.

ASSIGN t_newline->* TO <fs_dyntable>.

Populating Dynamic internal table

DATA: fieldname(20) TYPE c.

DATA: fieldvalue(10) TYPE c.

DATA: index(3) TYPE c.

DO p_cols TIMES.

index = sy-index.

MOVE sy-index TO wa_colno.

CONCATENATE 'COL'

wa_colno

INTO wa_flname.

  • Set up fieldvalue

CONCATENATE 'VALUE' index INTO

fieldvalue.

CONDENSE fieldvalue NO-GAPS.

ASSIGN COMPONENT wa_flname

OF STRUCTURE <fs_dyntable> TO <fs_fldval>.

<fs_fldval> = fieldvalue.

ENDDO.

  • Append to the dynamic internal table

APPEND <fs_dyntable> TO <t_dyntable>.

Displaying dynamic internal table using Grid.

DATA: wa_cat LIKE LINE OF fs_fldcat.

DO p_cols TIMES.

CLEAR wa_cat.

MOVE sy-index TO wa_colno.

CONCATENATE 'COL'

wa_colno

INTO wa_flname.

wa_cat-fieldname = wa_flname.

wa_cat-seltext_s = wa_flname.

wa_cat-outputlen = '10'.

APPEND wa_cat TO fs_fldcat.

ENDDO.

  • Call ABAP List Viewer (ALV)

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

it_fieldcat = fs_fldcat

TABLES

t_outtab = <t_dyntable>.

Thanks & Regards

Ashu Singh.

uwe_schieferstein
Active Contributor
0 Kudos
105

Hello Trivenn

If the dynamic itabs have the same line type then there is no need to create dynamic itabs. You could simplify your problem as following:


TYPES: BEGIN OF ty_s_itab.
TYPES: externalid     TYPE <datatype of external id>.
TYPES: data             TYPE STANDARD TABLE OF <line type>
                                WITH DEFAULT KEY.
TYPES: END OF ty_s_itab.
TYPES: ty_t_itab       TYPE STANDARD TABLE OF ty_s_itab
                                 WITH DEFAULT KEY.

DATA: 
  ls_record                 TYPE <line type>,
  lt_itab                     TYPE ty_t_itab,
  ls_itab                     TYPE ty_s_itab.

LOOP AT ...
  CLEAR: ls_itab.

  AT NEW externalid.
    ls_itab-externalid = <external id>.

    " Fill data
     LOOP AT ... INTO ls_record.
       APPEND ls_record TO ls_itab-data.
     ENDLOOP.
     
     APPEND ls_itab TO lt_itab.
  ENDAT.

ENDLOOP.

This way you get a complex itab where each record is identified by its external ID and it contains an itab for the data.

Regards

Uwe

Former Member
0 Kudos
104

Hi,

Dynamic internal table is internal table that we create on the fly with flexible column numbers.

For sample code, please look at this code tutorial. Hopefully it can help you

saptechnical.com/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm

saptechies.com/how-to-declare-an-internal-table-dynamically-2/

cheers,

vasavi.v

Former Member
0 Kudos
104

Please close your thread if you have got the answer.