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 without OOPs concept

Former Member
0 Likes
998

Can anybody suggest me how to make dynamic internal table containing fields

entered by the user in selection screen without using

OOPs concept (without calling any methods).

Thanks and Regards,

Rahul

1 ACCEPTED SOLUTION
Read only

raja_thangamani
Active Contributor
0 Likes
973

Check this code..


REPORT ZCLUST1 .
*
* Example: how to create a dynamic internal table
* 
* 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.

Message was edited by:

Raja T

9 REPLIES 9
Read only

raja_thangamani
Active Contributor
0 Likes
974

Check this code..


REPORT ZCLUST1 .
*
* Example: how to create a dynamic internal table
* 
* 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.

Message was edited by:

Raja T

Read only

0 Likes
973

Hello Raja,

Thanks for your response but the fields of the internal table are not static, they are to be taken from the selection screen.

Regards,

Rahul

Read only

0 Likes
973

Hi,

Instead of Hard coding the field names, you can get it from Selection screen.

Loop at s_select. "S_Select - selectiion Parameter

STRUCT-FILDNAME = s_select-Low. 

APPEND STRUCT.

Endloop.

Note: Reward each useful asnsers.

Raja T

Read only

0 Likes
973

Hi Raja,

Fine i can get the name of the field, but then how to get the type & length of the fields which the user has entered?

Regards,

Rahul

Read only

0 Likes
973

As far as i know,

you need to use the below code to get the data type dynamically..

**** Get type object from a data object

DATA:   DATATYPE TYPE REF TO CL_ABAP_DATADESCR,
        FIELD(5) TYPE C.

DATATYPE ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( FIELD ).

Raja T

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
973

I think that it might be possible, but I'm pretty sure not worth it. I guess you are on a release < 46c and can not use the code in my blog?

Regards,

Rich Heilman

Read only

0 Likes
973

I have seen your suggestion in weblog but there OOPs concept are used.

I am working on version 4.7, can you please help me out regarding this?

Thanks and regards,

Rahul

Read only

0 Likes
973

Why don't you want to use object oriented concepts, my blog will walk you thru the entrie process?

Regards,

Rich Heilman

Read only

0 Likes
973

Hello Rich,

Thanks for your support but my requirement is that i don't have to use the OOPs concept.

Regards,

Rahul