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: 

ALV grid

Former Member
0 Kudos

Hi,

In a alv report , i got the output vth some layout ,but i would like to change the layout

instead of selecting each and evry time the select layout button i would like to make the layout that i would like to get as default .How to do that plz suggest

thanks in advance

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

good

check this code , which will help you to select the layout before executing the report

Define one field on selection screen

PARAMETERS: alv_def LIKE disvariant-variant.

To populate F4 help

AT SELECTION-SCREEN ON VALUE-REQUEST FOR alv_def.

PERFORM layout.

FORM layout .

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.

alv_def = gx_variant-variant.

ENDIF.

  • Get values from the selection screen to determine layout set

wal_dynpfields-fieldname = 'ALV_DEF'.

APPEND wal_dynpfields TO tl_dynpfields.

CALL FUNCTION 'DYNP_VALUES_READ'

EXPORTING

dyname = sy-cprog

dynumb = '1000'

  • TRANSLATE_TO_UPPER = ' '

  • REQUEST = ' '

  • PERFORM_CONVERSION_EXITS = ' '

  • PERFORM_INPUT_CONVERSION = ' '

  • DETERMINE_LOOP_INDEX = ' '

TABLES

dynpfields = tl_dynpfields

  • EXCEPTIONS

  • INVALID_ABAPWORKAREA = 1

  • INVALID_DYNPROFIELD = 2

  • INVALID_DYNPRONAME = 3

  • INVALID_DYNPRONUMMER = 4

  • INVALID_REQUEST = 5

  • NO_FIELDDESCRIPTION = 6

  • INVALID_PARAMETER = 7

  • UNDEFIND_ERROR = 8

  • DOUBLE_CONVERSION = 9

  • STEPL_NOT_FOUND = 10

  • OTHERS = 11

.

IF sy-subrc 0.

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

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

ENDIF.

READ TABLE tl_dynpfields INTO wal_dynpfields INDEX 1.

IF sy-subrc EQ 0.

g_variant-variant = wal_dynpfields-fieldvalue.

ENDIF.

g_variant-report = sy-repid.

g_variant-username = sy-uname.

**-- Display all existing 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.

alv_def = gx_variant-variant.

g_variant = gx_variant.

ELSE.

MESSAGE 'No layouts found' TYPE 'I'.

ENDIF.

ENDIF.

ENDFORM. " layout

Pass Exporting parameter is_variant = gx_variant in CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

thanks

mrutyun^

4 REPLIES 4

Former Member
0 Kudos

hi sukruthi,

you can perform the desired fucntionality by using VARIANTS IN ALV LAYOUT

THEY ARE CATEGORIZED AS:

1) ALV DEFAULT LAYOUT VARIANT - the variant whcih you will get as default

2) ALV f4 HELP - WHEN MORE THAN ONE VARIANT IS PASSEd, AND F4 IS PRESSED ON ELECTION SCREE

3) EXISTENCE CHECK OF VARIANT

refer to this simple code to understand the all the basic FM used in calling and using ALV LAYOUT VARIANTS

-


• Work Areas *

-


DATA : wa_variant TYPE disvariant, "Work area for variant

wa_variant1 TYPE disvariant, "Work area for variant

wa_layout TYPE slis_layout_alv, "Work area for layout

wa_print TYPE slis_print_alv, "Work area for print

wa_mara TYPE t_mara, "Work area for mara

wa_makt TYPE t_makt, "Work area for makt

wa_lqua TYPE t_lqua, "Work area for lqua

wa_mchb TYPE t_mchb, "Work area for mchb

wa_mard TYPE t_mard, "Work area for mard

wa_marc TYPE t_marc, "Work area for marc

wa_t320 TYPE t_t320, "Work area for t320

wa_batch TYPE t_batch, "Work area for batch

wa_pkhd TYPE t_pkhd, "Work area for pkhd

wa_whouse TYPE t_whouse, "Work area for whouse

wa_final LIKE i_final, "Work area for final

wa_mbew TYPE t_mbew, "Work area for mbew

wa_lgort TYPE t_lgort, "WOrk area for lgort

wa_fieldcat TYPE slis_fieldcat_alv."Work area for fieldcatalog

&----


*& Form sub_get_default_variant *

&----


• This form will initialize the variant *

-


FORM sub_get_default_variant .

*--Clear

CLEAR wa_variant.

*--Pass the report name

v_repid = sy-repid. "Report ID

wa_variant-report = v_repid.

*--Call the function module to get the default variant

CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'

EXPORTING

i_save = c_save

CHANGING

cs_variant = wa_variant1

EXCEPTIONS

wrong_input = 1

not_found = 2

program_error = 3

OTHERS = 4.

*--Check Subrc

IF sy-subrc = 0.

p_varnt = wa_variant-variant.

ENDIF.

ENDFORM. "sub_get_default_variant

&----


*& Form sub_create_events *

&----


• This form will display the ALV Events *

-


FORM sub_create_events .

*--Local Work Area

DATA: lwa_event TYPE slis_alv_event. "Work area for Events

*--Call Function to display the events for the ALV

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 1

IMPORTING

et_events = i_events.

*--Sort by Name

SORT i_events BY name.

*--Clear

CLEAR lwa_event.

READ TABLE i_events INTO lwa_event WITH KEY name = slis_ev_top_of_page

BINARY SEARCH.

IF sy-subrc = 0.

MOVE c_top_of_page TO lwa_event-form.

MODIFY i_events FROM lwa_event TRANSPORTING form WHERE

name = slis_ev_top_of_page.

ENDIF.

CLEAR : lwa_event.

ENDFORM. "sub_create_events

&----


*& Form sub_f4_for_variant *

&----


• This form will display the List of Variants *

-


FORM sub_f4_for_variant .

*--Local Variables

DATA: lv_exit(1) TYPE c. "ALV exit

*--Call the function module to display the list of Variants

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = wa_variant

i_save = c_save

IMPORTING

e_exit = lv_exit

es_variant = wa_variant1

EXCEPTIONS

not_found = 1

program_error = 2.

*--Check Subrc

IF sy-subrc 2 AND lv_exit IS INITIAL.

p_varnt = wa_variant1-variant.

ENDIF.

ENDFORM. "sub_f4_for_variant

&----


*& Form sub_check_variant *

&----


• This form will check the variant *

-


FORM sub_check_variant .

IF NOT p_varnt IS INITIAL.

CLEAR wa_variant1.

MOVE wa_variant TO wa_variant1.

MOVE p_varnt TO wa_variant1-variant.

*--Call the function module to check the variant exist

CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'

EXPORTING

i_save = c_save

CHANGING

cs_variant = wa_variant1.

wa_variant = wa_variant1.

ENDIF.

ENDFORM. "sub_check_variant

<REMOVED BY MODERATOR>

Rohan malik

Edited by: Alvaro Tejada Galindo on Feb 12, 2008 10:02 AM

Former Member
0 Kudos

Hi,

Fill up the fieldcatalog with all the fields of final output internal table and display and make it as default layout, basing on the user requirement he can choose the fields.

Thanks,

Sriram POnna.

Former Member
0 Kudos

hi

good

check this code , which will help you to select the layout before executing the report

Define one field on selection screen

PARAMETERS: alv_def LIKE disvariant-variant.

To populate F4 help

AT SELECTION-SCREEN ON VALUE-REQUEST FOR alv_def.

PERFORM layout.

FORM layout .

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.

alv_def = gx_variant-variant.

ENDIF.

  • Get values from the selection screen to determine layout set

wal_dynpfields-fieldname = 'ALV_DEF'.

APPEND wal_dynpfields TO tl_dynpfields.

CALL FUNCTION 'DYNP_VALUES_READ'

EXPORTING

dyname = sy-cprog

dynumb = '1000'

  • TRANSLATE_TO_UPPER = ' '

  • REQUEST = ' '

  • PERFORM_CONVERSION_EXITS = ' '

  • PERFORM_INPUT_CONVERSION = ' '

  • DETERMINE_LOOP_INDEX = ' '

TABLES

dynpfields = tl_dynpfields

  • EXCEPTIONS

  • INVALID_ABAPWORKAREA = 1

  • INVALID_DYNPROFIELD = 2

  • INVALID_DYNPRONAME = 3

  • INVALID_DYNPRONUMMER = 4

  • INVALID_REQUEST = 5

  • NO_FIELDDESCRIPTION = 6

  • INVALID_PARAMETER = 7

  • UNDEFIND_ERROR = 8

  • DOUBLE_CONVERSION = 9

  • STEPL_NOT_FOUND = 10

  • OTHERS = 11

.

IF sy-subrc 0.

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

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

ENDIF.

READ TABLE tl_dynpfields INTO wal_dynpfields INDEX 1.

IF sy-subrc EQ 0.

g_variant-variant = wal_dynpfields-fieldvalue.

ENDIF.

g_variant-report = sy-repid.

g_variant-username = sy-uname.

**-- Display all existing 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.

alv_def = gx_variant-variant.

g_variant = gx_variant.

ELSE.

MESSAGE 'No layouts found' TYPE 'I'.

ENDIF.

ENDIF.

ENDFORM. " layout

Pass Exporting parameter is_variant = gx_variant in CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

thanks

mrutyun^

0 Kudos

hi ,

i used the following code

while selecting varitents i am able to get 2 varients but it is not the layout i am looking for

how to make the layout default

could u explain vat was the addtional code i should add in the code plz explain clearly

FORM select_layout.

CLEAR: d_extfg,

gx_vari.

g_vari-report = sy-repid.

g_vari-username = sy-uname.

g_vari-variant = p_varia.

CALL FUNCTION 'LVC_VARIANT_F4'

EXPORTING

is_variant = g_vari

i_save = 'A'

IMPORTING

e_exit = d_extfg

es_variant = gx_vari

EXCEPTIONS

not_found = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

IF d_extfg IS INITIAL.

g_vari-variant = gx_vari-variant.

p_varia = gx_vari-variant.

ENDIF.

Endform.

plz respond

Edited by: sukruthi raj on Feb 12, 2008 4:33 PM