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

ALV problem

Hi all,

I have stuck somewhere. I need solution ASAP. I have some data in Internal Table. I am passing this data to ALV_grid_display.

I want to see that data right justified. how can i do tat.

Thanks In advance.

Varu.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 06, 2007 at 05:33 PM

    Hi,

    For the corresponding column in the field catalog give JUST = 'R'.

    S_FIELDCATALOG-JUST = 'R'.

    Thanks,

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks Narendran.

      Thanks A lot.

      There is one more problem. in alv i want total and subtotals.

      the code is like this. but i m not getting options.

      FORM build_catalog .

      data: wa_layo TYPE slis_layout_alv.

      fieldcatalog-fieldname = 'SERVGES'.

      fieldcatalog-ref_tabname = 'IT_FINAL'.

      fieldcatalog-seltext_m = 'Service Compnay'.

      fieldcatalog-col_pos = 0.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      fieldcatalog-fieldname = 'PERNR'.

      fieldcatalog-ref_tabname = 'IT_FINAL'.

      fieldcatalog-seltext_m = 'Contractor ID'.

      fieldcatalog-col_pos = 1.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      fieldcatalog-fieldname = 'CONAME'.

      fieldcatalog-ref_tabname = 'IT_FINAL'.

      fieldcatalog-seltext_m = 'Contractor Name'.

      fieldcatalog-col_pos = 2.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      fieldcatalog-fieldname = 'LGTXT'.

      fieldcatalog-ref_tabname = 'IT_FINAL'.

      fieldcatalog-seltext_m = 'Compensation Elements'.

      fieldcatalog-col_pos = 3.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      fieldcatalog-fieldname = 'AUTO_POSTING'.

      fieldcatalog-ref_tabname = 'IT_FINAL'.

      fieldcatalog-seltext_m = 'Auto Posting'.

      fieldcatalog-just = 'R'.

      fieldcatalog-col_pos = 4.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      fieldcatalog-fieldname = 'MANUAL_POSTING'.

      fieldcatalog-ref_tabname = 'it_final'.

      fieldcatalog-seltext_m = 'Manual Posting'.

      fieldcatalog-just = 'R'.

      fieldcatalog-col_pos = 5.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      fieldcatalog-fieldname = 'PREAS'.

      fieldcatalog-ref_tabname = 'IT_FINAL'.

      fieldcatalog-seltext_m = 'Reason Code'.

      fieldcatalog-col_pos = 6.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      fieldcatalog-fieldname = 'TOTAL'.

      fieldcatalog-ref_tabname = 'IT_FINAL'.

      fieldcatalog-seltext_m = 'Total'.

      fieldcatalog-just = 'R'.

      fieldcatalog-col_pos = 7.

      fieldcatalog-do_sum = 'X'.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      fieldcatalog-fieldname = 'AMOUNT'.

      fieldcatalog-ref_tabname = 'IT_FINAL'.

      fieldcatalog-seltext_m = 'Distribution'.

      fieldcatalog-just = 'R'.

      fieldcatalog-col_pos = 8.

      fieldcatalog-do_sum = 'X'.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      fieldcatalog-fieldname = 'DIFF'.

      fieldcatalog-ref_tabname = 'IT_FINAL'.

      fieldcatalog-seltext_m = 'Difference (+/-)'.

      fieldcatalog-just = 'R'.

      fieldcatalog-col_pos = 9.

      fieldcatalog-do_sum = 'X'.

      APPEND fieldcatalog TO fieldcatalog_tab.

      CLEAR fieldcatalog.

      wa_sort-spos = '0'.

      wa_sort-fieldname = 'SERVGES'.

      wa_sort-tabname = 'IT_FINAL'.

      wa_sort-up = 'X'.

      wa_sort-subtot = 'X'.

      APPEND wa_sort TO it_sort.

      wa_sort-spos = '1'.

      wa_sort-fieldname = 'PERNR'.

      wa_sort-tabname = 'IT_FINAL'.

      wa_sort-up = 'X'.

      wa_sort-subtot = 'X'.

      APPEND wa_sort TO it_sort.

      wa_sort-spos = '2'.

      wa_sort-fieldname = 'CONAME'.

      wa_sort-tabname = 'IT_FINAL'.

      wa_sort-up = 'X'.

      wa_sort-subtot = 'X'.

      APPEND wa_sort TO it_sort.

      wa_layo-totals_text = TEXT-004.

      PERFORM pass_data_to_alv_grid

      USING

      fieldcatalog_tab

      it_sort

      wa_layo.

      ENDFORM. " build_catalog

      &----


      *& Form final_display

      &----


      • text

      ----


      form pass_data_to_alv_grid using it_fcat TYPE slis_t_fieldcat_alv

      it_sort TYPE slis_t_sortinfo_alv

      wa_layo TYPE slis_layout_alv.

      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

      EXPORTING

      • I_INTERFACE_CHECK = ' '

      • I_BYPASSING_BUFFER = ' '

      • I_BUFFER_ACTIVE = ' '

      i_callback_program = sy-repid

      • I_CALLBACK_PF_STATUS_SET = ' '

      i_callback_user_command = 'CALL_UCOMM_WILIST'

      • I_CALLBACK_TOP_OF_PAGE = ' '

      • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

      • I_CALLBACK_HTML_END_OF_LIST = ' '

      • I_STRUCTURE_NAME =

      • I_BACKGROUND_ID = ' '

      • I_GRID_TITLE =

      • I_GRID_SETTINGS =

      IS_LAYOUT = wa_layo

      it_fieldcat = it_fcat

      • IT_EXCLUDING =

      • IT_SPECIAL_GROUPS =

      it_sort = it_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

      • IT_ALV_GRAPHICS =

      • IT_HYPERLINK =

      • IT_ADD_FIELDCAT =

      • IT_EXCEPT_QINFO =

      • I_HTML_HEIGHT_TOP =

      • I_HTML_HEIGHT_END =

      • IMPORTING

      • E_EXIT_CAUSED_BY_CALLER =

      • ES_EXIT_CAUSED_BY_USER =

      TABLES

      t_outtab = it_final

      • 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. "final_display

  • Posted on Mar 06, 2007 at 05:41 PM

    Hi,

    Please try this.

    FIELDCATALOG-DO_SUM = 'X'.

    Regards,

    Ferry Lianto

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      hi varun

      pls try this code,change the field names as required,i am sending code which i have tried on some fields which i required for my job and i got it,pls try

      pls concentration on the bold text

      REPORT xxxxx.

      TYPE-POOLS: SLIS. " ALL THE DEFINATIONS INTERNAL TABLES STRUCTURES AND

      " CONSTANTS ARE DECLARED IN TYPE-POOL CALLED SLIS

      DATA: VT_FIELDCATLOG1 TYPE SLIS_T_FIELDCAT_ALV. " THIS INTERNAL TABLE

      " CONTAINS THE FIELD

      " ATTRIBUTES

      DATA:X TYPE I,Y TYPE I,a type i,b type i.

      &----


      • TABLE DECLARATION

      &----


      TABLES: marc, " PLANT DATA

      mara, " GENERAL MATERIAL DATA

      mbew, " MATERIAL VALUATION

      mard, " CURRENT INVENTORY

      makt, " MATERIAL DESCRIPTION

      mvke. " SALES DATA FOR MATERIAL

      &----


      • INTERNAL TABLE DECLARATION

      &----


      DATA: BEGIN OF i_marc OCCURS 0, " PLANT DATA

      matnr LIKE marc-matnr, " MATERIAL NUMBER

      werks LIKE marc-werks, " PLANT

      disgr LIKE marc-disgr, " MRP GROUP

      dismm LIKE marc-dismm, " MRP TYPE

      dispo LIKE marc-dispo, " MRP CONTROLLER

      END OF i_marc.

      DATA: BEGIN OF i_output OCCURS 0,

      matnr LIKE mara-matnr, " MATERIAL NUMBER

      mbrsh LIKE mara-mbrsh, " INDUSTRY SECTOR

      mtart LIKE mara-mtart, " Material type

      meins LIKE mara-meins, " BASE UNIT OF MEASURE

      matkl LIKE mara-matkl, " MATERIAL GROUP

      werks LIKE marc-werks, " PLANT

      disgr LIKE marc-disgr, " MRP GROUP

      dispo LIKE marc-dispo, " MRP CONTROLLER

      maktx LIKE makt-maktx, " MATERIAL DESCRIPTION

      lgort LIKE mard-lgort, " STORAGE LOCATION

      labst LIKE mard-labst, " STOCK QUANTITY

      vkorg LIKE mvke-vkorg, " SALES ORGANISATION

      <b>Y TYPE I,</b>

      END OF i_output.

      DATA: BEGIN OF i_mard OCCURS 0,

      matnr LIKE mard-matnr, "MATERIAL NUMBER

      lgort LIKE mard-lgort, "STORAGE LOCATION

      labst LIKE mard-labst, "STOCK QUANTITY

      END OF i_mard.

      DATA: BEGIN OF i_mvke OCCURS 0,

      matnr LIKE mvke-matnr, "MATERIAL NUMBER

      vkorg LIKE mvke-vkorg, "SALES ORGANIZATION

      END OF i_mvke.

      &----


      • START OF SELECTION

      &----


      SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

      SELECT-OPTIONS: s_matnr FOR marc-matnr.

      PARAMETER : p_werks LIKE marc-werks OBLIGATORY.

      SELECT-OPTIONS: s_lgort FOR mard-lgort,

      s_dispo FOR marc-dispo.

      SELECTION-SCREEN END OF BLOCK b1.

      &----


      • START OF SELECTION

      &----


      START-OF-SELECTION.

      SELECT matnr werks disgr dismm dispo

      FROM marc

      INTO CORRESPONDING FIELDS OF TABLE i_marc

      WHERE matnr IN s_matnr

      AND dispo IN s_dispo

      AND werks = p_werks.

      IF i_marc[] IS INITIAL.

      WRITE:/ 'NO DATA IS SELECTED FOR DISPLAY from MARC'.

      EXIT.

      ENDIF.

      SELECT matnr lgort labst FROM mard INTO TABLE i_mard

      FOR ALL ENTRIES IN i_marc

      WHERE matnr = i_marc-matnr

      AND werks = p_werks.

      IF i_mard[] IS INITIAL.

      WRITE:/ 'NO DATA IS SELECTED FOR DISPLAY from MARD'.

      EXIT.

      ENDIF.

      SELECT matnr vkorg

      FROM mvke

      INTO table i_mvke for all entries in I_marc

      WHERE matnr = i_marc-matnr.

      LOOP AT i_marc.

      MOVE-CORRESPONDING i_marc TO i_output.

      CLEAR marc.

      SELECT SINGLE matnr mbrsh mtart meins matkl

      FROM mara

      INTO CORRESPONDING FIELDS OF mara

      WHERE matnr = i_output-matnr.

      IF sy-subrc = 0.

      MOVE-CORRESPONDING mara TO i_output.

      ELSE.

      CONTINUE.

      ENDIF.

      SELECT SINGLE matnr maktx

      FROM makt

      INTO CORRESPONDING FIELDS OF makt

      WHERE matnr = i_output-matnr

      AND spras = SY-LANGU.

      IF sy-subrc = 0.

      MOVE-CORRESPONDING makt TO i_output.

      ENDIF.

      LOOP AT i_mvke WHERE matnr = i_marc-matnr.

      MOVE i_mvke-vkorg TO i_output-vkorg.

      ENDLOOP.

      LOOP AT i_mard WHERE matnr = i_marc-matnr.

      MOVE: i_mard-labst TO i_output-labst,

      i_mard-lgort TO i_output-lgort.

      APPEND i_output.

      ENDLOOP.

      CLEAR i_output.

      X = i_output-MATNR .

      ADD X TO Y.

      ENDLOOP.

      DATA: T_SORT TYPE slis_t_sortinfo_alv.

      DATA: S_SORT like line of t_sort.

      DATA: wa_sortinfo TYPE slis_sortinfo_alv,

      i_sortcat TYPE slis_t_sortinfo_alv.

      DATA: v_fieldcatlog TYPE SLIS_FIELDCAT_ALV,

      gd_tab_group type slis_t_sp_group_alv,

      gd_layout type slis_layout_alv,

      gd_repid like sy-repid.

      perform build_fieldcatalog.

      perform build_layout.

      PERFORM sortcat_init CHANGING i_sortcat.

      perform display_alv_report.

      &----


      *& Form build_fieldcatalog

      &----


      • text

      ----


      FORM build_fieldcatalog.

      v_fieldcatlog-col_pos = '1'.

      v_fieldcatlog-fieldname = 'MATNR'.

      v_fieldcatlog-seltext_m = 'MATERIAL NUMBER '.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'MATNR'.

      v_fieldcatlog-ref_tabname = 'MARC'.

      <b> v_FIELDCATLOG-DO_SUM = 'X'.</b>

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '2'.

      v_fieldcatlog-fieldname = 'WERKS'.

      v_fieldcatlog-seltext_m = 'PLANT '.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'WERKS'.

      v_fieldcatlog-ref_tabname = 'MARC'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '3'.

      v_fieldcatlog-fieldname = 'DISPO'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'DISPO'.

      v_fieldcatlog-ref_tabname = 'MARC'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '4'.

      v_fieldcatlog-fieldname = 'MBRSH'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'MBRSH'.

      v_fieldcatlog-ref_tabname = 'MARA'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '5'.

      v_fieldcatlog-fieldname = 'MEINS'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'MEINS'.

      v_fieldcatlog-ref_tabname = 'MARA'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '6'.

      v_fieldcatlog-fieldname = 'MATKL'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'MATKL'.

      v_fieldcatlog-ref_tabname = 'MARA'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '7'.

      v_fieldcatlog-fieldname = 'VKORG'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'VKORG'.

      v_fieldcatlog-ref_tabname = 'MVKE'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '8'.

      v_fieldcatlog-fieldname = 'MTART'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'MTART'.

      v_fieldcatlog-ref_tabname = 'MARA'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      *v_fieldcatlog-col_pos = '8'.

      *v_fieldcatlog-fieldname = 'VTWEG'.

      *v_fieldcatlog-tabname = 'I_OUT'.

      *v_fieldcatlog-ref_fieldname = 'VTWEG'.

      *v_fieldcatlog-ref_tabname = 'MVKE'.

      *APPEND v_fieldcatlog TO vt_fieldcatlog1.

      *CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '9'.

      v_fieldcatlog-fieldname = 'MAKTX'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'MAKTX'.

      v_fieldcatlog-ref_tabname = 'MAKT'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '10'.

      v_fieldcatlog-fieldname = 'DISPO'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'DISPO'.

      v_fieldcatlog-ref_tabname = 'MARC'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '11'.

      v_fieldcatlog-fieldname = 'LGORT'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'LGORT'.

      v_fieldcatlog-ref_tabname = 'MARD'.

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      v_fieldcatlog-col_pos = '12'.

      v_fieldcatlog-fieldname = 'LABST'.

      v_fieldcatlog-tabname = 'I_OUT'.

      v_fieldcatlog-ref_fieldname = 'LABST'.

      v_fieldcatlog-ref_tabname = 'MARD'.

      v_fieldcatlog-hotspot = 'X'.

      <b> v_FIELDCATLOG-DO_SUM = 'X'.</b>

      APPEND v_fieldcatlog TO vt_fieldcatlog1.

      CLEAR v_fieldcatlog.

      ENDFORM. "build_fieldcatalog

      &----


      *& Form build_layout

      &----


      • text

      ----


      <b>FORM build_layout.

      gd_layout-NO_INPUT = 'X'.

      gd_layout-colwidth_optimize = 'X'.

      GD_LAYOUT-TOTALS_TEXT = 'TOTALS'(201).

      ENDFORM. "build_layout</b>

      &----


      • ALV PROCESS

      &----


      form display_alv_report.

      gd_repid = sy-repid.

      call function 'REUSE_ALV_GRID_DISPLAY'

      EXPORTING

      <b> i_callback_program = gd_repid

      is_layout = gd_layout</b>

      it_fieldcat = vt_fieldcatlog1[]

      i_callback_top_of_page = 'TOP-OF-PAGE'

      <b> it_sort = i_sortcat</b>

      i_save = 'X'

      TABLES

      t_outtab = I_OUTPUT

      EXCEPTIONS

      program_error = 1

      others = 2.

      if sy-subrc <> 0.

      endif.

      endform. " DISPLAY_ALV_REPORT

      &----


      *& Form sortcat_init

      &----


      • text

      ----


      • -->I_SORTCAT text

      ----


      FORM sortcat_init CHANGING i_sortcat TYPE slis_t_sortinfo_alv.

      CLEAR wa_sortinfo.

      wa_sortinfo-fieldname = 'MATNR'.

      wa_sortinfo-tabname = 'I_OUTPUT'.

      wa_sortinfo-spos = 1. " First sort by this field.

      <b> wa_sortinfo-up = 'X'. " Ascending</b>

      <b>wa_sortinfo-subtot = 'X'. " Subtotal at Name1</b>

      APPEND wa_sortinfo TO i_sortcat.

      ENDFORM. " sortcat_init

  • author's profile photo Former Member
    Former Member
    Posted on Mar 06, 2007 at 06:27 PM

    Hi,

    I executed your program..It is showing the subtotals and totals..

    Please let me know what exactly you want to see in the output??

    Thanks,

    Naren

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

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

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