Skip to Content
0
Former Member
Dec 07, 2004 at 01:27 PM

dynamic table and field symbols!

51 Views

hi,

I AM converting an interactive report to alv format,

the output should be based on the users input, for eg) if the user is typing tranport no and the system eg)rd2 to rd4 .

it should display like this..

transportno transtype rd2 rd2(100) rd2(200) rd3 rd3(100) rd4 rd4(100) rd4(200) rd4(220) etc...

okay...

i am using field catalog to get the header part,

this header is dynamically generated and its working fine..

the first 2 columns or static it will not change, but the other sys column will be changing okay..

next,

based on the tranport type like values I, E, H, it will put a tick mark on the system field columns.

so what i am doing is i cannot assign a standard internal table with a proper stucture, therefore i am using a int table of type 1000 characters, with this i am concatenating the values and finally i got proper values which i need to be populated to ALV

I AM GETTING AN ERROR SOURCE STRUCTURE IS NOT MATCHING THE TARGET STRUCT.

I ALSO TRIED IN using field symbols..

but i dont know how to populated the values to the int table with the same struct to ALV.

I AM ALSO ATTACHING THE CODE FOR YOU....

INTERNAL TABLE OF 1000 CHAR.

DATA:  gt_itab TYPE zrepair_itab_table_type,
       wa_itab TYPE zrepair_itab_structure.

FIELD CATLOG
DATA: fieldcat    TYPE lvc_t_fcat,
      lt_alv_cat  TYPE TABLE OF lvc_s_fcat,
      ls_alv_cat  LIKE LINE OF lt_alv_cat,
      wa_fieldcat TYPE lvc_s_fcat.


wa_fieldcat-fieldname = 'TYP'.
  wa_fieldcat-dd_outlen = 10.
  wa_fieldcat-outputlen = 13.
  wa_fieldcat-coltext = 'TRANSPORT NO'.
  wa_fieldcat-seltext = 'TRANS'.
  wa_fieldcat-col_pos = 1.
  APPEND wa_fieldcat TO fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname = 'TY'.
  wa_fieldcat-dd_outlen = 1.
  wa_fieldcat-outputlen = 4.
  wa_fieldcat-coltext = 'TYPE'.
  wa_fieldcat-seltext = 'TYPE'.
  wa_fieldcat-col_pos = 2.
  APPEND wa_fieldcat TO fieldcat.
  CLEAR wa_fieldcat.

  w_color = 0.
  DATA : fieldname(10) TYPE c.
  DATA : d1 TYPE c VALUE '('.
  DATA : d2 TYPE c VALUE ')',sys(7),count TYPE i,count1(2).
*  Constants icon_id_okay LIKE icon-id value '@01@'.
  DATA : icon LIKE icon-id.
  count = 1.
  LOOP AT t_syscli.
    IF NOT t_syscli-mandt IS INITIAL.
      CONCATENATE t_syscli-sysid d1 t_syscli-mandt d2 INTO fieldname.

    ELSE.
      CONCATENATE t_syscli-sysid  ' ' INTO fieldname SEPARATED BY
      space.
    ENDIF.


    count1 = count.
    CONCATENATE 'SYSID' count1 INTO sys.
    wa_fieldcat-fieldname = sys.
    wa_fieldcat-symbol  = 'X'.
*    wa_fieldcat-EMPHASIZE = 'C811'.
    wa_fieldcat-outputlen = 9.
    wa_fieldcat-coltext = fieldname.
    wa_fieldcat-seltext = 'MANDT'.
    wa_fieldcat-col_pos = a.
    CLEAR fieldname.

    APPEND wa_fieldcat TO fieldcat.
    a = a + 1.
    CLEAR wa_fieldcat.
    count = count + 1.
    CLEAR: sys,count1.
  ENDLOOP.

&&&&&VALUES CONCATENATION IS DONE HERE

 DATA : cou TYPE i VALUE 0 .
  LOOP AT t_migtab.
    w_trtype = t_migtab-trtype.

    AT NEW trkorr.
      IF cou = 1 .
        APPEND wa_itab TO gt_itab.
        CLEAR wa_itab.
      ENDIF.
      cou = 1.
      wa_itab = t_migtab-trkorr.
*      WRITE: SY-VLINE, T_MIGTAB-TRKORR(10), SY-VLINE NO-GAP.
      HIDE t_migtab-trkorr.
      PERFORM write_type USING w_trtype.
*-  Write client template
      LOOP AT t_syscli.
        IF t_syscli-mandt IS INITIAL.
          CONCATENATE wa_itab 'W' INTO wa_itab SEPARATED BY space.
        ELSE.
          CONCATENATE wa_itab 'E' INTO wa_itab SEPARATED BY space.
        ENDIF.
      ENDLOOP.
    ENDAT.


THE OUTPUT WHICH I AM GETTING FROM GT_ITAB IS OKAY..

ITS LIKE THIS SAY FOR RD2 AND RDK1913456  ALONE: RDK1913456 E S E E E 



I AM PASSING THIS IN FIELD SYMBOLS
FIELD-SYMBOLS: <FS_DATA> type ref to DATA,
               <FS_1> type standard table,
               <FS_2>,
               <FS_3>.
            



  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
*    I_STYLE_TABLE             =
      it_fieldcatalog           = fieldcat
    IMPORTING
      ep_table                  = <fs_data>
*    E_STYLE_FNAME             =
    EXCEPTIONS
      generate_subpool_dir_full = 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.
**
*** So <FS_1> now points to our dynamic internal table.

  ASSIGN <fs_data>->* TO <fs_1>.

*** Next step is to create a work area for our dynamic internal table.

  CREATE DATA new_line LIKE LINE OF <fs_1>.

*** A field-symbol to access that work area
  ASSIGN new_line->*  TO <fs_2>.

  LOOP AT gt_itab assigning <fs_2>.

 ASSIGN <fs_2> TO <fs_1>.
ASSIGN COMPONENT  wa_fieldcat-fieldname  OF STRUCTURE <fs_2> TO <fs_1>.

 ENDLOOP.

alv output:

 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
       EXPORTING
            i_bypassing_buffer = 'X'
            i_callback_program = repid
*            is_layout_lvc     = layout
            it_fieldcat_lvc    = fieldcat[]
            i_save             = 'U'
*            is_variant         = variant
            it_events          = events[]
            it_event_exit      = evexits[]
       TABLES
            t_outtab           = <fs_1>

            EXCEPTIONS
            program_error      = 1
            OTHERS             = 2.


ENDFORM.                    " DISPLAY_ALV

now please tell me hoe can i passs the values from the field symbols to alv or from gt_itab to alv.

if i pass the gt_itab directly i getting an eror target struct is not matching...

is it possible to create a internal table of type field symbol, or i am getting the values in gt_itab can i pass it to a proper int table, but that should be dynamic, because the values or changing based on the user input...

any help and guidance will be appreciated...

thanks in advance

from

rajkumar