Application Development and Automation 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: 
Read only

ALV Error

Former Member
0 Likes
709

Hi guys,

I'm new to ABAP and trying now to create a simple ALV report, but I'm getting exception in the second ALV call function statement. This code is downloaded from the web with some modifications, so I thought it will work, but something is not ok. Can you please give me an advice?

Thank you, AR

the code:

REPORT ZTEST.

type-pools: slis.

types: begin of person,

name(20) type c,

surname(40) type c,

end of person.

data lt_person type table of person.

data ls_person type person.

data int_fcat type SLIS_T_FIELDCAT_ALV.

ls_person-name = 'xx'.

ls_person-surname = 'yy'.

append ls_person to lt_person.

ls_person-name = 'tt'.

ls_person-surname = 'ww'.

append ls_person to lt_person.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = sy-repid

I_INTERNAL_TABNAME = 'lt_person'

CHANGING

CT_FIELDCAT = int_fcat

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

if sy-subrc <> 0.

write: 'S:', sy-subrc.

endif.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = sy-repid

IT_FIELDCAT = int_fcat

I_SAVE = 'A'

TABLES

T_OUTTAB = lt_person

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

if sy-subrc <> 0.

write: 'D:', sy-subrc.

endif.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
682

hi,

its having problem in REUSE_ALV_FIELDCATALOG_MERGE

try like this


TYPE-POOLS: slis.

TYPES: BEGIN OF person,
name(20) TYPE c,
surname(40) TYPE c,
END OF person.

DATA lt_person TYPE TABLE OF person.
DATA ls_person TYPE person.
DATA int_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

ls_person-name = 'xx'.
ls_person-surname = 'yy'.
APPEND ls_person TO lt_person.

ls_person-name = 'tt'.
ls_person-surname = 'ww'.
APPEND ls_person TO lt_person.

*CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
*  EXPORTING
*    i_program_name         = sy-repid
*    i_internal_tabname     = 'PERSON'
*  CHANGING
*    ct_fieldcat            = int_fcat
*  EXCEPTIONS
*    inconsistent_interface = 1
*    program_error          = 2
*    OTHERS                 = 3.

*IF sy-subrc = 0.
*  WRITE: 'S:', sy-subrc.
*ENDIF.

int_fcat-tabname = 'LT_PERSON'.
int_fcat-fieldname = 'NAME'.
int_fcat-seltext_m = 'Name'.
APPEND int_fcat.

int_fcat-tabname = 'LT_PERSON'.
int_fcat-fieldname = 'SURNAME'.
int_fcat-seltext_m = 'Surname'.
APPEND int_fcat.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
    i_callback_program = sy-repid
    it_fieldcat        = int_fcat[]
    i_save             = 'A'
  TABLES
    t_outtab           = lt_person
  EXCEPTIONS
    program_error      = 1
    OTHERS             = 2.

*IF sy-subrc = 0.
*  WRITE: 'D:', sy-subrc.
*ENDIF.

reward if usefull..

4 REPLIES 4
Read only

Former Member
0 Likes
682

Hi

What kind of error do you get?

Please add additional exceptions to the function modules so that you could have more precise information on the error.

Rgds

Mat

Read only

Former Member
0 Likes
683

hi,

its having problem in REUSE_ALV_FIELDCATALOG_MERGE

try like this


TYPE-POOLS: slis.

TYPES: BEGIN OF person,
name(20) TYPE c,
surname(40) TYPE c,
END OF person.

DATA lt_person TYPE TABLE OF person.
DATA ls_person TYPE person.
DATA int_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

ls_person-name = 'xx'.
ls_person-surname = 'yy'.
APPEND ls_person TO lt_person.

ls_person-name = 'tt'.
ls_person-surname = 'ww'.
APPEND ls_person TO lt_person.

*CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
*  EXPORTING
*    i_program_name         = sy-repid
*    i_internal_tabname     = 'PERSON'
*  CHANGING
*    ct_fieldcat            = int_fcat
*  EXCEPTIONS
*    inconsistent_interface = 1
*    program_error          = 2
*    OTHERS                 = 3.

*IF sy-subrc = 0.
*  WRITE: 'S:', sy-subrc.
*ENDIF.

int_fcat-tabname = 'LT_PERSON'.
int_fcat-fieldname = 'NAME'.
int_fcat-seltext_m = 'Name'.
APPEND int_fcat.

int_fcat-tabname = 'LT_PERSON'.
int_fcat-fieldname = 'SURNAME'.
int_fcat-seltext_m = 'Surname'.
APPEND int_fcat.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
    i_callback_program = sy-repid
    it_fieldcat        = int_fcat[]
    i_save             = 'A'
  TABLES
    t_outtab           = lt_person
  EXCEPTIONS
    program_error      = 1
    OTHERS             = 2.

*IF sy-subrc = 0.
*  WRITE: 'D:', sy-subrc.
*ENDIF.

reward if usefull..

Read only

0 Likes
682

Dhwani,

thanx, just one question: why is this working w/o using the REUSE_ALV_FIELDCATALOG_MERGE FM? I've read, that it is mnecessary to build the catalogue. So when to use this FM?

Thank you, AR

Read only

0 Likes
682

hi,

ya its compulsary to build fieldcata log but its not necessary to use FM REUSE_ALV_FIELDCATALOG_MERGE for building field catalog..

i have never use this function module to create fieldcat...

here is the code for simple ALV

Hope this will be helpfull to u.



*&---------------------------------------------------------------------*
*& Report  ZALV_DS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zalv_ds LINE-SIZE 35.

TYPE-POOLS:slis.

TABLES:mara,
       makt,
       marc.

DATA:BEGIN OF itab OCCURS 0,
      matnr LIKE mara-matnr,
      maktx LIKE makt-maktx,
      werks LIKE marc-werks,
      mtart LIKE mara-mtart,
      matkl LIKE mara-matkl,
      meins LIKE mara-meins,
      ntgew LIKE mara-ntgew,
      cellcolors TYPE lvc_t_scol,
     END OF itab.

DATA:t_fcat TYPE slis_t_fieldcat_alv,
     t_eve TYPE slis_t_event.

DATA : st_layout TYPE slis_layout_alv.

SELECTION-SCREEN:BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:mat FOR mara-matnr.  " no intervals no-extension.
*PARAMETERS:mat LIKE mara-matnr.
SELECTION-SCREEN:END OF BLOCK blk1.

INITIALIZATION.
  PERFORM build_cata USING t_fcat.
  PERFORM build_event.

START-OF-SELECTION.
  PERFORM data_retrieval.
  PERFORM display_data.

*&---------------------------------------------------------------------*
*&      Form  build_cata
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->TEMP_FCAT  text
*----------------------------------------------------------------------*
FORM build_cata USING temp_fcat TYPE slis_t_fieldcat_alv.

  sy-tvar0 = sy-uname.
  WRITE sy-datum TO sy-tvar1.

  DATA:wa_fcat TYPE slis_fieldcat_alv.

  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MATNR'.
    wa_fcat-ref_tabname = 'MARA'.
  wa_fcat-ref_fieldname = 'MATNR'.
  wa_fcat-col_pos = 1.
  wa_fcat-seltext_m = 'Material'.
  wa_fcat-input = 'X'.
  wa_fcat-edit = 'X'.
  APPEND wa_fcat TO temp_fcat.

  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MAKTX'.
  wa_fcat-seltext_m = 'Description'.
  wa_fcat-fix_column = 'x'.
  wa_fcat-key = 'X'.                                        "To color a column
  wa_fcat-edit = ''.
  APPEND wa_fcat TO temp_fcat.

  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'WERKS'.
  wa_fcat-seltext_m = 'Plant'.
  wa_fcat-key = ' '.
  APPEND wa_fcat TO temp_fcat.

  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MTART'.
  wa_fcat-ddic_outputlen = 4.
  wa_fcat-row_pos = 2.
  APPEND wa_fcat TO temp_fcat.

  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MATKL'.
  wa_fcat-ref_tabname = 'MARA'.
  wa_fcat-ref_fieldname = 'MATKL'.
  wa_fcat-seltext_m = 'Group'.
  APPEND wa_fcat TO temp_fcat.

  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MEINS'.
  wa_fcat-ref_tabname = ' '.
  wa_fcat-ref_fieldname = ' '.
  wa_fcat-row_pos = 2.
  wa_fcat-seltext_m = 'Measurement Unit'.
  APPEND wa_fcat TO temp_fcat.

  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'NTGEW'.
  wa_fcat-seltext_m = 'Net Value'.
  wa_fcat-row_pos = 2.
  wa_fcat-no_out = ' '.
  APPEND wa_fcat TO temp_fcat.


ENDFORM.                    "build_cata


*&---------------------------------------------------------------------*
*&      Form  data_retrieval
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM data_retrieval.

  SELECT mara~matnr  mara~mtart mara~matkl mara~meins mara~ntgew
   makt~maktx  marc~werks
  INTO CORRESPONDING FIELDS OF TABLE itab
  FROM mara INNER JOIN makt ON
  mara~matnr = makt~matnr
  INNER JOIN marc ON
  mara~matnr = marc~matnr
  WHERE mara~matnr IN mat.

  SORT itab BY matnr.
  DELETE ADJACENT DUPLICATES FROM itab.
ENDFORM.                    "data_retrieval

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display_data.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = 'ZALV_DS'
      it_fieldcat        = t_fcat
    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.


ENDFORM.                    "display_data