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

Dynamic ALV Grid

Former Member
0 Likes
933

Dear expert,

my requirement is to create a custom program with dynamic ALV grid output. The fields cointaned into output header have to follow the selection parameter characteristics.

e.g.

INPUT = material X (material X has CLASS A with 6 characteristics)

OUTPUT = header with 6 fields

INPUT = material Y (material Y has CLASS B with 9 characteristics)

OUTPUT = header with 9 fields

INPUT = material X and Y (material X has CLASS A with 6 characteristics +material Y has CLASS B with 9 characteristics)

OUTPUT = header with 15 fields

Any help will be appreciated.

Thank you in advance,

Fuffo

Dear expert,

my requirement is to create a custom program with dynamic ALV grid output. The fields cointaned into output header have to follow the selection parameter characteristics.

e.g.

INPUT = material X (material X has CLASS A with 6 characteristics)

OUTPUT = header with 6 fields

INPUT = material Y (material Y has CLASS B with 9 characteristics)

OUTPUT = header with 9 fields

INPUT = material X and Y (material X has CLASS A with 6 characteristics +material Y has CLASS B with 9 characteristics)

OUTPUT = header with 15 fields

Any help will be appreciated.

Thank you in advance,

Fuffo

6 REPLIES 6
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
892

Just a rough code



TYPES:BEGIN OF ty,
matnr TYPE matnr,
END OF ty.

DATA:i_sclass TYPE TABLE OF sclass,
     i_object TYPE TABLE OF clobjdat,
     la_object TYPE  clobjdat,
     li_index(2) TYPE n,
     lines TYPE i.

DATA:i_tot_comp TYPE cl_abap_structdescr=>component_table,
     lf_struct TYPE REF TO cl_abap_structdescr,
     lf_element TYPE REF TO cl_abap_elemdescr,
     la_comp LIKE LINE OF i_tot_comp,
     i_comp TYPE cl_abap_structdescr=>component_table,
     lf_new_type TYPE REF TO cl_abap_structdescr,
     lf_new_tab TYPE REF TO cl_abap_tabledescr.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
892

DATA:wf_data TYPE REF TO data,
     wf_str TYPE REF TO data.
DATA: wf_alv TYPE REF TO cl_salv_table.

FIELD-SYMBOLS:<fs_tab> TYPE STANDARD TABLE,
              <fs_line> TYPE ANY,
              <fs_f> TYPE ANY,
              <fs_t> TYPE ANY..

CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
  EXPORTING
    class              = 'ENG-DATA-METALS'
    classtext          = ' '
    classtype          = 'Z03'
    features           = 'X'
    language           = sy-langu
    object             = '338127-1'
    objecttable        = 'MARA' "tcla-obtab
    key_date           = sy-datum
    initial_charact    = ' '
    change_service_clf = ' '
    inherited_char     = ' '
    change_number      = ' '
  TABLES
    t_class            = i_sclass[]
    t_objectdata       = i_object[]
  EXCEPTIONS
    no_classification  = 1
    no_classtypes      = 2
    invalid_class_type = 3
    OTHERS             = 4.

CHECK sy-subrc = 0.
lines = LINES( i_object ).
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
892

DO.
  IF sy-index > lines.
    EXIT.
  ENDIF.
  li_index = sy-index.
  IF sy-index = 1.
    lf_struct ?= cl_abap_typedescr=>describe_by_name( 'TY' ).
    i_comp = lf_struct->get_components( ).
    APPEND LINES OF i_comp TO i_tot_comp.
  ENDIF.

  lf_element ?= cl_abap_elemdescr=>describe_by_name( 'JBRGRXX' ).
  CONCATENATE 'JBRGR' li_index  INTO la_comp-name.
  la_comp-type =
    cl_abap_elemdescr=>get_c( p_length = lf_element->length ).

  APPEND la_comp TO i_tot_comp.
ENDDO.

lf_new_type = cl_abap_structdescr=>create( i_tot_comp ).
lf_new_tab =
cl_abap_tabledescr=>create( p_line_type = lf_new_type
p_table_kind = cl_abap_tabledescr=>tablekind_std p_unique = ' ' ).

CREATE DATA wf_data TYPE HANDLE lf_new_tab.
CREATE DATA wf_str TYPE HANDLE lf_new_type.

ASSIGN wf_data->* TO <fs_tab>.
ASSIGN wf_str->* TO <fs_line>.
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
892

LOOP AT i_object INTO la_object.
  AT FIRST.
    ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_line> TO <fs_t>.
    <fs_t> = '338127-1'.
    CONTINUE.
  ENDAT.
  li_index = sy-tabix - 1.
  CONCATENATE 'JBRGR' li_index  INTO la_comp-name.
  ASSIGN COMPONENT la_comp-name OF STRUCTURE <fs_line> TO <fs_t>.
  IF <fs_t> IS ASSIGNED.
    <fs_t> = la_object-atnam.
  ENDIF.
  AT LAST.
    APPEND <fs_line> TO <fs_tab>.
  ENDAT.
ENDLOOP.

TRY.
    cl_salv_table=>factory( IMPORTING r_salv_table = wf_alv
                            CHANGING  t_table      = <fs_tab> ).
  CATCH cx_salv_msg .                                   "#EC NO_HANDLER
ENDTRY.

wf_alv->display( ).
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
892

You have use the logic above and build your program.

Read only

0 Likes
892

Thank You for your reply Keshav,

I forgot to say that we are working on R/3 4.7 so I can't use the logic you propose.

Any other help?

Thank you in advance,

Fuffo