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: 

To Retieve Feilds of a Particular Table and Display it ...!

Former Member
0 Kudos

hi,

I am new to ABAP/4 Programming. Suppose we have a table called Zmaterial, it contains ID,NAME,DESCRIPTION and PICTURE fields, here what is my objective is i want to retrieve all of these field names from zmaterial in to my ABAP Program

Please Can Anyone Give me Solution ....!

Thanks

Prasad

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

For this you need to create an internal table of the same type as the Ztable i.e Zmaterial.

Then by looping on that internal table and using the work area you can work on it in your program.

For example,

Create an internal table of same type as Zmaterial-

data: itab type Zmaterial,

wa_itab like line of itab.

loop at itab into wa_itab.

..........

..........

.........

And do whatever ur requirement is.

Itab table will have all the fields as table Zmaterial has.

just use it as suppose, wa_itab-field1 etc.

and then using write statement display it on ur screen..

Thanks

Revert back if any queries

Reward points if useful

Edited by: Malvika Sharma on May 28, 2008 7:04 AM

Edited by: Malvika Sharma on May 28, 2008 7:06 AM

10 REPLIES 10

Former Member
0 Kudos

Hi,

For this you need to create an internal table of the same type as the Ztable i.e Zmaterial.

Then by looping on that internal table and using the work area you can work on it in your program.

For example,

Create an internal table of same type as Zmaterial-

data: itab type Zmaterial,

wa_itab like line of itab.

loop at itab into wa_itab.

..........

..........

.........

And do whatever ur requirement is.

Itab table will have all the fields as table Zmaterial has.

just use it as suppose, wa_itab-field1 etc.

and then using write statement display it on ur screen..

Thanks

Revert back if any queries

Reward points if useful

Edited by: Malvika Sharma on May 28, 2008 7:04 AM

Edited by: Malvika Sharma on May 28, 2008 7:06 AM

0 Kudos

i have an requirement like this, i know only the table name, i dont about the fields and how many fields it contains, i want to output total no of fields and their names

0 Kudos

Hi Lakshmi,

Try this

data : itab type table of <your table name>.

select * from <your table name> into table itab.

Then display

Hope it helps

Manish

0 Kudos

hi try using fieldsymbols

tables <ur ztable>.

data : itab type table of <urztable> with header line.

field-SYMBOLS : <fs> type any .

select * from <urztable> into table itab.

ASSIGN itab to <fs>.

loop at itab.

write : / <fs>.

endloop

regards

prasanth.

0 Kudos

Output should come like this Manish

Total no of fields in zmaterial table is : 4

Field names are :

ID

NAME

DESCRIPTION

PICTURE

suppose if the table contains hundrend fields it has show, i want logic for this req.....!

0 Kudos

hi,

check the following code

give your table name in selection screen

tables : DD03l.

parameters : p_table like dd03l-tabname.

data : lines type i.

data : begin of itab occurs 0,

fieldname like dd03l-fieldname,

end of itab.

select fieldname from dd03l into table itab where tabname = p_table.

describe table itab lines lines.

write : 'THE NUMBER OF FIELDS ARE' , lines.

WRITE : / 'THE FIELDS ARE AS FOLLOWS'.

loop at itab.

write 😕 itab-fieldname.

endloop.

waiting for your reward

prasanth

0 Kudos

Prashanth thank you ....!

Thanks

prasad

Former Member
0 Kudos

Report zmaterial_out.

tables : zmaterial.

data : it_zmaterial like zmaterial occurs 0 with header line.

select * from zmaterial into table it_zmaterial.

loop at it_zmaterial.

write : / it_zmaterial-ID, it_zmaterial-NAME, it_zmaterial-DESCRIPTION, it_zmaterial-PICTURE.

clear it_zmaterial.

endloop.

Regards,

Madan.

Former Member
0 Kudos

Hi,

For that u have to create the Report.

REPORT zfir_v.

TABLES : zmaterial.

TYPE-POOLS: slis.

DATA: BEGIN OF it_zmaterial OCCURS 0,

ID LIKE zmaterial-ID,

name hbkid LIKE zmaterial-NAME,

material LIKE zmaterial-material,

description LIKE zmaterial-description,

END OF it_zmaterial .

----


  • Generating field catalog for the display of errors in ALV display. *

----


DATA: v_repid LIKE sy-repid,

i_fieldcat1 TYPE slis_t_fieldcat_alv,

lv_layout TYPE slis_layout_alv,

v_events TYPE slis_t_event,

w_fieldcat TYPE slis_fieldcat_alv.

&----


*& START OF SELECTION SCREEN *

&----


SELECTION-SCREEN BEGIN OF BLOCK general WITH FRAME TITLE text-001.

SELECT-OPTIONS:

s_ID FOR zmaterial-ID ,

s_name FOR zmaterial-NAME ,

SELECTION-SCREEN END OF BLOCK general.

&----


*& INITIALIZATION. *

&----


INITIALIZATION.

v_repid = sy-repid.

lv_layout-colwidth_optimize = 'X'.

&----


*& START-OF-SELECTION event starts here. *

&----


START-OF-SELECTION.

SELECT ID material name description

FROM zmaterial

INTO CORRESPONDING FIELDS OF TABLE it_zmaterial

WHERE ID IN s_ID AND

name IN s_name.

&----


*& To prepare the field catalogue dynamically based on the input *

*& provided by the user on the selection-screen. *

&----


CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = v_repid

i_internal_tabname = 'IT_ZMATERIAL'

  • i_structure_name = 'ZMATERIAL'

i_inclname = v_repid

i_bypassing_buffer = 'X'

i_buffer_active = ' '

CHANGING

ct_fieldcat = i_fieldcat1

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

LOOP AT i_fieldcat1 INTO w_fieldcat.

CASE w_fieldcat-fieldname.

WHEN 'ID'.

w_fieldcat-col_pos = 1.

w_fieldcat-ddictxt = 'L'.

w_fieldcat-seltext_l = 'ID'.

MODIFY i_fieldcat1 FROM w_fieldcat.

WHEN 'NAME'.

w_fieldcat-col_pos = 2.

w_fieldcat-ddictxt = 'L'.

w_fieldcat-seltext_l = 'NAME'.

MODIFY i_fieldcat1 FROM w_fieldcat.

WHEN 'MATERIAL'.

w_fieldcat-col_pos = 3.

w_fieldcat-ddictxt = 'L'.

w_fieldcat-seltext_l = 'MATERIAL'.

MODIFY i_fieldcat1 FROM w_fieldcat.

WHEN 'DESCRIPTION'.

w_fieldcat-col_pos = 4.

w_fieldcat-ddictxt = 'L'.

w_fieldcat-seltext_l = 'DESCRIPTION'.

MODIFY i_fieldcat1 FROM w_fieldcat.

ENDCASE.

ENDLOOP.

&----


*& To output a simple list *

&----


CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = v_repid

is_layout = lv_layout

it_fieldcat = i_fieldcat1

it_events = v_events

TABLES

t_outtab = it_zmaterial

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Thanks

prasanth_kasturi
Active Contributor
0 Kudos

Hi Prasad,

Its very easy

follow the simple steps

1) create a internal table like your ztable

data : itab type table of <ur ztable> with header line.

2) write a select query to get contents from dbtable to your internal table

*select * from <ur ztable > into table itab .*

3) display the internal table

loop at itab.

write : / itab-id,

itab-name,

itab-description,

itab-picture.

endloop.

save and activate your program

then execute

reward if helpful

prasanth