Skip to Content
author's profile photo Former Member
Former Member

printing alv report with predefined layout

how to set a layout as default for printing..

my report has 20 coloumsn,i need 20 to be displayed but while printing ..i need to print only 12

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 27, 2008 at 10:01 AM

    Hi,

    Use this function module.

    CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'

    Then define the layout from the output and there will be a option to save that. Save that and you can set that as a default one . So you that every time you print.

    Check the below code for reference.

    
    REPORT  ZMK_ALV_VARIANT.
    TABLES: vbak.
    
    TYPE-POOLS: slis.
    
    
    SELECTION-SCREEN: BEGIN OF BLOCK b1.
    SELECT-OPTIONS: cust FOR vbak-kunnr.
    PARAMETERS: p_varint TYPE disvariant-variant,
                p_save TYPE c DEFAULT 'A' NO-DISPLAY.
    SELECTION-SCREEN: END OF BLOCK b1.
    
    
    TYPES: BEGIN OF ty_vbak,
            kunnr TYPE kunnr,
            vbeln TYPE vbeln,
            erdat TYPE erdat,
            erzet TYPE erzet,
            ernam TYPE ernam,
            netwr type netwr,
            POSNR type posnr,
            MATNR type matnr,
            MATKL type matkl,
          END OF ty_vbak.
    
    
    DATA: i_vbak TYPE TABLE OF ty_vbak,
          W_VBAK TYPE TY_VBAK,
          i_fieldcat TYPE slis_t_fieldcat_alv,
          W_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
          I_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
          ln_layoutinfo TYPE slis_layout_alv,
          I_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
          I_SORT TYPE SLIS_T_SORTINFO_ALV,
          W_SORT TYPE slis_sortinfo_alv.
    
    DATA: i_variant TYPE disvariant,
          i_variant1 TYPE disvariant,
          g_znsi_alv_exit TYPE c,
          repid TYPE sy-repid,
          i_event type slis_t_event.
    constants: "C_FORMNAME_top_OF_PAGE TYPE SLIS_FORMNAME value 'TOP_OF_PAGE',
               c_formname_usercommand type slis_formname value 'USER_COMMAND',
               c_formname_subtotal_text TYPE slis_formname VALUE 'SUBTOTAL_TEXT'.
    
    INITIALIZATION.
      repid = sy-repid.
      PERFORM fieldcat.
      PERFORM init.
      i_variant = i_variant1.
    
      CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
        EXPORTING
          i_save     = p_save
        CHANGING
          cs_variant = i_variant
        EXCEPTIONS
          NOT_FOUND  = 2.
      IF sy-subrc = 0.
        p_varint = i_variant-variant.
      ENDIF.
    
    
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varint.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant = i_variant1
          i_save     = p_save
        IMPORTING
          e_exit     = g_znsi_alv_exit
          es_variant = i_variant
    
           EXCEPTIONS
       NOT_FOUND                 = 2.
    
      IF sy-subrc = 2.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        IF g_znsi_alv_exit = space.
          p_varint = i_variant-variant.
        ENDIF.
    
      ENDIF.
    
    AT SELECTION-SCREEN.
      PERFORM existance.
    
    START-OF-SELECTION.
      SELECT vbak~kunnr
             vbak~vbeln
             vbak~erdat
             vbak~erzet
             vbak~ernam
             vbak~netwr
             vbap~posnr
             vbap~matnr
             vbap~matkl
             INTO TABLE i_vbak
             FROM vbak inner join vbap
             on vbak~vbeln = vbap~vbeln
             WHERE vbak~kunnr IN cust.
    
    END-OF-SELECTION.
      PERFORM layout.
    *  perform event using i_event.
      perform display.
    
    *&---------------------------------------------------------------------*
    *&      Form  fieldcat
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM fieldcat .
    w_fieldcat-fieldname = 'NETWR'.
    W_FIELDCAT-DO_SUM = 'X'.
    W_FIELDCAT-TABNAME = 'I_VBAK'.
    W_FIELDCAT-SELTEXT_M = 'AMOUNT'.
    W_FIELDCAT-REF_TABNAME = 'VBAK'.
    W_FIELDCAT-COL_POS = '9'.
    APPEND W_FIELDCAT TO I_FIELDCAT.
    
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
       I_PROGRAM_NAME               = repid
       I_INTERNAL_TABNAME           = 'I_VBAK'
       I_STRUCTURE_NAME             = 'ZVBAKP'
    *   I_CLIENT_NEVER_DISPLAY       = 'X'
    *   I_INCLNAME                   =
    *   I_BYPASSING_BUFFER           =
    *   I_BUFFER_ACTIVE              =
      CHANGING
        ct_fieldcat                  = I_FIELDCAT
    * EXCEPTIONS
    *   INCONSISTENT_INTERFACE       = 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.
    
    
    LOOP AT I_FIELDCAT INTO W_FIELDCAT.
    IF W_FIELDCAT-FIELDNAME = 'NETWR'.
    W_FIELDCAT-do_sum = 'X'.
    w_fieldcat-key = 'X'.
    *w_fieldcat-datatype = 'CURR'.
    elseif w_fieldcat-fieldname = 'ERNAM'.
    
    ENDIF.
    APPEND W_FIELDCAT TO I_FIELDCAT1.
    ENDLOOP.
    
    
    ENDFORM.                    " fieldcat
    
    *&---------------------------------------------------------------------*
    *&      Form  existance
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM existance.
      IF p_varint IS NOT INITIAL.
        MOVE i_variant1 TO i_variant.
        MOVE p_varint TO i_variant-variant.
        CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
         EXPORTING
           i_save              = p_save
          CHANGING
            cs_variant          = i_variant
    * EXCEPTIONS
    *   WRONG_INPUT         = 1
    *   NOT_FOUND           = 2
    *   PROGRAM_ERROR       = 3
    *   OTHERS              = 4
                  .
        i_variant1 = i_variant.
       ELSE.
        PERFORM init.
      ENDIF.
    ENDFORM.                    "existance
    *&---------------------------------------------------------------------*
    *&      Form  init
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM init .
      CLEAR i_variant1.
      i_variant1-report = repid.
    
    ENDFORM.                    " init
    *&---------------------------------------------------------------------*
    *&      Form  layout
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM layout .
      ln_layoutinfo-expand_all = 'X'.
    *ln_layoutinfo-colwidth_optimize = p_optimize_cols.
      ln_layoutinfo-no_min_linesize = space.
      ln_layoutinfo-zebra = 'X'.
      ln_layoutinfo-detail_popup = 'X'.
      ln_layoutinfo-detail_initial_lines = 'X'.
    *ln_layoutinfo-get_selinfos = pselinfo.
    ln_layoutinfo-totals_text = 'Grandtotal'.
    ln_layoutinfo-subtotals_text = 'Sub-total'.
    ENDFORM.                    " layout
    *&---------------------------------------------------------------------*
    *&      Form  display
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    form display .
    data: w_excluding type SLIS_EXTAB,
          i_excluding type SLIS_T_EXTAB.
    
      w_excluding-fcode = '&RNT_PREV'.
      APPEND w_excluding TO i_excluding.
    
    W_SORT-fieldname = 'KUNNR'.
    W_SORT-tabname = 'I_VBAK'.
    W_SORT-up = 'X'."alvdynp-sortup,
    W_SORT-subtot = 'X'. "like alvdynp-subtotals,
    APPEND W_SORT TO I_SORT.
    
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
    *   I_INTERFACE_CHECK                 = ' '
    *   I_BYPASSING_BUFFER                = ' '
    *   I_BUFFER_ACTIVE                   = ' '
       I_CALLBACK_PROGRAM                = sy-repid
    *   I_CALLBACK_PF_STATUS_SET          = 'SET_PF_STATUS'
    *   I_CALLBACK_USER_COMMAND           = 'PRINTPREVIEW'
       I_CALLBACK_TOP_OF_PAGE            = 'LOGO'
    *   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                         = ln_layoutinfo
       IT_FIELDCAT                       = i_fieldcat1
       IT_EXCLUDING                      = i_excluding
    *   IT_SPECIAL_GROUPS                 =
       IT_SORT                           = I_SORT
    *   IT_FILTER                         =
    *   IS_SEL_HIDE                       =
    *   I_DEFAULT                         = 'X'
       I_SAVE                            = 'X'
       IS_VARIANT                        = i_variant1
       IT_EVENTS                         = i_event[]
    *   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
    *   I_HTML_HEIGHT_TOP                 = 0
    *   I_HTML_HEIGHT_END                 = 0
    *   IT_ALV_GRAPHICS                   =
    *   IT_HYPERLINK                      =
    *   IT_ADD_FIELDCAT                   =
    *   IT_EXCEPT_QINFO                   =
    *   IR_SALV_FULLSCREEN_ADAPTER        =
    * IMPORTING
    *   E_EXIT_CAUSED_BY_CALLER           =
    *   ES_EXIT_CAUSED_BY_USER            =
      TABLES
        t_outtab                          = I_VBAK
    * 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
    

    reward if useful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 28, 2008 at 03:47 AM

    Hi Gaurav, 1. When we call function module REUSE_ALV_GRID_DISPLAY, pass I_SAVE = 'X' , it allows you to save a variant with 12 fields which u are required. 2. Create one parameter on the selection-screen for the variant and give the variant name. Pass that variant name, while calling REUSE_ALV_GRID_DISPLAY fm using exp parameter IS_VARIANT = i_variant1(type disvariant). 3. To get the f4 help for the parameter of variant, check the above code of fellow SDN. 4. Select the variant on selection-screen and execute the report,it displays with 12 columns . when u give print, 12 columns are only printed. I hope that it gives u some hope. Regards, Venkat.O

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.