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 can i see fields with their field names in application server

Former Member
0 Kudos

generally when ever we sent data to aplication server we wil see only field values ,how can i send field values with their field names to application server,

my requirement is to see all fields with their corresponding fieldnames in application server.

here i am having data in ITAB .

thnks in adv...

6 REPLIES 6

Former Member
0 Kudos

I suppose you want a header line with the names of the structure in a file?

0 Kudos

yes

0 Kudos

you need to do it manually...

concatenate bukrs gjahr comp.code.... into lv_string seperated by '|'.

append lv_string to i_data index 1.
i_data[].

0 Kudos

Hi

Plz chk if the code below helps..

DATA: g_msg(50) TYPE c, " Message

l_line(1024) TYPE c,

l_field(100) TYPE c,

g_file TYPE string, " Output file name

FIELD-SYMBOLS: <fs>.

g_file should be given the filename.

  • Open file

OPEN DATASET g_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc <> 0.

g_msg = 'Download Failed &'.

EXIT.

ENDIF.

  • Write data to file; separate fields by tabs

  • Write header to file

CLEAR l_line.

  • You can either add descriptions or add fieldnames in this depending on your interest

CONCATENATE 'Title 1' 'Title 2' 'Title 3' 'Title 4' INTO l_line

SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

TRANSFER l_line TO g_file.

LOOP AT t_out. "t_out is the internal table which has the records to be written in appln. server

CLEAR l_line.

WHILE 1 = 1.

ASSIGN COMPONENT sy-index OF STRUCTURE t_out TO <fs>.

IF sy-subrc <> 0.

EXIT.

ENDIF.

IF sy-index = 1.

l_line = <fs>. "This is to start a fresh line with the value of the 1st field.

ELSE.

l_field = <fs>. "This is to continue the values of rest of the fields of the same record.

CONDENSE l_field.

CONCATENATE l_line l_field INTO l_line

SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

ENDIF.

ENDWHILE.

TRANSFER l_line TO g_file.

IF sy-subrc <> 0.

g_msg = 'Download Failed &'.

EXIT.

ENDIF.

ENDLOOP.

  • Close file

CLOSE DATASET g_file.

IF sy-subrc <> 0.

g_msg = 'Download Failed &'.

ENDIF.

nkr1shna
Contributor
0 Kudos

Hi Mahendra,

You can get field names declared in your internal table by using the program logic given below.

TYPE-POOLS : abap.

  • SAMPLE INTERNAL TABLE

DATA: BEGIN OF tabl occurs 0,

mandt TYPE mara-mandt,

matnr TYPE mara-matnr,

ersda TYPE mara-ersda,

ernam TYPE mara-ernam,

laeda TYPE mara-laeda,

aenam TYPE mara-aenam,

vpsta TYPE mara-vpsta,

pstat TYPE mara-pstat,

lvorm TYPE mara-lvorm,

mtart TYPE mara-mtart,

mbrsh TYPE mara-mbrsh,

END OF tabl.

DATA : it_details TYPE abap_compdescr_tab,

wa_comp TYPE abap_compdescr.

DATA : ref_descr TYPE REF TO cl_abap_structdescr.

ref_descr ?= cl_abap_typedescr=>describe_by_data( tabl ).

it_details[] = ref_descr->components[].

loop at it_details into wa_comp.

write:/ wa_comp.

endloop.

You can write contents of this internal table it_details to display or write internal table fieldnames in your output file

Best Regards,

Krishna

p244500
Active Contributor
0 Kudos

hi

i think u wil be help this

REPORT test.

----


DATA:

ok_code LIKE sy-ucomm,

ref_struc TYPE REF TO data.

----


FIELD-SYMBOLS:

<fs_struc> TYPE ANY,

<fs_comp> TYPE ANY.

----


PARAMETERS:

pa_tab TYPE dd02l-tabname DEFAULT u2019SPFLIu2019.

----


START-OF-SELECTION.

----


CREATE DATA ref_struc TYPE (pa_tab).

ASSIGN ref_struc->* TO <fs_struc>.

SELECT * FROM (pa_tab)

INTO <fs_struc>

UP TO 100 ROWS

.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE <fs_struc> to <fs_comp>.

IF sy-subrc <> 0.

NEW-LINE.

EXIT.

ENDIF.

WRITE: <fs_comp>.

ENDDO.

ENDSELECT.

IF sy-subrc <> 0.

MESSAGE e041(bc402).

ENDIF.

Cheer

nawa