cancel
Showing results for 
Search instead for 
Did you mean: 

How to read fields of a structure or Table.

Former Member
0 Kudos

Hi,

I had a requirement where i will send a structure/table name into a Form(Subroutine). This form fills an internal table with all the fields in that structure/table .

Does any one could suggest any programming method to access the field names of structure/table.

Please don't suggest any database tables, as the structures iam going to send need not exist in database.

A quick reply is appreciated.

Thanks in Advance,

Anvitha.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi there,

Would this help

TYPES: BEGIN OF t_table ,

field1 type c,

field2 type i,

field3 type sy-datum,

end of t_table.

DATA : wa_table TYPE t_table,

ist_table TYPE STANDARD TABLE OF t_table.

PERFORM fill_table USING wa_table.

LOOP AT ist_table INTO wa_table

WRITE : wa_table-field1, wa_table-field2,

wa_table-field3.

ENDLOOP.

....

FORM fill_table USING p_wa_table.

APPEND p_wa_table INTO ist_table.

ENDFORM.

Regards,

Deva.

Former Member
0 Kudos

HI Anvitha,

You can use function REUSE_ALV_FIELDCATALOG_MERGE to get the field names and attributes.

REPORT test.

TYPE-POOLS : slis.

DATA : BEGIN OF itab1,

f1 LIKE vbak-vbeln,

f2 LIKE vbap-posnr,

f3 LIKE vbak-netwr,

END OF itab1.

DATA : rep TYPE sy-repid .

DATA : fcat TYPE slis_t_fieldcat_alv.

rep = sy-repid.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = rep

i_internal_tabname = 'ITAB1'

  • I_STRUCTURE_NAME = 'ITAB1'

i_client_never_display = 'X'

i_inclname = rep

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

ct_fieldcat = fcat

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

the internal table fcat will have field names and attributes of internal table.

Reagrds,

Gagan

former_member221770
Contributor
0 Kudos

Anvitha,

ALso if you declare a global internal table you can also populate it directly in the subroutine without passing and parameters.

eg.

data: begin of tbl_data occurs 0,

....

end of tbl_data.

perform fill_data.

form fill_data.

*fill tbl_data here...

append tbl_data.

endform.

In my previous example, I essentially passed the global internal table (tbl_data) into the subroutine, created a local internal table (ie it is only usable within the subroutine) called it_data which would have been populated with the data passed in from tbl_data, modify/populated it in the subroutine, and passed it's contents back out to tbl_data. Debug the program to see how this works, but feel free to get back to me if this still does not make sense.

Cheers,

Pat.

Former Member
0 Kudos

Hi ,

Sorry u didn't get my exact requirement. Let me explain with an Example.

DATA: BEGIN OF i_table1 ,

field1 type c,

field2 type i,

field3 type sy-datum,

end of i_table1.

now if i send this structure i_table1 to the form..( forget how iam sending )

In the form u should be able to populate the fields of i_table1 structure (i.e field1 .. field2 .. field3 ) into the internal table...

Hope my requirement is clear to everyone now.

Thanks,

Anvitha.

former_member221770
Contributor
0 Kudos

Anvitha,

Sorry for the mix up, so what you are trying to do is loop through the fields in the structure and use them to populate a table?

try using field-symbols:

data: begin of i_table1,

field1 type c,

field2 type i,

field3 type sy-datum,

end of i_table1.

perform fill_data.

form fill_data.

field-symbols: <fs> type any.

data: index type i.

do.

assign component index of structure i_table1 to <fs>.

if sy-subrc ne 0.

exit.

endif.

  • fill table here....

enddo.

endform.

Let me know if this is not what you are after.

Cheers,

Pat.

former_member221770
Contributor
0 Kudos

Anvitha,

You can also use Function Module GET_COMPONET_LIST.

data: begin of tbl_data occurs 0,

vbeln like vbak-vbeln,

posnr like vbap-posnr,

end of tbl_data.

data: begin of tbl_comp occurs 0.

include structure rstrucinfo.

data: end of tbl_comp.

call function 'GET_COMPONENT_LIST'

exposting

program = <insert program name here in upper case>

fieldname = 'TBL_DATA'

tables

components = tbl_comp.

tbl_comp will now hold all the information about the fields in TBL_DATA.

Hope this is what you are after. Sorry about my previous irrelevant emails...it's been that kind of day!

Cheers,

Pat.

Former Member
0 Kudos

i am not sure, but i think your problem can be solved if you pass table as reference rather than value.

if i am wrong just ignore this

regards

andreas_mann3
Active Contributor
0 Kudos

Hi,

i assume , you mean this:

perform process1 tables i_table1.
perform process1 tables i_table2.

...

form process1 tables itab structure i_table1.
..
endform.

regards Andreas

former_member221770
Contributor
0 Kudos

Anvitha,

Have any of our suggestions been of any help to you in resolving your issue? Don't forget to reward points to the suggestions that were helpful to you.

Cheers,

Pat.

former_member221770
Contributor
0 Kudos

Hi Anvitha,

Try the following:

data: begin of st_data,

....

end of st_data.

data: begin of tbl_data occurs 0.

include structure st_data.

data: end of tbl_data.

perform fill_data tables tbl_data.

form fill_data tables it_data structure st_data.

  • Fill up it_data here...

append it_data.

endform.

CHeers,

Pat