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: 

BCALV_GRID_01

sudhakara_reddy4
Participant
0 Kudos

Hi,

please run program,

actually it has to display the 5 fields, but it is displaying on two fields, i.e first merge function fields , can any body tell the solution.

create custom control ; BCALVC_EVENT1_CONT1

setpf: MAIN100.

-

-


REPORT ZSUDHA_BCALV_GRID_01 .

*********

  • Predefine a local class for event handling to allow the

  • declaration of a reference variable.

CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.

*

*********

*----


*

  • TABLES DECLARATIONS

*----


*

TABLES: KNA1, VBAK, VBAP.

*----


*

  • INTERNAL TABLES DECLARATION

*----


*

DATA : BEGIN OF GT_FINAL OCCURS 0,

KUNNR LIKE VBAK-KUNNR,

VBELN LIKE VBAK-VBELN,

POSNR LIKE VBAP-POSNR,

MATNR LIKE VBAP-MATNR,

NETPR LIKE VBAP-NETPR,

END OF GT_FINAL.

DATA: OK_CODE LIKE SY-UCOMM,

G_REPID LIKE SY-REPID,

GS_PRINT TYPE LVC_S_PRNT,

  • GS_LAYOUT TYPE LVC_S_LAYO,

MYCONTAINER TYPE SCRFNAME VALUE 'BCALVC_EVENT1_CONT1',

  • reference to custom container: neccessary to bind ALV Control

CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

GRID1 TYPE REF TO CL_GUI_ALV_GRID,

EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER,

  • fieldcatalog for output table

gt_fieldcat type lvc_t_fcat,

gt_fcatfcat type lvc_t_fcat,

gs_fcatlayo type lvc_s_layo.

CLASS LCL_EVENT_RECEIVER DEFINITION.

PUBLIC SECTION.

  • § 2. Define a method for each print event you need.

METHODS:

HANDLE_TOP_OF_PAGE

FOR EVENT PRINT_TOP_OF_PAGE OF CL_GUI_ALV_GRID,

HANDLE_END_OF_PAGE

FOR EVENT PRINT_END_OF_PAGE OF CL_GUI_ALV_GRID,

HANDLE_TOP_OF_LIST

FOR EVENT PRINT_TOP_OF_LIST OF CL_GUI_ALV_GRID,

HANDLE_END_OF_LIST

FOR EVENT PRINT_END_OF_LIST OF CL_GUI_ALV_GRID.

PRIVATE SECTION.

DATA: PAGENUM TYPE I.

ENDCLASS.

CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.

*§ 3. Implement your event handler methods. Use WRITE to provide output.

METHOD HANDLE_TOP_OF_PAGE.

DATA: TABLENAME(30) TYPE C.

PERFORM GET_TABLENAME CHANGING TABLENAME.

WRITE: /,'Event: PRINT_TOP_OF_PAGE'(001),

'Table: '(002),TABLENAME.

ENDMETHOD. "handle_top_of_page

*----

-


METHOD HANDLE_END_OF_PAGE.

DATA: TABLENAME(30) TYPE C.

PERFORM GET_TABLENAME CHANGING TABLENAME.

ADD 1 TO PAGENUM.

WRITE: /,'Event: PRINT_END_OF_PAGE'(003),

TEXT-002,TABLENAME,

'Number of pages so far: '(004), PAGENUM.

ENDMETHOD. "handle_end_of_page

*----

-


METHOD HANDLE_TOP_OF_LIST.

DATA: TABLENAME(30) TYPE C.

CLEAR PAGENUM.

PERFORM GET_TABLENAME CHANGING TABLENAME.

WRITE: /,'Event: PRINT_TOP_OF_LIST'(005),

TEXT-002,TABLENAME.

ENDMETHOD. "handle_top_of_list

*----

-


METHOD HANDLE_END_OF_LIST.

DATA: TABLENAME(30) TYPE C.

PERFORM GET_TABLENAME CHANGING TABLENAME.

WRITE: /,'Event: PRINT_END_OF_LIST'(006),

TEXT-002,TABLENAME.

ENDMETHOD. "handle_end_of_list

*----

-


ENDCLASS.

*----


*

  • SELECTION SCREEN

*----


*

SELECT-OPTIONS : S_VBELN FOR VBAP-VBELN.

*----


*

  • START-OF-SELECTION *

*----


*

START-OF-SELECTION.

PERFORM GET_FINAL_DATA.

END-OF-SELECTION.

G_REPID = SY-REPID.

CALL SCREEN 100.

*&----


*

*& Form GET_FINAL_DATA

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM GET_FINAL_DATA.

SELECT VBAKKUNNR VBAKVBELN VBAPPOSNR VBAPMATNR VBAP~NETPR

INTO TABLE GT_FINAL

FROM VBAK INNER JOIN VBAP

ON VBAKVBELN = VBAPVBELN

WHERE VBAK~VBELN IN S_VBELN.

SORT GT_FINAL BY KUNNR VBELN POSNR.

WRITE: 'Success'.

ENDFORM. " GET_FINAL_DATA

*&----


*

*& Module PBO OUTPUT

*&----


*

  • text

*----


*

MODULE PBO OUTPUT.

SET PF-STATUS 'MAIN100'.

IF CUSTOM_CONTAINER IS INITIAL.

  • create a custom container control for our ALV Control

CREATE OBJECT CUSTOM_CONTAINER

EXPORTING

CONTAINER_NAME = MYCONTAINER

EXCEPTIONS

CNTL_ERROR = 1

CNTL_SYSTEM_ERROR = 2

CREATE_ERROR = 3

LIFETIME_ERROR = 4

LIFETIME_DYNPRO_DYNPRO_LINK = 5.

IF SY-SUBRC NE 0.

  • add your handling, for example

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

TITEL = G_REPID

TXT2 = SY-SUBRC

TXT1 = 'The control could not be created'(010).

ENDIF.

  • create an instance of alv control

CREATE OBJECT GRID1

EXPORTING I_PARENT = CUSTOM_CONTAINER.

*

  • Set a titlebar for the grid control

*

gs_fcatlayo-GRID_TITLE = 'CUSTOMER'(100).

  • § 5. In case of PRINT_END_OF_PAGE, you must set 'reservelns' to

  • the number of reserved lines at the end of a page.

*

  • reserve two lines for the PRINT_END_OF_PAGE event

*

*GS_PRINT-RESERVELNS = 2.

perform build_fieldcatalog changing gt_fieldcat.

*perform modify_fieldcatalog changing gt_fcatfcat.

  • optimize column width of grid displaying fieldcatalog

gs_fcatlayo-cwidth_opt = 'X'.

CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IS_PRINT = GS_PRINT

IS_LAYOUT = gs_fcatlayo

CHANGING

it_outtab = gt_FINAL[]

it_fieldcatalog = gt_fieldcat.

********

  • ->Create Object to receive events and link them to handler methods.

  • When the ALV Control raises the event for the specified instance

  • the corresponding method is automatically called.

*

  • § 4. Link used print events and event handler methods.

CREATE OBJECT EVENT_RECEIVER.

SET HANDLER EVENT_RECEIVER->HANDLE_TOP_OF_LIST FOR GRID1.

SET HANDLER EVENT_RECEIVER->HANDLE_TOP_OF_PAGE FOR GRID1.

SET HANDLER EVENT_RECEIVER->HANDLE_END_OF_LIST FOR GRID1.

SET HANDLER EVENT_RECEIVER->HANDLE_END_OF_PAGE FOR GRID1.

*

********

ENDIF.

  • Controls are not integrated into the TAB-Order

  • Call "set_focus" if you want to make sure that 'the cursor'

  • is active in your control.

CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = GRID1.

  • Control Framework flushes at the end of PBO automatically!

ENDMODULE. " PBO OUTPUT

*&----


*

*& Module PAI INPUT

*&----


*

  • text

*----


*

MODULE PAI INPUT.

CASE OK_CODE.

WHEN 'EXIT'.

PERFORM EXIT_PROGRAM.

ENDCASE.

CLEAR OK_CODE.

ENDMODULE.

*----


*

  • FORM EXIT_PROGRAM *

*----


*

FORM EXIT_PROGRAM.

CALL METHOD CUSTOM_CONTAINER->FREE.

CALL METHOD CL_GUI_CFW=>FLUSH.

IF SY-SUBRC NE 0.

  • add your handling, for example

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

TITEL = G_REPID

TXT2 = SY-SUBRC

TXT1 = 'Error in Flush'(009).

ENDIF.

LEAVE PROGRAM.

ENDFORM.

*&----


*

*& Form GET_TABLENAME

*&----


*

  • text

*----


*

  • <--P_TABLENAME text

*----


*

FORM GET_TABLENAME CHANGING P_TABLENAME.

DATA: LT_FIELDCAT TYPE STANDARD TABLE OF LVC_S_FCAT,

LS_FIELDCAT TYPE LVC_S_FCAT.

CALL METHOD GRID1->GET_FRONTEND_FIELDCATALOG

IMPORTING ET_FIELDCATALOG = LT_FIELDCAT.

CALL METHOD CL_GUI_CFW=>FLUSH.

IF SY-SUBRC <> 0.

P_TABLENAME = 'No tablename in fieldcatalog!'(008).

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

TITEL = G_REPID

TXT2 = P_TABLENAME

TXT1 = 'Error in Flush'(011).

ELSE.

READ TABLE LT_FIELDCAT INDEX 1 INTO LS_FIELDCAT.

P_TABLENAME = LS_FIELDCAT-REF_TABLE.

ENDIF.

ENDFORM. " GET_TABLENAME ENDFORM. " GET_FINAL_DATA

*&----


*

*& Form build_fieldcatalog

*&----


*

  • text

*----


*

  • <--P_GT_FIELDCAT text

*----


*

FORM build_fieldcatalog CHANGING P_FIELDCAT type lvc_t_fcat.

data: ls_fcat type lvc_s_fcat.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

  • I_BUFFER_ACTIVE =

I_STRUCTURE_NAME = 'VBAK'

  • I_CLIENT_NEVER_DISPLAY = 'X'

  • I_BYPASSING_BUFFER =

CHANGING

CT_FIELDCAT = p_fieldcat[]

  • 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 'LVC_FIELDCATALOG_MERGE'

EXPORTING

  • I_BUFFER_ACTIVE =

I_STRUCTURE_NAME = 'VBAP'

  • I_CLIENT_NEVER_DISPLAY = 'X'

  • I_BYPASSING_BUFFER =

CHANGING

CT_FIELDCAT = p_fieldcat[]

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

  • Delete All Feilds Except present in GT_FINAL

LOOP AT p_fieldcat INTO ls_fcat.

IF ( ls_fcat-fieldname NE 'VBELN' and

ls_fcat-fieldname NE 'KUNNR' and

ls_fcat-fieldname NE 'POSNR' and

ls_fcat-fieldname NE 'MATNR' and

ls_fcat-fieldname NE 'NETPR' ).

ls_fcat-fieldname = ' '.

modify p_fieldcat from ls_fcat.

ENDIF.

ENDLOOP.

DELETE p_fieldcat WHERE fieldname = ' '.

  • Change Column Postion

LOOP AT p_fieldcat INTO ls_fcat.

ls_fcat-col_pos = SY-TABIX.

ls_fcat-row_pos = '0'.

IF ls_fcat-fieldname EQ 'KUNNR'.

ls_fcat-key = 'X'.

ENDIF.

modify p_fieldcat from ls_fcat.

ENDLOOP.

LOOP AT p_fieldcat INTO ls_fcat.

IF ( ls_fcat-fieldname EQ 'VBELN' ).

add 1 to ls_fcat-col_pos.

modify p_fieldcat from ls_fcat.

ELSEIF ls_fcat-fieldname EQ 'KUNNR'.

SUBTRACT 1 from ls_fcat-col_pos.

modify p_fieldcat from ls_fcat.

ELSE.

*Nothing

ENDIF.

ENDLOOP.

sort p_fieldcat by col_pos.

ENDFORM. " build_fieldcatalog

*&----


*

*& Form modify_fieldcatalog

*&----


*

  • text

*----


*

  • <--P_GT_FCATFCAT text

*----


*

FORM modify_fieldcatalog CHANGING P_FCATFCAT type lvc_t_fcat.

data ls_fcat type lvc_s_fcat.

loop at p_fcatfcat into ls_fcat.

ls_fcat-coltext = ls_fcat-fieldname.

ls_fcat-edit = 'X'.

if ls_fcat-fieldname = 'COL_POS' or ls_fcat-fieldname = 'FIELDNAME'.

ls_fcat-key = 'X'.

endif.

modify p_fcatfcat from ls_fcat.

endloop.

ENDFORM. " modify_fieldcatalog

12 REPLIES 12

Former Member
0 Kudos

Hi,

you can build the fieldcat table and instead that to use the function ''LVC_FIELDCATALOG_MERGE'.

Former Member
0 Kudos

Hello Sudhakar,

In the program code u have given, the NO_OUT field of the fieldcatalog table GT_FIELDCAT is taking in value of 'X' for the fields POSNR,MATNR and NETPR .

That is why only the first two fields KUNNR and VBELN are getting displayed in grid.

Just in case u are not aware of the usage of NO_OUT......

NO_OUT is the field of fieldcatlog which when set to 'X' makes the field disappear in the output in the grid.

Hope the problem is solved .

Pls dont forget to award points if answer is found helpful.

Regards,

Sanghamitra.

0 Kudos

Hello Sudhakar,

Just the code in debugger and u can easily find out that the NO_OUT field is set to 'X' for the missing fields.

Make NO_OUT = SPACE for these fields (POSNR,MATNR and NETPR) in the fieldcatalog.

Regards,

Sanghmitra.

0 Kudos

Hi when i make no_out = space it is giving dump, what is reason

0 Kudos

comment the no_out completly and try it should work

0 Kudos

Hello Sudhakar,

1) U can as well comment out the NO_OUT column for the fields which u dont want to display OR

2) try GWA_FCAT-NO_OUT = ' '.

U will get the task done.

Regards,

Sanghamitra.

0 Kudos

Hi sangha mitra ,

i am not able to get what you are saying , please explain once more, or please paste your code here, thank you very much for cooperation in my report, i am working last 10days to get output, it will great appreciated, if you give good idea.

0 Kudos

I have made a change in your program just copy and paste and run that...



* Predefine a local class for event handling to allow the
* declaration of a reference variable.
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
*
*********

*----------------------------------------------------------------------*
* TABLES DECLARATIONS
*----------------------------------------------------------------------*
TABLES: KNA1, VBAK, VBAP.
*----------------------------------------------------------------------*
* INTERNAL TABLES DECLARATION
*----------------------------------------------------------------------*
DATA : BEGIN OF GT_FINAL OCCURS 0,
KUNNR LIKE VBAK-KUNNR,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
NETPR LIKE VBAP-NETPR,
END OF GT_FINAL.

DATA: OK_CODE LIKE SY-UCOMM,
G_REPID LIKE SY-REPID,
GS_PRINT TYPE LVC_S_PRNT,
* GS_LAYOUT TYPE LVC_S_LAYO,
MYCONTAINER TYPE SCRFNAME VALUE 'BCALVC_EVENT1_CONT1',
* reference to custom container: neccessary to bind ALV Control
CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
GRID1 TYPE REF TO CL_GUI_ALV_GRID,
EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER,
* fieldcatalog for output table
gt_fieldcat type lvc_t_fcat,
gt_fcatfcat type lvc_t_fcat,
gs_fcatlayo type lvc_s_layo.

CLASS LCL_EVENT_RECEIVER DEFINITION.

PUBLIC SECTION.
* § 2. Define a method for each print event you need.
METHODS:
HANDLE_TOP_OF_PAGE
FOR EVENT PRINT_TOP_OF_PAGE OF CL_GUI_ALV_GRID,

HANDLE_END_OF_PAGE
FOR EVENT PRINT_END_OF_PAGE OF CL_GUI_ALV_GRID,

HANDLE_TOP_OF_LIST
FOR EVENT PRINT_TOP_OF_LIST OF CL_GUI_ALV_GRID,

HANDLE_END_OF_LIST
FOR EVENT PRINT_END_OF_LIST OF CL_GUI_ALV_GRID.

PRIVATE SECTION.
DATA: PAGENUM TYPE I.

ENDCLASS.
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
*§ 3. Implement your event handler methods. Use WRITE to provide output.
METHOD HANDLE_TOP_OF_PAGE.
DATA: TABLENAME(30) TYPE C.
PERFORM GET_TABLENAME CHANGING TABLENAME.
WRITE: /,'Event: PRINT_TOP_OF_PAGE'(001),
'Table: '(002),TABLENAME.

ENDMETHOD. "handle_top_of_page
*-------------------------------------------
METHOD HANDLE_END_OF_PAGE.
DATA: TABLENAME(30) TYPE C.

PERFORM GET_TABLENAME CHANGING TABLENAME.
ADD 1 TO PAGENUM.
WRITE: /,'Event: PRINT_END_OF_PAGE'(003),
TEXT-002,TABLENAME,
'Number of pages so far: '(004), PAGENUM.

ENDMETHOD. "handle_end_of_page
*-------------------------------------------
METHOD HANDLE_TOP_OF_LIST.
DATA: TABLENAME(30) TYPE C.
CLEAR PAGENUM.
PERFORM GET_TABLENAME CHANGING TABLENAME.
WRITE: /,'Event: PRINT_TOP_OF_LIST'(005),
TEXT-002,TABLENAME.

ENDMETHOD. "handle_top_of_list
*-------------------------------------------
METHOD HANDLE_END_OF_LIST.
DATA: TABLENAME(30) TYPE C.
PERFORM GET_TABLENAME CHANGING TABLENAME.
WRITE: /,'Event: PRINT_END_OF_LIST'(006),
TEXT-002,TABLENAME.

ENDMETHOD. "handle_end_of_list
*-------------------------------------------
ENDCLASS.


*----------------------------------------------------------------------*
* SELECTION SCREEN
*----------------------------------------------------------------------*
SELECT-OPTIONS : S_VBELN FOR VBAP-VBELN.

*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM GET_FINAL_DATA.
END-OF-SELECTION.
G_REPID = SY-REPID.
CALL SCREEN 100.

*&---------------------------------------------------------------------*
*& Form GET_FINAL_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_FINAL_DATA.
SELECT VBAK~KUNNR VBAK~VBELN VBAP~POSNR VBAP~MATNR VBAP~NETPR
INTO TABLE GT_FINAL
FROM VBAK INNER JOIN VBAP
ON VBAK~VBELN = VBAP~VBELN
WHERE VBAK~VBELN IN S_VBELN.
SORT GT_FINAL BY KUNNR VBELN POSNR.
WRITE: 'Success'.
ENDFORM. " GET_FINAL_DATA

*&---------------------------------------------------------------------*
*& Module PBO OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE PBO OUTPUT.
SET PF-STATUS 'MAIN100'.
IF CUSTOM_CONTAINER IS INITIAL.
* create a custom container control for our ALV Control
CREATE OBJECT CUSTOM_CONTAINER
EXPORTING
CONTAINER_NAME = MYCONTAINER
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5.
IF SY-SUBRC NE 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = G_REPID
TXT2 = SY-SUBRC
TXT1 = 'The control could not be created'(010).
ENDIF.
* create an instance of alv control
CREATE OBJECT GRID1
EXPORTING I_PARENT = CUSTOM_CONTAINER.
*
* Set a titlebar for the grid control
*
gs_fcatlayo-GRID_TITLE = 'CUSTOMER'(100).
* § 5. In case of PRINT_END_OF_PAGE, you must set 'reservelns' to
* the number of reserved lines at the end of a page.
*
* reserve two lines for the PRINT_END_OF_PAGE event
*
*GS_PRINT-RESERVELNS = 2.

perform build_fieldcatalog changing gt_fieldcat.
*perform modify_fieldcatalog changing gt_fcatfcat.
* optimize column width of grid displaying fieldcatalog
gs_fcatlayo-cwidth_opt = 'X'.

CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_PRINT = GS_PRINT
IS_LAYOUT = gs_fcatlayo

CHANGING
it_outtab = gt_FINAL[]
it_fieldcatalog = gt_fieldcat.



********
* ->Create Object to receive events and link them to handler methods.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
*
* § 4. Link used print events and event handler methods.
CREATE OBJECT EVENT_RECEIVER.
SET HANDLER EVENT_RECEIVER->HANDLE_TOP_OF_LIST FOR GRID1.
SET HANDLER EVENT_RECEIVER->HANDLE_TOP_OF_PAGE FOR GRID1.
SET HANDLER EVENT_RECEIVER->HANDLE_END_OF_LIST FOR GRID1.
SET HANDLER EVENT_RECEIVER->HANDLE_END_OF_PAGE FOR GRID1.
*
********

ENDIF.
* Controls are not integrated into the TAB-Order
* Call "set_focus" if you want to make sure that 'the cursor'
* is active in your control.
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = GRID1.

* Control Framework flushes at the end of PBO automatically!


ENDMODULE. " PBO OUTPUT
*&---------------------------------------------------------------------*
*& Module PAI INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE PAI INPUT.
CASE OK_CODE.
WHEN 'EXIT'.
PERFORM EXIT_PROGRAM.
ENDCASE.
CLEAR OK_CODE.
ENDMODULE.
*---------------------------------------------------------------------*
* FORM EXIT_PROGRAM *
*---------------------------------------------------------------------*
FORM EXIT_PROGRAM.
CALL METHOD CUSTOM_CONTAINER->FREE.
CALL METHOD CL_GUI_CFW=>FLUSH.
IF SY-SUBRC NE 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = G_REPID
TXT2 = SY-SUBRC
TXT1 = 'Error in Flush'(009).
ENDIF.
LEAVE PROGRAM.
ENDFORM.





*&---------------------------------------------------------------------*
*& Form GET_TABLENAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_TABLENAME text
*----------------------------------------------------------------------*
FORM GET_TABLENAME CHANGING P_TABLENAME.
DATA: LT_FIELDCAT TYPE STANDARD TABLE OF LVC_S_FCAT,
LS_FIELDCAT TYPE LVC_S_FCAT.

CALL METHOD GRID1->GET_FRONTEND_FIELDCATALOG
IMPORTING ET_FIELDCATALOG = LT_FIELDCAT.


CALL METHOD CL_GUI_CFW=>FLUSH.
IF SY-SUBRC <> 0.
P_TABLENAME = 'No tablename in fieldcatalog!'(008).
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = G_REPID
TXT2 = P_TABLENAME
TXT1 = 'Error in Flush'(011).
ELSE.
READ TABLE LT_FIELDCAT INDEX 1 INTO LS_FIELDCAT.
P_TABLENAME = LS_FIELDCAT-REF_TABLE.
ENDIF.

ENDFORM. " GET_TABLENAME ENDFORM. " GET_FINAL_DATA
*&---------------------------------------------------------------------*
*& Form build_fieldcatalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FIELDCAT text
*----------------------------------------------------------------------*
FORM build_fieldcatalog CHANGING P_FIELDCAT type lvc_t_fcat.

data: ls_fcat type lvc_s_fcat.


CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = 'VBAK'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
CHANGING
CT_FIELDCAT = p_fieldcat[]
* 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 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = 'VBAP'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
CHANGING
CT_FIELDCAT = p_fieldcat[]
* 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.
* Delete All Feilds Except present in GT_FINAL
LOOP AT p_fieldcat INTO ls_fcat.
IF ( ls_fcat-fieldname NE 'VBELN' and
ls_fcat-fieldname NE 'KUNNR' and
ls_fcat-fieldname NE 'POSNR' and
ls_fcat-fieldname NE 'MATNR' and
ls_fcat-fieldname NE 'NETPR' ).

ls_fcat-fieldname = ' '.
modify p_fieldcat from ls_fcat.
ENDIF.
ENDLOOP.
DELETE p_fieldcat WHERE fieldname = ' '.
* Change Column Postion
LOOP AT p_fieldcat INTO ls_fcat.
ls_fcat-col_pos = SY-TABIX.
ls_fcat-row_pos = '0'.
<b>ls_fcat-no_out = ''.</b>
IF ls_fcat-fieldname EQ 'KUNNR'.
ls_fcat-key = 'X'.
ENDIF.
modify p_fieldcat from ls_fcat.
ENDLOOP.

LOOP AT p_fieldcat INTO ls_fcat.
IF ( ls_fcat-fieldname EQ 'VBELN' ).
add 1 to ls_fcat-col_pos.
modify p_fieldcat from ls_fcat.
ELSEIF ls_fcat-fieldname EQ 'KUNNR'.
SUBTRACT 1 from ls_fcat-col_pos.
modify p_fieldcat from ls_fcat.
ELSE.
*Nothing
ENDIF.
ENDLOOP.
sort p_fieldcat by col_pos.


ENDFORM. " build_fieldcatalog
*&---------------------------------------------------------------------*
*& Form modify_fieldcatalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_FCATFCAT text
*----------------------------------------------------------------------*
FORM modify_fieldcatalog CHANGING P_FCATFCAT type lvc_t_fcat.
data ls_fcat type lvc_s_fcat.

loop at p_fcatfcat into ls_fcat.
ls_fcat-coltext = ls_fcat-fieldname.
ls_fcat-edit = 'X'.

if ls_fcat-fieldname = 'COL_POS' or ls_fcat-fieldname = 'FIELDNAME'.
ls_fcat-key = 'X'.
endif.

modify p_fcatfcat from ls_fcat.
endloop.

ENDFORM. " modify_fieldcatalog

regards

shiba dutta

0 Kudos

Hi shiba,

this is the change you made,

ls_fcat-no_out = ' '.

if it is case it is giving dump, are able to execute successfully.

runtime error: GETWA_NOT_ASSIGNED

0 Kudos

but i have run it in my system and it is running properly with 5 fields display...Just put a break point on that statement and check whether it is the error due to that or not?

regards

shiba dutta

0 Kudos

there is no error, when i run program it is going going to dump, when i comment this statement it is executing successfully with 2 fields

Former Member
0 Kudos

hi

good

go through this link,

thanks

mrutyun^