2006 Aug 06 11:00 PM
Hi friends,
I am working on a ALV report and I need to include a selection for the layout at selection screen. I went through the forum and found some code and included that code in my program. My program has the code
parameters: variant LIKE disvariant-variant.
at selection-screen on value-request for variant.
g_save = 'A'.
clear g_variant.
g_variant-report = sy-repid.
gx_variant = g_variant.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
I_SAVE = g_save
CHANGING
CS_VARIANT = gx_variant
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 0.
variant = gx_variant-variant.
ENDIF.
*at selection-screen on value-request for variant.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT = g_variant
I_SAVE = g_save
IMPORTING
E_EXIT = g_exit
ES_VARIANT = gx_variant
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 2.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF g_exit = SPACE.
variant = gx_variant-variant.
ENDIF.
ENDIF.
And I am passing to REUSE_ALV_GRID_DISPLAY
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = repid
IS_LAYOUT = layout
IT_FIELDCAT = field_body
IT_EXCLUDING = it_exclude
I_SAVE = g_save
IS_VARIANT = g_variant
IT_EVENTS = events
TABLES
T_OUTTAB = t_itab.
My problem is, after displaying the report I saved two layouts. One layout has 10 columns and the other 9 columns. I came back to the selection screen and performed input help for the 'layout' field. Now I see two layouts to select. But when I select anyone particular layout it is not displaying that layout. For example I have a layout which has 10 columns. I removed one column and saved the 9 columns into another layout. Now at the selection screen when I select the layout with 9 columns it is displaying all the ten columns. But actually it should display 9 columns. Can anyone findout what I am missing in my code.
Something urgent please help.... Waiting.........
2006 Aug 07 12:03 AM
Hi,
The value of the variant parameter should be passed to the PARAMETER IS_VARIANT (field variant with in the structure of IS_VARIANT).
IS_VARIANT-VARIANT = VARIANT.
Regards,
Ravi
Note : Please mark all the helpful answers
2006 Aug 06 11:53 PM
2006 Aug 07 12:03 AM
Hi,
The value of the variant parameter should be passed to the PARAMETER IS_VARIANT (field variant with in the structure of IS_VARIANT).
IS_VARIANT-VARIANT = VARIANT.
Regards,
Ravi
Note : Please mark all the helpful answers
2006 Aug 07 12:18 AM
2006 Aug 07 1:24 AM
Rich n Ravi,
I have a doubt. For the very first time executing my report there wont be any saved layouts i.e., when I go with the input help at the Layout field at selection screen it says no layouts found. What is the normal way of saving the layouts. Do we need to first display the output and then save the layout. PLease clarify.
In my case the number of columns I display is dynamic. Number of columns is not fixed. In that case how can save a layout I mean for how many columns I can save the layout. PLease clarify.
PLease help. Waiting.......
2006 Aug 07 1:26 AM
Hi,
Initially when you execute a report, there will not be any layouts. So, the user will have to create his / her own layouts for the report.
There is no restriction as such for the number of fields in a layout.
regards,
Ravi
Message was edited by: Ravikumar Allampallam
2006 Aug 07 1:38 AM
2013 Aug 28 8:49 AM
hi Raju , Rich n Ravi
I m getting exactly the same problem as described by raju....
could you please findout what i am missing in my code..?
parameters: variant LIKE disvariant-variant.
at selection-screen on value-request for variant.
g_save = 'A'.
clear g_variant.
g_variant-report = sy-repid.
gx_variant = g_variant.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
I_SAVE = g_save
CHANGING
CS_VARIANT = gx_variant
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 0.
variant = gx_variant-variant.
ENDIF.
*at selection-screen on value-request for variant.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT = g_variant
I_SAVE = g_save
IMPORTING
E_EXIT = g_exit
ES_VARIANT = gx_variant
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 2.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF g_exit = SPACE.
variant = gx_variant-variant.
ENDIF.
ENDIF.
And I am passing to REUSE_ALV_GRID_DISPLAY
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = repid
IS_LAYOUT = layout
IT_FIELDCAT = field_body
IT_EXCLUDING = it_exclude
I_SAVE = g_save
IS_VARIANT = g_variant
IT_EVENTS = events
TABLES
T_OUTTAB = t_itab.
2013 Aug 28 1:35 PM
Hi Pankaj,
In your code just replace like below bold text.
at selection-screen on value-request for variant.
g_save = 'A'.
clear g_variant.
g_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
I_SAVE = g_save
CHANGING
CS_VARIANT = g_variant
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 0.
variant = g_variant-variant.
ENDIF.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT = g_variant
I_SAVE = g_save
IMPORTING
E_EXIT = g_exit
ES_VARIANT = g_variant
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 2.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF g_exit = SPACE.
variant = g_variant-variant.
ENDIF.
ENDIF.
I hope it will resolve your issue.
Regards,
Venkat.
2013 Aug 28 1:54 PM
Hi,
I guess you are passing the variant to "variant" variable
variant = gx_variant-variant
then in REUSE_ALV_GRID_DISPLAY you are passing g_variant, which is empty. Please replace the above line by
g_variant = gx_variant-variant.
Regards,
Supratik
2013 Aug 29 5:59 AM
Hi Venkat n Supratik ,
First of all thanks for your inputs.
@ venkat :
when i am using g_variant then i am not getting any F4 help.
@ Supratik :
here "variant" is my parameter that i am taking as an input from the user .
if i replace this variant by g_variant , then it(parameter field in selection screen) is coming blank .
I have done some modifications in this code ..:
include zrfi_top.
include zrfi_d01.
include zrfi_f01.
PARAMETERS: P_VARI LIKE DISVARIANT-VARIANT. " This is the selection screen "parameter
INITIALIZATION.
G_REPID = SY-REPID.
perform variant_initz.
gx_variant = g_variant.
*perform VARIANT_EXIST_CHECK.
perform get_default_variant.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.
PERFORM F4_FOR_VARIANT1.
start-of-selection.
perform fill_output_table.
end-of-selection.
perform display_alv1.
*&---------------------------------------------------------------------*
*& Include ZRFI_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form VARIANT_EXIST_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
*FORM VARIANT_EXIST_CHECK .
*g_variant-variant = p_vari.
* g_variant-report = sy-repid.
* CALL FUNCTION 'LVC_VARIANT_EXISTENCE_CHECK' "Check for display variant
* EXPORTING
* i_save = g_save "Variants Can be Saved
* CHANGING
* cs_variant = g_variant "Variant information
* EXCEPTIONS
* wrong_input = 1 "Inconsistent input parameters
* not_found = 2 "Variant not found
* program_error = 3 "Program Errors
* . " LVC_VARIANT_EXISTENCE_CHECK
* IF sy-subrc = 2.
* MESSAGE 'Display Variant Not Found, Displaying Default Variant'
* TYPE 'S'.
* ENDIF.
*
*ENDFORM. " VARIANT_EXIST_CHECK
*&---------------------------------------------------------------------*
*& Form GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DEFAULT_VARIANT .
if p_vari is initial.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = g_save
CHANGING
cs_variant = gx_variant
EXCEPTIONS
not_found = 2.
IF sy-subrc = 0.
p_vari = gx_variant-variant.
endif.
endif.
ENDFORM. " GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
*& Form FILL_OUTPUT_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_OUTPUT_TABLE .
select * from mard into table i_mard
where matnr in s_matnr.
loop at i_mard.
select single maktx from makt into makt-maktx
where matnr = i_mard-matnr
and spras = 'E'.
if sy-subrc eq 0.
i_output-maktx = makt-maktx.
endif.
i_output-matnr = i_mard-matnr.
i_output-werks = i_mard-werks.
i_output-lgort = i_mard-lgort.
append i_output.
endloop.
ENDFORM. " FILL_OUTPUT_TABLE
*&---------------------------------------------------------------------*
*& Form VARIANT_INITZ
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM VARIANT_INITZ .
CLEAR g_variant.
g_save = 'A'.
g_variant-report = g_repid.
ENDFORM. " VARIANT_INITZ
*&---------------------------------------------------------------------*
*& Form F4_FOR_VARIANT1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F4_FOR_VARIANT1 .
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT = G_VARIANT
I_SAVE = G_SAVE
* I_TABNAME_HEADER = G_TABNAME_HEADER
*
* I_TABNAME_ITEM = G_TABNAME_ITEM
* it_default_fieldcat =
IMPORTING
E_EXIT = G_EXIT
ES_VARIANT = Gx_VARIANT
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 2.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF G_EXIT = SPACE.
P_VARI = GX_VARIANT-VARIANT.
ENDIF.
ENDIF.
ENDFORM. " F4_FOR_VARIANT1
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_ALV1 .
perform fieldcatalog.
g_variant = p_vari.
g_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
*• I_INTERFACE_CHECK = ' '
*
*• I_BYPASSING_BUFFER =
*
*• I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = g_repid
*• I_CALLBACK_PF_STATUS_SET = ' '
*
*• I_CALLBACK_USER_COMMAND = ' '
*
*• I_CALLBACK_TOP_OF_PAGE = ' '
*
*• I_CALLBACK_HTML_TOP_OF_PAGE = ' '
*
*• I_CALLBACK_HTML_END_OF_LIST = ' '
*
*• I_STRUCTURE_NAME =
*
*• I_BACKGROUND_ID = ' '
*
*• I_GRID_TITLE =
*
*• I_GRID_SETTINGS =
*
*• IS_LAYOUT =
IT_FIELDCAT = i_field
*• IT_EXCLUDING =
*
*• IT_SPECIAL_GROUPS =
*
*• IT_SORT =
*
*• IT_FILTER =
*
*• IS_SEL_HIDE =
*
*• I_DEFAULT = 'X'
I_SAVE = g_save
IS_VARIANT = g_variant
*• IT_EVENTS = gt_events[]
*
*• IT_EVENT_EXIT =
*
*• IS_PRINT =
*
*• IS_REPREP_ID =
*
*• I_SCREEN_START_COLUMN = 0
*
*• I_SCREEN_START_LINE = 0
*
*• I_SCREEN_END_COLUMN = 0
*
*• I_SCREEN_END_LINE = 0
*
*• IT_ALV_GRAPHICS =
*
*• IT_ADD_FIELDCAT =
*
*• IT_HYPERLINK =
*
*• I_HTML_HEIGHT_TOP =
*
*• I_HTML_HEIGHT_END =
*
*• IT_EXCEPT_QINFO =
*
*•IMPORTING
*
*• E_EXIT_CAUSED_BY_CALLER =
*
*• ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = i_output
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_ALV1
*&---------------------------------------------------------------------*
*& Form FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FIELDCATALOG .
clear wa_field.
wa_field-tabname = 'I_OUTPUT'.
wa_field-fieldname = 'MATNR'.
wa_field-seltext_l = 'Material'.
wa_field-seltext_m = 'Material'.
wa_field-seltext_s = 'Material'.
append wa_field to i_field.
clear wa_field.
wa_field-tabname = 'I_OUTPUT'.
wa_field-fieldname = 'WERKS'.
wa_field-seltext_l = 'Plant'.
wa_field-seltext_m = 'Plant'.
wa_field-seltext_s = 'Plant'.
append wa_field to i_field.
clear wa_field.
wa_field-tabname = 'I_OUTPUT'.
wa_field-fieldname = 'LGORT'.
wa_field-seltext_l = 'Storage Location'.
wa_field-seltext_m = 'Stroage loaction'.
wa_field-seltext_s = 'Storage Location'.
append wa_field to i_field.
clear wa_field.
wa_field-tabname = 'I_OUTPUT'.
wa_field-fieldname = 'MAKTX'.
wa_field-seltext_l = 'Desc'.
wa_field-seltext_m = 'Desc'.
wa_field-seltext_s = 'Desc'.
append wa_field to i_field.
ENDFORM. " FIELDCATALOG
2013 Aug 29 6:55 AM
Hi Raju Boda,
See this code and try like this...
TABLES : sflight.
TYPE-POOLS : slis.
**INTERNAL TABLE DECLARTION
DATA : wa_sflight TYPE sflight,
it_sflight TYPE TABLE OF sflight.
**DATA DECLARTION
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid,
g_save TYPE c VALUE 'X',
g_variant TYPE disvariant,
gx_variant TYPE disvariant,
g_exit TYPE c,
ispfli TYPE TABLE OF spfli.
* To understand the importance of the following parameter, click here.
**SELECTION SCREEN DETAILS
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002 .
PARAMETERS: variant LIKE disvariant-variant.
SELECTION-SCREEN END OF BLOCK b1.
**GETTING DEFAULT VARIANT
INITIALIZATION.
gx_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = g_save
CHANGING
cs_variant = gx_variant
EXCEPTIONS
not_found = 2.
IF sy-subrc = 0.
variant = gx_variant-variant.
ENDIF.
** F4 Help for Varient
AT SELECTION-SCREEN ON VALUE-REQUEST FOR variant.
**-- Display all existing variants
g_variant-report = sy-repid.
* Utilizing the name of the report, this function module will search for a list of
* variants and will fetch the selected one into the parameter field for variants
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = g_variant
i_save = g_save
IMPORTING
e_exit = g_exit
es_variant = gx_variant
EXCEPTIONS
not_found = 2.
IF sy-subrc = 2.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
IF g_exit = space.
variant = gx_variant-variant.
ENDIF.
ENDIF.
**PERFORM DECLARATIONS
START-OF-SELECTION.
PERFORM data_retrivel.
PERFORM build_fieldcatalog.
PERFORM check_variant.
PERFORM display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
fieldcatalog-fieldname = 'CARRID'.
fieldcatalog-seltext_m = 'Airline Code'.
fieldcatalog-col_pos = 0.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'CONNID'.
fieldcatalog-seltext_m = 'Flight Connection Number'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog. fieldcatalog-fieldname = 'FLDATE'.
fieldcatalog-seltext_m = 'Flight date'.
fieldcatalog-col_pos = 2.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog. fieldcatalog-fieldname = 'PRICE'.
fieldcatalog-seltext_m = 'Airfare'.
fieldcatalog-col_pos = 3.
fieldcatalog-outputlen = 20.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_alv_report .
gd_repid = sy-repid.
g_variant-variant = variant.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = fieldcatalog[]
i_save = 'X'
is_variant = g_variant
TABLES
t_outtab = it_sflight
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" DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIVEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM data_retrivel .
SELECT * FROM sflight INTO TABLE it_sflight.
ENDFORM. " DATA_RETRIVEL
*-------------------------------------------------------------------*
* 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 = 'SFLIGHT 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. "Today's date
APPEND wa_header TO t_header.
CLEAR: wa_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
ENDFORM. "Top-of-page
*&---------------------------------------------------------------------*
*& Form CHECK_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check_variant .
g_variant-variant = variant.
g_variant-report = sy-repid.
CALL FUNCTION 'LVC_VARIANT_EXISTENCE_CHECK'
EXPORTING
i_save = space
CHANGING
cs_variant = g_variant
EXCEPTIONS
wrong_input = 1
not_found = 2
program_error = 3
.
IF sy-subrc = 2.
MESSAGE 'Display Variant Not Found, Displaying Default Variant'
TYPE 'S'.
ENDIF.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = g_save
CHANGING
cs_variant = gx_variant
EXCEPTIONS
not_found = 2.
IF sy-subrc = 0.
variant = gx_variant-variant.
ENDIF.
ENDFORM. "CHECK_VARIANT
if select testing1 three fields display
if you select testing2 output like this
Regards,
Ramesh.T
2013 Aug 29 7:07 AM
Hi,
In which tcode the above variants testing1 and testing 2 have been created?
Regards
Purnand
2013 Aug 29 7:13 AM
Hi All ,
I got it..
it's working now.
The issue was in g_variant values before calling FM
'REUSE_ALV_GRID_DISPLAY' .
previously , i was doing this:
g_variant = p_vari.
g_variant-report = sy-repid.
this is incorrect.
Correct Solution :
g_variant-variant = p_vari.
g_variant-report = sy-repid.
Thanks to all for your help.
2013 Aug 29 7:23 AM
Hi Purnand Dhingra,
For above program only...
Like this
Copy above program in se38
then execute it with out variant like this
do like this
click save layout
layout creates like this.
like that create testing2 also
and run once again your program then you will get the layouts in selection screen.
2013 Aug 29 9:28 AM
Good....
Then this thread posted by Former Member, so he should close this thread...