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

Internal Table output in customer format ; write statement

Former Member
0 Likes
1,698

Hello All,

I need help in printing the O/P.

Currently the program is displaying ALV.

However I need the O/P to be displayed like.

FIELDANAME1;FIELDNAME2;FIELDNAME3;....FNZ.

VALUE1;VALUE2;VALUE3....VZ.

-


;----;--;--;--;.......----;.

Code is below - Dynamically it will show the table contents

according to the tabel name.

&----


*& Report YREN_FIELDSDISPLAY

*&

&----


*&

*&

&----


REPORT YREN_FIELDSDISPLAY.

FIELD-SYMBOLS:

<f_tab1> TYPE STANDARD TABLE.

PARAMETERS:

p_tname TYPE tabname16 OBLIGATORY, " DEFAULT 'MARA' ,

p_rows(5) TYPE c DEFAULT '200'.

----


  • CLASS lcl_dynamic DEFINITION

----


*

----


CLASS lcl_dynamic DEFINITION CREATE PRIVATE.

PUBLIC SECTION.

CLASS-METHODS:

check_selection

EXCEPTIONS invalid_table,

main

EXCEPTIONS no_data_found,

display.

PRIVATE SECTION.

TYPE-POOLS: abap.

CLASS-DATA: tab TYPE REF TO cl_abap_structdescr,

wa_tab TYPE REF TO cl_abap_structdescr,

comp_tab TYPE cl_abap_structdescr=>component_table,

i_tab TYPE REF TO cl_abap_tabledescr,

i_table TYPE REF TO data.

ENDCLASS. "lcl_dynamic DEFINITION

----


  • CLASS lcl_dynamic IMPLEMENTATION

----


*

----


CLASS lcl_dynamic IMPLEMENTATION.

METHOD check_selection.

SELECT COUNT( * )

FROM dd02l

WHERE tabname = p_tname

AND as4local = 'A'

AND tabclass = 'TRANSP'.

IF sy-subrc = 0.

RAISE invalid_table.

ENDIF.

ENDMETHOD. "check_selection

METHOD main.

tab ?= cl_abap_typedescr=>describe_by_name( p_tname ).

comp_tab = tab->get_components( ).

wa_tab = cl_abap_structdescr=>create( comp_tab ).

i_tab = cl_abap_tabledescr=>create( wa_tab ).

CREATE DATA i_table TYPE HANDLE i_tab.

ASSIGN i_table->* TO <f_tab1>.

IF p_rows IS INITIAL.

p_rows = '50000'.

ENDIF.

*Get data

SELECT * FROM (p_tname)

INTO TABLE <f_tab1>

UP TO p_rows ROWS.

IF sy-subrc EQ 0.

RAISE no_data_found.

ENDIF.

ENDMETHOD. "main

METHOD display.

SET TITLEBAR sy-title

OF PROGRAM sy-cprog

WITH 'Display table:' p_tname.

DATA:

l_gr_alv TYPE REF TO cl_salv_table,

l_gr_functions TYPE REF TO cl_salv_functions.

TRY.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = l_gr_alv

CHANGING

t_table = <f_tab1>.

CATCH cx_salv_msg . "#EC NO_HANDLER

ENDTRY.

l_gr_functions = l_gr_alv->get_functions( ).

l_gr_functions->set_all( abap_true ).

l_gr_alv->display( ).

ENDMETHOD. "display

ENDCLASS. "lcl_dynamic IMPLEMENTATION

AT SELECTION-SCREEN.

CALL METHOD lcl_dynamic=>check_selection

EXCEPTIONS

invalid_table = 1.

IF sy-subrc EQ 0.

MESSAGE e001(00) WITH

p_tname ' is not a Transparant Table'.

ENDIF.

START-OF-SELECTION.

CALL METHOD lcl_dynamic=>main

EXCEPTIONS

no_data_found = 1.

IF sy-subrc EQ 0.

MESSAGE i001(00) WITH 'No data found'.

LEAVE LIST-PROCESSING.

ENDIF.

END-OF-SELECTION.

CALL METHOD lcl_dynamic=>display.

Thanks,

Varun.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
783

Hi,

Instead of this method CALL METHOD lcl_dynamic=>display use function module REUSE_ALV_LIST_DISPLAY.

in method display call the above mentioned function module and don;t forget to create a field catalog of the fields you want to display.

Hope this helps.

Amandeep

3 REPLIES 3
Read only

Former Member
0 Likes
784

Hi,

Instead of this method CALL METHOD lcl_dynamic=>display use function module REUSE_ALV_LIST_DISPLAY.

in method display call the above mentioned function module and don;t forget to create a field catalog of the fields you want to display.

Hope this helps.

Amandeep

Read only

0 Likes
783

Could u please tell me teh code what i need to replace ..

as i m very confused

Read only

Former Member
0 Likes
783

hi varun,

amandep is correct ...use REUSE_ALV_GRID_DISPLAY .If still you have problem in formatting then go through this code used for ALV display.

&----


*& Report ZYOGALVEX1

*&

&----


*&

*&

&----


REPORT ZYOGALVEX1.

type-pools: slis.

tables: zyogstudent,t001.

data: itab like zyogstudent occurs 0 with header line.

data: begin of jtab occurs 0,

bukrs like t001-bukrs,

butxt like t001-butxt,

ort01 like t001-ort01,

stceg like t001-stceg,

end of jtab.

data: field_cat type slis_t_fieldcat_alv,

xlayout type slis_layout_alv,

i_sort type slis_t_sortinfo_alv.

start-of-selection.

perform get_data.

perform dis_lay.

perform dis_sort.

perform display.

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_data .

select * from zyogstudent into table itab.

select bukrs ort01 stceg butxt from t001 into corresponding fields of table jtab.

perform field_init using field_cat.

endform. " get_data

&----


*& Form dis_lay

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form dis_lay .

xlayout-zebra = 'X'.

xlayout-no_keyfix = 'X'.

xlayout-flexible_key = 'X'.

xlayout-colwidth_optimize = 'skip'.

xlayout-header_text = 'this is using header text'.

endform. " dis_lay

&----


*& Form dis_sort

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form dis_sort .

data l_sort type slis_sortinfo_alv.

l_sort-fieldname = 'ZNAME'.

l_sort-tabname = 'ZYOGSTUDENT'.

l_sort-spos = 1.

l_sort-up = 'X'.

append l_sort to i_sort.

endform. " dis_sort

&----


*& Form field_init

&----


  • text

----


  • -->P_FIELD_CAT text

----


form field_init using p_field_cat.

data wa_cat type slis_fieldcat_alv.

wa_cat-fieldname = 'ZNAME'.

wa_cat-tabname = 'zyogstudent'.

wa_cat-outputlen = 25.

wa_cat-seltext_m = 'ZNAME'.

wa_cat-just = 'L'.

append wa_cat to field_cat.

wa_cat-fieldname = 'ZCLASS'.

wa_cat-tabname = 'zyogstudent'.

wa_cat-outputlen = 25.

wa_cat-seltext_m = 'ZCLASS'.

wa_cat-just = 'C'.

append wa_cat to field_cat.

wa_cat-fieldname = 'ZFEES'.

wa_cat-tabname = 'zyogstudent'.

wa_cat-outputlen = 25.

wa_cat-seltext_m = 'ZFEES'.

wa_cat-just = 'C'.

append wa_cat to field_cat.

wa_cat-fieldname = 'ZADD'.

wa_cat-tabname = 'zyogstudent'.

wa_cat-outputlen = 25.

wa_cat-seltext_m = 'ZADD'.

wa_cat-just = 'R'.

append wa_cat to field_cat.

endform. " field_init

&----


*& Form display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = 'sy-repid'

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_STRUCTURE_NAME = itab

I_GRID_TITLE = 'This is grid title'

IS_LAYOUT = xlayout

IT_FIELDCAT = FIELD_CAT

IT_SORT = i_sort

I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IT_EVENTS =

TABLES

t_outtab = itab.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

endform. " display