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: 

problem regarding alv

Former Member
0 Kudos

report zalv_grid.

tables: kna1.

type-pools: slis.

data: fact type slis_t_fieldcat_alv,

i_repid like sy-repid.

data: begin of itab occurs 0,

kunnr like kna1-kunnr,

name1 like kna1-name1,

end of itab.

select-options: s_kunnr for kna1-kunnr.

select * from kna1 into corresponding fields of table itab up to 10 rows

where kunnr in s_kunnr.

call function 'reuse_alv_fieldcatalog_merge'

exporting

i_program_name = i_repid.

i_internal_tabname = 'itab'

i_inclname = i_repid

changing

ct_fieldcat = fcat.

call function 'resuse_alv_list_display'

exporting

i_callback_program = i_repid

it_fieldcat = fcat

i_save = 'a'

table

t_outtab = itab.

when i run this program it runs without any syntex errror but it gives message "fieldcatalog does not exist". how to resolve this problem plz help me i am new in ALV.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

i_repid must contain the progrm name

try one of the following before the fieldcatalog_merge call:

i_repid = 'ZALV_GRID'.

i_repid = sy-repid.

You may also need to put internal table name in upper case:

i_internal_tabname = 'ITAB'

Andrew

4 REPLIES 4

Former Member
0 Kudos

i_repid must contain the progrm name

try one of the following before the fieldcatalog_merge call:

i_repid = 'ZALV_GRID'.

i_repid = sy-repid.

You may also need to put internal table name in upper case:

i_internal_tabname = 'ITAB'

Andrew

Former Member
0 Kudos

fieldcatalog is not define properly.

see this example program,

REPORT ALV.

  • REPORT Z_LIST_MATERIALS.

TYPE-POOLS: SLIS.

TABLES:MARC, MARD, VBAP, LIPS, EKPO, VBFA, EKBE, MARM, VBBE, MARA, MBEW.

SELECTION-SCREEN BEGIN OF BLOCK SEL WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS: S_WERKS FOR MARC-WERKS, " Plant

S_MATNR FOR MARC-MATNR, " Material

S_MTART FOR MARA-MTART. " Material Type

SELECTION-SCREEN END OF BLOCK SEL.

PARAMETERS: P_VARI LIKE DISvariant-VARIANT. " ALV Variant

CONSTANTS: FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

DATA: BEGIN OF INV OCCURS 100,

WERKS LIKE MARD-WERKS, " Plant

MATNR LIKE MARD-MATNR, " Material

MTART LIKE MARA-MTART, " Material Type

STPRS LIKE MBEW-STPRS, " Standard Price

AVAIL LIKE MARD-LABST, " Available

LABST LIKE MARD-LABST, " Unrestricted use

INSME LIKE MARD-INSME, " Quality Inspection

RETME LIKE MARD-RETME, " Returns

TRANS LIKE MARC-UMLMC, " Stock in transit (calculated)

UMLMC LIKE MARC-UMLMC, " Stock Transfer (plant)

UMLME LIKE MARD-UMLME, " Transfer (SLoc)

WESBS LIKE EKBE-WESBS, " GR Blocked Stock

TRAME LIKE MARC-TRAME, " Stock in transit

SPEME LIKE MARD-SPEME, " Blocked

KWMENG LIKE VBAP-KWMENG, " Sales orders

LFIMG LIKE LIPS-LFIMG, " Scheduled for Delivery

MENGE LIKE EKPO-MENGE, " Open Purch. Orders

VALUE LIKE MBEW-SALK3, " Stock Value (Calculated)

MEINS LIKE MARA-MEINS, " Unit of measure

END OF INV.

DATA: FIELDTAB TYPE SLIS_T_FIELDCAT_ALV,

HEADING TYPE SLIS_T_LISTHEADER,

LAYOUT TYPE SLIS_LAYOUT_ALV,

EVENTS TYPE SLIS_T_EVENT,

REPNAME LIKE SY-REPID,

F2CODE LIKE SY-UCOMM VALUE '&ETA',

G_SAVE(1) TYPE C,

G_EXIT(1) TYPE C,

G_VARIANT LIKE DISVARIANT,

GX_VARIANT LIKE DISVARIANT.

break-point.

INITIALIZATION.

REPNAME = SY-REPID.

PERFORM INITIALIZE_FIELDCAT USING FIELDTAB[].

PERFORM BUILD_EVENTTAB USING EVENTS[].

PERFORM BUILD_COMMENT USING HEADING[].

PERFORM INITIALIZE_VARIANT.

break-point.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.

PERFORM F4_FOR_VARIANT.

break-point.

AT SELECTION-SCREEN.

PERFORM PAI_OF_SELECTION_SCREEN.

break-point.

START-OF-SELECTION.

PERFORM GET_MARD.

PERFORM GET_UNIT_OF_MEASURE.

PERFORM GET_MARC.

PERFORM GET_EKPO.

PERFORM GET_LIPS.

PERFORM GET_VBAP.

PERFORM GET_OPEN.

PERFORM GET_PRICE.

END-OF-SELECTION.

break-point.

PERFORM BUILD_LAYOUT USING LAYOUT.

PERFORM WRITE_OUTPUT.

&----


*& Form INITIALIZE_FIELDCAT

&----


  • text

----


  • -->P_FIELDTAB[] text *

----


FORM INITIALIZE_FIELDCAT USING P_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV.

DATA: L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

  • fixed columns (obligatory)

CLEAR L_FIELDCAT.

L_FIELDCAT-TABNAME = 'INV'.

L_FIELDCAT-FIX_COLUMN = 'X'.

L_FIELDCAT-NO_OUT = 'O'.

L_FIELDCAT-FIELDNAME = 'WERKS'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'MATNR'.

APPEND L_FIELDCAT TO P_FIELDTAB.

  • totalized columns

CLEAR L_FIELDCAT.

L_FIELDCAT-TABNAME = 'INV'.

L_FIELDCAT-SP_GROUP = 'A'.

L_FIELDCAT-DO_SUM = 'X'.

L_FIELDCAT-FIELDNAME = 'LABST'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'INSME'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'RETME'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'UMLME'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'WESBS'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'SPEME'.

APPEND L_FIELDCAT TO P_FIELDTAB.

  • columns with different description

L_FIELDCAT-FIELDNAME = 'KWMENG'.

L_FIELDCAT-SELTEXT_M = 'Sales Orders'.

L_FIELDCAT-SELTEXT_S = 'Sales Or'.

L_FIELDCAT-SELTEXT_L = 'Sales Orders Qty'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'LFIMG'.

L_FIELDCAT-SELTEXT_M = 'Sched. Delivery'.

L_FIELDCAT-SELTEXT_S = 'Schd. Del'.

L_FIELDCAT-SELTEXT_L = 'Scheduled for Delivery'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'TRANS'.

L_FIELDCAT-SELTEXT_M = 'Stk. in transit'.

L_FIELDCAT-SELTEXT_S = 'Stk. trns'.

L_FIELDCAT-SELTEXT_L = 'Stock in transit (sum)'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'AVAIL'.

L_FIELDCAT-SELTEXT_M = 'Available'.

L_FIELDCAT-SELTEXT_S = 'Avail.'.

L_FIELDCAT-SELTEXT_L = 'Stock Available'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'MENGE'.

L_FIELDCAT-SELTEXT_M = 'Open Orders'.

L_FIELDCAT-SELTEXT_S = 'Open Ord'.

L_FIELDCAT-SELTEXT_L = 'Open Purchase Orders'.

APPEND L_FIELDCAT TO P_FIELDTAB.

  • columns not displayed

CLEAR L_FIELDCAT.

L_FIELDCAT-TABNAME = 'INV'.

L_FIELDCAT-SP_GROUP = 'A'.

L_FIELDCAT-NO_OUT = 'X'.

L_FIELDCAT-FIELDNAME = 'MEINS'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'UMLMC'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'TRAME'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'STPRS'.

APPEND L_FIELDCAT TO P_FIELDTAB.

L_FIELDCAT-FIELDNAME = 'VALUE'.

APPEND L_FIELDCAT TO P_FIELDTAB.

ENDFORM. " INITIALIZE_FIELDCAT

&----


*& Form BUILD_EVENTTAB

&----


  • text

----


  • -->P_EVENTS[] text *

----


FORM BUILD_EVENTTAB USING P_EVENTS TYPE SLIS_T_EVENT.

DATA: LS_EVENT TYPE SLIS_ALV_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = P_EVENTS.

READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

INTO LS_EVENT.

IF SY-SUBRC = 0.

MOVE FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.

APPEND LS_EVENT TO P_EVENTS.

ENDIF.

ENDFORM. " BUILD_EVENTTAB

&----


*& Form BUILD_COMMENT

&----


  • text

----


  • -->P_HEADING[] text *

----


FORM BUILD_COMMENT USING P_HEADING TYPE SLIS_T_LISTHEADER.

DATA: HLINE TYPE SLIS_LISTHEADER,

TEXT(60) TYPE C,

SEP(20) TYPE C.

CLEAR: HLINE, TEXT.

HLINE-TYP = 'H'.

WRITE: TEXT-101 TO TEXT+23.

HLINE-INFO = TEXT.

APPEND HLINE TO P_HEADING.

CLEAR TEXT.

WRITE: 'User: ' TO TEXT,

SY-UNAME TO TEXT+6,

'Date: ' TO TEXT+25,

SY-DATUM TO TEXT+31,

'Page: ' TO TEXT+50,

SY-PAGNO TO TEXT+56.

HLINE-INFO = TEXT.

APPEND HLINE TO P_HEADING.

ENDFORM. " BUILD_COMMENT

----


  • FORM TOP_OF_PAGE *

----


  • ........ *

----


FORM TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEADING.

ENDFORM.

&----


*& Form INITIALIZE_VARIANT

&----


  • text

----


FORM INITIALIZE_VARIANT.

G_SAVE = 'A'.

CLEAR G_VARIANT.

G_VARIANT-REPORT = REPNAME.

GX_VARIANT = G_VARIANT.

CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'

EXPORTING

I_SAVE = G_SAVE

CHANGING

CS_VARIANT = GX_VARIANT

EXCEPTIONS

NOT_FOUND = 2.

IF SY-SUBRC = 0.

P_VARI = GX_VARIANT-VARIANT.

ENDIF.

ENDFORM. " INITIALIZE_VARIANT

&----


*& Form F4_FOR_VARIANT

&----


  • text

----


FORM F4_FOR_VARIANT.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

IS_VARIANT = G_VARIANT

I_SAVE = G_SAVE

IMPORTING

E_EXIT = G_EXIT

ES_VARIANT = GX_VARIANT

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.

IF G_EXIT = SPACE.

P_VARI = GX_VARIANT-VARIANT.

ENDIF.

ENDIF.

ENDFORM. " F4_FOR_VARIANT

&----


*& Form PAI_OF_SELECTION_SCREEN

&----


  • text

----


FORM PAI_OF_SELECTION_SCREEN.

IF NOT P_VARI IS INITIAL.

MOVE G_VARIANT TO GX_VARIANT.

MOVE P_VARI TO GX_VARIANT-VARIANT.

CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'

EXPORTING

I_SAVE = G_SAVE

CHANGING

CS_VARIANT = GX_VARIANT.

G_VARIANT = GX_VARIANT.

ELSE.

PERFORM INITIALIZE_VARIANT.

ENDIF.

ENDFORM. " PAI_OF_SELECTION_SCREEN

&----


*& Form GET_MARD

&----


  • text

----


FORM GET_MARD.

SELECT MATNR WERKS LABST INSME RETME UMLME SPEME

FROM MARD

INTO CORRESPONDING FIELDS OF INV

WHERE MATNR IN S_MATNR

AND WERKS IN S_WERKS.

COLLECT INV.

ENDSELECT.

PERFORM FILTER_BY_MATERIAL_TYPE.

ENDFORM. " GET_MARD

&----


*& Form FILTER_BY_MATERIAL_TYPE

&----


  • text

----


FORM FILTER_BY_MATERIAL_TYPE.

LOOP AT INV.

CLEAR INV-MTART.

SELECT SINGLE MTART

INTO INV-MTART

FROM MARA

WHERE MATNR EQ INV-MATNR

AND MTART IN S_MTART.

IF SY-SUBRC EQ 0.

MODIFY INV.

ELSE.

DELETE INV.

ENDIF.

ENDLOOP.

ENDFORM. " FILTER_BY_MATERIAL_TYPE

&----


*& Form GET_MARC

&----


  • text

----


FORM GET_MARC.

LOOP AT INV.

SELECT SINGLE UMLMC TRAME

FROM MARC

INTO CORRESPONDING FIELDS OF INV

WHERE MATNR EQ INV-MATNR

AND WERKS EQ INV-WERKS.

IF SY-SUBRC EQ 0.

INV-TRANS = INV-UMLMC + INV-TRAME.

MODIFY INV.

ENDIF.

ENDLOOP.

ENDFORM. " GET_MARC

&----


*& Form GET_EKPO

&----


  • text

----


FORM GET_EKPO.

DATA: WESBS LIKE INV-WESBS,

SHKZG LIKE EKBE-SHKZG,

MEINS LIKE EKPO-MEINS,

LMEIN LIKE EKPO-LMEIN.

LOOP AT INV.

CLEAR: WESBS, SHKZG, MEINS, LMEIN.

SELECT YWESBS YSHKZG XMEINS XLMEIN

INTO (WESBS, SHKZG, MEINS, LMEIN)

FROM EKPO AS X JOIN EKBE AS Y

ON XEBELN = YEBELN

AND XEBELP = YEBELP

WHERE X~MATNR EQ INV-MATNR

AND X~WERKS EQ INV-WERKS

AND X~LOEKZ NE 'L'.

IF SHKZG EQ 'H'.

MULTIPLY WESBS BY -1.

ENDIF.

IF MEINS NE LMEIN.

PERFORM CONVERT_UNIT_OF_MEASURE CHANGING INV-MATNR MEINS WESBS.

ENDIF.

ADD WESBS TO INV-WESBS.

ENDSELECT.

MODIFY INV.

ENDLOOP.

ENDFORM. " GET_EKPO

&----


*& Form GET_LIPS

&----


  • text

----


FORM GET_LIPS.

DATA: LFIMG LIKE INV-LFIMG.

LOOP AT INV.

CLEAR: LFIMG, INV-LFIMG.

SELECT OMENG

INTO LFIMG

FROM VBBE

WHERE MATNR EQ INV-MATNR

AND WERKS EQ INV-WERKS

AND VBTYP EQ 'J'.

ADD LFIMG TO INV-LFIMG.

ENDSELECT.

MODIFY INV.

ENDLOOP.

ENDFORM. " GET_LIPS

&----


*& Form GET_VBAP

&----


  • text

----


FORM GET_VBAP.

DATA: KWMENG LIKE INV-KWMENG.

LOOP AT INV.

CLEAR: KWMENG, INV-KWMENG.

SELECT OMENG

INTO KWMENG

FROM VBBE

WHERE MATNR EQ INV-MATNR

AND WERKS EQ INV-WERKS

AND VBTYP EQ 'C'.

ADD KWMENG TO INV-KWMENG.

ENDSELECT.

INV-AVAIL = INV-LABST - INV-INSME - INV-KWMENG - INV-LFIMG.

MODIFY INV.

ENDLOOP.

ENDFORM. " GET_VBAP

&----


*& Form GET_UNIT_OF_MEASURE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_UNIT_OF_MEASURE.

LOOP AT INV.

SELECT SINGLE MEINS

FROM MARA

INTO INV-MEINS

WHERE MATNR EQ INV-MATNR.

MODIFY INV.

ENDLOOP.

ENDFORM. " GET_UNIT_OF_MEASURE

&----


*& Form GET_OPEN

&----


  • text

----


FORM GET_OPEN.

DATA: BEGIN OF XTAB OCCURS 10, " Open orders table

WERKS LIKE EKPO-WERKS,

LGORT LIKE EKPO-LGORT,

MATNR LIKE EKPO-MATNR,

MENGE LIKE EKPO-MENGE,

MENGK LIKE EKPO-MENGE,

END OF XTAB.

RANGES: L_WERKS FOR MARD-WERKS.

LOOP AT INV.

REFRESH XTAB.

CLEAR: XTAB, L_WERKS.

MOVE INV-WERKS TO L_WERKS-LOW.

CALL FUNCTION 'MB_ADD_PURCHASE_ORDER_QUANTITY'

EXPORTING

X_MATNR = INV-MATNR

X_MEINS = INV-MEINS

X_ELIKZ = SPACE

X_LOEKZ = SPACE

TABLES

XTAB = XTAB

XWERKS = L_WERKS.

MOVE XTAB-MENGE TO INV-MENGE.

MODIFY INV.

ENDLOOP.

ENDFORM. " GET_OPEN

&----


*& Form GET_PRICE

&----


  • text

----


FORM GET_PRICE.

LOOP AT INV.

SELECT SINGLE STPRS

FROM MBEW

INTO INV-STPRS

WHERE MATNR EQ INV-MATNR

AND BWKEY EQ INV-WERKS

AND BWTAR EQ SPACE.

IF SY-SUBRC EQ 0.

INV-VALUE = INV-STPRS *

( INV-LABST + INV-INSME + INV-TRANS + INV-SPEME ).

MODIFY INV.

ENDIF.

ENDLOOP.

ENDFORM. " GET_PRICE

----


  • FORM CONVERT_UNIT_OF_MEASURE *

----


  • text *

----


  • --> P_MATNR *

  • --> P_VRKME *

  • --> P_QUANT *

----


FORM CONVERT_UNIT_OF_MEASURE USING P_MATNR P_VRKME P_QUANT.

DATA: UMREZ LIKE MARM-UMREZ,

UMREN LIKE MARM-UMREN.

SELECT SINGLE UMREZ UMREN

INTO (UMREZ, UMREN)

FROM MARM

WHERE MATNR EQ P_MATNR

AND MEINH EQ P_VRKME.

IF SY-SUBRC EQ 0.

COMPUTE P_QUANT = ( P_QUANT * UMREZ ) / UMREN.

ENDIF.

ENDFORM.

&----


*& Form BUILD_LAYOUT

&----


  • text

----


  • -->P_LAYOUT text *

----


FORM BUILD_LAYOUT USING P_LAYOUT TYPE SLIS_LAYOUT_ALV.

P_LAYOUT-F2CODE = F2CODE.

P_LAYOUT-ZEBRA = 'X'.

P_LAYOUT-DETAIL_POPUP = 'X'.

ENDFORM. " BUILD_LAYOUT

&----


*& Form WRITE_OUTPUT

&----


  • text

----


FORM WRITE_OUTPUT.

SORT INV BY WERKS MATNR.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = REPNAME

I_INTERNAL_TABNAME = 'INV'

I_INCLNAME = REPNAME

CHANGING

CT_FIELDCAT = FIELDTAB.

IF SY-SUBRC <> 0.

WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_FIELDCATALOG_MERGE'.

ENDIF.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = REPNAME

I_STRUCTURE_NAME = 'INV'

IS_LAYOUT = LAYOUT

IT_FIELDCAT = FIELDTAB

I_DEFAULT = 'A'

I_SAVE = G_SAVE

IS_VARIANT = G_VARIANT

IT_EVENTS = EVENTS[]

TABLES

T_OUTTAB = INV.

break-point.

IF SY-SUBRC <> 0.

WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_LIST_DISPLAY'.

ENDIF.

ENDFORM. " WRITE_OUTPUT

The function REUSE_ALV_FIELDCATALOG_MERGE is used for retrieve a catalog =

from a table defined in DDICT. Then you can modify it as you want. You =

can see an example in BALV* programs demos.

Look this example:

in the program J_1AINFG is called as:

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' =20

EXPORTING =20

i_internal_tabname = TABLEINT

i_structure_name = 'J_1AIFALVHDR' =20

CHANGING =20

ct_fieldcat = i_fieldcat[]. =20

where i_structure name is defined in DDICT. Then you can add, delete, or =

modify masks, lengths, etc. properties of fields in this table.

In my program I need add a lot of fields

LOOP AT i_fieldcat INTO wa_fieldcat. =20

MOVE wa_fieldcat TO wa_auxfieldcat. =20

CASE wa_fieldcat-col_pos. =20

WHEN 27. =20

CLEAR wa_fieldcat. =20

wa_fieldcat-fieldname = 'COEFIC1'. =20

wa_fieldcat-tabname = g_tabname_header. =20

wa_fieldcat-col_pos = 27. =20

wa_fieldcat-seltext_s = 'Coef.Per.'. =20

wa_fieldcat-seltext_m = 'Coefic.Per=EDodo'. =20

wa_fieldcat-seltext_l = 'Coeficiente del Per=EDodo'. =20

wa_fieldcat-outputlen = 9. =20

wa_fieldcat-just = 'R'. =20

APPEND wa_fieldcat TO auxcatalogo. =20

ADD 1 TO wa_auxfieldcat-col_pos. =20

..

ENDCASE.

ENDLOOP.

i_fieldcat[] = auxcatalogo[].

0 Kudos

the function REUSE_ALV_FIELDCATALOG_MERGE does not require the definition of the catalog structure to be stored in the dictionary - It can just as easily use an internal table that is only defined in your program.

When you have an internal table defined with a lot of fields using this function to set up the field catalog can greatly simplify your program. As long as all fields in the internal table are defined as 'LIKE' a dictionary field they will inherit the attribute of that dictionary field. One note is that the function does not recognise fields defined as 'TYPE' except for basic types like "TYPE C". So "WERKS LIKE MARD-WERKS" will work, but "WERKS TYPE MARD-WERKS" will not.

You simply need to call the REUSE_ALV_FIELDCATALOG_MERGE function and give it your program name and the name of the structure defining your internal table - it then returns a field catalog which you can loop at to modify descriptions, widths, etc.

Andrew

Former Member
0 Kudos

REPORT ZALV_GRID .

tables kna1.

type-pools slis.

data: fcat type slis_t_fieldcat_alv,

i_repid like sy-repid.

data: begin of itab occurs 0,

kunnr like kna1-kunnr,

name1 like kna1-name1,

end of itab.

select-options: s_kunnr for kna1-kunnr.

i_repid = sy-repid.

select * from kna1 into corresponding fields of table itab up to 10 rows

where kunnr in s_kunnr.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = i_repid

I_INTERNAL_TABNAME = 'ITAB'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = i_repid

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = fcat

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

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = 'i_repid'

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_STRUCTURE_NAME =

  • IS_LAYOUT =

IT_FIELDCAT = fcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

I_SAVE = 'A'

  • 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

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

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.

i made

"I_INTERNAL_TABNAME = 'ITAB'"

and

"I_SAVE = 'A'"

previously i used lower case.

thanks for solution