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 grid

Former Member
0 Likes
739

i need code for alv grid control with out using field catalog for all the fields, i need to pass it by subroutines (actual and formal) parameters as many fields i required.

i need code for alv grid control with out using field catalog for all the fields, i need to pass it by subroutines (actual and formal) parameters as many fields i required.

4 REPLIES 4
Read only

Former Member
0 Likes
681

Hi,

In ur case instead of using the Function Module for building Fieldcatalog, u can do the following coding :

DATA: T_WFIELD TYPE SLIS_FIELDCAT_ALV.

T_WFIELD-TABNAME = 'T_STATFIN'.

T_WFIELD-COL_POS = W-COUNT.

T_WFIELD-FIELDNAME = 'ERROR'.

T_WFIELD-REF_TABNAME = 'ZMATSTAT'.

T_WFIELD-REPTEXT_DDIC = TEXT-004.

APPEND T_WFIELD .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IT_FIELDCAT = T_WFIELD.

Hope it helps.

U can also create subroutines for defining the fieldcatalog where in u can pass the parameters and define fieldcatalog.

e.g. in the code below :

======================================================================

  • This report was initially created by ALVRobot.com.ar

  • Please, read terms and conditions on the site.

======================================================================

  • Author: Himanshu Aggarwal

  • 04.04.07 - TEST ALV Report

  • Trial of ALV Robot

======================================================================

report ZTESTER.

========================== Global definitions =======================

**

  • Data Types

**

type-pools: slis.

types: begin of tp_data,

matnr like mara-matnr,

ersda like mara-ersda,

mtart like mara-mtart,

werks like marc-werks,

end of tp_data,

tp_tbl_data type standard table of tp_data.

**

  • Constants

**

**

  • Data objects (variable declarations and definitions)

**

  • Report data to be shown.

data: it_data type standard table of tp_data.

  • Heading of the report.

data: t_heading type slis_t_listheader.

========================== Selection Screen ==========================

selection-screen: begin of block b1 with frame title text-t01.

DATA: w_aux_matnr like mara-matnr.

SELECT-OPTIONS s_matnr for w_aux_matnr OBLIGATORY .

PARAMETER p_mtart like mara-mtart .

DATA: w_aux_ersda like mara-ersda.

SELECT-OPTIONS s_ersda for w_aux_ersda .

DATA: w_aux_werks like marc-werks.

SELECT-OPTIONS s_werks for w_aux_werks .

DATA: w_aux_pstat like marc-pstat.

SELECT-OPTIONS s_pstat for w_aux_pstat .

selection-screen: end of block b1.

=========================== Event Blocks =============================

at selection-screen.

start-of-selection.

perform get_data using it_data.

end-of-selection.

perform build_alv using it_data t_heading.

=========================== Subroutines ==============================

&----


*& Form get_data

&----


  • Gets the information to be shown in the report.

----


form get_data using t_data type tp_tbl_data.

SELECT a~matnr

a~ersda

a~mtart

b~werks

INTO CORRESPONDING FIELDS OF TABLE t_data

FROM mara as a

inner join marc as b on amatnr = bmatnr

WHERE a~matnr in s_matnr

AND a~mtart = p_mtart

AND a~ersda in s_ersda

AND b~werks in s_werks

AND b~pstat in s_pstat

.

endform. " get_data

&----


*& Form build_alv

&----


  • Builds and display the ALV Grid.

----


form build_alv using t_data type tp_tbl_data

t_heading type slis_t_listheader.

  • ALV required data objects.

data: w_title type lvc_title,

w_comm type slis_formname,

w_status type slis_formname,

x_layout type slis_layout_alv,

t_event type slis_t_event,

t_fieldcat type slis_t_fieldcat_alv,

t_sort type slis_t_sortinfo_alv.

refresh t_fieldcat.

refresh t_event.

refresh t_sort.

clear x_layout.

clear w_title.

  • Field Catalog

perform set_fieldcat2 using:

1 'MATNR' 'MATNR' 'MARA' space space space space space space space space space space space space t_fieldcat ,

2 'ERSDA' 'ERSDA' 'MARA' space space space space space space space space space space space space t_fieldcat ,

3 'MTART' 'MTART' 'MARA' space space space space space space space space space space space space t_fieldcat ,

4 'WERKS' 'WERKS' 'MARC' space space space space space space space space space space space space t_fieldcat .

  • Layout

x_layout-zebra = 'X'.

  • Top of page heading

perform set_top_page_heading using t_heading t_event.

  • Events

perform set_events using t_event.

  • GUI Status

w_status = ''.

  • User commands

w_comm = 'USER_COMMAND'.

  • Order

  • Example

  • PERFORM set_order USING '<field>' 'IT_DATA' 'X' space space t_sort.

  • Displays the ALV grid

call function 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

it_fieldcat = t_fieldcat

is_layout = x_layout

it_sort = t_sort

i_callback_pf_status_set = w_status

i_callback_user_command = w_comm

i_save = 'X'

it_events = t_event

i_grid_title = w_title

TABLES

t_outtab = t_data

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. " build_alv.

&----


*& Form set_top_page_heading

&----


  • Creates the report headings.

----


form set_top_page_heading using t_heading type slis_t_listheader

t_events type slis_t_event.

data: x_heading type slis_listheader,

x_event type line of slis_t_event.

  • Report title

clear t_heading[].

clear x_heading.

x_heading-typ = 'H'.

x_heading-info = 'TEST ALV Report'(001).

append x_heading to t_heading.

  • Program name

clear x_heading.

x_heading-typ = 'S'.

x_heading-key = 'Program: '.

x_heading-info = sy-repid.

append x_heading to t_heading.

  • User who is running the report

clear x_heading.

x_heading-typ = 'S'.

x_heading-key = 'User: '.

x_heading-info = sy-uname.

append x_heading to t_heading.

  • Date of execution

clear x_heading.

x_heading-typ = 'S'.

x_heading-key = 'Date: '.

write sy-datum to x_heading-info.

append x_heading to t_heading.

  • Time of execution

clear x_heading.

x_heading-typ = 'S'.

x_heading-key = 'Time: '.

write sy-uzeit to x_heading-info.

append x_heading to t_heading.

  • Top of page event

x_event-name = slis_ev_top_of_page.

x_event-form = 'TOP_OF_PAGE'.

append x_event to t_events.

endform. "set_top_page_heading

&----


*& Form set_events

&----


  • Sets the events for ALV.

  • The TOP_OF_PAGE event is alredy being registered in

  • the set_top_page_heading subroutine.

----


form set_events using t_events type slis_t_event.

data: x_event type line of slis_t_event.

**

  • Example

  • -------

  • clear x_event.

  • x_event-name = .

  • x_event-form = .

  • append x_event to t_event.

**

endform. "set_events

&----


*& Form set_order

&----


  • Adds an entry to the order table.

----


FORM set_order USING p_fieldname p_tabname p_up p_down p_subtot

t_sort TYPE slis_t_sortinfo_alv.

DATA: x_sort TYPE slis_sortinfo_alv.

CLEAR x_sort.

x_sort-fieldname = p_fieldname.

x_sort-tabname = p_tabname.

x_sort-up = p_up.

x_sort-down = p_down.

x_sort-subtot = p_subtot.

APPEND x_sort TO t_sort.

ENDFORM. "set_order

&----


*& Form set_fieldcat2

&----


  • Adds an entry to the field catalog.

----


FORM set_fieldcat2 USING p_colpos p_fieldname p_ref_fieldname p_ref_tabname

p_outputlen p_noout

p_seltext_m p_seltext_l p_seltext_s p_reptext_ddic p_ddictxt

p_hotspot p_showasicon p_checkbox p_edit

p_dosum

t_fieldcat TYPE slis_t_fieldcat_alv.

DATA: wa_fieldcat TYPE slis_fieldcat_alv.

CLEAR wa_fieldcat.

  • General settings

wa_fieldcat-fieldname = p_fieldname.

wa_fieldcat-col_pos = p_colpos.

wa_fieldcat-no_out = p_noout.

wa_fieldcat-hotspot = p_hotspot.

wa_fieldcat-checkbox = p_checkbox.

wa_fieldcat-icon = p_showasicon.

wa_fieldcat-do_sum = p_dosum.

  • Set reference fieldname, tablenam and rollname.

  • If p_ref_tabname is not given, the ref_fieldname given is a data element.

  • If p_ref_tabname is given, the ref_fieldname given is a field of a table. In case ref_fieldname is not given, it is copied from the fieldname.

IF p_ref_tabname IS INITIAL.

wa_fieldcat-rollname = p_ref_fieldname.

ELSE.

wa_fieldcat-ref_tabname = p_ref_tabname.

IF p_ref_fieldname EQ space.

wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.

ELSE.

wa_fieldcat-ref_fieldname = p_ref_fieldname.

ENDIF.

ENDIF.

  • Set output length.

IF NOT p_outputlen IS INITIAL.

wa_fieldcat-outputlen = p_outputlen.

ENDIF.

  • Set text headers.

IF NOT p_seltext_m IS INITIAL.

wa_fieldcat-seltext_m = p_seltext_m.

ENDIF.

IF NOT p_seltext_l IS INITIAL.

wa_fieldcat-seltext_l = p_seltext_l.

ENDIF.

IF NOT p_seltext_s IS INITIAL.

wa_fieldcat-seltext_s = p_seltext_s.

ENDIF.

IF NOT p_reptext_ddic IS INITIAL.

wa_fieldcat-reptext_ddic = p_reptext_ddic.

ENDIF.

IF NOT p_ddictxt IS INITIAL.

wa_fieldcat-ddictxt = p_ddictxt.

ENDIF.

  • Set as editable or not.

IF p_edit IS NOT INITIAL.

wa_fieldcat-input = 'X'.

wa_fieldcat-edit = 'X'.

ENDIF.

APPEND wa_fieldcat TO t_fieldcat.

ENDFORM. "set_fieldcat2

=========================== Subroutines called by ALV ================

&----


*& Form top_of_page

&----


  • Called on top_of_page ALV event.

  • Prints the heading.

----


form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

  • i_logo = 'XXXXX'

it_list_commentary = t_heading.

endform. " alv_top_of_page

&----


*& Form user_command

&----


  • Called on user_command ALV event.

  • Executes custom commands.

----


form user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

**

  • Example Code

*

  • Executes a command considering the sy-ucomm.

  • CASE r_ucomm.

  • WHEN '&IC1'.

*

  • Set your "double click action" response here.

*

  • Example code: Create and display a status message.

  • DATA: w_msg TYPE string,

  • w_row(4) TYPE n.

  • w_row = rs_selfield-tabindex.

  • CONCATENATE 'You have clicked row' w_row

  • 'field' rs_selfield-fieldname

  • 'with value' rs_selfield-value

  • INTO w_msg SEPARATED BY space.

  • MESSAGE w_msg TYPE 'S'.

*

  • ENDCASE.

*

  • End of example code.

**

endform. "user_command

Regards,

Himanshu

Read only

0 Likes
681

sorry for late reply the code u have sent is not working up.

Read only

Former Member
0 Likes
681

Hi,

the includes have also been provided.Check if it worked for you...

REPORT Y16S_VIEW_IDOC_CONTENT LINE-SIZE 230

NO STANDARD PAGE HEADING.

  • Data declarations

INCLUDE Y16S_VIEW_IDOC_CONTENT_D01I.

  • Selection screen

INCLUDE Y16S_VIEW_IDOC_CONTENT_S01I.

  • Events

INCLUDE Y16S_VIEW_IDOC_CONTENT_E01I.

  • Routines for program

INCLUDE Y16S_VIEW_IDOC_CONTENT_F01I.

START-OF-SELECTION.

  • Get the fieldcatalog

PERFORM get_fcat.

**Method for getting the reference for the structure

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING it_fieldcatalog = g_t_fieldcat

IMPORTING ep_table = dref.

**Passing the reference of the structure to field-symbol of type table

ASSIGN dref->* TO .

  • Fill IDoc data

PERFORM fill_data.

  • Display ALV

perform display_grid.

*----


*

  • INCLUDE Y16S_VIEW_IDOC_CONTENT_D01I *

*----


*

*----


*

  • Data declaration : Tables used *

*----


*

TABLES : edidd, "Data record (IDoc)

edidc, "Control record (IDoc)

edid4, "IDoc Data Records from 4.0 onwards

dd03d, "Dynpro fields for table fields

edsappl, "EDI: IDoc Segment Application Structure

int_seg, "Data record details display

dd03l, "Table Fields

edisegment. "IDoc Development : IDoc Segment

  • Name of segment

DATA : g_f_segment LIKE dntab-tabname.

*--Data Declaration.

FIELD-SYMBOLS : TYPE ANY.

DATA : BEGIN OF g_t_edid OCCURS 0,

docnum LIKE edid4-docnum,

segnum LIKE edid4-segnum,

sdata LIKE edid4-sdata,

END OF g_t_edid.

*DATA : g_t_edid LIKE edid4 OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF g_t_edidc OCCURS 0,

docnum LIKE edidc-docnum,

credat LIKE edidc-credat,

mestyp LIKE edidc-mestyp,

END OF g_t_edidc.

DATA : BEGIN OF g_t_appl OCCURS 0,

fieldname LIKE edsappl-fieldname,

END OF g_t_appl.

DATA : g_v_tabix LIKE sy-tabix.

*----


*

  • ALV Declarations

*----


*

*Declaration of type groups

TYPE-POOLS :

slis. "Globale Typen für generische Listbausteine

DATA: g_f_okcode LIKE sy-ucomm,

g_container TYPE scrfname VALUE 'G_C_ALV',

grid1 TYPE REF TO cl_gui_alv_grid,

g_custom_container TYPE REF TO cl_gui_custom_container.

FIELD-SYMBOLS: .

  • Class

CLASS: g_cl_event DEFINITION DEFERRED.

  • Alv Grid Constants

DATA : g_c_handle(4) TYPE c VALUE '0100',

g_c_save(1) TYPE c VALUE 'A',

g_c_exit(4) TYPE c VALUE 'EXIT'.

DATA: g_v_layout TYPE lvc_s_layo,

g_f_print TYPE lvc_s_prnt,

g_f_variant TYPE disvariant,

g_v_recv TYPE REF TO g_cl_event.

CONSTANTS : gc_ucomm_sel_criteria(12) VALUE 'SEL_CRITERIA'.

*----


*

  • CLASS G_Cl_EVENT DEFINITION

*----


*

  • Class to handle GRID Events *

*----


*

CLASS g_cl_event DEFINITION.

PUBLIC SECTION.

METHODS:

constructor IMPORTING value(grid_name) TYPE REF TO

cl_gui_alv_grid,

handle_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object e_interactive,

handle_user_command

FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING e_ucomm.

PRIVATE SECTION.

DATA: g_v_alv TYPE REF TO cl_gui_alv_grid.

ENDCLASS. "g_cl_event DEFINITION

**----


*

    • CLASS g_cl_events IMPLEMENTATION

**----


*

    • Class to handle GRID Events *

**----


*

CLASS g_cl_event IMPLEMENTATION.

  • Handling methods

METHOD constructor.

g_v_alv = grid_name.

ENDMETHOD. "constructor

  • Tool bar

METHOD handle_toolbar.

CONSTANTS:

lc_quickinfo_sel_criteria(111) VALUE 'Show Selection Criteria'.

DATA:

l_toolbar TYPE stb_button.

CLEAR l_toolbar.

MOVE 0 TO l_toolbar-butn_type.

MOVE gc_ucomm_sel_criteria TO l_toolbar-function.

MOVE icon_select_with_condition TO l_toolbar-icon.

MOVE lc_quickinfo_sel_criteria TO l_toolbar-quickinfo.

MOVE space TO l_toolbar-disabled.

APPEND l_toolbar TO e_object->mt_toolbar.

ENDMETHOD. "handle_toolbar

  • User Command

METHOD handle_user_command.

CASE e_ucomm.

  • When Exit button is used

WHEN 'EXIT'.

PERFORM exit_program.

WHEN OTHERS.

ENDCASE.

ENDMETHOD. "handle_user_command

ENDCLASS. "g_cl_event IMPLEMENTATION

*----


*

  • INCLUDE Y16S_VIEW_IDOC_CONTENT_S01I *

*----


*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.

  • Creation Date of IDoc

SELECT-OPTIONS : s_date FOR edidc-credat.

  • IDoc Number

SELECT-OPTIONS : s_idocnm FOR edidc-docnum.

  • Basic IDoc type

SELECT-OPTIONS : s_idoctp FOR edidc-idoctp.

*Message type

SELECT-OPTIONS : s_mestyp FOR edidc-mestyp.

  • Segment name

PARAMETERS : p_segnam LIKE edisegment-segtyp OBLIGATORY.

  • Field name

SELECT-OPTIONS : s_fldnam FOR dd03d-fieldname NO INTERVALS.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.

  • Field name

PARAMETERS : p_fldnam LIKE dd03d-fieldname.

  • Field contents of a field of an IDoc segment

SELECT-OPTIONS : s_fldval FOR int_seg-string.

SELECTION-SCREEN END OF BLOCK b2.

*----


*

  • INCLUDE Y16S_VIEW_IDOC_CONTENT_E01I *

*----


*

  • Check for IDoc number on selection screen

AT SELECTION-SCREEN ON s_idocnm.

IF NOT s_idocnm IS INITIAL.

  • Data fetch : Control record (IDoc)

SELECT COUNT( * ) FROM edidc

WHERE docnum IN s_idocnm.

IF sy-subrc NE 0.

MESSAGE e429(mo).

ENDIF.

ELSE.

  • message for required entry.

MESSAGE e055(00).

ENDIF.

  • Check for segment name on selection screen

AT SELECTION-SCREEN ON p_segnam.

  • Check segment name is an input on selection screen

IF NOT p_segnam IS INITIAL.

  • Data fetch : Table Fields

SELECT SINGLE * FROM dd03l

WHERE tabname EQ p_segnam.

IF sy-subrc NE 0.

MESSAGE e429(mo).

ENDIF.

ENDIF.

  • F4 help for fieldname

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_fldnam-low.

DATA : l_rc LIKE sy-subrc.

  • Check segment name on selection screen is not empty

IF NOT p_segnam IS INITIAL.

PERFORM get_f4help USING l_rc.

IF l_rc = 0.

  • Fill the selected field name

READ TABLE g_t_appl INDEX g_v_tabix.

CHECK sy-subrc = 0.

s_fldnam-low = g_t_appl-fieldname.

s_fldnam-sign = 'I'.

s_fldnam-option = 'EQ'.

APPEND s_fldnam.

ENDIF.

ENDIF.

  • Check for field name on selection screen

AT SELECTION-SCREEN ON s_fldnam.

IF NOT p_fldnam IS INITIAL.

  • Data fetch : Table Fields

SELECT SINGLE * FROM dd03l

WHERE tabname EQ p_segnam

AND fieldname IN s_fldnam.

IF sy-subrc NE 0.

MESSAGE e429(mo).

ENDIF.

ENDIF.

  • F4 help for fieldname

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fldnam.

DATA : l_rc LIKE sy-subrc.

  • Check segment name on selection screen is not empty

IF NOT p_segnam IS INITIAL.

  • F4 Help for fieldname

PERFORM get_f4help USING l_rc.

IF l_rc = 0.

  • Fill the selected field name

READ TABLE g_t_appl INDEX g_v_tabix.

CHECK sy-subrc = 0.

p_fldnam = g_t_appl-fieldname.

ENDIF.

ENDIF.

  • Check for field name on selection screen

AT SELECTION-SCREEN ON p_fldnam.

IF NOT p_fldnam IS INITIAL.

  • Data fetch : Table Fields

SELECT SINGLE * FROM dd03l

WHERE tabname EQ p_segnam

AND fieldname EQ p_fldnam.

IF sy-subrc NE 0.

MESSAGE e429(mo).

ENDIF.

ENDIF.

  • Check for field name on selection screen

AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_fldval-low.

  • Check field name is an input on selection screen

IF NOT p_fldnam IS INITIAL.

  • Get the domain values as F4 help

PERFORM get_domain_value.

ENDIF.

*Check for Message type on selection screen

AT SELECTION-SCREEN ON s_mestyp.

IF NOT s_mestyp IS INITIAL.

  • Data fetch : Logical message types

SELECT COUNT( * ) FROM edmsg

WHERE msgtyp IN s_mestyp.

IF sy-subrc NE 0.

MESSAGE e429(mo).

ENDIF.

ENDIF.

*Check for Basic type on selection screen

AT SELECTION-SCREEN ON s_idoctp.

IF NOT s_idoctp IS INITIAL.

  • Data fetch : Basic types

SELECT COUNT( * ) FROM edbas

WHERE idoctyp IN s_idoctp.

IF sy-subrc NE 0.

MESSAGE e429(mo).

ENDIF.

ENDIF.

*&----


*

*& Form GET_F4HELP

*&----


*

  • text

*----


*

  • -->P_L_RC text

*----


*

FORM get_f4help USING p_l_rc LIKE sy-subrc.

DATA : l_v_segment LIKE edsappl-segtyp.

DATA : l_t_help_value LIKE help_value OCCURS 0 WITH HEADER LINE.

  • Segment name

l_v_segment = p_segnam.

  • Data fetch : EDI: IDoc Segment Application Structure

SELECT pos fieldname FROM edsappl

INTO CORRESPONDING FIELDS OF TABLE g_t_appl

WHERE segtyp = l_v_segment

ORDER BY pos.

    • Popup having data

CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'

EXPORTING

endpos_col = 110

endpos_row = 16

startpos_col = 90

startpos_row = 1

titletext = text-001

IMPORTING

choise = g_v_tabix

TABLES

valuetab = g_t_appl

EXCEPTIONS

break_off = 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.

  • Return code

p_l_rc = sy-subrc.

ENDFORM. " GET_F4HELP

*&----


*

*& Form GET_DOMAIN_VALUE

*&----


*

  • text

*----


*

  • -->P_L_RC text

*----


*

FORM get_domain_value.

  • DD: Domain header with text

DATA : l_s_dd01v LIKE dd01v.

  • Value table

DATA : l_v_valuetab LIKE l_s_dd01v-entitytab.

  • RFC Table Read: Description of Fields to Retrieve

DATA : l_t_db_fld LIKE rfc_db_fld OCCURS 0 WITH HEADER LINE.

  • RFC Table Read: Select Options / WHERE Clause

DATA : l_t_options LIKE rfc_db_opt OCCURS 0 WITH HEADER LINE.

  • Table with a 512 byte field

DATA : l_t_valuetab LIKE tab512 OCCURS 0 WITH HEADER LINE.

*Data Dictionary access routines

CALL FUNCTION 'G_DOMAIN_READ'

EXPORTING

domain = p_fldnam

langu = sy-langu

IMPORTING

domain_attr = l_s_dd01v

EXCEPTIONS

not_found = 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.

l_v_valuetab = l_s_dd01v-entitytab.

l_t_db_fld-fieldname = p_fldnam.

APPEND l_t_db_fld.

  • External access to R/3 tables via RFC

CALL FUNCTION 'RFC_READ_TABLE'

EXPORTING

query_table = l_v_valuetab

  • DELIMITER = ' '

  • NO_DATA = ' '

  • ROWSKIPS = 0

  • ROWCOUNT = 0

TABLES

options = l_t_options

fields = l_t_db_fld

data = l_t_valuetab

EXCEPTIONS

table_not_available = 1

table_without_data = 2

option_not_valid = 3

field_not_valid = 4

not_authorized = 5

data_buffer_exceeded = 6

OTHERS = 7

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CLEAR g_v_tabix.

IF NOT l_t_valuetab[] IS INITIAL.

    • Popup having data

CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'

EXPORTING

endpos_col = 110

endpos_row = 16

startpos_col = 90

startpos_row = 1

titletext = text-001

IMPORTING

choise = g_v_tabix

TABLES

valuetab = l_t_valuetab

EXCEPTIONS

break_off = 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.

READ TABLE l_t_valuetab INDEX g_v_tabix.

CHECK sy-subrc = 0.

  • Fill the select-options of Fieldvalue

s_fldval-low = l_t_valuetab-wa.

s_fldval-sign = 'I'.

s_fldval-option = 'EQ'.

APPEND s_fldval.

ENDIF.

ENDFORM. " GET_DOMAIN_VALUE

*----


*

  • INCLUDE Y16S_VIEW_IDOC_CONTENT_F01I *

*----


*

*&----


*

*& Module STATUS_0100 OUTPUT

*&----


*

  • ALV grid output

*----


*

MODULE status_0100 OUTPUT.

*set the screen elements

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'TITLE100'.

*instantiation

IF g_custom_container IS INITIAL.

g_v_layout-zebra = 'X'.

g_v_layout-sel_mode = 'A'.

  • Create custom container

CREATE OBJECT g_custom_container

EXPORTING container_name = g_container.

  • Create ALV grid

CREATE OBJECT grid1

EXPORTING i_parent = g_custom_container.

CREATE OBJECT g_v_recv EXPORTING grid_name = grid1.

  • Display ALV grid

CALL METHOD grid1->set_table_for_first_display

EXPORTING

i_save = g_c_save

is_layout = g_v_layout

is_print = g_f_print

is_variant = g_f_variant

CHANGING

it_fieldcatalog = g_t_fieldcat

it_outtab = refresh_table_display.

ENDIF.

  • User command

SET HANDLER g_v_recv->handle_user_command FOR grid1.

CALL METHOD grid1->set_toolbar_interactive.

ENDMODULE. " STATUS_0100 OUTPUT

*&----


*

*& Module USER_COMMAND_0100 INPUT

*&----


*

  • User actions on grid

*----


*

MODULE user_command_0100 INPUT.

  • Dispatch the okcode

CALL METHOD cl_gui_cfw=>dispatch.

CASE g_f_okcode.

WHEN g_c_exit.

PERFORM exit_program.

WHEN OTHERS.

*do nothing

ENDCASE.

CLEAR g_f_okcode.

ENDMODULE. " USER_COMMAND_0100 INPUT

*&----


*

*& Form EXIT_PROGRAM

*&----


*

  • Exit from the Grid

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM exit_program.

  • Container for Custom Controls in the Screen Area

CALL METHOD g_custom_container->free.

*Control Framework Basic Class

CALL METHOD cl_gui_cfw=>flush.

  • Call the selection screen

SET SCREEN 0.

LEAVE SCREEN.

ENDFORM. " EXIT_PROGRAM

*&----


*

*& Form GET_FCAT

*&----


*

  • Field catalog fill

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM get_fcat.

*Segment details regarding fields

PERFORM get_segment_details.

  • Populate the Fieldcatalog

PERFORM fill_fieldcat.

IF g_f_variant-variant IS INITIAL.

  • Get the default variant

g_f_repid = sy-repid.

CLEAR : g_f_variant.

g_f_variant-report = g_f_repid.

g_r_x_variant = g_f_variant.

  • Get default variant

CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'

EXPORTING

i_save = g_c_save

CHANGING

cs_variant = g_r_x_variant

EXCEPTIONS

not_found = 2.

g_f_variant = g_r_x_variant.

g_f_variant-variant = 'X'.

ENDIF.

ENDFORM. " GET_FCAT

*&----


*

*& Form FILL_DATA

*&----


*

  • Fill the output internal table

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM fill_data.

FIELD-SYMBOLS TYPE ANY.

DATA : l_rc LIKE sy-subrc.

*Get the IDoc data

PERFORM get_data.

LOOP AT g_t_edid.

*Check for filtering the values

IF ( NOT ( p_fldnam IS INITIAL AND s_fldval[] IS INITIAL ) ).

  • Field value check

PERFORM check_fieldvalue USING l_rc.

IF l_rc NE 0.

CONTINUE.

ENDIF.

ENDIF.

ASSIGN LOCAL COPY OF g_t_edid TO .

ENDLOOP.

ENDFORM. " FILL_DATA

*&----


*

*& Form DISPLAY_GRID

*&----


*

  • Display ALV grid

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM display_grid.

  • Call ALV grid

CALL SCREEN 100.

ENDFORM. " DISPLAY_GRID

*&----


*

*& Form CHECK_FIELDVALUE

*&----


*

  • Check the fieldvalue

*----


*

  • -->P_L_RC text

*----


*

FORM check_fieldvalue USING p_l_rc LIKE sy-subrc.

  • Segment data

ASSIGN g_t_edid-sdata TO CASTING TYPE (p_segnam).

  • Segment fields

LOOP AT g_t_segment WHERE fieldname = p_fldnam.

ASSIGN COMPONENT g_t_segment-fieldname

OF STRUCTURE IN s_fldval.

p_l_rc = 0.

ELSE.

p_l_rc = 4.

ENDIF.

ENDLOOP.

ENDFORM. " CHECK_FIELDVALUE

*&----


*

*& Form GET_DATA

*&----


*

  • Get the IDoc data

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM get_data.

*Clear the header line of the internal table

CLEAR : g_t_edid,

g_t_edidc.

  • Clear the body of the internal table

REFRESH : g_t_edid,

g_t_edidc.

*Data fetch : Control record (IDoc)

SELECT docnum credat mestyp FROM edidc

INTO TABLE g_t_edidc

WHERE docnum IN s_idocnm AND

credat IN s_date AND

mestyp IN s_mestyp AND

idoctp IN s_idoctp.

*Date/Message type if not initial

IF ( ( NOT ( s_date[] IS INITIAL ) )

OR ( NOT ( s_mestyp[] IS INITIAL ) )

OR ( NOT ( s_idoctp[] IS INITIAL ) ) ).

  • Check the control record of the IDoc

PERFORM check_control_data.

ELSE.

  • Data fetch : IDoc Data Records from 4.0 onwards

SELECT docnum segnum sdata FROM edid4 INTO TABLE g_t_edid

WHERE docnum IN s_idocnm AND

segnam EQ p_segnam.

ENDIF.

ENDFORM. " GET_DATA

*&----


*

*& Form CHECK_CONTROL_DATA

*&----


*

  • Check the control data of IDoc

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM check_control_data.

CHECK NOT g_t_edidc[] IS INITIAL.

  • Data fetch : IDoc Data Records from 4.0 onwards

SELECT docnum segnum sdata FROM edid4 INTO TABLE g_t_edid

WHERE docnum IN s_idocnm AND

segnam EQ p_segnam.

LOOP AT g_t_edid.

READ TABLE g_t_edidc WITH KEY docnum = g_t_edid-docnum.

*Check for the correct MT

IF sy-subrc = 0.

CONTINUE.

ELSE.

*Delete, if unsuccessful

DELETE g_t_edid.

ENDIF.

ENDLOOP.

ENDFORM. " CHECK_CONTROL_DATA

*&----


*

*& Form GET_SEGMENT_DETAILS

*&----


*

  • Segment details regarding fields

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM get_segment_details.

  • Segment name

g_f_segment = p_segnam.

CALL FUNCTION 'NAMETAB_GET'

EXPORTING

  • langu = sy-langu

tabname = g_f_segment

TABLES

nametab = g_t_segment

EXCEPTIONS

internal_error = 1

table_has_no_fields = 2

table_not_activ = 3

no_texts_found = 4

OTHERS = 5.

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. " GET_SEGMENT_DETAILS

*&----


*

*& Form FILL_FIELDCAT

*&----


*

  • Populate the Fieldcatalog

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM fill_fieldcat.

DATA : lv_pos TYPE i.

  • IDoc number in the catalog

lv_pos = 1.

g_r_fieldcat-fieldname = 'DOCNUM'.

g_r_fieldcat-ref_table = 'EDID4'.

g_r_fieldcat-ref_field = 'DOCNUM'.

g_r_fieldcat-key = 'X'.

g_r_fieldcat-col_pos = lv_pos.

g_r_fieldcat-outputlen = '10'.

APPEND g_r_fieldcat TO g_t_fieldcat.

  • Segment number in the catalog

ADD 1 TO lv_pos.

g_r_fieldcat-fieldname = 'SEGNUM'.

g_r_fieldcat-ref_table = 'EDID4'.

g_r_fieldcat-ref_field = 'SEGNUM'.

g_r_fieldcat-key = 'X'.

g_r_fieldcat-col_pos = lv_pos.

g_r_fieldcat-outputlen = '10'.

g_r_fieldcat-colddictxt = 'X'.

  • g_r_fieldcat-reptext = text-002.

APPEND g_r_fieldcat TO g_t_fieldcat.

**Populating fieldcatalog with segment field

LOOP AT g_t_segment .

ADD 1 TO lv_pos.

CLEAR g_r_fieldcat.

g_r_fieldcat-fieldname = g_t_segment-fieldname .

g_r_fieldcat-ref_table = p_segnam.

g_r_fieldcat-ref_field = g_t_segment-fieldname .

g_r_fieldcat-key = 'X'.

g_r_fieldcat-col_pos = lv_pos.

g_r_fieldcat-outputlen = '10'.

  • Check for given fields on the selection screen

IF NOT g_t_segment-fieldname IN s_fldnam.

g_r_fieldcat-no_out = 'X'.

ENDIF.

*Column text

IF g_t_segment-fieldtext IS INITIAL.

*Get the DDIC texts for columns

PERFORM get_ddic_texts.

ENDIF.

APPEND g_r_fieldcat TO g_t_fieldcat.

ENDLOOP.

ENDFORM. " FILL_FIELDCAT

*&----


*

*& Form GET_DDIC_TEXTS

*&----


*

  • Get the DDIC texts

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM get_ddic_texts.

DATA : l_f_descr TYPE string.

  • Get the texts for the data element

CALL FUNCTION 'TB_DATAELEMENT_GET_TEXTS'

EXPORTING

name = g_t_segment-fieldname

IMPORTING

description = l_f_descr

  • LENGTH_FIELD =

  • LENGTH_HEADER =

  • LENGTH_LONG =

  • LENGTH_MIDDLE =

  • LENGTH_SHORT =

  • TEXT_HEADER =

  • TEXT_LONG =

  • TEXT_MIDDLE =

  • TEXT_SHORT =

EXCEPTIONS

not_found = 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.

*Add DDIC text..

g_r_fieldcat-colddictxt = 'X'.

g_r_fieldcat-reptext = l_f_descr.

ENDFORM. " GET_DDIC_TEXTS


Do tell if it worked and dont forget to reward if it did.

Read only

Former Member
0 Likes
681

HI,

DATA: WS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

PERFORM FILL_FIELDCAT USING 'VBELN'

'1'

....

.

PERFORM FILL_FIELDCAT USING 'POSNR'

'2'

....

.

FORM FILL_FIELDCAT XS_FIELDNAME TYPE SLIS_FIELDCAT_ALV-FIELDNAME

XS_COLPOS TYPE SLIS_FIELDCAT_ALV-COLPOS.

WS_FIELDCAT-FIELDNAME = XS_FIELDNAME.

WS_FIELDCAT-COL_POS = XS_COLPOS.

....

....

APPEND WS_FIELDCAT TO GT_FIELDCAT

ENDFORM.

REGARDS

RAMESH