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

Runtime error with Reuse_alv_fieldcat_merge (FM)

Hello guys,im facing problem wit Reuse_alv_fieldcat_merge (FM)... At frst i tried to fill the fieldcat manually, as i kept in comments in below code, it worked properly, bt im getting run time error when it did with FM. Help me out.


REPORT ZHI11.

TYPE-POOLS : slis.

tables : kna1.

types : BEGIN OF ty_kna1,

kunnr TYPE kna1-kunnr,

name1 TYPE kna1-name1,

land1 TYPE kna1-land1,

END OF ty_kna1.

data : v1 type kna1-kunnr,

program TYPE sy-repid,

lt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

DATA: it_kna1 TYPE STANDARD TABLE OF ty_kna1,

wa_kna1 TYPE ty_kna1.

SELECT-OPTIONS: s_kunnr FOR v1.

SELECT kunnr name1 land1 FROM kna1

INTO TABLE it_kna1 WHERE kunnr IN s_kunnr.

REFRESH lt_fieldcat[].

** Kunnr

*lt_fieldcat-col_pos = 0.

*lt_fieldcat-fieldname = 'KUNNR'.

*lt_fieldcat-tabname = 'it_kna1'.

*lt_fieldcat-ref_fieldname = 'KUNNR'.

*lt_fieldcat-ref_tabname = 'KNA1'.

*lt_fieldcat-seltext_m = 'Customer Number'.

*APPEND lt_fieldcat.

*

** Name1

*lt_fieldcat-col_pos = 1.

*lt_fieldcat-fieldname = 'NAME1'.

*lt_fieldcat-tabname = 'it_kna1'.

*lt_fieldcat-ref_fieldname = 'NAME1'.

*lt_fieldcat-ref_tabname = 'KNA1'.

*lt_fieldcat-seltext_m = 'Customer Name'.

*APPEND lt_fieldcat.

*

** Land1

*lt_fieldcat-col_pos = 2.

*lt_fieldcat-fieldname = 'LAND1'.

*lt_fieldcat-tabname = 'it_kna1'.

*lt_fieldcat-ref_fieldname = 'LAND1'.

*lt_fieldcat-ref_tabname = 'KNA1'.

*lt_fieldcat-seltext_m = 'Country'.

*APPEND lt_fieldcat.

*

program = sy-repid.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = program

i_internal_tabname = 'it_kna1'

i_inclname = program

i_client_never_display = 'X'

CHANGING

ct_fieldcat = lt_fieldcat.

program = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = program

IT_FIELDCAT = lt_fieldcat[]

TABLES

T_OUTTAB = it_kna1

.

IF SY-SUBRC <> 0.

* Implement suitable error handling here

ENDIF.


Message was edited by: Manish Kumar <subject edited and some commented lines removed>

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 18, 2014 at 09:57 AM

    Hi Santosh,

    I made some changes in your program please try this this will work,

    TYPE-POOLS : slis.

    TABLES : kna1.

    data: BEGIN OF IT_KNA1 OCCURS 2,

    kunnr like kna1-kunnr,

    name1 like kna1-name1,

    land1 like kna1-land1,

    END OF IT_KNA1.

    DATA : v1 TYPE kna1-kunnr,

    lt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

    DATA: ty_kna1 LIKE LINE OF IT_KNA1 .

    SELECT-OPTIONS: s_kunnr FOR v1.

    START-OF-SELECTION.

    SELECT kunnr name1 land1 FROM kna1

    INTO TABLE it_kna1 WHERE kunnr IN s_kunnr.

    END-OF-SELECTION.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    i_program_name = sy-repid

    i_internal_tabname = 'IT_KNA1'

    i_inclname = sy-repid

    * i_client_never_display = 'X'

    CHANGING

    ct_fieldcat = lt_fieldcat[]

    EXCEPTIONS

    inconsistent_interface = 1

    program_error = 2

    OTHERS = 3.

    IF sy-subrc <> 0.

    * Implement suitable error handling here

    ENDIF.

    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 = ' '

    * 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 =

    it_fieldcat = lt_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 =

    * IS_PRINT =

    * IS_REPREP_ID =

    * I_SCREEN_START_COLUMN = 0

    * I_SCREEN_START_LINE = 0

    * I_SCREEN_END_COLUMN = 0

    * I_SCREEN_END_LINE = 0

    * I_HTML_HEIGHT_TOP = 0

    * I_HTML_HEIGHT_END = 0

    * IT_ALV_GRAPHICS =

    * IT_HYPERLINK =

    * IT_ADD_FIELDCAT =

    * IT_EXCEPT_QINFO =

    * IR_SALV_FULLSCREEN_ADAPTER =

    * IMPORTING

    * E_EXIT_CAUSED_BY_CALLER =

    * ES_EXIT_CAUSED_BY_USER =

    TABLES

    t_outtab = it_kna1

    * EXCEPTIONS

    * PROGRAM_ERROR = 1

    * OTHERS = 2

    .

    IF sy-subrc <> 0.

    * Implement suitable error handling here

    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Santosh,

      When use the REUSE_ALV_FIELDCATALOG_MERGE function module to build field catalog, you have to use LIKE instead of TYPE I am exactly not sure why it is .

      Anyways, as declaring variable using LIKE is obsolete, I suggest to use Type. But when you use Type you have to change your program little bit to make it work.

      You have 2 options.

      1) using the types with in the program as explained in the below example

      2) declaring a global structure in SE11(with required fields) and passing structure name to the REUSE_ALV_FIELDCATALOG_MERGE. In this it is very straight thing you no need to do even looping to filter the unwanted fields as explained in the below example.

      here is the example:

      TYPE-POOLS : slis.

      TABLES : kna1.

      types: BEGIN OF Ty_KNA1,

      kunnr type kna1-kunnr,

      name1 type kna1-name1,

      land1 type kna1-land1,

      END OF Ty_KNA1.

      DATA : v1 TYPE kna1-kunnr,

      lt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,

      wa_fieldcat like line of lt_fieldcat.

      DATA: it_kna1 type table of ty_kna1 .

      SELECT-OPTIONS: s_kunnr FOR v1.

      START-OF-SELECTION.

      SELECT kunnr name1 land1 FROM kna1

      INTO TABLE it_kna1 WHERE kunnr IN s_kunnr.

      END-OF-SELECTION.

      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

      EXPORTING

      i_program_name = sy-repid

      i_structure_name = 'KNA1'

      i_inclname = sy-repid

      * i_client_never_display = 'X'

      CHANGING

      ct_fieldcat = lt_fieldcat[]

      EXCEPTIONS

      inconsistent_interface = 1

      program_error = 2

      OTHERS = 3.

      IF sy-subrc <> 0.

      * Implement suitable error handling here

      ENDIF.

      LOOP AT lt_fieldcat INTO wa_fieldcat .

      wa_fieldcat-NO_OUT = ’X' .

      IF wa_fieldcat-FIELDNAME = ’KUNNR’ OR

      wa_fieldcat-FIELDNAME = ’NAME1’ OR

      wa_fieldcat-FIELDNAME = ’LAND1’ OR

      wa_fieldcat-NO_OUT = ’ ’ .

      ENDIF .

      MODIFY lt_fieldcat FROM wa_fieldcat INDEX SY-TABIX .

      ENDLOOP.

      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 = ' '

      * 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 =

      it_fieldcat = lt_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 =

      * IS_PRINT =

      * IS_REPREP_ID =

      * I_SCREEN_START_COLUMN = 0

      * I_SCREEN_START_LINE = 0

      * I_SCREEN_END_COLUMN = 0

      * I_SCREEN_END_LINE = 0

      * I_HTML_HEIGHT_TOP = 0

      * I_HTML_HEIGHT_END = 0

      * IT_ALV_GRAPHICS =

      * IT_HYPERLINK =

      * IT_ADD_FIELDCAT =

      * IT_EXCEPT_QINFO =

      * IR_SALV_FULLSCREEN_ADAPTER =

      * IMPORTING

      * E_EXIT_CAUSED_BY_CALLER =

      * ES_EXIT_CAUSED_BY_USER =

      TABLES

      t_outtab = it_kna1

      * EXCEPTIONS

      * PROGRAM_ERROR = 1

      * OTHERS = 2

      .

      IF sy-subrc <> 0.

      * Implement suitable error handling here

      ENDIF.



      Note: What you pass it in single quotes it has to be in Capitals, not only just this case any where if you are passing some text with single quotes then it should always Capitals.

      Hope this helps...

  • Posted on Jul 18, 2014 at 11:30 AM

    Hi Santosh..

    If u want to use FM ( Field Catalog Merge ) then u should follow some rules...

    Those in the place of Type u should use LIKE because it is capturing memory of that standard ...

    thats y we dont define structure using TYPES ..........directly we take it with DATA and work area with LIKE keyword...

    Just see this below code..........execute it ...works fine....

    *&---------------------------------------------------------------------*
    *& Report YVAMC_FLD_MRG1
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*

    REPORT YVAMC_FLD_MRG1.
    TYPE-POOLS : SLIS.
    TABLES : KNA1.
    DATA : BEGIN OF IT_KNA1 OCCURS 0,
    KUNNR LIKE KNA1-KUNNR,
    NAME1 LIKE KNA1-NAME1,
    LAND1 LIKE KNA1-LAND1,
    END OF IT_KNA1.

    DATA : V1 TYPE KNA1-KUNNR,
    PROGRAM TYPE SY-REPID,
    LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.

    DATA: WA_KNA1 LIKE LINE OF IT_KNA1.


    SELECT-OPTIONS: S_KUNNR FOR V1.

    SELECT KUNNR NAME1 LAND1 FROM KNA1
    INTO CORRESPONDING FIELDS OF TABLE IT_KNA1 WHERE KUNNR IN S_KUNNR.

    REFRESH LT_FIELDCAT[].

    ** Kunnr
    *lt_fieldcat-col_pos = 0.
    *lt_fieldcat-fieldname = 'KUNNR'.
    *lt_fieldcat-tabname = 'it_kna1'.
    *lt_fieldcat-ref_fieldname = 'KUNNR'.
    *lt_fieldcat-ref_tabname = 'KNA1'.
    *lt_fieldcat-seltext_m = 'Customer Number'.
    *APPEND lt_fieldcat.
    *
    ** Name1
    *lt_fieldcat-col_pos = 1.
    *lt_fieldcat-fieldname = 'NAME1'.
    *lt_fieldcat-tabname = 'it_kna1'.
    *lt_fieldcat-ref_fieldname = 'NAME1'.
    *lt_fieldcat-ref_tabname = 'KNA1'.
    *lt_fieldcat-seltext_m = 'Customer Name'.
    *APPEND lt_fieldcat.
    *
    ** Land1
    *lt_fieldcat-col_pos = 2.
    *lt_fieldcat-fieldname = 'LAND1'.
    *lt_fieldcat-tabname = 'it_kna1'.
    *lt_fieldcat-ref_fieldname = 'LAND1'.
    *lt_fieldcat-ref_tabname = 'KNA1'.
    *lt_fieldcat-seltext_m = 'Country'.
    *APPEND lt_fieldcat.
    *
    PROGRAM = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
    I_PROGRAM_NAME = PROGRAM
    I_INTERNAL_TABNAME = 'IT_KNA1'
    I_INCLNAME = PROGRAM
    I_CLIENT_NEVER_DISPLAY = 'X'
    CHANGING
    CT_FIELDCAT = LT_FIELDCAT[].

    PROGRAM = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = PROGRAM
    IT_FIELDCAT = LT_FIELDCAT[]
    TABLES
    T_OUTTAB = IT_KNA1.
    IF SY-SUBRC <> 0.
    * Implement suitable error handling here
    ENDIF.




    Thanks,

    Vamsilakshman.p

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 18, 2014 at 09:12 AM

    Hi Santosh,

    Please try substituting 'it_kna1' with 'IT_KNA1'.

    BR/Thanks

    Pranav Agrawal

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 18, 2014 at 09:49 AM

    Hi,

    Try this . I made a small modification in " lt_fieldcat " and used work area . Check this code. It working fine.

    Try to understand the logic behind the coding. You will get it.

    TYPE-POOLS : slis.

    tables : kna1.

    types : BEGIN OF ty_kna1,

    kunnr TYPE kna1-kunnr,

    name1 TYPE kna1-name1,

    land1 TYPE kna1-land1,

    END OF ty_kna1.

    data : v1 type kna1-kunnr,

    program TYPE sy-repid,

    wa_fieldcat type slis_fieldcat_alv,

    lt_fieldcat TYPE slis_t_fieldcat_alv." WITH HEADER LINE.

    DATA: it_kna1 TYPE STANDARD TABLE OF ty_kna1,

    wa_kna1 TYPE ty_kna1.

    SELECT-OPTIONS: s_kunnr FOR v1.

    SELECT kunnr name1 land1 FROM kna1

    INTO TABLE it_kna1 WHERE kunnr IN s_kunnr.

    REFRESH lt_fieldcat[].

    * Kunnr

    wa_fieldcat-col_pos = 0.

    wa_fieldcat-fieldname = 'KUNNR'.

    wa_fieldcat-tabname = 'it_kna1'.

    wa_fieldcat-ref_fieldname = 'KUNNR'.

    wa_fieldcat-ref_tabname = 'KNA1'.

    wa_fieldcat-seltext_m = 'Customer Number'.

    APPEND wa_fieldcat to lt_fieldcat.

    * Name1

    Wa_fieldcat-col_pos = 1.

    wa_fieldcat-fieldname = 'NAME1'.

    wa_fieldcat-tabname = 'it_kna1'.

    wa_fieldcat-ref_fieldname = 'NAME1'.

    wa_fieldcat-ref_tabname = 'KNA1'.

    wa_fieldcat-seltext_m = 'Customer Name'.

    APPEND wa_fieldcat to lt_fieldcat.

    * Land1

    Wa_fieldcat-col_pos = 2.

    wa_fieldcat-fieldname = 'LAND1'.

    Wa_fieldcat-tabname = 'it_kna1'.

    wa_fieldcat-ref_fieldname = 'LAND1'.

    wa_fieldcat-ref_tabname = 'KNA1'.

    wa_fieldcat-seltext_m = 'Country'.

    APPEND wa_fieldcat to lt_fieldcat.

    program = sy-repid.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    i_program_name = program

    i_internal_tabname = 'it_kna1'

    i_inclname = program

    i_client_never_display = 'X'

    CHANGING

    ct_fieldcat = lt_fieldcat.

    program = sy-repid.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = program

    IT_FIELDCAT = lt_fieldcat[]

    TABLES

    T_OUTTAB = it_kna1

    EXCEPTIONS

    PROGRAM_ERROR = 1

    OTHERS = 2

    .

    IF SY-SUBRC <> 0.

    * Implement suitable error handling here

    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Santosh,

      I get your requirement. You are right about " Reuse_alv_fieldcat_merge ". It is actually used for auto filling but most of the cases we use the other way round.

      Thanks for reminding it to Santosh.

      PS: I see that Mrs. Sunitha has explained the same below. Even I had the same in mind.

      Regards,

      Naren Krishna.

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.