2012 Jul 28 5:36 AM
Hi,
ALV Column Width Issue
I want to fix my width of columns in my ALV attached is snapshot of my report please guide me
Regards
2012 Jul 28 6:07 AM
Hiiii,
Just do this ,
In your fieldcatalog set property
<FIELD_CAT_NAME>-outputlen = <specify length>. or provide your code .
2012 Jul 28 6:06 AM
In the layout options , you will ahve a field colwidth_optimize , set the value of that to 'X'
2012 Jul 28 6:12 AM
Hi,
Please check i have done like this, but nothing gonna happen
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = '20'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
gd_layout-expand_fieldname = 'EXPAND'.
gd_layout-window_titlebar = 'Hierarchical ALV list display'.
gd_layout-lights_tabname = 'it_proj'.
gd_layout-colwidth_optimize = 'X'.
2012 Jul 28 6:31 AM
Your issue is that for the first field Serial Number, you have set the Output length as '10' for Header in field catalog, but your internal table which prints the output for the Serial Number has a length less than a length of 10.
Ensure that both are of the same length, either reduce the length of the Field catalog or increase the llength of the field in ur internal table...
2012 Jul 28 10:30 AM
Hi,
gd_layout-colwidth_optimize
colwidth_optimize is a flag with possible values 'X' and space. 'X' means all columns and headers have the width they need to display full content.
You can not set any width if colwidth_optimize is enabled.
Regards,
Clemens
2012 Jul 28 6:07 AM
Hiiii,
Just do this ,
In your fieldcatalog set property
<FIELD_CAT_NAME>-outputlen = <specify length>. or provide your code .
2012 Jul 28 6:13 AM
Helloo,
Below is my code please guide me
form build_fieldcatalog.
fieldcatalog-fieldname = 'SNO'.
fieldcatalog-seltext_m = 'Serial number'.
fieldcatalog-col_pos = 1.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POSTU'.
fieldcatalog-seltext_m = 'Description'.
fieldcatalog-col_pos = 2.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
2012 Jul 28 6:38 AM
Hiii,
As per your earlier post i saw code and modify it . now you can see this example your column has been adjusted properly check below code ..... changes shows in bold font.
*&---------------------------------------------------------------------*
*& Report ZASHPROG1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZASHPROG1.
TABLES: proj, prps, afvc, afvv, afvu, cosp, coss.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF p_proj,
SNO TYPE int4,
* v_sno(6) type c,
pspid TYPE proj-pspid,
ernam TYPE proj-ernam,
stspr TYPE proj-stspr,
pwhie TYPE proj-pwhie,
besta TYPE proj-besta,
scope TYPE proj-scope,
xstat TYPE proj-xstat,
postu TYPE proj-postu,
smprf TYPE proj-smprf,
erdat TYPE prps-erdat,
a type i,
b type i,
c type i,
END OF p_proj.
*DATA: IT_PRPS TYPE TABLE OF PRPS.
DATA: it_proj TYPE STANDARD TABLE OF p_proj,
wa_proj TYPE p_proj,
VSNO TYPE INT4.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
VSNO = VSNO + 1.
* it_proj-SNO = VSNO.
form build_fieldcatalog.
fieldcatalog-fieldname = 'SNO'.
fieldcatalog-seltext_m = 'Serial number'.
fieldcatalog-col_pos = 1.
* fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-just = 'L'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PSPID'.
fieldcatalog-seltext_m = 'Purchase Order'.
* fieldcatalog-REF_TABNAME = 'PROJ'.
fieldcatalog-col_pos = 2.
* fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'A'.
fieldcatalog-seltext_m = 'A'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'B'.
fieldcatalog-seltext_m = 'B'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'C'.
fieldcatalog-seltext_m = ' C = Sum a + b'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERNAM'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STSPR'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 7.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PWHIE'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BESTA'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 9.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SCOPE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 10.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'XSTAT'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 11.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POSTU'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 12.
* fieldcatalog-outputlen = 15.
* fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SMPRF'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 13.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERDAT'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 14.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
gd_layout-zebra = 'X'.
* gd_layout-colwidth_optimize = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
* gd_layout-expand_fieldname = 'EXPAND'.
*
* gd_layout-window_titlebar = 'Hierarchical ALV list display'.
*
* gd_layout-lights_tabname = 'IT_PROJ'.
* gd_layout-colwidth_optimize = 'X'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = gd_repid
* i_callback_top_of_page = 'TOP_OF_PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tab_group
* IT_EVENTS = GT_XEVENTS
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_proj
* t_outtabnew = it_prps
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. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
select PSPID ERNAM STSPR PWHIE BESTA SCOPE XSTAT POSTU SMPRF from proj into corresponding fields of table it_proj.
SELECT ERDAT INTO PRPS-ERDAT "Cost Center Id and Description
FROM PRPS. "AND SPRAS = 'E'.
ENDSELECT.
LOOP AT it_proj INTO wa_proj .
wa_proj-sno = sy-tabix.
wa_proj-a = sy-tabix.
wa_proj-b = sy-tabix * 2.
wa_proj-c = wa_proj-a + wa_proj-b.
MODIFY it_proj FROM wa_proj TRANSPORTING SNO a b c.
CLEAR wa_proj.
ENDLOOP.
*select ERDAT from prps into corresponding fields of table it_proj.
*select * from prps into corresponding fields of table it_PRPS.
endform. " DATA_RETRIEVAL
*up to 10 rows
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
*-------------------------------------------------------------------*
* Form TOP-OF-PAGE *
*-------------------------------------------------------------------*
* ALV Report Header *
*-------------------------------------------------------------------*
Form top_of_page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
* Total No. of Records Selected
describe table it_proj lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
* i_logo = 'Z_LOGO'.
endform.
2012 Jul 28 7:10 AM
Hi,
Its very helpful for me but my code has been alot changed since last couple of days, so if possible kindly make these changes in my updated code, which written below
Add Columns for SUM
Adjust columns width
CODE
*&---------------------------------------------------------------------*
*& Report /BWN0/Z_PROJECT_SUMMERY
* created by sarosh durrani
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT /BWN0/Z_PROJECT_SUMMERY.
TABLES: proj, prps, afvc, afvv, afvu, cosp, coss.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF p_proj,
SNO TYPE int4,
* v_sno(6) type c,
pspid TYPE proj-pspid,
pspnr TYPE proj-pspnr,
ernam TYPE proj-ernam,
stspr TYPE proj-stspr,
pwhie TYPE proj-pwhie,
besta TYPE proj-besta,
scope TYPE proj-scope,
xstat TYPE proj-xstat,
postu TYPE proj-postu,
smprf TYPE proj-smprf,
erdat TYPE proj-erdat,
post1 TYPE proj-post1,
sakto TYPE afvc-sakto,
END OF p_proj.
TYPES: BEGIN OF pl_afvc,
* SNO TYPE int4,
sakto TYPE afvc-sakto,
projn TYPE afvc-projn,
psphi TYPE prps-psphi,
END OF pl_afvc.
*DATA: IT_PRPS TYPE TABLE OF PRPS.
DATA: it_proj TYPE STANDARD TABLE OF p_proj WITH HEADER LINE,
it_afvc TYPE STANDARD TABLE OF pl_afvc WITH HEADER LINE,
wa_proj TYPE p_proj,
VSNO TYPE INT4.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
VSNO = VSNO + 1.
* it_proj-SNO = VSNO.
form build_fieldcatalog.
fieldcatalog-fieldname = 'SNO'.
fieldcatalog-seltext_m = 'Serial number'.
fieldcatalog-col_pos = 1.
fieldcatalog-outputlen = 5.
* fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POSTU'.
fieldcatalog-seltext_m = 'Description'.
fieldcatalog-col_pos = 2.
fieldcatalog-outputlen = 50.
fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERNAM'.
fieldcatalog-seltext_m = 'Quantity'.
fieldcatalog-col_pos = 3.
fieldcatalog-outputlen = 20.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STSPR'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PWHIE'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BESTA'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SCOPE'.
fieldcatalog-seltext_m = 'Crane'.
fieldcatalog-col_pos = 7.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'XSTAT'.
fieldcatalog-seltext_m = 'Total'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PSPID'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 9.
* fieldcatalog-outputlen = 15.
* fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SMPRF'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 10.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERDAT'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 11.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POST1'.
fieldcatalog-seltext_m = 'Erection1'.
fieldcatalog-col_pos = 12.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SAKTO'.
fieldcatalog-seltext_m = 'Cost Element'.
fieldcatalog-col_pos = 13.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = '30'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
gd_layout-expand_fieldname = 'EXPAND'.
gd_layout-window_titlebar = 'Hierarchical ALV list display'.
gd_layout-lights_tabname = 'it_proj'.
gd_layout-colwidth_optimize = '30'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = gd_repid
* i_callback_top_of_page = 'TOP_OF_PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tab_group
* IT_EVENTS = GT_XEVENTS
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_proj
* t_outtabnew = it_prps
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. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
*select PSPID ERNAM STSPR PWHIE BESTA SCOPE XSTAT POSTU SMPRF ERDAT from proj into corresponding fields of table it_proj.
select * from proj into corresponding fields of table it_proj.
select afvc~sakto afvc~projn prps~psphi FROM afvc INNER JOIN prps
ON AFVC~PROJN = PRPS~PSPNR into corresponding fields of table it_afvc FOR ALL ENTRIES IN it_proj WHERE PRPS~PSPHI = it_PROJ-PSPNR .
LOOP AT it_proj INTO wa_proj .
wa_proj-sno = sy-tabix.
READ TABLE it_afvc with key psphi = wa_proj-pspnr .
IF sy-SUBRC eq 0.
wa_proj-sakto = it_afvc-sakto.
ENDIF.
MODIFY it_proj FROM wa_proj TRANSPORTING SNO sakto .
CLEAR wa_proj.
ENDLOOP.
endform. " DATA_RETRIEVAL
*up to 10 rows
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
*-------------------------------------------------------------------*
* Form TOP-OF-PAGE *
*-------------------------------------------------------------------*
* ALV Report Header *
*-------------------------------------------------------------------*
Form top_of_page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
* Total No. of Records Selected
describe table it_proj lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
* i_logo = 'Z_LOGO'.
endform. "top_of_page
2012 Jul 28 7:21 AM
Hiii,
Check below modified code .... if you need more help tell me
*&---------------------------------------------------------------------*
*& Report /BWN0/Z_PROJECT_SUMMERY
* created by sarosh durrani
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
TABLES: proj, prps, afvc, afvv, afvu, cosp, coss.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF p_proj,
SNO TYPE int4,
* v_sno(6) type c,
pspid TYPE proj-pspid,
pspnr TYPE proj-pspnr,
ernam TYPE proj-ernam,
stspr TYPE proj-stspr,
pwhie TYPE proj-pwhie,
besta TYPE proj-besta,
scope TYPE proj-scope,
xstat TYPE proj-xstat,
postu TYPE proj-postu,
smprf TYPE proj-smprf,
erdat TYPE proj-erdat,
post1 TYPE proj-post1,
sakto TYPE afvc-sakto,
a type i,
b type i,
c type i,
END OF p_proj.
TYPES: BEGIN OF pl_afvc,
* SNO TYPE int4,
sakto TYPE afvc-sakto,
projn TYPE afvc-projn,
psphi TYPE prps-psphi,
END OF pl_afvc.
*DATA: IT_PRPS TYPE TABLE OF PRPS.
DATA: it_proj TYPE STANDARD TABLE OF p_proj WITH HEADER LINE,
it_afvc TYPE STANDARD TABLE OF pl_afvc WITH HEADER LINE,
wa_proj TYPE p_proj,
VSNO TYPE INT4.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
VSNO = VSNO + 1.
* it_proj-SNO = VSNO.
form build_fieldcatalog.
fieldcatalog-fieldname = 'SNO'.
fieldcatalog-seltext_m = 'Serial number'.
fieldcatalog-col_pos = 1.
* fieldcatalog-outputlen = 5.
* fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POSTU'.
fieldcatalog-seltext_m = 'Description'.
fieldcatalog-col_pos = 2.
fieldcatalog-outputlen = 50.
fieldcatalog-emphasize = 'C170'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERNAM'.
fieldcatalog-seltext_m = 'Quantity'.
fieldcatalog-col_pos = 3.
fieldcatalog-outputlen = 20.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STSPR'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PWHIE'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BESTA'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SCOPE'.
fieldcatalog-seltext_m = 'Crane'.
fieldcatalog-col_pos = 7.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'XSTAT'.
fieldcatalog-seltext_m = 'Total'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PSPID'.
fieldcatalog-seltext_m = 'Ex-Factory'.
fieldcatalog-col_pos = 9.
* fieldcatalog-outputlen = 15.
* fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SMPRF'.
fieldcatalog-seltext_m = 'Delivery'.
fieldcatalog-col_pos = 10.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ERDAT'.
fieldcatalog-seltext_m = 'Erection'.
fieldcatalog-col_pos = 11.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'POST1'.
fieldcatalog-seltext_m = 'Erection1'.
fieldcatalog-col_pos = 12.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SAKTO'.
fieldcatalog-seltext_m = 'Cost Element'.
fieldcatalog-col_pos = 13.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'A'.
fieldcatalog-seltext_m = 'A'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'B'.
fieldcatalog-seltext_m = 'B'.
* fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'C'.
fieldcatalog-seltext_m = ' C = Sum a + b'.
* fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = '30'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
* gd_layout-expand_fieldname = 'EXPAND'.
*
* gd_layout-window_titlebar = 'Hierarchical ALV list display'.
*
* gd_layout-lights_tabname = 'it_proj'.
*
* gd_layout-colwidth_optimize = '30'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = gd_repid
* i_callback_top_of_page = 'TOP_OF_PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tab_group
* IT_EVENTS = GT_XEVENTS
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_proj
* t_outtabnew = it_prps
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. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
*select PSPID ERNAM STSPR PWHIE BESTA SCOPE XSTAT POSTU SMPRF ERDAT from proj into corresponding fields of table it_proj.
select * from proj into corresponding fields of table it_proj.
select afvc~sakto afvc~projn prps~psphi FROM afvc INNER JOIN prps
ON AFVC~PROJN = PRPS~PSPNR into corresponding fields of table it_afvc FOR ALL ENTRIES IN it_proj WHERE PRPS~PSPHI = it_PROJ-PSPNR .
LOOP AT it_proj INTO wa_proj .
wa_proj-sno = sy-tabix.
READ TABLE it_afvc with key psphi = wa_proj-pspnr .
IF sy-SUBRC eq 0.
wa_proj-sakto = it_afvc-sakto.
ENDIF.
wa_proj-a = sy-tabix.
wa_proj-b = sy-tabix * 2.
wa_proj-c = wa_proj-a + wa_proj-b.
MODIFY it_proj FROM wa_proj TRANSPORTING SNO sakto a b c.
CLEAR wa_proj.
ENDLOOP.
endform. " DATA_RETRIEVAL
*up to 10 rows
*PARAMETER: CURRDATE TYPE EKPO-AEDAT.
*SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.
*-------------------------------------------------------------------*
* Form TOP-OF-PAGE *
*-------------------------------------------------------------------*
* ALV Report Header *
*-------------------------------------------------------------------*
Form top_of_page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
* Total No. of Records Selected
describe table it_proj lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
* i_logo = 'Z_LOGO'.
endform. "top_of_page
2012 Jul 28 12:36 PM
Data: gt_layout TYPE slis_layout_alv OCCURS 0 WITH HEADER LINE.
gt_layout-colwidth_optimize ='X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'
I_CALLBACK_USER_COMMAND = ' '
i_callback_top_of_page = 'TOP_OF_PAGE'
i_grid_title = '
* I_GRID_SETTINGS =
is_layout = gt_layout
* it_events = gt_event
i_save = 'A'
it_fieldcat = gt_fieldcat
TABLES
t_outtab = gt_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
TRY like this it will help u.