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

report

Former Member
0 Likes
618

I have internal table int_final with data to be diaplayed in report

Now what are the steps to show the ALV report, how to build a catalog, ALV et cetera

6 REPLIES 6
Read only

Former Member
0 Likes
592

Hi,

Refer to the following link:

http://sapdev.co.uk/reporting/alvhome.htm

Hope this helps.

Reward if helpful.

Regards,

Sipra

Read only

Former Member
0 Likes
592

Hi,

Please refer to below code :

Declare custom control CC_ALV in the screen(101).

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .

*--- Name of the custom control added on the screen

DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV' .

*--- Custom container instance reference

DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .

*--- Field catalog table

DATA gt_fieldcat TYPE lvc_t_fcat .

*--- Layout structure

DATA gs_layout TYPE lvc_s_layo .

CALL SCREEN 101.

&----


*& Module STATUS_0101 OUTPUT

&----


  • text

----


MODULE status_0101 OUTPUT.

SET PF-STATUS 'TEST'.

  • SET TITLEBAR 'xxx'.

PERFORM display_alv.

ENDMODULE. " STATUS_0101 OUTPUT

&----


*& Form display_alv

&----


  • text

----


FORM display_alv.

IF gr_alvgrid IS INITIAL.

*----Creating custom container instance

CREATE OBJECT gr_ccontainer

EXPORTING

container_name = gc_custom_control_name

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

OTHERS = 6.

IF sy-subrc <> 0.

*--exception handling

ENDIF.

*----Creating ALV Grid instance

CREATE OBJECT gr_alvgrid

EXPORTING

i_parent = gr_ccontainer

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

OTHERS = 5.

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

*----Preparing field catalog.

PERFORM prepare_field_catalog CHANGING gt_fieldcat .

*----Preparing layout structure

PERFORM prepare_layout CHANGING gs_layout .

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

is_layout = gs_layout

CHANGING

it_outtab = lt_test[](Table having data)

it_fieldcatalog = gt_fieldcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

ELSE .

CALL METHOD gr_alvgrid->refresh_table_display

EXCEPTIONS

finished = 1

OTHERS = 2.

IF sy-subrc <> 0.

*--exception handling

ENDIF.

ENDIF.

ENDFORM. "display_alv

&----


*& Form prepare_field_catalog

&----


  • text

----


  • -->PT_FIELDCAT text

----


FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .

DATA ls_fcat TYPE lvc_s_fcat .

ls_fcat-fieldname = 'NAME' .

ls_fcat-inttype = 'C' .

ls_fcat-outputlen = '10' .

ls_fcat-coltext = 'NAME' .

APPEND ls_fcat TO pt_fieldcat .

CLEAR ls_fcat .

ls_fcat-fieldname = 'CLASS1' .

ls_fcat-inttype = 'C' .

ls_fcat-outputlen = '10' .

ls_fcat-coltext = 'CLASS' .

ls_fcat-edit = 'X'.

APPEND ls_fcat TO pt_fieldcat .

CLEAR ls_fcat .

ENDFORM. "prepare_field_catalog

&----


*& Form prepare_layout

&----


  • text

----


  • -->PS_LAYOUT text

----


FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.

  • ps_layout-zebra = 'X' .

ps_layout-grid_title = 'STUDENT' .

ps_layout-smalltitle = 'X' .

ps_layout-sel_mode = 'D'.

ENDFORM. " prepare_layout

Give me your email ID so that I can send you ALV doc. for reference for several other options.

Reward points if it helps you.

Regards,

Mukul

Read only

Former Member
0 Likes
592

check this link... u might find it helpful....

http://www.sapbrainsonline.com/TUTORIALS/TECHNICAL/ALV_tutorial.html

Read only

Former Member
0 Likes
592

Hi,

I'd write a simple ALV report. You can refer to the following for the code.

REPORT zastest_2 .

  • Declare type-pools, tables and infotypes

TYPE-POOLS: slis.

TABLES: pernr.

INFOTYPES: 0001, 0002.

----


  • DATA

----


DATA: l_date(11) TYPE c,

l_gender(7) TYPE c.

DATA: l_line TYPE i VALUE 0.

TYPES: BEGIN OF t_emp,

pernr TYPE pa0002-pernr,

werks TYPE pa0001-werks, "personnel area

btrtl TYPE pa0001-btrtl, "personnel subarea

nachn TYPE pa0002-nachn, "last name

vorna TYPE pa0002-vorna, "first name

gesch(7) TYPE c, "gender

gbdat(11) TYPE c, "birth date

ftext TYPE fatxt, "marital status

END OF t_emp.

DATA: li_emp TYPE STANDARD TABLE OF t_emp INITIAL SIZE 0.

DATA: wa_emp TYPE t_emp.

  • To build ALV

DATA : wa_layout TYPE slis_layout_alv,

li_fieldcat TYPE slis_t_fieldcat_alv,

wa_fieldcat TYPE slis_fieldcat_alv.

&----


*& AT SELECTION-SCREEN

&----


START-OF-SELECTION.

GET pernr.

IF p0002-natio NE 'US'.

REJECT.

ENDIF.

----


  • pernr

----


wa_emp-pernr = pernr-pernr.

----


  • infotype 0001

----


wa_emp-werks = p0001-werks.

wa_emp-btrtl = p0001-btrtl.

----


  • infotype 0002

----


wa_emp-nachn = p0002-nachn.

wa_emp-vorna = p0002-vorna.

PERFORM format_gender USING p0002-gesch CHANGING l_gender.

wa_emp-gesch = l_gender.

  • birth date

IF p0002-gbdat <> ''.

PERFORM format_date USING p0002-gbdat CHANGING l_date.

wa_emp-gbdat = l_date.

ENDIF.

  • marital status

SELECT SINGLE ftext

INTO wa_emp-ftext

FROM t502t

WHERE famst EQ p0002-famst

AND sprsl EQ sy-langu.

  • append work area into itab

APPEND wa_emp TO li_emp.

CLEAR wa_emp.

END-OF-SELECTION.

DESCRIBE TABLE li_emp LINES l_line.

IF l_line GE 0.

PERFORM: build_layout,

build_fieldcat,

write_report.

ELSE.

MESSAGE e001(00) WITH 'No record found'.

ENDIF.

&----


*& Form format_date

&----


  • text

----


  • -->P_L_DATE text

  • <--P_L_DATE2 text

----


FORM format_date USING p_l_date

CHANGING p_l_date_format.

DATA: l_month(3) TYPE c.

CASE p_l_date+4(2).

WHEN '01'.

l_month = 'JAN'.

WHEN '02'.

l_month = 'FEB'.

WHEN '03'.

l_month = 'MAR'.

WHEN '04'.

l_month = 'APR'.

WHEN '05'.

l_month = 'MAY'.

WHEN '06'.

l_month = 'JUN'.

WHEN '07'.

l_month = 'JUL'.

WHEN '08'.

l_month = 'AUG'.

WHEN '09'.

l_month = 'SEP'.

WHEN '10'.

l_month = 'OCT'.

WHEN '11'.

l_month = 'NOV'.

WHEN '12'.

l_month = 'DEC'.

ENDCASE.

CONCATENATE p_l_date6(2) '-' l_month '-' p_l_date0(4) INTO

p_l_date_format.

ENDFORM. " format_date

&----


*& Form format_gender

&----


  • text

----


  • -->P_L_GENDER text

  • <--P_L_GENDER2 text

----


FORM format_gender USING p_l_gender

CHANGING p_l_gender_format.

IF p_l_gender = '1'.

p_l_gender_format = 'Male'.

ELSEIF p_l_gender = '2'.

p_l_gender_format = 'Female'.

ELSE.

p_l_gender_format = 'Unknown'.

ENDIF.

ENDFORM. " format_gender

&----


*& Form write_itab

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM write_itab .

LOOP AT li_emp INTO wa_emp.

WRITE: / sy-tabix, ') ', wa_emp-pernr, wa_emp-nachn, wa_emp-vorna,

wa_emp-gesch, wa_emp-gbdat, wa_emp-ftext.

ENDLOOP.

ENDFORM. " write_itab

&----


*& Form build_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_layout.

wa_layout-colwidth_optimize = 'X'.

wa_layout-zebra = 'X'.

wa_layout-no_input = 'X'.

wa_layout-window_titlebar = sy-title.

ENDFORM. "build_layout

&----


*& Form build_fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_fieldcat .

  • Assign variables to Table gt_fieldcat

PERFORM : build_fieldcat_assign USING '1' 'PERNR' 'Employee Number',

build_fieldcat_assign USING '2' 'WERKS' 'Personnel Area',

build_fieldcat_assign USING '3' 'BTRTL' 'Personnel Subarea',

build_fieldcat_assign USING '4' 'NACHN' 'Last Name',

build_fieldcat_assign USING '5' 'VORNA' 'First Name',

build_fieldcat_assign USING '6' 'GESCH' 'Gender',

build_fieldcat_assign USING '7' 'GBDAT' 'Birth Date',

build_fieldcat_assign USING '8' 'FTEXT' 'Marital Status'.

ENDFORM. " build_fieldcat

&----


*& Form build_fieldcat_assign

&----


  • text

----


  • -->P_0334 text

  • -->P_0335 text

  • -->P_0336 text

  • -->P_0337 text

----


FORM build_fieldcat_assign USING l_col_pos

l_fieldname

l_seltext_l.

wa_fieldcat-col_pos = l_col_pos.

wa_fieldcat-fieldname = l_fieldname.

wa_fieldcat-seltext_l = l_seltext_l.

  • Append and Clear

APPEND wa_fieldcat TO li_fieldcat.

CLEAR wa_fieldcat.

ENDFORM. " build_fieldcat_assign

&----


*& Form write_report

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM write_report .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = wa_layout

it_fieldcat = li_fieldcat

  • I_SAVE = ' '

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = li_emp

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.

ENDFORM. " write_report

Please reward if found useful.

Thanks, Loo

Read only

Former Member
0 Likes
592

Please learn to use the search function - this question has been asked countless times before.