Function key in ALV output

hi all,
i have to make a function key(Re-process) in ALV  grid output and if user selects any ALV row and click on that function key then it will reprocess the selected data. so can any one please tell how would i make Function key in ALV output and also how to trap the selected row data of ALV?
regards.

For this you will have to write the a Call back routine you will have to add a custom button in allv
and when your added button is pressed then this routine will be triggred you will have to write  a operation for the function code inteh call back routine
you Get the CALL BACK ROUTING NAME PARAMETER in the REUSE_ALV_GRID_DISPLAY
in this routine you will ge the current selected row also.
call function 'REUSE_ALV_GRID_DISPLAY'
   exporting
*   I_INTERFACE_CHECK              = ' '
*   I_BYPASSING_BUFFER             =
*   I_BUFFER_ACTIVE                = ' '
    i_callback_program             = sy-cprog
    i_callback_html_top_of_page = 'TOP_OF_PAGE'
*    i_callback_top_of_page         = 'TOP_OF_PAGE'
*   I_CALLBACK_PF_STATUS_SET       = ' '
    i_callback_user_command        = 'USER_COMMAND'
*    I_GRID_TITLE                   = 'VIRAJ PROFILES LTD.'
*   I_STRUCTURE_NAME               =
      is_layout                      = layout
      it_fieldcat                    = fieldcat
*   IT_EXCLUDING                   =
*   IT_SPECIAL_GROUPS              =
     it_sort                        = i_sort
*   IT_FILTER                      =
*   IS_SEL_HIDE                    =
*   I_DEFAULT                      = 'X'
*   I_SAVE                         = ' '
*   IS_VARIANT                     =
*   IT_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
*   IR_SALV_LIST_ADAPTER           =
*   IT_EXCEPT_QINFO                =
*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER        =
*   ES_EXIT_CAUSED_BY_USER         =
    tables
      t_outtab                       = <table>
* EXCEPTIONS
*   PROGRAM_ERROR                  = 1
*   OTHERS                         = 2
form user_command using r_ucomm like sy-ucomm
                 rs_selfield type slis_selfield.
  case r_ucomm.
    when '&IC1'.
      loop at it_ekko into wa_it_ekko.
        if rs_selfield-fieldname cs wa_it_ekko-ebeln.
          set parameter id  'ANF' field wa_it_ekko-ebeln.
          call transaction 'ME47' and skip first screen.
        endif.
      endloop.
    when '%_GC 117 3'.
      data : msg type string.
      concatenate 'Click' 'on' rs_selfield-fieldname into msg separated by space.
      message msg type 'I'.
    when others.
  endcase.
endform.                    "USER_COMMAND
Above is sample code ...just debug it you will get it all
Edited by: Anup Deshmukh on Feb 2, 2010 4:43 AM

Similar Messages

  • F3 function key not work in this ALV pgm

    Hi,
    How to make the F3 function key (go back to previous screen) work in this ALV program?
    Thanks,
    Helen
    REPORT  z_pgm.
    TYPE-POOLS : slis.
    INITIALIZATION.
      PERFORM sub_fieldcat_init CHANGING gi_fieldcat.
      PERFORM sub_eventtab_build USING gi_events[].
      PERFORM sub_event_exit_build CHANGING gi_event_exit.
      CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
        EXPORTING
          i_save     = g_save
        CHANGING
          cs_variant = g_xvariant
        EXCEPTIONS
          not_found  = 2.
    *EVENT : AT SELECTION-SCREEN OUTPUT                                    *
    AT SELECTION-SCREEN OUTPUT.
               EVENT : START-OF-SELECTION
    START-OF-SELECTION.
      PERFORM sub_comment_build  USING gi_list_top_of_page.
      PERFORM sub_get_data.
               EVENT : END-OF-SELECTION
    END-OF-SELECTION.
      IF l_error IS INITIAL.
        PERFORM sub_grid_display USING gi_adrc_disp.
      ENDIF.
    *&      Form  sub_fieldcat_init
    FORM sub_fieldcat_init CHANGING li_fieldcat LIKE gi_fieldcat[]."#EC *
      DATA : lw_fieldcat TYPE slis_fieldcat_alv.
      REFRESH gi_fieldcat[].
      CLEAR lw_fieldcat.
      lw_fieldcat-fieldname = 'SELKZ'.
      lw_fieldcat-tabname   = 'gi_adrc_disp'.
      lw_fieldcat-hotspot   = 'X'.
      lw_fieldcat-outputlen = '8'.
      APPEND lw_fieldcat TO li_fieldcat.
      CLEAR lw_fieldcat.
      lw_fieldcat-fieldname = 'LOCATION'.
      lw_fieldcat-tabname   = 'gi_adrc_disp'.
      lw_fieldcat-seltext_s = text-002.
      lw_fieldcat-seltext_m = text-002.
      lw_fieldcat-seltext_l = text-002.
      lw_fieldcat-outputlen = '20'.
      APPEND lw_fieldcat TO li_fieldcat.
    ENDFORM.                    " sub_fieldcat_init
    *&      Form  SUB_EVENTTAB_BUILD
    FORM sub_eventtab_build  USING    li_events TYPE slis_t_event.
      DATA: lw_event TYPE slis_alv_event.
    *to call top_of_page event
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = li_events.
      READ TABLE li_events WITH KEY name =  slis_ev_top_of_page
                               INTO lw_event.
      IF sy-subrc = 0.
        MOVE c_formname_top_of_page TO lw_event-form.
        APPEND lw_event TO li_events.
      ENDIF.
    ENDFORM.                    " SUB_EVENTTAB_BUILD
          FORM SUB_COMMENT_BUILD                                        *
    FORM sub_comment_build USING li_lt_top_of_page TYPE slis_t_listheader.
      DATA: lw_line TYPE slis_listheader.
    Listenüberschrift: Typ H
      CLEAR lw_line.
      lw_line-typ  = 'H'.
      lw_line-info = text-013.
      APPEND lw_line TO li_lt_top_of_page.
    Kopfinfo: Typ S
      CLEAR lw_line.
      lw_line-typ  = 'S'.
      lw_line-key  = text-014.
      lw_line-info = text-015.
      APPEND lw_line TO li_lt_top_of_page.
    ENDFORM.                    "SUB_COMMENT_BUILD
    *&      Form  sub_VARIANT_INIT
    FORM sub_variant_init .
      CLEAR g_variant.
      g_variant-report = g_repid.
    ENDFORM.                    " sub_VARIANT_INIT
    *&      Form  SUB_F4_FOR_VARIANT
          To get the existing variant
    FORM sub_f4_for_variant .
      g_variant-report = g_repid.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
             EXPORTING
                  is_variant          = g_variant
                  i_save              = g_save
                it_default_fieldcat =
             IMPORTING
                  e_exit              = g_exit
                  es_variant          = g_xvariant
             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.
      ENDIF.
    ENDFORM.                    " SUB_F4_FOR_VARIANT
          FORM TOP_OF_PAGE
    FORM top_of_page.                                           "#EC CALLED
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = gi_list_top_of_page.
    ENDFORM.                    "TOP_OF_PAGE
    FORM sub_grid_display USING li_final_disp LIKE gi_final_disp.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'                  "#EC *
          EXPORTING
            i_callback_pf_status_set = 'SET_PF_STATUS'
            i_callback_program       = g_repid
            i_callback_user_command  = 'SUB_CB_USER_COMMAND'
          i_grid_title       = l_title
            it_fieldcat              = gi_fieldcat
           is_layout          = gw_layout
            i_save                   = g_save
            is_variant               = g_variant
            it_events                = gi_events[]
            it_event_exit            = gi_event_exit[]
          IMPORTING
            e_exit_caused_by_caller  = g_exit_caused_by_caller
            es_exit_caused_by_user   = gs_exit_caused_by_user
          TABLES
            t_outtab                 = gi_adrc_disp
          EXCEPTIONS
            program_error            = 1
            OTHERS                   = 2.
    ENDFORM.                    " sub_grid_display
    *&      Form                                          *
    FORM sub_get_data .
      CLEAR l_error.
      IF NOT rb_loc IS INITIAL.
        IF p_loc EQ space.
          MESSAGE i100(zm01) WITH
                  'Please Enter Location Code and SET ID'.
          l_error = 'X'.
        ENDIF.
        SELECT addrnumber location name1 name2 building floor
                   name_co country street str_suppl1 str_suppl3 city1
                   city2 region post_code1 transpzone
                INTO TABLE gi_adrc_disp
                FROM adrc
                WHERE region = p_region
                  AND str_suppl3 = p_loc.
      ELSEIF NOT rb_all IS INITIAL.
        SELECT addrnumber location name1 name2 building floor
                   name_co country street str_suppl1 str_suppl3 city1
                   city2 region post_code1 transpzone
                INTO TABLE gi_adrc_disp
                FROM adrc
                WHERE transpzone NE space.
      ENDIF.
      IF sy-subrc NE 0.
        l_error = 'X'.
        MESSAGE i100(zm01) WITH
                  'No Record Exists for Input'.
        EXIT.
      ENDIF.
      lw_adrc-selkz = c_add.
      MODIFY gi_adrc_disp FROM lw_adrc TRANSPORTING selkz
            WHERE transpzone = space.
      lw_adrc-selkz = c_remove.
      MODIFY gi_adrc_disp FROM lw_adrc TRANSPORTING selkz
            WHERE transpzone NE space.
    ENDFORM.                    " sub_get_data
    *&      Form  sub_cb_user_command
    FORM sub_cb_user_command  USING r_ucomm LIKE sy-ucomm                               rs_selfield TYPE slis_selfield.
       l_index = rs_selfield-tabindex.
      ENDFORM.                        "sub_cb_user_command
    *&      Form  sub_cb_user_command
    FORM set_pf_status USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'MAIN'.
    ENDFORM.                        "set_pf_status

    Hi,
    this is for setting the PF-status.
    FORM set_pf_status USING rt_extab TYPE slis_t_extab.
    SET PF-STATUS 'MAIN'.
    ENDFORM. "set_pf_status
    and double click on main and see what is the Function key and function code associated for BACK.
    FORM sub_cb_user_command USING r_ucomm LIKE sy-ucomm
    rs_selfield TYPE slis_selfield.
    case r_ucomm.
    when <b>'BACK'.</b>  <<<<i assumed Focde is BACK for BACK
    leave to screen 0.
    endform.
    Regards
    vijay

  • Function Module to edit the ALV Output

    Hi,
      I have an ALV report output.I need the edit values based on some conditions in the ALV output and 
      save the changes. Is there any function module to edit the output and proceed further.
      Thanks in advance.
    Regards,
    Navas

    First create the field catalog of the field that you want to edit in this way
    WA_fieldcat-fieldname  = 'MENGE'.
      WA_fieldcat-qfieldname = 'MEINS'.
      WA_fieldcat-seltext_m  = 'PO Quan.'
      WA_fieldcat-edit = 'X' .
    Secondly you keep a custom button like 'SAVE' in the toolbar and  also try to keep a checkbox in your ALV.
    for checkbox you have to keep a following code snippet in your finallly displayed interanal table:
    chk(1)    TYPE c, and in the fieldcatalog you have to write following piece of code
      WA_fieldcat-fieldname = 'CHK'.
      WA_fieldcat-seltext_m = 'CheckBox'.
      WA_fieldcat-checkbox = 'X'.
      WA_fieldcat-edit = 'X' .
      WA_fieldcat-input = 'X'.
      WA_fieldcat-tabname = 'IT_FINAL'.
      WA_fieldcat-col_pos = 1.
    then you have to set the parameter i_callback_user_command           = 'USER_COMMAND'
    of FM REUSE_ALV_GRID_DISPLAY.
    Then write a subroutine like the following one to handle the SAVE operation
    FORM user_command USING I_r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
    DATA:l_cntr TYPE i.
    CASE I_r_ucomm.
    WHEN '&ZXZ'.
          CLEAR l_cntr.
          CLEAR WA_final.
          LOOP AT IT_final INTO WA_final.
            IF WA_final-chk = 'X'.
              l_cntr = l_cntr + 1.
            ENDIF.
          ENDLOOP.
          IF l_cntr GT 1.
            MESSAGE i011.
          ELSEIF l_cntr = 1.
               READ TABLE IT_final INTO WA_final WITH KEY chk = 'X'.
               MODIFY IT_final FROM WA_final TRANSPORTING menge
              WHERE chk = 'X'.
              CLEAR WA_final.
              PERFORM disp_alv. <<<This is to display the refreshed alv after saving your data
         endif.
    ENDCASE.
    ENDFORM.

  • Transfer ALV Output through Function Module

    Hi All,
    I have a requirement where I am dealing with two systems.
    1) There is a report program which run in ECC Server and it makes an RFC Call to trigger another program in APO Server
    2) The target program generates an ALV Output and I just want to bring back the output into ECC system
    3) How to achieve this ? How can transport the AVL Output throug the parameters of the RFC Function Module.
    Any help/clue  on this would be highly appreciated
    Thanks,
    Babu Kilari

    Hello Babu,
    If you are submitting the standard report in background mode, try this algo:
    1. You can export the output list to the ABAP memory using the EXPORTING LIST TO MEMORY.
    2. Then get the list details using the FM: LIST_FROM_MEMORY. Return the resultant internal table to your RFC.
    Hope this helps.
    BR,
    Suhas

  • I am not getting the headings of the fields in ALV output.

    I am not getting ALV out put but  the headings of the fields in ALV output.
    Please see my below code .
    TYPES : BEGIN OF ty_zgxmit.
              INCLUDE STRUCTURE zgxmit.
    TYPES : END OF ty_zgxmit.
    DATA : gt_zgxmit TYPE TABLE OF ty_zgxmit.
    *&      Form  alv_display                                              *
    This subroutine is to display the out put in ALV.                    *
    FORM alv_display .
    Local data
      DATA: y_x          LIKE boole  VALUE 'X'.
    DATA: lt_fieldcat  TYPE slis_t_fieldcat_alv.
      DATA: lf_fieldcat  TYPE slis_fieldcat_alv.
      DATA: lh_index     LIKE lf_fieldcat-col_pos.
    For variant
    DATA: ws_repid LIKE sy-repid,
          g_save TYPE c VALUE 'A',
          g_exit TYPE c,
          g_variant LIKE disvariant,
          gx_variant LIKE disvariant.
      For 1st field.( RPT_LOC )
        CLEAR lf_fieldcat.
        lf_fieldcat-fieldname = 'RPT_LOC'.
        lf_fieldcat-tabname = 'GT_ZGXMIT'.
        lf_fieldcat-ref_tabname = 'RPT_LOC'.
        lf_fieldcat-ref_fieldname = 'ZGXMIT'.
        lh_index = lh_index + 1.
        lf_fieldcat-col_pos = lh_index.
        lf_fieldcat-key = y_x.
        lf_fieldcat-no_sum = y_x.
        APPEND lf_fieldcat TO lt_fieldcat.
    For 2nd field.( BAL_XMIT )
        CLEAR lf_fieldcat.
        lf_fieldcat-fieldname = 'BAL_XMIT'.
        lf_fieldcat-tabname = 'GT_ZGXMIT'.
        lf_fieldcat-ref_tabname = 'BAL_XMIT'.
        lf_fieldcat-ref_fieldname = 'ZGXMIT'.
        lh_index = lh_index + 1.
        lf_fieldcat-col_pos = lh_index.
        lf_fieldcat-key = y_x.
        lf_fieldcat-no_sum = y_x.
        APPEND lf_fieldcat TO lt_fieldcat.
    For 3rd field.( INC_XMIT )
        CLEAR lf_fieldcat.
        lf_fieldcat-fieldname = 'INC_XMIT'.
        lf_fieldcat-tabname = 'GT_ZGXMIT'.
        lf_fieldcat-ref_tabname = 'INC_XMIT'.
        lf_fieldcat-ref_fieldname = 'ZGXMIT'.
        lh_index = lh_index + 1.
        lf_fieldcat-col_pos = lh_index.
        lf_fieldcat-key = y_x.
        lf_fieldcat-no_sum = y_x.
        APPEND lf_fieldcat TO lt_fieldcat.
    For 4th field.( Z500_XMIT )
        CLEAR lf_fieldcat.
        lf_fieldcat-fieldname = 'Z500_XMIT'.
        lf_fieldcat-tabname = 'GT_ZGXMIT'.
        lf_fieldcat-ref_tabname = 'Z500_XMIT'.
        lf_fieldcat-ref_fieldname = 'ZGXMIT'.
        lh_index = lh_index + 1.
        lf_fieldcat-col_pos = lh_index.
        lf_fieldcat-key = y_x.
        lf_fieldcat-no_sum = y_x.
        APPEND lf_fieldcat TO lt_fieldcat.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program       = 'ZJV_2245'
                it_fieldcat              = lt_fieldcat
           TABLES
                t_outtab                 = gt_zgxmit
           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.                    " alv_display

    You can force the headings like so.
    CLEAR lf_fieldcat.
    lf_fieldcat-fieldname = 'RPT_LOC'.
    lf_fieldcat-tabname = 'GT_ZGXMIT'.
    lf_fieldcat-ref_tabname = 'RPT_LOC'.
    lf_fieldcat-ref_fieldname = 'ZGXMIT'.
    lf_fieldcat-reptext_ddic  = 'Whatever Heading'.    "<-  Right here
    lh_index = lh_index + 1.
    lf_fieldcat-col_pos = lh_index.
    lf_fieldcat-key = y_x.
    lf_fieldcat-no_sum = y_x.
    APPEND lf_fieldcat TO lt_fieldcat.
    Regards,
    Rich Heilman

  • ALV output converted into PDF format and send that PDF to user through mail

    Hi Experts,
    I have report earlier its output was in alv grid.
    Now i want that ALV output converted into PDF format.And that PDF output send to user through mail.
    Can u please tell how to do?
    My code is here(output is displaying in ALV grid).
    INCLUDE <icon>.
    TYPE-POOLS: slis, kkblo.
    TABLES : zmsd_freight_hdr, zmsd_freight_det, zmsd_blinfo, zmsd_diheader.
    TABLES : lfa1.
    DATA : t_hdr   LIKE   zmsd_freight_hdr   OCCURS 0 WITH HEADER LINE,
           T_DET   LIKE   ZMSD_FREIGHT_DET   OCCURS 0 WITH HEADER LINE,
           t_bl    LIKE   zmsd_blinfo        OCCURS 0 WITH HEADER LINE,
           t_di    LIKE   zmsd_diheader      OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF t_det OCCURS 0.
            INCLUDE STRUCTURE zmsd_freight_det.
    DATA    type(30).
    DATA: END OF t_det.
    DATA: v_target2(30),
          v_zsammg LIKE t_det-zsammg,
          v_gsttotal LIKE t_det-zamount.
    DATA : BEGIN OF t_data OCCURS 0,
             zsammg       LIKE  zmsd_freight_hdr-zsammg,
             zdidbl       LIKE  zmsd_freight_hdr-zdidbl,
             zvkorg       LIKE  zmsd_freight_hdr-zvkorg,
             zinvno       LIKE  zmsd_freight_hdr-zinvno,
             zttlamt      LIKE  zmsd_freight_hdr-zttlamt,
             zstatus      LIKE  zmsd_freight_hdr-zstatus,
             ztype        LIKE  zmsd_freight_hdr-ztype,
             zconfirm     LIKE  zmsd_freight_hdr-zconfirm,
             zconfirmdate LIKE  zmsd_freight_hdr-zconfirmdate,
             erdat        LIKE  zmsd_freight_hdr-erdat,
             ernam        LIKE  zmsd_freight_hdr-ernam,
             erzet        LIKE  zmsd_freight_hdr-erzet,
             aedat(10),
             aenam        LIKE  zmsd_freight_hdr-aenam,
             aezet        LIKE  zmsd_freight_hdr-aezet,
             zline        LIKE  zmsd_freight_det-zline,
             zfptype      LIKE  zmsd_freight_det-zfptype,
             zchrcode     LIKE  zmsd_freight_det-zchrcode,
             zcurcode     LIKE  zmsd_freight_det-zcurcode,
             zqty         LIKE  zmsd_freight_det-zqty,
             zuom         LIKE  zmsd_freight_det-zuom,
             zrate        LIKE  zmsd_freight_det-zrate,
             zamount      LIKE  zmsd_freight_det-zamount,
             zexrate      LIKE  zmsd_freight_det-zexrate,
           zccode       LIKE  zmsd_blinfo-zccode,      "MADK991565
             zccode       like  ZMSD_FREIGHT_HDR-zfcode, "MADK991565
             zbldate(10),
             zbl          LIKE  zmsd_blinfo-zbl,
             type(3),
             waerk        LIKE  zmsd_freight_det-zcurcode,
             zamountl     LIKE  zmsd_freight_det-zamount,
           END OF t_data.
    DATA : w_layout      TYPE   slis_layout_alv,
           w_catalog     TYPE   slis_fieldcat_alv,
           t_catalog     TYPE   slis_t_fieldcat_alv,
           w_sort        TYPE   slis_sortinfo_alv,
           t_sort        TYPE   slis_t_sortinfo_alv.
    DATA   V_ZINVNO    like   T_HDR-ZINVNO.                   "MADK991565
    DATA : v_count  TYPE  i.
    SELECTION-SCREEN BEGIN OF BLOCK a0 WITH FRAME TITLE text-001.
    PARAMETERS     :  p_zvkorg LIKE zmsd_freight_hdr-zvkorg  OBLIGATORY .
    SELECT-OPTIONS :  s_zdidbl FOR  zmsd_freight_hdr-zdidbl             ,
                      s_zccode FOR  lfa1-lifnr                          ,
                      s_status FOR  zmsd_freight_hdr-zstatus            ,
                      s_ztype  FOR  zmsd_freight_hdr-ztype              ,
                      s_erdat  FOR  zmsd_freight_hdr-erdat              ,
                      s_ernam  FOR  zmsd_freight_hdr-ernam              ,
                      s_zconfd FOR  zmsd_freight_hdr-zconfirmdate       .
    PARAMETERS     :  p_zconf  AS   CHECKBOX                            .
    SELECTION-SCREEN END OF BLOCK a0.
    SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-002.
    PARAMETERS     :  p_hdr    RADIOBUTTON GROUP rad DEFAULT 'X'        ,
                      p_det    RADIOBUTTON GROUP rad                    .
    SELECTION-SCREEN END OF BLOCK a1.
    INITIALIZATION.
    AT SELECTION-SCREEN.
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM process.
      PERFORM display.
    END-OF-SELECTION.
      PERFORM fm_get_num_pages.
    AT USER-COMMAND.
    AT LINE-SELECTION.
    TOP-OF-PAGE.
      PERFORM fm_top_of_page USING '7010' sy-title space.
    FORM get_data.
      SELECT   *
        FROM   zmsd_freight_hdr
        INTO   TABLE t_hdr
       WHERE   zvkorg        EQ  p_zvkorg
         AND   zdidbl        IN  s_zdidbl
         AND   zstatus       IN  s_status
         AND   ztype         IN  s_ztype
         AND   erdat         IN  s_erdat
         AND   ernam         IN  s_ernam
         AND   zconfirmdate  IN  s_zconfd
         AND   ZFCODE        IN  S_ZCCODE.                      "MADK991565
      IF p_zconf = 'X'.
        DELETE t_hdr WHERE zconfirm NE 'C'.
      ENDIF.
      CHECK NOT t_hdr[] IS INITIAL.
      SELECT   *
        FROM   zmsd_blinfo
        INTO   TABLE t_bl
         FOR   ALL ENTRIES IN t_hdr
       WHERE   zsammg = t_hdr-zsammg.
      SORT t_bl BY zsammg.
      SELECT   *
        FROM   zmsd_diheader
        INTO   TABLE t_di
         FOR   ALL ENTRIES IN t_hdr
       WHERE   zsammg = t_hdr-zsammg.
      SORT t_di BY zsammg.
    IF P_DET = 'X'. "MADK933361
      SELECT   *
        FROM   zmsd_freight_det
        INTO   TABLE t_det
         FOR   ALL ENTRIES IN t_hdr
       WHERE   zsammg  =  t_hdr-zsammg
       AND ZINVNO =  T_HDR-ZINVNO .                           "MADK991565
    SORT t_det BY zsammg zline.                            "MADK991565
       SORT T_DET BY ZSAMMG ZINVNO ZLINE.                     "MADK991565
    ENDIF. "MADK933361
    ENDFORM.
    FORM process.
      REFRESH t_data.
      CLEAR v_gsttotal.                                         "MADK933361
      LOOP AT t_hdr.
    Start of MADK933361
        CLEAR: v_target2.
        v_zsammg = t_hdr-zsammg.
        V_ZINVNO = T_HDR-ZINVNO.                                "MADK991565
       AT NEW zsammg.                                         "MADK991565
         AT NEW ZINVNO.                                         "MADK991565
          PERFORM get_gst_value.
        ENDAT.
    End of MADK933361
        PERFORM move_header.
        CHECK t_data-zccode IN s_zccode.
        IF p_det = 'X'.
    CSF Project Changes Starts   DEV34    MADK985782
        LOOP AT T_DET WHERE ZSAMMG = T_HDR-ZSAMMG..
          LOOP AT t_det WHERE zsammg = t_hdr-zsammg AND
                              zinvno = t_hdr-zinvno.
    CSF Project Changes Ends     DEV34    MADK985782
            PERFORM move_header.
            CHECK t_data-zccode IN s_zccode.
            MOVE-CORRESPONDING t_det TO t_data.
            t_data-zamountl = t_data-zamount * t_data-zexrate.
            APPEND t_data.
            CLEAR t_data.
          ENDLOOP.
        ELSE.
          APPEND t_data.
          CLEAR t_data.
        ENDIF.
        AT END OF zsammg.
          CLEAR v_gsttotal.
        ENDAT.
    *Start of changes for  IS090901289-PIA MADK991565
        AT END OF ZINVNO.
          CLEAR V_GSTTOTAL.
        ENDAT.
    *End of changes for  IS090901289-PIA MADK991565
      ENDLOOP.
    ENDFORM.
    FORM move_header.
      MOVE-CORRESPONDING t_hdr TO t_data.
      t_data-zttlamt = t_data-zttlamt + v_gsttotal.             "MADK933361
      t_data-waerk = 'SGD'.
      IF NOT t_hdr-aedat IS INITIAL.
        WRITE: t_hdr-aedat TO t_data-aedat.
      ELSE.
        CLEAR : t_data-aedat.
      ENDIF.
      READ TABLE t_bl WITH KEY zsammg = t_hdr-zsammg BINARY SEARCH.
      IF sy-subrc EQ 0.
      t_data-zccode  = t_bl-zccode.   "MADK991565
        T_DATA-ZCCODE = T_HDR-ZFCODE.   "MADK991565     
        IF NOT t_bl-zbldate IS INITIAL.
          WRITE: t_bl-zbldate TO t_data-zbldate.
        ENDIF.
        t_data-zbl     = t_bl-zbl.
        t_data-type    = 'DBL'.
      ELSE.
        READ TABLE t_di WITH KEY zsammg = t_hdr-zsammg BINARY SEARCH.
        IF sy-subrc EQ 0.
        t_data-zccode  = t_di-zdiforcode.     "MADK991565
          T_DATA-ZCCODE = T_HDR-ZFCODE.         "MADK991565
          t_data-type    = 'DI'.
        ENDIF.
      ENDIF.
    ENDFORM.
    FORM display.
      IF t_data[] IS INITIAL.
        MESSAGE s398(00) WITH 'No Data Selected'.
        EXIT.
      ENDIF.
      DATA : l_repid LIKE sy-repid.
      l_repid = sy-repid.
      REFRESH t_catalog.
      CLEAR   t_catalog.
      w_layout-cell_merge = 'X'.
      PERFORM map_fields.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program      = l_repid
                i_callback_user_command = 'ALV_USER_COMMAND'
                is_layout               = w_layout
                it_fieldcat             = t_catalog[]
                i_grid_title            = sy-title
                i_save                  = 'A'
                it_sort                 = t_sort[]
           TABLES
                t_outtab                = t_data
           EXCEPTIONS
                program_error           = 1
                OTHERS                  = 2.
      IF sy-subrc <> 0.
      ENDIF.
    ENDFORM.
    FORM map_fields.
    Sort Order
      CLEAR v_count.
      PERFORM sf USING 'ZDIDBL'   'X'  'X'.
    Fields to be displayed
      CLEAR v_count.
      IF p_hdr = 'X'.
        PERFORM af USING :
       DESCRIPTION       FIELD        LEN   RTABLE             RFIELD
        'DI/DBL         ' 'ZDIDBL'     '14' '                ' '        ',
        'Type           ' 'TYPE'       '04' '                ' '        ',
        'Forwarder Code ' 'ZCCODE'     '14' '                ' '        ',
        'BL Number      ' 'ZBL'        '14' '                ' '        ',
        'BL Date        ' 'ZBLDATE'    '10' '                ' '        ',
        'Invoice Number ' 'ZINVNO'     '15' '                ' '        ',
        'Extraction     ' 'ZSTATUS'    '05' 'ZMSD_FREIGHT_HDR' 'ZSTATUS ',
        'Freight Type   ' 'ZTYPE'      '05' 'ZMSD_FREIGHT_HDR' 'ZTYPE   ',
        'Confirmation   ' 'ZCONFIRM'   '05' 'ZMSD_FREIGHT_HDR' 'ZCONFIRM',
        'Confirm Date   ' 'ZCONFIRMDATE' '10' 'ZMSD_FREIGHT_HDR'
    'ZCONFIRMDATE',
        'Total Amount   ' 'ZTTLAMT'    '18' '                ' '        ',
        'Created On     ' 'ERDAT'      '10' '                ' '        ',
        'Created By     ' 'ERNAM'      '10' '                ' '        ',
        'Changed On     ' 'AEDAT'      '10' '                ' '        ',
        'Changed By     ' 'AENAM'      '10' '                ' '        '.
      ELSE.
        PERFORM af USING :
       DESCRIPTION         FIELD     LEN   RTABLE             RFIELD
        'DI/DBL           ' 'ZDIDBL'   '14' '                ' '        ',
        'Type             ' 'TYPE'     '04' '                ' '        ',
        'Forwarder Code   ' 'ZCCODE'   '14' '                ' '        ',
        'BL Number        ' 'ZBL'      '14' '                ' '        ',
        'BL Date          ' 'ZBLDATE'  '10' '                ' '        ',
        'Invoice Number   ' 'ZINVNO'   '15' '                ' '        ',
        'Extraction       ' 'ZSTATUS'  '05' 'ZMSD_FREIGHT_HDR' 'ZSTATUS ',
        'Freight Type     ' 'ZTYPE'    '05' 'ZMSD_FREIGHT_HDR' 'ZTYPE   ',
        'Confirmation     ' 'ZCONFIRM' '05' 'ZMSD_FREIGHT_HDR' 'ZCONFIRM',
        'Confirm Date     ' 'ZCONFIRMDATE' '10' 'ZMSD_FREIGHT_HDR'
    'ZCONFIRMDATE',
        'Total Amount     ' 'ZTTLAMT'  '18' '                ' '        ',
        'Freight Payment  ' 'ZFPTYPE'  '14' '                ' '        ',
        'Charge Code      ' 'ZCHRCODE' '10' '                ' '        ',
        'Currency         ' 'ZCURCODE' '08' '                ' '        ',
        'Quantity         ' 'ZQTY'     '13' '                ' '        ',
        'UoM              ' 'ZUOM'     '04' '                ' '        ',
        'Rate             ' 'ZRATE'    '15' '                ' '        ',
        'Amt(Foreign Curr)' 'ZAMOUNT'  '16' '                ' '        ',
        'Exchange Rate    ' 'ZEXRATE'  '13' '                ' '        ',
        'Amt(Local Curr)  ' 'ZAMOUNTL' '16' '                ' '        ',
        'Created On       ' 'ERDAT'    '10' '                ' '        ',
        'Created By       ' 'ERNAM'    '10' '                ' '        ',
        'Changed On       ' 'AEDAT'    '10' '                ' '        ',
        'Changed By       ' 'AENAM'    '10' '                ' '        '.
      ENDIF.
    ENDFORM.
    FORM af USING text
                  field
                  len
                  table
                  reffield.
      v_count = v_count + 1.
      w_catalog-col_pos       = v_count.
      w_catalog-fieldname     = field.
      w_catalog-ref_tabname   = table.
      w_catalog-ref_fieldname = reffield.
      w_catalog-seltext_s     = text.
      w_catalog-seltext_m     = text.
      w_catalog-seltext_l     = text.
      w_catalog-outputlen     = len.
      IF field = 'ZTTLAMT' OR field = 'ZAMOUNTL'.
        w_catalog-no_zero     = 'X'.
        w_catalog-cfieldname  = 'WAERK'.
        w_catalog-datatype    = 'CURR'.
      ENDIF.
    IF FIELD = 'ZRATE' OR FIELD = 'ZAMOUNT'.
      IF field = 'ZAMOUNT'.
        w_catalog-no_zero     = 'X'.
        w_catalog-cfieldname  = 'ZCURCODE'.
        w_catalog-datatype    = 'CURR'.
      ENDIF.
      IF field = 'ZQTY' OR field = 'ZRATE'.
        w_catalog-no_zero     = 'X'.
        w_catalog-datatype  =  'DEC'.
      ENDIF.
      APPEND w_catalog TO t_catalog.
      CLEAR  w_catalog.
    ENDFORM.
    FORM sf    USING   fieldname  sortup  group.
      v_count = v_count + 1.
      CLEAR w_sort.
      w_sort-fieldname = fieldname.
      w_sort-spos      = v_count.
      w_sort-up        = sortup.
      w_sort-group     = group.
      APPEND w_sort TO t_sort.
    ENDFORM.
    FORM alv_user_command USING  in_ucomm    LIKE sy-ucomm
                                 in_selfield TYPE slis_selfield.
      DATA: lfs_data LIKE t_data.
      IF in_ucomm = '&IC1'.
        READ TABLE t_data INDEX in_selfield-tabindex INTO lfs_data.
        CHECK NOT lfs_data-zdidbl IS INITIAL.
        IF lfs_data-type = 'DBL'.
          DATA: l_zdbl LIKE zmsd_diheader-zdinum.
          l_zdbl = in_selfield-value.
          EXPORT l_zdbl TO MEMORY ID 'VBL'.
          CALL TRANSACTION 'ZMSD_BL01'.
        ENDIF.
        IF lfs_data-type = 'DI'.
          DATA: v_dinum LIKE zmsd_diheader-zdinum.
          v_dinum = in_selfield-value.
          EXPORT v_dinum TO MEMORY ID 'VDI'.
          CALL TRANSACTION 'ZMSD_DI01'.
        ENDIF.
      ENDIF.
    ENDFORM.
    FORM get_gst_value.
      LOOP AT t_det WHERE zsammg = v_zsammg
         AND ZINVNO = V_ZINVNO.                              "MADK991565
        CHECK t_data-zccode IN s_zccode.
        t_det-zamount  = t_det-zamount * t_det-zexrate.
        SELECT SINGLE  y0mmtarget2
                INTO   v_target2
                FROM   y0mmipstranslate
                WHERE  y0mmdatatype = '70' AND
                       y0mmsource = t_det-zchrcode.
        SELECT SINGLE y0mmtarget1
               INTO   t_det-type
               FROM   y0mmipstranslate
               WHERE  y0mmdatatype = '76' AND
                      y0mmsource = v_target2.
        IF t_det-type NE '3Z'.
          v_gsttotal    = v_gsttotal +
                               ( t_det-zamount * 5 / 100 ).
        ENDIF.
      ENDLOOP.
    Regards,
    Raj.

    Hello,
    Following is the procedure to convert alv output to spool and then it to PDF Format.
    After we display the ALV, we can check whether it is running in the background using system field u2018sy-batchu2018. Then,we call an function module named u2018GET_JOB_RUNTIME_INFOu2019 to get the current job information. Then go to spool request table tbtcp to get the spool id.
    Get current job details
      CALL FUNCTION u2018GET_JOB_RUNTIME_INFOu2019
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                               AND jobcount = gd_jobcount
                               AND stepcount = gd_stepcount
                               AND listident <> u20180000000000u2032
                               ORDER BY   jobname
                                                   jobcount
                                                   stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
    Finally, we can call function module u2018CONVERT_ABAPSPOOLJOB_2_PDFu2018 to convert spool reqeust(which is stored in OTF format) to PDF format. Then we can call either function module u2018SO_DOCUMENT_SEND_API1u2032 or SAP BCS (Business Communication Service) to send the pdf as an email attachment.
    CALL FUNCTION u2018CONVERT_ABAPSPOOLJOB_2_PDFu2019
           EXPORTING
                src_spoolid              = gd_spool_nr
                no_dialog                = c_no
                dst_device               = c_device
           IMPORTING
                pdf_bytecount = gd_bytecount
           TABLES
                pdf = it_pdf_output
           EXCEPTIONS
                err_no_abap_spooljob     = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_destdevice       = 5
                user_cancelled           = 6
                err_spoolerror           = 7
                err_temseerror           = 8
                err_btcjob_open_failed   = 9
                err_btcjob_submit_failed = 10
                err_btcjob_close_failed  = 11
                OTHERS                   = 12.
    Regards,
    Sayali
    Edited by: Sayali Paradkar on Apr 20, 2010 12:51 PM

  • Page-break in alv background job for alv output variant not coming correctl

    Hi,
    I have created an ALV grid report. When i run the report in background i get the output with correct page-break on FIELD1. Now when i run the report in background with an "ALV output variant" (its the ALV variant that controls the fields display in the output; this is not the program variant), i do not get the page-break on FIELD1.  I have already build the sort criteria and using:
    gs_sort-group = '* '.     "New-Page
    Please let me know what could be reason for not getting the page-break in background when i am using the alv output variant and how do i correct this problem.
    Regards,
    Rakesh

    Hello Everyone,
    I have solved the problem. While running the program in background, we get the page-breaks when we use the below part of code in the sort catalogue with the condition that the program variant should not use any ALV layout variant.
    gs_sort-group = '* '.     "New-Page
    If you are using the ALV layout variant in the program variant then we can check the ROWPOS, COLPOS, and NO_OUT for that ALV layout variant and pass them along in the fieldcatalog table. You should be careful with not to pass the layout variant in the DISVARIANT. You can notice that i have cleared it and simply passing the program name into that.
    *C-- Process separately for jobs running in Background. Actually
    *C-- sortcat-group solves the problem only in Foreground. In background
    *C-- when ALV layout variant is not selected then it works otherwise it
    *C-- fails. So for background jobs we are reading the fieldcat and then
    *C-- passing the same in the display FM.
      IF sy-batch = 'X'.
        CALL FUNCTION 'REUSE_ALV_VARIANT_SELECT'
          EXPORTING
           i_dialog                  = ' '
           i_user_specific           = ' '
           i_default                 = ' '
    *   I_TABNAME_HEADER          =
    *   I_TABNAME_ITEM            =
            it_default_fieldcat       = gt_fieldcat
            i_layout                  = gs_layout
    *   I_BYPASSING_BUFFER        =
    *   I_BUFFER_ACTIVE           =
         IMPORTING
    *   E_EXIT                    =
           et_fieldcat               = lt_fieldcat
    *     et_sort                   = gt_sort[]
    *   ET_FILTER                 =
    *     es_layout                 = gs_layout
         CHANGING
           cs_variant                = gs_disvariant
         EXCEPTIONS
           wrong_input               = 1
           fc_not_complete           = 2
           not_found                 = 3
           program_error             = 4
           OTHERS                    = 5
        IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
        CLEAR gs_fieldcat.
        LOOP AT gt_fieldcat INTO gs_fieldcat.
    *C-- Transfer all position changes to gt_fieldcat from lt_fieldcat
          CLEAR ls_fieldcat.
          READ TABLE lt_fieldcat
                INTO ls_fieldcat
                WITH KEY fieldname = gs_fieldcat-fieldname.
          IF sy-subrc = 0.
            gs_fieldcat-row_pos = ls_fieldcat-row_pos.
            gs_fieldcat-col_pos = ls_fieldcat-col_pos.
            gs_fieldcat-no_out = ls_fieldcat-no_out.
            MODIFY gt_fieldcat FROM gs_fieldcat INDEX sy-tabix.
            CLEAR gs_fieldcat.
          ENDIF.
        ENDLOOP.
    *C-- Clear the disvariant for the background job as it contains the ALV
    *C-- layout varinat
        CLEAR gs_disvariant.
        gs_disvariant-report = 'ZGPPMP0001'.
    Then pass gt_fieldcat to 'REUSE_ALV_GRID_DISPLAY'.
    The reason i'm doing it this way is that when we pass the layout variant name, the contents in gt_fieldcat were getting modified.
    One more thing i'd like to point out is that that, i tried to delete the fields with no_out = 'x'. Now when i ran the program in background with all the fields in sort catalog (suppose there are 2 fields field1 and field2) also in fieldcatalog it ran fine. In the next run in background i removed one of the fields in sort catalog from the fieldcatalog (delete the fields with no_out = 'x') and i got dump. Basically i had hidden field1 and so the code which was deleting fields with no_out = 'x' deleted this field from gt_fieldcat. So basically we should not delete fields with no_out = 'x'.
    I was getting ABAP runtime errors    MESSAGE_TYPE_X in the following part of the standard code.
    000310     LOOP AT CT_SORT INTO LS_SORT.
    000320
    000330       READ TABLE IT_FIELDCAT ASSIGNING <LS_FIELDCAT>
    000340            WITH KEY FIELDNAME = LS_SORT-FIELDNAME BINARY SEARCH.
    000350       IF SY-SUBRC NE 0.
         >         MESSAGE X000(0K).
    000370       ENDIF.
    000380
    000390       LS_SORT-SELTEXT = <LS_FIELDCAT>-SELTEXT.
    i have just mentioned this part because when i checked the forum many people were getting such errors "MESSAGE_TYPE_X". This could also be one of the reasons.

  • How to get check box in alv output

    hi gurus
    can anyone explian me how to get check box in alv output
    it should not be a pop up window
    i want to get in output itself
    tahnk you
    regards
    kals.

    Hi
    by using rs_selfield
    ty to call dynamic subroutine..
    FORM user_command USING r_ucomm LIKE sy-ucomm
    rs_selfield TYPE slis_selfield. "#EC CALLED
    read table rs-selfield with key cond = 'X'
    endform.
    see the below example
    REPORT Z_GET_REFRESH no standard page heading.
    type-pools : slis.
    tables : makt,
    mara.
    data : i_fieldcat type slis_t_fieldcat_alv.
    CONSTANTS :
    gc_refresh TYPE syucomm VALUE '&REFRESH'.
    data : begin of i_makt occurs 0,
    matnr like makt-matnr,
    maktx like makt-maktx,
    end of i_makt.
    data : v_repid like sy-repid,
    g_user_command type slis_formname value 'USER_COMMAND',
    g_status_set type slis_formname value 'SET_PF_STATUS',
    lt_event_exit TYPE slis_t_event_exit,
    ls_event_exit TYPE slis_event_exit.
    DATA:LC_GLAY TYPE LVC_S_GLAY.
    select-options s_matnr for mara-matnr .
    start-of-selection.
    select matnr maktx from makt into table i_makt
    where matnr in s_matnr.
    end-of-selection.
    Fill the fieldcatlog
    perform fill_field.
    Call the FM
    perform call_fm.
    *& Form fill_field
    text
    --> p1 text
    <-- p2 text
    FORM fill_field.
    data wa_fieldcat type slis_fieldcat_alv.
    clear : wa_fieldcat.
    wa_fieldcat-tabname = 'I_MAKT'.
    wa_fieldcat-fieldname = 'MATNR'.
    wa_fieldcat-outputlen = '18'.
    wa_fieldcat-seltext_l = 'Material #'.
    wa_fieldcat-col_pos = '1'.
    append wa_fieldcat to i_fieldcat.
    clear : wa_fieldcat.
    wa_fieldcat-tabname = 'I_MAKT'.
    wa_fieldcat-fieldname = 'MAKTX'.
    wa_fieldcat-outputlen = '40'.
    wa_fieldcat-seltext_l = 'Material Desc'.
    wa_fieldcat-col_pos = '2'.
    append wa_fieldcat to i_fieldcat.
    ENDFORM. " fill_field
    *& Form call_fm
    text
    --> p1 text
    <-- p2 text
    FORM call_fm.
    v_repid = sy-repid.
    LC_GLAY-EDT_CLL_CB = 'X'.
    CLEAR ls_event_exit.
    ls_event_exit-ucomm = gc_refresh. " Refresh
    ls_event_exit-after = 'X'.
    APPEND ls_event_exit TO lt_event_exit.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_INTERFACE_CHECK = ' '
    I_BYPASSING_BUFFER =
    I_BUFFER_ACTIVE = ' '
    I_CALLBACK_PROGRAM = v_repid
    I_CALLBACK_PF_STATUS_SET = g_status_set
    I_CALLBACK_USER_COMMAND = g_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 = LC_GLAY
    IS_LAYOUT =
    IT_FIELDCAT = i_fieldcat
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
    IT_SORT =
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = ' '
    IS_VARIANT =
    IT_EVENTS =
    IT_EVENT_EXIT = lt_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_makt
    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. " call_fm
    FORM USER_COMMAND *
    FORM user_command USING r_ucomm LIKE sy-ucomm
    rs_selfield TYPE slis_selfield. "#EC CALLED
    data i_RSPARAMS like RSPARAMS occurs 0.
    CASE R_UCOMM.
    WHEN '&IC1'.
    read table i_makt index rs_selfield-tabindex.
    SET PARAMETER ID 'MAT' FIELD i_makt-matnr.
    if not i_makt-matnr is initial.
    call transaction 'MM02' and skip first screen.
    endif.
    when '&REFRESH'.
    CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
    EXPORTING
    CURR_REPORT = v_repid
    IMPORTING
    SP =
    TABLES
    SELECTION_TABLE = i_RSPARAMS
    EXCEPTIONS
    NOT_FOUND = 1
    NO_REPORT = 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.
    submit z_get_refresh with selection-table i_RSPARAMS.
    rs_selfield-refresh = 'X'.
    ENDCASE.
    MOVE '&REFRESH' TO r_ucomm.
    ENDFORM.
    FORM set_pf_status *
    FORM SET_PF_STATUS USING rt_extab TYPE slis_t_extab.
    DELETE Rt_extab WHERE fcode = gc_refresh.
    SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
    EXCLUDING Rt_extab.
    *SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.
    SET TITLEBAR sy-tcode.
    ENDFORM.

  • Transpose ALV output format in Vertical

    Hi ,
      I want to transpose the ALV output. For this i have coded like below, but there is no output displaying.Please check the below code & advise me where to write our own fielcatalog & how to write the fieldcatogue.
    TABLES:EKKO,EKPO.
    TYPE-POOLS: SLIS.
    TYPES:BEGIN OF PH_TY,
    PH_EBELN LIKE EKKO-EBELN,
    PH_AEDAT LIKE EKKO-AEDAT,
    PH_LIFNR LIKE EKKO-LIFNR,
    PH_SUBMI LIKE EKKO-SUBMI,
    PH_EKORG LIKE EKKO-EKORG,
    END OF PH_TY.
    DATA: PH_ITAB TYPE STANDARD TABLE OF PH_TY.
    DATA: L_COL TYPE SY-TABIX,
          L_STRUCTURE TYPE REF TO DATA,
          L_DYNTABLE TYPE REF TO DATA,
          WA_LVC_CAT TYPE LVC_S_FCAT,
          LT_LVC_CAT TYPE LVC_T_FCAT,
          LT_FIELDCATALOGUE TYPE SLIS_T_FIELDCAT_ALV,
          WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
          LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
          LT_LAYOUT TYPE SLIS_LAYOUT_ALV.
    FIELD-SYMBOLS : <HEADER> TYPE ANY,
                    <DYNHEADER> TYPE ANY,
                    <DYNDATA> TYPE ANY,
                    <LS_TABLE> TYPE ANY,
                    <DYNAMICTABLE> TYPE STANDARD TABLE,
                    <IT_TABLE> TYPE STANDARD TABLE.
    SELECTION-SCREEN:BEGIN OF BLOCK B1.
    SELECT-OPTIONS:P_EBELN FOR EKKO-EBELN,
                   P_LIFNR FOR EKKO-LIFNR,
                   P_MATNR FOR EKPO-MATNR.
    SELECTION-SCREEN END OF BLOCK B1.
    INITIALIZATION.
    START-OF-SELECTION.
      CREATE DATA L_DYNTABLE TYPE STANDARD TABLE OF PH_TY WITH NON-UNIQUE DEFAULT KEY.
      ASSIGN L_DYNTABLE->* TO <IT_TABLE>.
      SELECT EBELN AEDAT LIFNR SUBMI EKORG FROM EKKO
                      INTO TABLE <IT_TABLE> WHERE EBELN IN P_EBELN
                      AND LIFNR IN P_LIFNR.
      WA_LVC_CAT-FIELDNAME = 'COLUMNTEXT'.
      WA_LVC_CAT-REF_TABLE = 'LVC_S_DETA'.
      APPEND WA_LVC_CAT TO LT_LVC_CAT.
      WA_FIELDCAT-FIELDNAME = 'COLUMNTEXT'.
      WA_FIELDCAT-REF_TABNAME = 'LVC_S_DETA'.
      WA_FIELDCAT-KEY = 'X'.
      APPEND WA_FIELDCAT TO LT_FIELDCAT.
    *  WA_FIELDCAT-TABNAME = 'IT_TABLE'.
    *  WA_FIELDCAT-FIELDNAME = 'PH_EBELN'.
    *  WA_FIELDCAT-SELTEXT_M = 'PO'.
    *  APPEND WA_FIELDCAT TO LT_FIELDCAT.
    *  CLEAR WA_FIELDCAT.
      DESCRIBE TABLE <IT_TABLE>.
      DO
      SY-TFILL TIMES.
        WRITE SY-INDEX TO WA_LVC_CAT-FIELDNAME LEFT-JUSTIFIED.
        CONCATENATE 'VALUE' WA_LVC_CAT-FIELDNAME INTO WA_LVC_CAT-FIELDNAME.
        WA_LVC_CAT-REF_FIELD = 'VALUE'.
        WA_LVC_CAT-REF_TABLE = 'LVC_S_DETA'.
        APPEND WA_LVC_CAT TO LT_LVC_CAT.
        CLEAR WA_FIELDCAT.
        WA_FIELDCAT-FIELDNAME = WA_LVC_CAT-FIELDNAME.
        WA_FIELDCAT-REF_FIELDNAME = 'VALUE'.
        WA_FIELDCAT-REF_TABNAME = 'LVC_S_DETA'.
        APPEND WA_FIELDCAT TO LT_FIELDCAT.
      ENDDO.
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG = LT_LVC_CAT
        IMPORTING
          EP_TABLE        = L_DYNTABLE.
      ASSIGN L_DYNTABLE->* TO <DYNAMICTABLE>.
      CREATE DATA L_STRUCTURE LIKE LINE OF <DYNAMICTABLE>.
      ASSIGN L_STRUCTURE->* TO <HEADER>.
      CREATE DATA L_STRUCTURE LIKE LINE OF <IT_TABLE>.
      ASSIGN L_STRUCTURE->* TO <LS_TABLE>.
      DESCRIBE TABLE LT_FIELDCATALOGUE.
      DO SY-TFILL TIMES.
        IF SY-INDEX = 1.
        READ TABLE LT_FIELDCATALOGUE INTO WA_FIELDCAT INDEX 1.
        ENDIF.
        ASSIGN COMPONENT 1 OF STRUCTURE <HEADER> TO <DYNHEADER>.
        IF SY-SUBRC NE 0. EXIT .ENDIF.
        READ TABLE LT_FIELDCATALOGUE INTO WA_FIELDCAT INDEX SY-INDEX.
        <DYNHEADER> = WA_FIELDCAT-SELTEXT_M.
        IF <DYNHEADER> IS INITIAL.
        <DYNHEADER> = WA_FIELDCAT-FIELDNAME.
        ENDIF.
        LOOP AT <IT_TABLE> INTO <LS_TABLE>.
          L_COL = SY-TABIX + 1.
          ASSIGN COMPONENT SY-INDEX OF STRUCTURE <LS_TABLE> TO <DYNDATA>.
          IF SY-SUBRC NE 0. EXIT .
          ENDIF.
          ASSIGN COMPONENT L_COL OF STRUCTURE <HEADER> TO <DYNHEADER>.
          IF SY-SUBRC NE 0.
          EXIT .
          ENDIF.
          WRITE <DYNDATA> TO <DYNHEADER> LEFT-JUSTIFIED.
        ENDLOOP.
        APPEND <HEADER> TO <DYNAMICTABLE>.
      ENDDO.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          IS_LAYOUT   = LT_LAYOUT
          IT_FIELDCAT = LT_FIELDCAT
        TABLES
          T_OUTTAB    = <DYNAMICTABLE>.

    Hi,
    Please go thorugh the below sample code , Commenting is done for your easy understanding.
    TYPE-POOLS: slis."*Declarations for ALV, dynamic table and col no for transpose
    DATA:    l_col    TYPE sy-tabix,
             l_structure   TYPE REF TO data,
             l_dyntable    TYPE REF TO data,
             wa_lvc_cat  TYPE lvc_s_fcat,
             lt_lvc_cat  TYPE lvc_t_fcat,
             lt_fieldcatalogue     TYPE slis_t_fieldcat_alv,
             wa_fieldcat TYPE slis_fieldcat_alv,
             lt_fieldcat TYPE slis_t_fieldcat_alv,
             lt_layout   TYPE slis_layout_alv."*Field symbols declarations
    FIELD-SYMBOLS :
      <header>    TYPE ANY,
      <dynheader> TYPE ANY,
      <dyndata>   TYPE ANY,
      <ls_table>      TYPE ANY,
      <dynamictable>      TYPE STANDARD TABLE,
      <it_table> TYPE STANDARD TABLE."*Input the name of the table
    PARAMETERS p_table TYPE dd02l-tabname OBLIGATORY."*Initialization event
    INITIALIZATION."*Start of selection event
    START-OF-SELECTION."* Create internal table of dynamic type
      CREATE DATA l_dyntable TYPE STANDARD TABLE OF (p_table)
                           WITH NON-UNIQUE DEFAULT KEY.
      ASSIGN l_dyntable->* TO <it_table>."*select statement to select data from the table as input into
    *our dynamic internal table.
    *Here i have restricted only till 5 rows.
    *You can set a variable and give no of rows to be fetched
    *The variable can be set in your select statement  SELECT * INTO CORRESPONDING FIELDS OF TABLE <it_table>
                   FROM (p_table) up to 5 rows."*Fieldcatalogue definitions
      wa_lvc_cat-fieldname = 'COLUMNTEXT'.
      wa_lvc_cat-ref_table = 'LVC_S_DETA'.
      APPEND wa_lvc_cat TO lt_lvc_cat.  wa_fieldcat-fieldname = 'COLUMNTEXT'.
      wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
      wa_fieldcat-key  = 'X'..
      APPEND wa_fieldcat TO lt_fieldcat.  DESCRIBE TABLE <it_table>.  DO sy-tfill TIMES.
      For each line, a column 'VALUEx' is created in the fieldcatalog
      Build Fieldcatalog
        WRITE sy-index TO wa_lvc_cat-fieldname LEFT-JUSTIFIED.
        CONCATENATE 'VALUE' wa_lvc_cat-fieldname
               INTO wa_lvc_cat-fieldname.
        wa_lvc_cat-ref_field = 'VALUE'.
        wa_lvc_cat-ref_table = 'LVC_S_DETA'.
        APPEND wa_lvc_cat TO lt_lvc_cat.
      Build Fieldcatalog
        CLEAR wa_fieldcat.
        wa_fieldcat-fieldname = wa_lvc_cat-fieldname.
        wa_fieldcat-ref_fieldname = 'VALUE'.
        wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
        APPEND wa_fieldcat TO lt_fieldcat.
      ENDDO."* Create dynamic internal table
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = lt_lvc_cat
        IMPORTING
          ep_table        = l_dyntable.  ASSIGN l_dyntable->* TO <dynamictable>."* Create structure as structure of the internal table
      CREATE DATA l_structure LIKE LINE OF <dynamictable>.
      ASSIGN l_structure->* TO <header>."* Create structure = structure of the internal table
      CREATE DATA l_structure LIKE LINE OF <it_table>.
      ASSIGN l_structure->* TO <ls_table>."* Create field catalog from our table structure
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       = p_table
        CHANGING
          ct_fieldcat            = lt_fieldcatalogue
        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.  DESCRIBE TABLE lt_fieldcatalogue."* Fill the internal to display <dynamictable>
      DO sy-tfill TIMES.
        IF sy-index = 1.
          READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX 1.
        ENDIF.
      For each field of it_table
        ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <dynheader>.
        IF sy-subrc NE 0. EXIT .ENDIF.
        READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX sy-index.
      Fill 1st column
        <dynheader> = wa_fieldcat-seltext_m.
        IF <dynheader> IS INITIAL.
          <dynheader> = wa_fieldcat-fieldname.
        ENDIF."*Filling the other columns
        LOOP AT <it_table> INTO <ls_table>.
          l_col = sy-tabix + 1.
          ASSIGN COMPONENT sy-index OF STRUCTURE <ls_table> TO <dyndata>.
          IF sy-subrc NE 0. EXIT .ENDIF.
          ASSIGN COMPONENT l_col OF STRUCTURE <header> TO
    <dynheader>.
          IF sy-subrc NE 0. EXIT .ENDIF.
          WRITE <dyndata> TO <dynheader> LEFT-JUSTIFIED.
        ENDLOOP.
        APPEND <header> TO <dynamictable>.
      ENDDO."*Layout for ALV output
      lt_layout-zebra = 'X'.
      lt_layout-no_colhead = 'X'..
      lt_layout-colwidth_optimize ='X'.
      lt_layout-window_titlebar = 'ALV GRID TRANSPOSED'."*ALV Grid output for display
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          is_layout   = lt_layout
          it_fieldcat = lt_fieldcat
        TABLES
          t_outtab    = <dynamictable>.
    Regards,
    Arun

  • ALV: Send ALV output as mail - background processing

    Hi all,
    I'm a newbie in SDC and try to implement the following functionality (Version 4.0B):
    A ABAP report (to be scheduled as e.g. a daily job run) with ALV output should send an automated email containing the ALV informations to a receiver specified in the selection criterias.
    I already have the following pieces:
    1) The report with ALV output (running online and clicking on List/send/office works perfectly, the alv-output is attached to the mail). The report runs also in background and generates a spool.
    2) A subroutine wich sends a email (input has to be in an itab)
    Now I try to put them together.
    Question: How can I automate the send process?
    I did a little bit of debugging, but got lost in the SAP Office functions.
    Any help appreciated!
    Thomas

    Hi Michael,
    thank you again a helpfull reply. To solve the issue I ended up writing a second little report.
    Here is a short description of my solution just in case anybody else is also interested in.
    I set up a Job with two steps.
    Step 1 is the ABAP that creates e.g. a ALV output (anything that goes to spool).
    Step 2 is a little ABAP that does nothing else than reading the output of step 1 (Spool) and send it as SAP Office Document. (To be a little more flexible I added some selection criterias for step 2 like Jobstep number, receiver, sendmode, ...).
    It works fine online (by keying in the spool number manually) and in batch mode (by determining the spool  number based on the job number). I think this solution is flexible and lightwight.
    Kind regards,
    Thomas
    Message was edited by: Thomas Hager
    Message was edited by: Thomas Hager

  • Repetition of header in ALV output once excel download is selected

    Hi Experts,
    I have alv report where I use FM as below
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program     = w_repid
          i_callback_top_of_page = 'TOP-OF-PAGE'  "see FORM
          is_layout              = l_layout
          it_fieldcat            = lt_fieldcat
          it_sort                = l_sort
          i_save                 = 'X'
        TABLES
          t_outtab               = itab
        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.
    and top of page as below
    FORM top-of-page.
    * Title
      w_header-typ  = 'H'.
      w_header-info = text-033.
      APPEND w_header TO t_header.
      CLEAR w_header.
    * Report Name
      w_header-typ  = 'S'.
      w_header-key = text-034.
      w_header-info =  sy-repid.
      APPEND w_header TO t_header.
      CLEAR w_header.
    * Date
      w_header-typ  = 'S'.
      w_header-key = text-035.
      CONCATENATE  sy-datum6(2) '.'+
                   sy-datum4(2) '.'+
                   sy-datum(4) INTO w_header-info.
      APPEND w_header TO t_header.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = t_header.
    ENDFORM.                    "top-of-page
    Its displaying well in output, but when I select excel download, the header is getting printed 4 times in the alv output and in the excel download it is printing twice. Please advise how to keep the header once. Note : I am not using any paging concept, simple header at the top.
    Please advise.
    Regards,
    Kiran.

    Hi kiran,
    While creating top-of-page,
    You have to refresh your header internal table before populating it with data i.e,
    FORM TOP.
    Refresh IT_HEADER                   -->with this the header text will not get repeatedly printed
    WA_HEADER-TYP = 'S'.
    WA_HEADER-KEY = TEXT-001.
    WA_HEADER-INFO = SY-REPID.
    APPEND WA_HEADER TO IT_HEADER.
    CLEAR WA_HEADER.
    WA_HEADER-TYP = 'S'.
    WA_HEADER-KEY = TEXT-002.
    WA_HEADER-INFO = SY-UNAME.
    APPEND WA_HEADER TO IT_HEADER.
    CLEAR WA_HEADER.
    WA_HEADER-TYP = 'S'.
    WA_HEADER-KEY = TEXT-003.
    WA_HEADER-INFO = SY-DATUM.
    APPEND WA_HEADER TO IT_HEADER.
    CLEAR WA_HEADER.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        it_list_commentary       = IT_HEADER
      I_LOGO                   =
      I_END_OF_LIST_GRID       =
      I_ALV_FORM               =
    ENDFORM.
    Hope it helps you
    Regards
    Mansi

  • Editing Alv Output

    Hi all ,
    Iam Generating ALV Grid using OOPs method, In the output list Iam editing some of the entries , now i need to store the edited output in a custom table.
    Can anyubody tell me how to capture these changes into an internal table.
    Early replies would be rewarded points.
    Thanks In advance,
    Neha

    Hi Neha,
    check this code
    *& Report  ZLAXMI_REPORT6                                              *
    REPORT  ZLAXMI_REPORT6     NO STANDARD PAGE HEADING
                               MESSAGE-ID ZZ
                               LINE-SIZE 132
                               LINE-COUNT 65 .
    TABLES: MARA.
    TYPE-POOLS: SLIS.
    TYPES: BEGIN OF T_MARA,
            MATNR TYPE MARA-MATNR, "Material Number
            ERSDA TYPE MARA-ERSDA, "Creation date
            BRGEW TYPE MARA-BRGEW, "Gross weight
            NTGEW TYPE MARA-NTGEW, "Net weight
            MTART TYPE MARA-MTART, "Material type
            MBRSH TYPE MARA-MBRSH, "Industry Sector
            REC_SEL   TYPE C , "checkbox
          END OF T_MARA.
                   V A R I A B L E S
    DATA: V_REPID LIKE SY-REPID,
          V_FLAG(1) TYPE C.
    CONSTANTS :
           C_X(1) TYPE C VALUE 'X',
           C_PF_STATUS TYPE SLIS_FORMNAME VALUE 'F_SET_PF_STATUS',
           C_FC_DELETE(6) TYPE C VALUE 'DELETE',
           C_FC_MODIFY(6) TYPE C VALUE 'MODIFY',
           C_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'F_USER_COMMAND',
           C_USER_COMMAND_MODIFY TYPE SLIS_FORMNAME
                                      VALUE 'F_USER_COMMAND_MODIFY',
           C_ICON_DELETE TYPE ICON-NAME VALUE 'ICON_DELETE', " Icon,Delete'
           C_ICON_CANCEL TYPE ICON-NAME VALUE 'ICON_CANCEL', " Icon,Cancel'
           C_FC_SAVE(4)  TYPE C VALUE 'SAVE'.
    *internal table declarations.
    DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,
          IT_MODIFY TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,
          IT_TEMP TYPE STANDARD TABLE OF MARA WITH HEADER LINE,
    *-ALV Internal Tables.
    *--Field Catalog
           IT_FIELDCAT TYPE STANDARD TABLE OF
                            SLIS_FIELDCAT_ALV WITH HEADER LINE,
    *--Layout
           WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
    *--Sort
           IT_SORT TYPE SLIS_T_SORTINFO_ALV,
           WA_SORT TYPE SLIS_SORTINFO_ALV  ,
    **-Structure for excluding function codes
           WA_EXTAB TYPE SLIS_EXTAB,
    **-To hold function codes to be excluded in ALV toolbar
           IT_EXTAB TYPE SLIS_T_EXTAB.
    *selection screen.
    SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR,
                    S_ERSDA FOR MARA-ERSDA.
    SELECTION-SCREEN: END OF BLOCK B1.
    *--Radio buttons to select either Display/Delete/Modify
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME
                    TITLE TEXT-002.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN  COMMENT 1(20) TEXT-003.
    PARAMETERS: P_DISP RADIOBUTTON GROUP RAD1 DEFAULT 'X'.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) TEXT-005.
    PARAMETERS: P_UPD RADIOBUTTON GROUP RAD1.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) TEXT-004.
    PARAMETERS: P_DEL RADIOBUTTON GROUP RAD1.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN END OF BLOCK B2 .
    AT SELECTION-SCREEN.
      PERFORM VALIDATE_SCREEN.
    *start of selection
    START-OF-SELECTION.
    *clear the internal tables to be used.
      CLEAR: IT_MARA,IT_MARA[],
             V_FLAG.
    *get the data
      PERFORM GET_DATA.
    *end of selection
    END-OF-SELECTION.
      IF IT_MARA[] IS INITIAL.
        MESSAGE I000 WITH
              'No Records found for the given Selection Criteria'(012).
      ELSE.
    *do alv process
        V_REPID = SY-REPID.
    *--Sort the Output Fields
        PERFORM SORT_FIELDS.
    *--Build Field catalog for the Output fields
        PERFORM BUILD_FIELDCAT.
    *--Set the Layout for ALV
        PERFORM SET_LAYOUT.
        IF P_DISP = C_X.
    *--Exclude any Buttons on the Appn tool bar
       perform change_default_pf_status.
          MOVE C_FC_DELETE TO WA_EXTAB-FCODE.    " DELETE button on ALV
          APPEND WA_EXTAB TO IT_EXTAB.
          MOVE C_FC_MODIFY TO WA_EXTAB-FCODE.    " MODIFY button on ALV
          APPEND WA_EXTAB TO IT_EXTAB.
        ELSEIF P_UPD = C_X.
    *--Exclude DELETE Button on the appn tool bar
          MOVE C_FC_DELETE TO WA_EXTAB-FCODE.    " DELETE button on ALV
          APPEND WA_EXTAB TO IT_EXTAB.
        ELSEIF P_DEL = C_X.
    *--Exclude MODIFY button on appn tool bar
          MOVE C_FC_MODIFY TO WA_EXTAB-FCODE.    " MODIFY button on ALV
          APPEND WA_EXTAB TO IT_EXTAB.
        ENDIF.
    *--Exclude SAVE button for all options
        MOVE 'SAVE' TO WA_EXTAB-FCODE.    " SAVE button on ALV
        APPEND WA_EXTAB TO IT_EXTAB.
    *--Display ALV output
        PERFORM LIST_DISPLAY TABLES IT_MARA
                             USING  C_USER_COMMAND.
      ENDIF.
    *&      Form  get_data
          text
    -->  p1        text
    <--  p2        text
    FORM GET_DATA .
      SELECT MATNR
             ERSDA
             BRGEW
             NTGEW
             MTART
             MBRSH
             FROM MARA
             INTO TABLE IT_MARA
             WHERE MATNR IN S_MATNR
             AND ERSDA IN S_ERSDA.
      IF SY-SUBRC <> 0.
    *no records selected leave processing
        STOP.
      ENDIF.
      SORT IT_MARA.
    ENDFORM.                    " get_data
    *&      Form  sort_fields
          text
    -->  p1        text
    <--  p2        text
    FORM SORT_FIELDS .
      CLEAR WA_SORT.
      WA_SORT-FIELDNAME = 'MATNR'.
      WA_SORT-SPOS = '1'.
      WA_SORT-UP = 'X'.
      APPEND WA_SORT TO IT_SORT.
      CLEAR WA_SORT.
      WA_SORT-FIELDNAME = 'ERSDA'.
      WA_SORT-SPOS = '2'.
      WA_SORT-UP = 'X'.
      APPEND WA_SORT TO IT_SORT.
    ENDFORM.                    " sort_fields
    *&      Form  build_fieldcat
          text
    -->  p1        text
    <--  p2        text
    FORM BUILD_FIELDCAT .
      IT_FIELDCAT-COL_POS    = '1'.
      IT_FIELDCAT-FIELDNAME  = 'MATNR'.
      IT_FIELDCAT-KEY        = 'X'.
      IT_FIELDCAT-OUTPUTLEN  = '15'.
      IT_FIELDCAT-SELTEXT_L  = 'Material number'(022).
      APPEND IT_FIELDCAT.
      CLEAR  IT_FIELDCAT.
      IT_FIELDCAT-COL_POS    = '2'.
      IT_FIELDCAT-FIELDNAME  = 'ERSDA'.
      IT_FIELDCAT-KEY        = 'X'.
      IT_FIELDCAT-OUTPUTLEN  = '10'.
      IT_FIELDCAT-SELTEXT_L  = 'Created on'(023).
      APPEND IT_FIELDCAT.
      CLEAR  IT_FIELDCAT.
      IT_FIELDCAT-COL_POS    = '3'.
      IT_FIELDCAT-FIELDNAME  = 'BRGEW'.
      IT_FIELDCAT-OUTPUTLEN  = '10'.
      IT_FIELDCAT-SELTEXT_L  = 'GROSS WEIGHT'(024).
      APPEND IT_FIELDCAT.
      CLEAR  IT_FIELDCAT.
      IT_FIELDCAT-COL_POS    = '4'.
      IT_FIELDCAT-FIELDNAME  = 'NTGEW'.
      IT_FIELDCAT-OUTPUTLEN  = '15'.
      IT_FIELDCAT-SELTEXT_L  = 'NET WEIGHT'(025).
      APPEND IT_FIELDCAT.
      CLEAR  IT_FIELDCAT.
      IT_FIELDCAT-COL_POS    = '5'.
      IT_FIELDCAT-FIELDNAME  = 'MTART'.
      IT_FIELDCAT-OUTPUTLEN  = '3'.
      IT_FIELDCAT-SELTEXT_L  = 'Material type'(026).
      APPEND IT_FIELDCAT.
      CLEAR  IT_FIELDCAT.
      IT_FIELDCAT-COL_POS    = '6'.
      IT_FIELDCAT-FIELDNAME  = 'MBRSH'.
      IT_FIELDCAT-OUTPUTLEN  = '25'.
      IT_FIELDCAT-SELTEXT_L  = 'Industry sector'(027).
      APPEND IT_FIELDCAT.
      CLEAR  IT_FIELDCAT.
      IT_FIELDCAT-FIELDNAME  = 'REC_SEL'.
      IT_FIELDCAT-NO_OUT = C_X.
      APPEND IT_FIELDCAT.
      CLEAR  IT_FIELDCAT.
    ENDFORM.                    " build_fieldcat
    *&      Form  list_display
          text
         -->P_IT_MARA  text
         -->P_C_USER_COMMAND  text
    FORM LIST_DISPLAY  TABLES   P_IT_MARA
                       USING    P_USER_COMMAND TYPE SLIS_FORMNAME.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM       = V_REPID
          I_CALLBACK_PF_STATUS_SET = C_PF_STATUS
          I_CALLBACK_USER_COMMAND  = P_USER_COMMAND
          IS_LAYOUT                = WA_LAYOUT
          IT_FIELDCAT              = IT_FIELDCAT[]
          IT_EXCLUDING             = IT_EXTAB[]
          IT_SORT                  = IT_SORT[]
        TABLES
          T_OUTTAB                 = P_IT_MARA
        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.                    " list_display
    *&      Form  F_SET_PF_STATUS
          Set PF_STATUS STANDARD modifying the standard toolbar
          by excluding some buttons
         -->P_IT_EXTAB  -- TABLE OF EXCLUDING FUNCTIONS
    FORM F_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
      CLEAR : WA_EXTAB,
              IT_EXTAB.
    *--Set the Modified PF status for the ALV.
      SET PF-STATUS 'ALV_STATUS_01' EXCLUDING RT_EXTAB.
    ENDFORM.                               " SET_PF_STATUS
    *&      Form  f_user_command
          Handle user action on ALV toolbar
    FORM F_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
                              RS_SELFIELD TYPE SLIS_SELFIELD.
      RS_SELFIELD-REFRESH = C_X.
      IF R_UCOMM = C_FC_DELETE.
    *--User Selected DELETE button.
        PERFORM DELETE_SELECTED_RECORDS.
      ELSEIF R_UCOMM = C_FC_MODIFY.
    *--If user selects MODIFY button.
        PERFORM CHANGE_RECORDS.
      ENDIF.
    ENDFORM.                    "F_USER_COMMAND
    *&      Form  POP_UP_CONFIRMATION
          text
         <--P_ANSWER  text
    FORM POP_UP_CONFIRMATION
                                CHANGING P_ANSWER TYPE C.
      DATA:
         L_TITLE(14) TYPE C,               " Title of pop-up
         L_TXT_QUESTION(52) TYPE C,        " Text displayed in pop-up
        L_DISP_CANCEL TYPE C,             " Display 'Cancel' button?
         L_BTN1 TYPE ICON-NAME,            " Icon on button 1
         L_BTN2 TYPE ICON-NAME.            " Icon on button 2
      L_TITLE        = 'Delete'(017).                   " delete
      L_TXT_QUESTION = 'Are you sure to delete?'(018).
      L_BTN1         = C_ICON_DELETE.
      L_BTN2         = C_ICON_CANCEL.
    **-Display pop-up asking user for confirmation
      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          TITLEBAR              = L_TITLE
          TEXT_QUESTION         = L_TXT_QUESTION
          TEXT_BUTTON_1         = 'Yes'
          ICON_BUTTON_1         = L_BTN1
          TEXT_BUTTON_2         = 'No'
          ICON_BUTTON_2         = L_BTN2
          DEFAULT_BUTTON        = '2'
          DISPLAY_CANCEL_BUTTON = 'X'
        IMPORTING
          ANSWER                = P_ANSWER
        EXCEPTIONS
          TEXT_NOT_FOUND        = 1
          OTHERS                = 2.
      IF SY-SUBRC <> 0.
        MESSAGE E000 WITH 'Error executing function module:'(019)
                                 'POPUP_TO_CONFIRM'.
      ENDIF.
    ENDFORM.                    "pop_up_confirmation
    *&      Form  set_layout
          text
    -->  p1        text
    <--  p2        text
    FORM SET_LAYOUT .
      IF P_DEL = C_X OR P_UPD = C_X.
    *--Allow Input only if user choose 'UPDATE'/ 'DELETE' radio buttons
        WA_LAYOUT-BOX_FIELDNAME = 'REC_SEL'.
        WA_LAYOUT-BOX_TABNAME = 'IT_MARA'.
      ENDIF.
    *--Display Header based on the user selection
      IF P_DISP = C_X.
        WA_LAYOUT-WINDOW_TITLEBAR =
                              'Display '(036).
      ELSEIF P_DEL = C_X.
        WA_LAYOUT-WINDOW_TITLEBAR =
                     'Delete '(037).
      ELSEIF P_UPD = C_X.
        WA_LAYOUT-WINDOW_TITLEBAR =
                     'Change '(038).
      ENDIF.
    ENDFORM.                    " set_layout
    *&      Form  change_default_pf_status
          text
    -->  p1        text
    <--  p2        text
    FORM CHANGE_DEFAULT_PF_STATUS .
      MOVE C_FC_DELETE TO WA_EXTAB-FCODE.    " DELETE button on ALV
      APPEND WA_EXTAB TO IT_EXTAB.
      MOVE C_FC_MODIFY TO WA_EXTAB-FCODE.    " MODIFY button on ALV
      APPEND WA_EXTAB TO IT_EXTAB.
    ENDFORM.                    " change_default_pf_status
    *&      Form  f_user_command
          Handle user action on ALV toolbar
    FORM F_USER_COMMAND_MODIFY USING R_UCOMM LIKE SY-UCOMM      "#EC *
                              RS_SELFIELD TYPE SLIS_SELFIELD.
      DATA :     L_ANSWER TYPE C.                               "#EC *
      IF R_UCOMM = C_FC_SAVE.
    *user selected save button
        READ TABLE IT_MODIFY WITH KEY REC_SEL = 'X'.
    *check if user selected atleast one line.
        IF SY-SUBRC <> 0.
          MESSAGE I000 WITH 'No record(s) Selected to Modify'(016).
          EXIT.
        ENDIF.
        LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.
    *--Check the entered values are valid or not.
         IF NOT ( it_modify-status = 'A' OR
                  it_modify-status = 'C' OR
                  it_modify-status = 'E' ).
    *--User Entered invalid value for STATUS field,so Display Error Msg
          CLEAR R_UCOMM.
           MESSAGE e000 WITH 'Invalid value '''(031)
                            '' for Status in the Record # '(032)
                            sy-tabix.
         ENDIF.
        ENDLOOP.
        CLEAR: IT_TEMP,
               IT_TEMP[].
        LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.
          MOVE-CORRESPONDING IT_MODIFY TO IT_TEMP.
          APPEND IT_TEMP.
          CLEAR IT_TEMP.
        ENDLOOP.
    *--start new code
        DATA : IT_TEMP2 LIKE STANDARD TABLE OF MARA WITH HEADER LINE.
        SELECT * FROM MARA
                  INTO TABLE IT_TEMP2
                  FOR ALL ENTRIES IN IT_TEMP
                  WHERE MATNR = IT_TEMP-MATNR.
        IF SY-SUBRC = 0.
          LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.
            READ TABLE IT_TEMP2 WITH KEY MATNR = IT_MODIFY-MATNR.
            IF SY-SUBRC = 0.
              IT_TEMP2-NTGEW = IT_MODIFY-NTGEW.
              IT_TEMP2-BRGEW = IT_MODIFY-BRGEW.
              MODIFY IT_TEMP2 INDEX SY-TABIX.
            ENDIF.
          ENDLOOP.
        ENDIF.
    *modify mara table with the changed values
        MODIFY MARA FROM TABLE IT_TEMP2 .
    *--end new code
        IF SY-SUBRC = 0.
          COMMIT WORK AND WAIT.
    *--Display message with Success in Updating database
          MESSAGE I000 WITH SY-DBCNT
                            ' Record(s) has been Updated'(020).
          CLEAR :
                 IT_MARA,
                 IT_MARA[].
    *get-data again from database.
          PERFORM GET_DATA.
            RS_SELFIELD-REFRESH = C_X.
        ELSE.
    *--Error occurred
          MESSAGE I000 WITH 'Error occured in Modifying the database'(021).
        ENDIF.
      ENDIF.
    ENDFORM.                    "f_user_command_modify
    *&      Form  validate_screen
          text
    -->  p1        text
    <--  p2        text
    FORM VALIDATE_SCREEN .
      DATA  : LV_MATNR LIKE MARA-MATNR.
    *--validate product
       IF NOT S_MATNR[] IS INITIAL.
      SELECT MATNR
             INTO MARA-MATNR
             FROM MARA
             WHERE MATNR IN S_MATNR.
      ENDSELECT.
      IF SY-SUBRC <> 0.
    *--Error
        MESSAGE E000 WITH 'Invalid Material'(034).
      ENDIF.
    ENDIF.
    ENDFORM.                    " validate_screen
    *&      Form  delete_records
          text
    -->  p1        text
    <--  p2        text
    FORM DELETE_RECORDS .
      LOOP AT IT_MARA.
        MOVE-CORRESPONDING IT_MARA TO IT_TEMP.
        APPEND IT_TEMP.
        CLEAR IT_TEMP.
      ENDLOOP.
      DELETE MARA FROM TABLE IT_TEMP.
      IF SY-SUBRC = 0.
    *--Successfully selected records Deleted.
        COMMIT WORK AND WAIT.
    *--Display Success Message to the user
        MESSAGE I000  WITH SY-DBCNT
                          ' Record(s) deleted Successfully'(010).
      ELSE.
    *--Error occured in deletion
        MESSAGE I000 WITH 'Error occured in Deleting the Record(s)'(011).
      ENDIF.
      CLEAR: IT_MARA,
             IT_MARA[],
             IT_TEMP,
             IT_TEMP[].
      V_FLAG = C_X.
      STOP.
    ENDFORM.                    " delete_records
    *&      Form  delete_selected_records
          text
    -->  p1        text
    <--  p2        text
    FORM DELETE_SELECTED_RECORDS .
      DATA  : L_ANSWER(1) TYPE C.
      READ TABLE IT_MARA WITH KEY REC_SEL = C_X.
      IF SY-SUBRC <> 0.
        MESSAGE I000 WITH 'No record(s) Selected to Delete'(013).
        EXIT.
      ELSE.
    *--Ask for delete confirmation
        PERFORM POP_UP_CONFIRMATION
                                    CHANGING L_ANSWER.
        IF L_ANSWER = '1'.             " 'Yes'
          CLEAR: IT_TEMP,
                 IT_TEMP[].
          LOOP AT IT_MARA WHERE REC_SEL = 'X'.
            MOVE-CORRESPONDING IT_MARA TO IT_TEMP.
            APPEND IT_TEMP.
            CLEAR IT_TEMP.
          ENDLOOP.
          DELETE MARA FROM TABLE IT_TEMP.
          IF SY-SUBRC = 0.
    *--Successfully selected records Deleted.
            COMMIT WORK AND WAIT.
    *--Display completed work information to the user
            MESSAGE I000  WITH SY-DBCNT
                              ' Record(s) deleted Successfully'(014).
    *--Clear the Internal tables
            CLEAR: IT_MARA,
                   IT_MARA[].
    *--Reselects entries from Database again & display in ALV
            PERFORM GET_DATA.
          ELSE.
    *--Error occured
            MESSAGE I000 WITH
                        'Error occured in Deleting the Record(s)'(015).
          ENDIF.
        ENDIF.
      ENDIF.
    ENDFORM.                    " delete_selected_records
    *&      Form  change_records
          text
    -->  p1        text
    <--  p2        text
    FORM CHANGE_RECORDS .
      READ TABLE IT_MARA WITH KEY REC_SEL = 'X'.
    *--check user selected at least 1 record to MODIFY or not
      IF SY-SUBRC <> 0.
        MESSAGE I000 WITH 'No record(s) Selected to Modify'(016).
        EXIT.
      ELSE.
        CLEAR : IT_MODIFY,
                IT_MODIFY[].
        LOOP AT IT_MARA WHERE REC_SEL = 'X'.
          IT_MODIFY = IT_MARA.
          APPEND IT_MODIFY.
          CLEAR IT_MODIFY.
        ENDLOOP.
    *--Change PF status for this new ALV list.
        PERFORM CHANGE_PF_STATUS_AGAIN.
    *--Change Field Catalog to make INPUT enabled.
        READ TABLE IT_FIELDCAT WITH KEY FIELDNAME = 'NTGEW'.
        IT_FIELDCAT-INPUT = C_X.
        MODIFY IT_FIELDCAT INDEX SY-TABIX.
    *--Call ALV LIST DISPLAY with this new values.
        PERFORM  LIST_DISPLAY TABLES IT_MODIFY
                              USING C_USER_COMMAND_MODIFY.
      ENDIF.
    ENDFORM.                    " change_records
    *&      Form  change_pf_status_again
          text
    -->  p1        text
    <--  p2        text
    FORM CHANGE_PF_STATUS_AGAIN .
      MOVE C_FC_DELETE TO WA_EXTAB-FCODE.    " DELETE button on ALV
      APPEND WA_EXTAB TO IT_EXTAB.
      MOVE C_FC_MODIFY TO WA_EXTAB-FCODE.    " MODIFY button on ALV
      APPEND WA_EXTAB TO IT_EXTAB.
    ENDFORM.                    " change_pf_status_again
    Regards,
    Laxmi.

  • How to capture multiple(Random) records of an ALV output report?

    Hi  Friends,
      1) I have an output in Grid format(using reuse_alv_grid_displlay). I have 3 push buttons on the menu bar(for ex.. Approve, reject and forward). The user will select multiple lines on the ALV output and hits either one of these push buttons. My question is how do I capture the multiple selected output lines.
    2) This question has been asked before..and I tried to implement the answer. The problem I am facing is ..I need a function key to say that everytime I select a line(single click)..it should modify the internal tabel with CHECK = 'X'.
    Any help is kindly appreciated.

    Hi
    If you should have in your output table a field for MARK, the system'll set this field for every selected fields.
    DATA: BEGIN OF T_OUTPUT,
           FIELD1,....
           FIELDN,
           MARK,
          END   OF T_OUTPUT
    Before calling ALV GRID
    You have to indicate tne name of field for selection:
    gt_layout-box_fieldname     = 'MARK'.
    gt_layout-box_tabname       = 'T_OUTPUT'.
    So in your user command
    LOOP AT T_OUTPUT WHERE MARK = 'X'.
    ENDLOOP.
    Max

  • Add ALV Button to VKM1 ALV output

    Can you tell me the best way to add a button to the ALV grid output
    from the VKM1 transaction? I wanted to add it to the GUI Status, but
    all the function keys for the STANDAKR status are taken, so it wouldn't
    let me. I then tried to add the Classes and Events for handle_toolbar
    and handle_user_command, but without success - if this is the way to
    add the button, please just let me know and I will investigate
    further. I have also read about creating my own pf_status since the
    program uses "CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'". Is that what I
    should look into doing? I have been trying different things for a
    couple of days, and I just want to know which way would be the best way
    for adding the button.

    I found that I could add the button throught the GUI Status, although I would need to replace one of the other buttons because all the function keys were taken. In place of this, I found I could add a function code to the Menu Bar without needing a function key, so that is what I intend to use.

  • How can we modify alv output list

    Hi
    this is fazil.
    Please tell me any body How can we modify alv output list.
    Thanks & Regards
    Fazil
    [email protected]

    Fazil,
    check the program,
    You can find the code in this program 'BCALV_FIELDCAT_TEST'
    *& Report  BCALV_FIELDCAT_TEST                                         *
    This report allows to modify the fieldcatalog of a corresponding
    output table and to view the effects of your changes directly.
    Note that for some changes you need to newly display the whole
    ALV Grid Control, e.g., DDIC-Fields are read only the first time
    you call SET_READY_FOR_FIRST_DISPLAY.
    Note also that not all scenarios can be tested since the output
    table does not comprise all fields to test available features
    of the fieldcatalog. Copy this program and extend the output
    table accordingly if you want to test such a special feature.
    (The field CARRNAME in 'gt_sflight' was added to test field REF_FIELD
    and TXT_FIELD of the fieldcatalog - see what happens if you
    calculate subtotals by carrier-id).
    report  bcalvt_fieldcatalog           .
    data: ok_code               type sy-ucomm,
          save_ok_code          type sy-ucomm,
    fieldcatalog for output table
          gt_fieldcat           type lvc_t_fcat,
    fieldcatalog for fieldcatalog itself:
          gt_fcatfcat           type lvc_t_fcat,
          gs_fcatlayo           type lvc_s_layo.
    Output table
    data: begin of gt_sflight occurs 0.
    data: carrname type s_carrname.
            include structure sflight.
    data: end of gt_sflight.
    data: g_max type i value 100.
    data: g_all type c value SPACE.
    Controls to display gt_sflight and corresponding fieldcatalog
    data: g_docking type ref to cl_gui_docking_container,
          g_alv     type ref to cl_gui_alv_grid.
    data: g_custom_container type ref to cl_gui_custom_container,
          g_editable_alv     type ref to cl_gui_alv_grid.
    LOCAL CLASS Definition
    class lcl_event_receiver definition.
      public section.
        methods handle_data_changed
          for event data_changed of cl_gui_alv_grid
          importing er_data_changed.
    endclass.
    class lcl_event_receiver implementation.
      method handle_data_changed.
    at the time being, no checks are made...
      endmethod.
    endclass.
    data: event_receiver type ref to lcl_event_receiver.
    end-of-selection.
      set screen 100.
    *&      Module  STATUS_0100  OUTPUT
          text
    module status_0100 output.
      set pf-status 'BASIC'.
      set titlebar 'BASICTITLE'.
    create ALV Grid Control in the first run
      if g_docking is initial.
        perform create_and_init_controls.
      endif.
    endmodule.                             " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
          text
    module user_command_0100 input.
      save_ok_code = ok_code.
      clear ok_code.
      case save_ok_code.
        when 'SUBMIT'.
    set the frontend fieldcatalog
    ATTENTION: DDIC-Fields are not updated using this method!
    (see 'RESTART')
          call method g_alv->set_frontend_fieldcatalog
               exporting
                 it_fieldcatalog = gt_fieldcat.
          call method g_alv->refresh_table_display.
          call method cl_gui_cfw=>flush.
        when 'RESTART'.
    Destroy the control currently visible and display it again
    using the changed fieldcatalog.
          perform restart_sflight.
        when '&ALL'.
          perform switch_visibility.
      endcase.
    endmodule.                             " USER_COMMAND_0100  INPUT
    *&      Form  CREATE_AND_INIT_CONTROLS
          text
    -->  p1        text
    <--  p2        text
    form create_and_init_controls.
      create object g_docking
          exporting
               dynnr = '100'
               extension = 150
               side = cl_gui_docking_container=>dock_at_bottom.
      create object g_alv
          exporting
               i_parent = g_docking.
      create object g_custom_container
          exporting
               container_name = 'CC_0100_FIELDCAT'.
      create object g_editable_alv
          exporting
               i_parent = g_custom_container.
    register events
      create object event_receiver.
      set handler event_receiver->handle_data_changed for g_editable_alv.
      call method g_editable_alv->register_edit_event
                    exporting
                       i_event_id = cl_gui_alv_grid=>mc_evt_modified.
      perform build_fieldcatalogs changing gt_fieldcat gt_fcatfcat.
      perform modify_fieldcatalog changing gt_fcatfcat.
      perform select_data.                 "CHANGING gt_sflight
      call method g_alv->set_table_for_first_display
              changing
                   it_outtab       = gt_sflight[]
                   it_fieldcatalog = gt_fieldcat[].
    optimize column width of grid displaying fieldcatalog
      gs_fcatlayo-cwidth_opt = 'X'.
    Get fieldcatalog of table sflight - alv might have
    modified it after passing.
      call method g_alv->get_frontend_fieldcatalog
                importing et_fieldcatalog = gt_fieldcat[].
      call method cl_gui_cfw=>flush.
    Display fieldcatalog of table sflight:
      call method g_editable_alv->set_table_for_first_display
              exporting
                   is_layout       = gs_fcatlayo
              changing
                   it_outtab       = gt_fieldcat[]
                   it_fieldcatalog = gt_fcatfcat[].
    register events
      create object event_receiver.
      set handler event_receiver->handle_data_changed for g_editable_alv.
    endform.                               " CREATE_AND_INIT_CONTROLS
    *&      Form  restart_sflight
          text
    -->  p1        text
    <--  p2        text
    form restart_sflight.
      data: ls_fieldcat type lvc_s_fcat.
    free g_docking and thus g_alv
      call method g_docking->free.
      clear g_docking.
      clear g_alv.
    create new instances
      create object g_docking
          exporting
               dynnr = '100'
               extension = 150
               side = cl_gui_docking_container=>dock_at_bottom.
      create object g_alv
          exporting
               i_parent = g_docking.
    This is an internal method to invalidate all fields in the fieldcat
      loop at gt_fieldcat into ls_fieldcat.
        clear ls_fieldcat-tech_comp.
        modify gt_fieldcat from ls_fieldcat.
      endloop.
    Newly display the list with current fieldcatalog.
      call method g_alv->set_table_for_first_display
              changing
                   it_outtab       = gt_sflight[]
                   it_fieldcatalog = gt_fieldcat.
    Get fieldcatalog - it might be changed by ALV in the last call
      call method g_alv->get_frontend_fieldcatalog
              importing
                   et_fieldcatalog = gt_fieldcat[].
      call method g_editable_alv->refresh_table_display.
      call method cl_gui_cfw=>flush.
    endform.                               " restart_sflight
    *&      Form  select_data
          text
    -->  p1        text
    <--  p2        text
    form select_data.
      data: lt_sflight type table of sflight with header line,
            ls_scarr type scarr.
    select data of sflight
      select * from sflight into table lt_sflight up to g_max rows.
    copy data to gt_sflight and update CARRNAME
      loop at lt_sflight.
        move-corresponding lt_sflight to gt_sflight.
        select single * from scarr into ls_scarr
           where carrid = gt_sflight-carrid.
        gt_sflight-carrname = ls_scarr-carrname.
        append gt_sflight.
      endloop.
    endform.                               " select_data
    *&      Form  BUILD_FIELDCATALOGS
          text
         <--P_GT_FIELDCAT  text
         <--P_GT_FCATFCAT  text
    form build_fieldcatalogs changing p_fieldcat type lvc_t_fcat
                                      p_fcatfcat type lvc_t_fcat.
      data: ls_fcat     type lvc_s_fcat.
    Fieldcatalog for table SFLIGHT: p_fieldcat
    generate fieldcatalog automatically
      call function 'LVC_FIELDCATALOG_MERGE'
          exporting
               i_structure_name       = 'SFLIGHT'
            I_CLIENT_NEVER_DISPLAY = 'X'
           changing
                ct_fieldcat            = p_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.
    shift all column positions to the right except for MANDT
      loop at p_fieldcat into ls_fcat.
        if ls_fcat-fieldname ne 'MANDT'.
          add 1 to ls_fcat-col_pos.
          if ls_fcat-fieldname = 'CARRID'.
            ls_fcat-txt_field = 'CARRNAME'."link CARRNAME to CARRID
          endif.
          modify p_fieldcat from ls_fcat.
        endif.
      endloop.
    create a new line for CARRNAME in p_fieldcat
      clear ls_fcat.
      ls_fcat-fieldname = 'CARRNAME'.
      ls_fcat-ref_table = 'SCARR'.
      ls_fcat-col_pos = 1.
    insert new line before CARRID (do not forget MANDT!).
      insert ls_fcat into p_fieldcat index 1.
    Fieldcatalog for table LVC_T_FCAT:p_fcatfcat
    Generate fieldcatalog of fieldcatalog structure.
    This fieldcatalog is used to display fieldcatalog 'p_fieldcat'
    on the top of the screen.
      call function 'LVC_FIELDCATALOG_MERGE'
          exporting
               i_structure_name       = 'LVC_S_FCAT'
            I_CLIENT_NEVER_DISPLAY = 'X'
           changing
                ct_fieldcat            = p_fcatfcat[]
       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.
    Hide all fields that are not documented (valid for release 4.6A)
      perform hide_fields changing p_fcatfcat.
    endform.                               " BUILD_FIELDCATALOGS
    *&      Module  EXIT_PROGRAM  INPUT
          text
    module exit_program input.
      leave program.
    endmodule.                             " EXIT_PROGRAM  INPUT
    *&      Form  MODIFY_FIELDCATALOG
          text
         <--P_GT_FCATFCAT  text
    form modify_fieldcatalog changing p_fcatfcat type lvc_t_fcat.
      data ls_fcat type lvc_s_fcat.
      loop at p_fcatfcat into ls_fcat.
        ls_fcat-coltext = ls_fcat-fieldname.
        ls_fcat-edit = 'X'.
        if ls_fcat-fieldname = 'COL_POS' or ls_fcat-fieldname = 'FIELDNAME'.
          ls_fcat-key = 'X'.
        endif.
        modify p_fcatfcat from ls_fcat.
      endloop.
    endform.                               " MODIFY_FIELDCATALOG
    form hide_fields changing p_fieldcat type lvc_t_fcat.
      data: ls_fcat type lvc_s_fcat.
    Only show documented fields of fieldcatalog.
    For a documentation choose "Help->Application Help" in the menu.
      loop at p_fieldcat into ls_fcat.
        if not (
             ls_fcat-fieldname eq 'CFIELDNAME'
        or   ls_fcat-fieldname eq 'COL_POS'
        or   ls_fcat-fieldname eq 'COLDDICTXT'
        or   ls_fcat-fieldname eq 'COLTEXT'
        or   ls_fcat-fieldname eq 'CURRENCY'
        or   ls_fcat-fieldname eq 'DD_OUTLEN'
        or   ls_fcat-fieldname eq 'DECIMALS_O'
        or   ls_fcat-fieldname eq 'DECMLFIELD'
        or   ls_fcat-fieldname eq 'DO_SUM'
        or   ls_fcat-fieldname eq 'DRAGDROPID'
        or   ls_fcat-fieldname eq 'EDIT_MASK'
        or   ls_fcat-fieldname eq 'EMPHASIZE'
        or   ls_fcat-fieldname eq 'EXPONENT'
        or   ls_fcat-fieldname eq 'FIELDNAME'
        or   ls_fcat-fieldname eq 'HOTSPOT'
        or   ls_fcat-fieldname eq 'ICON'
        or   ls_fcat-fieldname eq 'INTLEN'
        or   ls_fcat-fieldname eq 'INTTYPE'
        or   ls_fcat-fieldname eq 'JUST'
        or   ls_fcat-fieldname eq 'KEY'
        or   ls_fcat-fieldname eq 'LOWERCASE'
        or   ls_fcat-fieldname eq 'LZERO'
        or   ls_fcat-fieldname eq 'NO_OUT'
        or   ls_fcat-fieldname eq 'NO_SIGN'
        or   ls_fcat-fieldname eq 'NO_SUM'
        or   ls_fcat-fieldname eq 'NO_ZERO'
        or   ls_fcat-fieldname eq 'OUTPUTLEN'
        or   ls_fcat-fieldname eq 'QFIELDNAME'
        or   ls_fcat-fieldname eq 'QUANTITY'
        or   ls_fcat-fieldname eq 'REF_FIELD'
        or   ls_fcat-fieldname eq 'REF_TABLE'
        or   ls_fcat-fieldname eq 'REPREP'
        or   ls_fcat-fieldname eq 'REPTEXT'
        or   ls_fcat-fieldname eq 'ROLLNAME'
        or   ls_fcat-fieldname eq 'ROUND'
        or   ls_fcat-fieldname eq 'ROUNDFIELD'
        or   ls_fcat-fieldname eq 'SCRTEXT_L'
        or   ls_fcat-fieldname eq 'SCRTEXT_M'
        or   ls_fcat-fieldname eq 'SCRTEXT_S'
        or   ls_fcat-fieldname eq 'SELDDICTXT'
        or   ls_fcat-fieldname eq 'SELTEXT'
        or   ls_fcat-fieldname eq 'SP_GROUP'
        or   ls_fcat-fieldname eq 'SYMBOL'
        or   ls_fcat-fieldname eq 'TECH'
        or   ls_fcat-fieldname eq 'TIPDDICTXT'
        or   ls_fcat-fieldname eq 'TOOLTIP'
        or   ls_fcat-fieldname eq 'TXT_FIELD' ).
          ls_fcat-tech = 'X'.
        endif.
        modify p_fieldcat from ls_fcat.
      endloop.
    endform.
    form switch_visibility.
    data:  lt_fcatfcat type lvc_t_fcat,
            ls_fcat type lvc_s_fcat.
    call method g_editable_alv->get_frontend_fieldcatalog
                 importing ET_FIELDCATALOG = lt_fcatfcat.
    if not g_all is initial.
         perform hide_fields changing lt_fcatfcat.
         g_all = SPACE.
    else.
        loop at lt_fcatfcat into ls_fcat.
           if ls_fcat-tech eq 'X'.
               ls_fcat-tech = SPACE.
               ls_fcat-no_out = 'X'.
               modify lt_fcatfcat from ls_fcat.
           endif.
        endloop.
        g_all = 'X'.
    endif.
    call method g_editable_alv->set_frontend_fieldcatalog
                exporting it_fieldcatalog = lt_fcatfcat.
    call method g_editable_alv->refresh_table_display.
    endform.
    Don't forget to rewaard if useful..

Maybe you are looking for

  • How can I modify memory limitation to a Java thread?

    While I using java -Xms64M xxxx (class name) it seems that 64M is the biggest memory capacity Jvm allows. How if i wish to use more than 64M ? Ps: I am using Windows XP Thanks

  • Flash Player not installing for IE8

    I'm trying to install Flash Player into my IE8, but when I go to "Get Adobe Flash Player", it brings up a page saying "Sorry Adobe® Flash® Player is not available from Adobe.com for your device's operating system or browser." I checked the 'supported

  • Problem with ie6 displaying different to every other browser

    I have just created my website and after testing with all browsers except (stupidly) ie6 it all works fine but for some reason in ie6 it displays incorrectly on this page http://www.flitecarz.co.uk/WD-Postcodes-Covered.html the part with the problem

  • Does front row?

    i was wondering does front row save you battery time on your macbook/pro? like if i'm on an airplane and want to watch a DVD is it worth it to watch it in front row or in iDVD? or some other program entirely?

  • IMac Running Windows 7 can't 'detect a properly installed network adapter'

    I just put windows 7 on my brand new iMac 27'' i7, but to my surprise I cannot connect to a wireless network, and when I go to the trouble shooting section it says- "Windows did not detect a properlu installed network adapter. If you have a network a