Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get this output format in ALV report

Former Member
0 Kudos

Hi.

Can any one pls let me know how to get the following output format in ALV report.

companycode location position approver

300 800 01 watson

02 mike

03 candy

04 smith

05 michael

one empty line after this again

300 800 01 ryant

02 tom

03 patil

Thanks in advance.

Kind Regards,

samiulla.

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

using the sort function you can get that .

in your casse you have to populate the sort on these fields

companycode ,location, position, approver

sort-fieldname = 'SOMEFIELD'.

sort-up = 'X'.

sort-group = 'UL'. "It add a line between the set of data

append sort to it_sort.

pass this it_sort to alv function.

2 REPLIES 2

former_member188685
Active Contributor
0 Kudos

using the sort function you can get that .

in your casse you have to populate the sort on these fields

companycode ,location, position, approver

sort-fieldname = 'SOMEFIELD'.

sort-up = 'X'.

sort-group = 'UL'. "It add a line between the set of data

append sort to it_sort.

pass this it_sort to alv function.

Former Member
0 Kudos

hi,

just use FM : 'REUSE_ALV_LIST_DISPLAY'

OR

'REUSE_ALV_GRID_DISPLAY'

SAMPLE CODE:

*                         TABLES
*----------------------------------------------------------------------*
TABLES: vbak.    " standard table

*----------------------------------------------------------------------*
*                           Type Pools                                 *
*----------------------------------------------------------------------*
TYPE-POOLS: slis.
*----------------------------------------------------------------------*
*                     Global Structure Definitions                     *
*----------------------------------------------------------------------*
*-- Structure to hold data from table CE1MCK2
TYPES: BEGIN OF tp_itab1,
       vbeln LIKE vbap-vbeln,
       posnr LIKE vbap-posnr,
       werks LIKE vbap-werks,
       lgort LIKE vbap-lgort,
       END OF tp_itab1.

*-- Data Declaration
DATA: t_itab1 TYPE TABLE OF tp_itab1.
DATA : i_fieldcat TYPE slis_t_fieldcat_alv.

*----------------------------------------------------------------------*
*                    Selection  Screen                                 *
*----------------------------------------------------------------------*
*--Sales document-block
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN END OF  BLOCK b1.

*--Display option - block
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
PARAMETERS: alv_list RADIOBUTTON GROUP g1,
            alv_grid RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF  BLOCK b2.

*file download - block
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-t03.
PARAMETERS: topc AS CHECKBOX,
            p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF  BLOCK b3.

*---------------------------------------------------------------------*
*                      Initialization.                                *
*---------------------------------------------------------------------*


*---------------------------------------------------------------------*
*                      At Selection Screen                            *
*---------------------------------------------------------------------*


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_DXFILENAME_4_DYNP'
    EXPORTING
      dynpfield_filename = 'P_FILE'
      dyname             = sy-cprog
      dynumb             = sy-dynnr
      filetype           = 'P'      "P-->Physical
      location           = 'P'     "P Presentation Srever
      server             = space.

AT SELECTION-SCREEN ON s_vbeln.
  PERFORM vbeln_validate.


*----------------------------------------------------------------------*
*                           Start Of Selection                         *
*----------------------------------------------------------------------*
START-OF-SELECTION.

*-- Fetching all the required data into the internal table
  PERFORM select_data.

*----------------------------------------------------------------------*
*                           End Of Selection                           *
*----------------------------------------------------------------------*
END-OF-SELECTION.

  IF t_itab1[] IS NOT INITIAL.
    IF topc IS NOT INITIAL.

      PERFORM download.
      MESSAGE 'Data Download Completed' TYPE 'S'.
    ENDIF.
    PERFORM display.
  ELSE.
    MESSAGE 'No Records Found' TYPE 'I'.
  ENDIF.

*----------------------------------------------------------------------*
*                           Top Of Page Event                          *
*----------------------------------------------------------------------*
TOP-OF-PAGE.

*&---------------------------------------------------------------------*
*& Form           :      select_data
*&---------------------------------------------------------------------*
* Description     : Fetching all the data into the internal tables
*----------------------------------------------------------------------*
*  parameters    :  none
*
*----------------------------------------------------------------------*
FORM select_data .
  SELECT vbeln
     posnr
     werks
     lgort
     INTO CORRESPONDING  FIELDS OF TABLE t_itab1
     FROM vbap
     WHERE  vbeln IN s_vbeln.
  IF sy-subrc <> 0.
    MESSAGE 'Enter The Valid Sales Document Number'(t04) TYPE 'I'.
    EXIT.
  ENDIF.
ENDFORM.                    " select_data



*&---------------------------------------------------------------------*
*& Form        : display
*&---------------------------------------------------------------------*
*  decription  : to display data in given format
*----------------------------------------------------------------------*
* parameters   :  none
*----------------------------------------------------------------------*
FORM display .

  IF alv_list = 'X'.
    PERFORM build_fieldcat TABLES i_fieldcat[]
                           USING :
*-Output-field Table      Len  Ref fld Ref tab Heading    Col_pos
   'VBELN'       'T_ITAB1'     10   'VBAP'  'VBELN'    ''            1,
   'POSNR'       'T_ITAB1'     6    'VBAP'  'POSNR'    ''            2,
   'WERKS'       'T_ITAB1'     4    'VBAP'  'WERKS'    ''            3,
   'LGORT'       'T_ITAB1'     4    'VBAP'  'LGORT'    ''            4.



    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      EXPORTING
        i_callback_program       = sy-repid
*        i_callback_pf_status_set = c_pf_status
        i_callback_user_command  = 'USER_COMMAND '
*        it_events                = t_alv_events[]
        it_fieldcat              = i_fieldcat[]
      TABLES
        t_outtab                 = t_itab1[]
      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.

  ENDIF.

  IF alv_grid = 'X'.

    PERFORM build_fieldcat TABLES i_fieldcat[]
                             USING :
*-Output-field Table      Len  Ref fld Ref tab Heading    Col_pos
     'VBELN'       'T_ITAB1'     10   'VBAP'  'VBELN'    ''            1,
     'POSNR'       'T_ITAB1'     6    'VBAP'  'POSNR'    ''            2,
     'WERKS'       'T_ITAB1'     4    'VBAP'  'WERKS'    ''            3,
     'LGORT'       'T_ITAB1'     4    'VBAP'  'LGORT'    ''            4.


    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program       = sy-repid
*        i_callback_pf_status_set = c_pf_status
        i_callback_user_command  = 'USER_COMMAND '
        it_fieldcat              = i_fieldcat
      TABLES
        t_outtab                 = t_itab1[]

    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.


  ENDIF.

ENDFORM.                    " display
*&---------------------------------------------------------------------*
*& Form        : vbeln_validate
*&---------------------------------------------------------------------*
*  description : to validate sales document number
*----------------------------------------------------------------------*
* parameters   :  none
*
*----------------------------------------------------------------------*
FORM vbeln_validate .
  DATA: l_vbeln TYPE vbak-vbeln.
  SELECT SINGLE vbeln
    FROM vbak
    INTO l_vbeln
    WHERE vbeln IN s_vbeln.
  IF sy-subrc NE 0.
    MESSAGE 'ENTER THE VALID SALES DOCUMENT NO:' TYPE 'I'.
    EXIT.
  ENDIF.

ENDFORM.                    " vbeln_validate




*&---------------------------------------------------------------------*
*& Form       :build_fieldcat
*&---------------------------------------------------------------------*
* Description : This routine fills field-catalogue
*----------------------------------------------------------------------*
*  Prameters  : none
*----------------------------------------------------------------------*
FORM build_fieldcat TABLES  fpt_fieldcat TYPE slis_t_fieldcat_alv
                    USING   fp_field     TYPE slis_fieldname
                            fp_table     TYPE slis_tabname
                            fp_length    TYPE dd03p-outputlen
                            fp_ref_tab   TYPE dd03p-tabname
                            fp_ref_fld   TYPE dd03p-fieldname
                            fp_seltext   TYPE dd03p-scrtext_l
                            fp_col_pos   TYPE sy-cucol.


*-- Local data declaration
  DATA:   wl_fieldcat TYPE slis_fieldcat_alv.

*-- Clear WorkArea

  wl_fieldcat-fieldname       = fp_field.
  wl_fieldcat-tabname         = fp_table.
  wl_fieldcat-outputlen       = fp_length.
  wl_fieldcat-ref_tabname     = fp_ref_tab.
  wl_fieldcat-ref_fieldname   = fp_ref_fld.
  wl_fieldcat-seltext_l       = fp_seltext.
  wl_fieldcat-col_pos         = fp_col_pos.


*-- Update Field Catalog Table
  APPEND wl_fieldcat  TO  fpt_fieldcat.
ENDFORM.                    "build_fieldcat
*&---------------------------------------------------------------------*
*& Form        : download
*&---------------------------------------------------------------------*
*  description : To Download The Data
*----------------------------------------------------------------------*
*  Parameters  :  none
*----------------------------------------------------------------------*
FORM download .

  DATA: l_file TYPE string.

  l_file = p_file.
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = l_file
      filetype                = 'ASC'
    TABLES
      data_tab                = t_itab1
    EXCEPTIONS
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6.
  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.                    " download

REGARDS

RAHUL SHARMA

Edited by: RAHUL SHARMA on Sep 19, 2008 8:41 AM