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: 

How to create an internal table with fields from different sources

Former Member
0 Kudos

Hi.

I need to create an internal table where some of the fields are from a database table, and the other fields are user specified. How do i do that?

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

Example:

DB table ZTAB with fields ZTAB-FIELD1, ZTAB-FIELD2.

I want to create an internal table ITAB with the fields ZTAB-FIELD1, ZTAB-FIELD2 from ZTAB. In addition, I also want to have one more field RECORD_NO, which is not from ZTAB. How do I do it? Could I do something like below?

DATA BEGIN OF ITAB.

INCLUDE STRUCTURE ZTAB.

DATA RECORD_NO TYPE I.

DATA END OF UPLINE.

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

Or, are there more efficient way of doing it? Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi keon kong,

there is nothing wrong in it. u can give like that.

regards

karthik

4 REPLIES 4

JozsefSzikszai
Active Contributor
0 Kudos

hi KIan,

go:

  • general type

TYPE : BEGIN OF ty_itab,

field1 TYPE ztab-field1,

field2 TYPE ztab-field2,

*your own fields here:

field TYPE i,

field(30) TYPE c,

END OF ty_itab.

  • work area

DATA : gw_itab TYPE ty_itab.

  • internal table

DATA : gt_itab TYPE TABLE OF ty_itab.

hope this helps

ec

Former Member
0 Kudos

hi keon kong,

there is nothing wrong in it. u can give like that.

regards

karthik

Former Member
0 Kudos

Hi Kian,

here a shor example.

TABLES: MARA.

*

DATA: BEGIN OF ITAB OCCURS 0.

DATA: NO LIKE SY-DBCNT.

INCLUDE STRUCTURE MARA.

DATA: END OF ITAB.

*

SELECT * FROM MARA UP TO 100 ROWS.

*

ITAB-NO = SY-DBCNT.

MOVE-CORRESPONDING MARA TO ITAB.

APPEND ITAB.

*

ENDSELECT.

*

LOOP AT ITAB. WRITE: / ITAB-NO, ITAB-MATNR, ITAB-BRGEW. ENDLOOP.

Regards, Dieter

Former Member
0 Kudos

Thanks to all who replied