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: 

dynamic screen and custom control

Former Member
0 Kudos

Hi,

I have to create a screen and custom control dynamically within a method and display alv grid. Is this possible?

regards,

Madhu

1 REPLY 1

Former Member
0 Kudos

hi,

this is a smple program just try in this way.plz do reward points if it is of some use

data:obj type ref to zcl_test_alv.

parameter:p_mblnr type zbshd-mblnr.

start-of-selection.

set screen 100.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


module STATUS_0100 output.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

if obj is initial.

create object obj

exporting p_con = 'MATERIAL_DOC'.

endif.

CALL METHOD obj->get_data

exporting p_mat = p_mblnr.

endmodule. " STATUS_0100 OUTPUT

The above is an executable program.

zcl_test_alv is a class which u need to create in se24 according to ur requirement

u need to define methods and attributes.

for example there are 3 methods

constructor

get_data

put_data

method GET_DATA.

SELECT mblnr

mblpo

matnr

maktx

meins

menge

waers

dmbtr

INTO corresponding fields of TABLE it_mm

FROM zbsit

WHERE mblnr = p_mat.

if sy-subrc = 0.

call method put_data.

endif.

endmethod.

method PUT_DATA.

DATA : it_fldcat TYPE lvc_t_fcat.

DATA : wa_fldcat LIKE LINE OF it_fldcat.

DATA : it_sort TYPE lvc_t_sort,

wa_sort LIKE LINE OF it_sort.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

  • I_BUFFER_ACTIVE =

I_STRUCTURE_NAME = 'ZBMDC'

  • I_CLIENT_NEVER_DISPLAY = 'X'

  • I_BYPASSING_BUFFER =

  • I_INTERNAL_TABNAME = 'ZBSIT'

CHANGING

ct_fieldcat = it_fldcat[]

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

EXIT.

ELSE.

LOOP AT it_fldcat INTO wa_fldcat.

CASE wa_fldcat-fieldname.

WHEN 'MBLNR'.

wa_fldcat-reptext = 'Material Doc no'.

WHEN 'MBLPO'.

wa_fldcat-reptext = 'Item Material Doc'.

wa_fldcat-ref_table = 'X'.

WHEN 'MATNR'.

wa_fldcat-reptext = 'Material No'.

wa_fldcat-ref_table = 'X'.

WHEN 'MAKTX'.

wa_fldcat-reptext = 'Description'.

wa_fldcat-do_sum = 'X'.

WHEN 'MEINS'.

wa_fldcat-reptext = 'UOM'.

wa_fldcat-do_sum = 'X'.

WHEN 'MENGE'.

wa_fldcat-reptext = 'QUAN'.

wa_fldcat-do_sum = 'X'.

WHEN 'WAERS'.

wa_fldcat-reptext = 'CurrKey'.

wa_fldcat-do_sum = 'X'.

WHEN 'DMBTR'.

wa_fldcat-reptext = 'curr'.

wa_fldcat-do_sum = 'X'.

ENDCASE.

MODIFY it_fldcat FROM wa_fldcat INDEX sy-tabix.

ENDLOOP.

wa_sort-fieldname = 'MBLNR'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort.

ENDIF.

CALL METHOD o_grid->set_table_for_first_display

  • EXPORTING

  • i_buffer_active =

  • i_bypassing_buffer =

  • i_consistency_check =

  • i_structure_name =

  • is_variant =

  • i_save =

  • i_default = 'x'

  • is_layout =

  • is_print =

  • it_special_groups =

  • it_toolbar_excluding =

  • it_hyperlink =

  • it_alv_graphics =

  • it_except_qinfo =

  • ir_salv_adapter =

CHANGING

it_outtab = it_mm[]

it_fieldcatalog = it_fldcat[]

it_sort = it_sort

  • it_filter =

  • EXCEPTIONS

  • invalid_parameter_combination = 1

  • program_error = 2

  • too_many_lines = 3

  • others = 4

.

IF sy-subrc <> 0.

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

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

ENDIF.

endmethod.

method CONSTRUCTOR.

CREATE OBJECT o_con

EXPORTING

container_name = p_con .

IF sy-subrc = 0.

CREATE OBJECT o_grid

EXPORTING

i_parent = o_con .

ENDIF.

endmethod.

Attributes are

o_con type ref to CL_GUI_CUSTOM_CONTAINER

o_grid type ref to CL_GUI_ALV_GRID

it_mm type zmdoc

to get alv grid ,in layout editor u need to create custom control

for constructor method u should have a parameter p_con with default value as 'MATERIAL_DOC'

Im just explaining the above program use this as reference and try.