Appending Objects in an internal Table

Hallo Guru,
I'm looking for a way to append newly created objects of a class "XYZ" in an internal table.
Best Regards,
Kais

Hi
U need to append the object in the table like a normal workarea:
CLASS LC_MY_CLASS DEFINITION.
  PUBLIC SECTION.
    METHODS: CONSTRUCTOR
              IMPORTING P_NAME TYPE CHAR20,
             WRITE_NAME.
  PRIVATE SECTION.
    DATA: NAME TYPE CHAR20.
ENDCLASS.                    "LC_MY_CLASS DEFINITION
CLASS LC_MY_CLASS IMPLEMENTATION.
  METHOD CONSTRUCTOR.
    NAME = P_NAME.
  ENDMETHOD.                    "CONSTRUCTOR
  METHOD WRITE_NAME.
    WRITE: / NAME.
  ENDMETHOD.                    "WRITE_NAME
ENDCLASS.                    "LC_MY_CLASS IMPLEMENTATION
TYPES: TY_OBJ TYPE REF TO LC_MY_CLASS.
DATA: MY_OBJ TYPE REF TO LC_MY_CLASS,
      T_OBJ  TYPE TABLE OF TY_OBJ.
START-OF-SELECTION.
  CREATE OBJECT MY_OBJ
    EXPORTING
      P_NAME = 'MAX'.
  APPEND MY_OBJ TO T_OBJ.
  CREATE OBJECT MY_OBJ
    EXPORTING
      P_NAME = 'MAX 2'.
  APPEND MY_OBJ TO T_OBJ.
  LOOP AT T_OBJ INTO MY_OBJ.
    CALL METHOD MY_OBJ->WRITE_NAME.
  ENDLOOP.
Max

Similar Messages

  • How to append contents of a local object to dynamic internal table ?

    Dear ABAP-Specialists,
    i am trying to append contents of a local object to a dynamic table. The most relevant lines are the ones written in bold
    I guess the append is the problem due to the reason that a unknown format has to be assigned to a fixed format somehow.
    +METHOD wddomodifyview .+
      +DATA lo_ui_root                TYPE REF TO  if_wd_view_element.+
      +DATA lo_container              TYPE REF TO  cl_wd_uielement_container.+
      +DATA lo_table                  TYPE REF TO  cl_wd_table.+
      +DATA lo_table_column           TYPE REF TO  cl_wd_table_column.+
      +DATA lv_tabname                TYPE         tabname.+
      +DATA lt_output                 TYPE TABLE OF sychar512.+
      +DATA lo_data TYPE REF TO data.+
      +DATA:+
        +lo_node_output_data                    TYPE REF TO if_wd_context_node,+
        +lo_node_table_list                     TYPE REF TO if_wd_context_node,+
        +lo_node_differences                    TYPE REF TO if_wd_context_node,+
        +lo_node_output                         TYPE REF TO if_wd_context_node,+
        +lt_all_elem_differences                TYPE        wdr_context_element_set,+
        +lo_elem_table_list                     TYPE REF TO if_wd_context_element,+
        +lo_elem_differences                    TYPE REF TO if_wd_context_element,+
        +ls_differences                         TYPE        if_table_differences=>element_differences,+
        +lt_differences                         TYPE STANDARD TABLE OF if_table_differences=>element_differences.+
      +FIELD-SYMBOLS:+
                     +<ls_output> TYPE ANY,+
                     +<lt_output> TYPE ANY TABLE.+
    +     ....+
        +*CREATE DATA lo_data TYPE TABLE OF (lv_tabname).*+
        +*ASSIGN lo_data->* TO <lt_output>.*+
        +*LOOP AT lt_differences INTO ls_differences.*+
    +**      APPEND ls_differences-ct_line TO lo_data->*.*+
        +*ENDLOOP.*     ....+
    +ENDMETHOD.+
    Thanks a lot in advance for your Ideas.
    Best regards
    Carsten Klatt
    Please post in the correct forum and use code tags to format your code
    Edited by: Rob Burbank on Oct 1, 2010 1:27 PM

    This might help - you should not reference the data reference directly:
    DATA: lt_t001 TYPE TABLE OF t001,
          ls_t001 TYPE t001.
    DATA: lr_dref    TYPE REF TO data.
    DATA: lv_tabname TYPE tabname.
    FIELD-SYMBOLS: <lfs>      TYPE table,
                   <lfs_line> TYPE ANY.
    lv_tabname = 'T001'.
    TRY.
        CREATE DATA lr_dref TYPE TABLE OF (lv_tabname).
        ASSIGN lr_dref->* TO <lfs>.
      CATCH cx_sy_create_data_error.
    *     Do something
    ENDTRY.
    SELECT * FROM t001 INTO TABLE lt_t001.
    LOOP AT lt_t001 INTO ls_t001.
      ASSIGN ls_t001 TO <lfs_line>.
      APPEND <lfs_line> TO <lfs>.
    ENDLOOP.

  • Append a record to internal table

    hello:
    when i execute the code below,there is a runtime error." In die sortierte interne Tabelle (Typ SORTED_TABLE)
      "PROGRAM=ZJOIN_INTER_TABLEDATA=T_ITAB1" sollte an
    Position 1 eine Zeile eingefügt bzw. geändert werden.
    Dadurch wurde die für die Tabelle durch ihren Schlüssel festgelegte
    Sortierreihenfolge zerstört."
    how can i resolve it?which one can tell me?Thanks very much
    REPORT  ZJOIN_INTER_TABLE.
    DATA:BEGIN OF WA_ITAB,
            COL1 TYPE I,
            COL2(10) TYPE C,
          END OF WA_ITAB.
    DATA:T_ITAB1 LIKE SORTED TABLE OF WA_ITAB WITH NON-UNIQUE KEY COL1.
    WA_ITAB-COL1 = 10.
    WA_ITAB-COL2 = 'col2'.
    APPEND WA_ITAB TO T_ITAB1.
    WA_ITAB-COL1 = 9.
    WA_ITAB-COL2 = 'col2'.
    APPEND WA_ITAB TO T_ITAB1.

    hi
    kindly go thro the lines.
    syntax:
    DATA itab {TYPE tabkind OF linetype|LIKE tabkind OF lineobj}
              WITH [UNIQUE|NON-UNIQUE] keydef
              [INITIAL SIZE n] [WITH HEADER LINE].
    The system creates an internal table with table type tabkind. Since there is no generic field definition, you cannot use the table types ANY TABLE or SORTED TABLE.
    The construction of the table lines is defined by linetype (if you are using a TYPE reference) or by the type of the referred object lineobj (if you are using a LIKE reference). If you specify the line type, you can also use REF TO to refer to a reference type.
    The same rules apply to UNIQUE and NON-UNIQUE as apply to the TYPES definition. You may only omit this specification with standard tables.
    If you do not specify an INITIAL SIZE, the system assumes a default value of INITIAL SIZE 0.
    i think now u r clear... now yr code will work.
    DATA:BEGIN OF WA_ITAB,
    COL1 TYPE I,
    COL2(10) TYPE C,
    END OF WA_ITAB.
    DATA:T_ITAB1 like TABLE OF WA_ITAB WITH NON-UNIQUE KEY COL1.
    WA_ITAB-COL1 = 10.
    WA_ITAB-COL2 = 'col2'.
    APPEND WA_ITAB TO T_ITAB1.
    WA_ITAB-COL1 = 9.
    WA_ITAB-COL2 = 'col2'.
    APPEND WA_ITAB TO T_ITAB1.

  • How to append records between two internal tables

    hi all,
    im trying to append from an internal table to another internal table with same structure. i tried the following but it overwrites previous contents of i_dest:
    move i_src to i_dest
    thanks,
    sid

    hey u try to move it record by record
    <b>itab2 = itab.
    append itab2.</b>
    This should work I guess
    just check the code below, if u want to move the whole itab into itab2 then use <b>itab2[] = itab.</b>
    <b>loop at it_pgm.
      read table itab with key obj_name = it_pgm-pgm_name.
      if sy-subrc = 0.
        itab_final-obj_name = itab-obj_name.
        itab_final-func_spec = itab-func_spec.
        itab_final-func_area = itab-func_area.
        itab_final-dev_class = itab-dev_class.
        append itab_final.
    else.
       itab_alt-pgm_name = it_pgm-pgm_name.
       append itab_alt.
      endif.</b>
    please reward points if found helpful

  • How to append Header of an internal table to another internal table

    Hello Experts,
    Can we append the header of an internal table to another internal table? Do we have have to use work area for this?
    Thanks.

    Wrong - it will append only the header. If you want to append the whole table, you would:
    APPEND LINES OF itab1 TO itab2.
    If you need more help, please press F1 on APPEND.
    Rob
    Edited by: Rob Burbank on Mar 3, 2008 4:06 PM

  • Append new column to internal table

    Hi all,
    i have an internal table that was generated based on an ddic structure - now i want to add a column to that table. how can i do that ?
    thank you!
    clemens

    Hi to all, thank you for your help! here is the code that i have:
    REPORT *************_4 .
    TYPE-POOLS : abap.
    FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                   <dyn_wa>,
                   <dyn_field>.
    TYPE-POOLS: slis.
    TABLES: dd03l, dd04t.
    TYPES:
      BEGIN OF ty_table_struct,
        fieldname   TYPE dd03l-fieldname, " Tabellenname
        ddtext      TYPE dd04t-ddtext,    " Kurztext
        checkbox,
       END OF ty_table_struct.
    DATA:t_fieldcat TYPE slis_t_fieldcat_alv,
         w_fieldcat TYPE slis_fieldcat_main.
    DATA:
    gt_table_struct TYPE TABLE OF ty_table_struct.
    DATA: v_repid TYPE sy-repid.
    DATA:
          dy_table TYPE REF TO data,
          dy_line  TYPE REF TO data,
          xfc TYPE lvc_s_fcat,
          ifc TYPE lvc_t_fcat,
          l_tab_fields TYPE STANDARD TABLE OF ty_table_struct,
          w_tab_fields LIKE LINE OF l_tab_fields.
    SELECTION-SCREEN :
      SKIP, BEGIN OF LINE,COMMENT 5(28) v_1 FOR FIELD p_table.
    PARAMETERS p_table TYPE dd03l-tabname OBLIGATORY VALUE CHECK.
    SELECTION-SCREEN END OF LINE.
    INITIALIZATION.
      v_1 = 'Tabelle für Dublettenprüfung'.
      v_repid = sy-repid.
    START-OF-SELECTION.
      PERFORM f_read_data.
      PERFORM f_display_data.
      PERFORM get_structure.
      PERFORM create_dynamic_itab.
      PERFORM get_data.
      PERFORM write_out.
    *&      Form  get_structure
    FORM get_structure.
      DATA : idetails TYPE abap_compdescr_tab,
             xdetails TYPE abap_compdescr.
      DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
    * Get the structure of the table.
      ref_table_des ?=
          cl_abap_typedescr=>describe_by_name( p_table ).
      idetails[] = ref_table_des->components[].
      LOOP AT idetails INTO xdetails.
        READ TABLE l_tab_fields INTO w_tab_fields
        WITH KEY fieldname = xdetails-name.
        IF sy-subrc = 0.
          CLEAR xfc.
          xfc-fieldname = xdetails-name.
          xfc-datatype = xdetails-type_kind.
          xfc-inttype = xdetails-type_kind.
          xfc-intlen = xdetails-length.
          xfc-decimals = xdetails-decimals.
          APPEND xfc TO ifc.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    "get_structure
    *&      Form  create_dynamic_itab
    *       text
    FORM create_dynamic_itab.
    * Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ifc
        IMPORTING
          ep_table        = dy_table.
      ASSIGN dy_table->* TO <dyn_table>.
    * Create dynamic work area and assign to FS
      CREATE DATA dy_line LIKE LINE OF <dyn_table>.
      ASSIGN dy_line->* TO <dyn_wa>.
    ENDFORM.                    "create_dynamic_itab
    *&      Form  get_data
    *       text
    FORM get_data.
    * Select Data from table.
      SELECT (l_tab_fields) INTO CORRESPONDING FIELDS OF TABLE <dyn_table>
                 FROM (p_table).
    ENDFORM.                    "get_data
    *&      Form  write_out
    *       text
    FORM write_out.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
           EXPORTING
                i_program_name         = v_repid
                i_structure_name       = p_table
           CHANGING
                ct_fieldcat            = t_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.
    * Show only fields that are needed
      LOOP AT t_fieldcat INTO w_fieldcat.
        READ TABLE l_tab_fields INTO w_tab_fields
        WITH KEY fieldname = w_fieldcat-fieldname.
        IF sy-subrc <> 0.
               DELETE t_fieldcat.
        ENDIF.
      ENDLOOP.
      w_fieldcat-tabname = '<dyn_table>'.
      w_fieldcat-fieldname = 'NETPR'.
      w_fieldcat-seltext_m = 'Net Price'.
      w_fieldcat-outputlen = 15.
      w_fieldcat-col_pos = 10.
    *  w_fieldcat-do_sum = 'X'. "Display column total
      w_fieldcat-datatype = 'CURR'.
      append w_fieldcat to t_fieldcat.
    * Write out data from table.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                it_fieldcat   = t_fieldcat
                I_BYPASSING_BUFFER = 'X'
           TABLES
                t_outtab      = <dyn_table>
           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.                    "write_out
    *&      Form  f_read_data
    *       text
    FORM f_read_data.
      SELECT * FROM ( dd03l
                INNER JOIN dd04t
                ON  dd03l~rollname = dd04t~rollname
                AND dd04t~ddlanguage = syst-langu
                AND dd04t~as4local = 'A' ) INTO CORRESPONDING FIELDS OF
    TABLE
      gt_table_struct WHERE dd03l~tabname = p_table .
    ENDFORM.                               " F_READ_DATA
    *      Form  f_display_data
    FORM f_display_data.
    * Macro definition
      DEFINE m_fieldcat.
        add 1 to ls_fieldcat-col_pos.
        ls_fieldcat-fieldname   = &1.
        ls_fieldcat-ref_tabname = &2.
        ls_fieldcat-rollname = &3.
        append ls_fieldcat to lt_fieldcat.
      END-OF-DEFINITION.
      TYPE-POOLS: slis.                    " ALV Global types
      DATA:
        l_exit,
        ls_private  TYPE slis_data_caller_exit,
        ls_field    TYPE ty_table_struct,
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv.
    * Build the field catalog
      m_fieldcat 'FIELDNAME' 'ty_table_struct' 'FIELDNAME'.
      m_fieldcat 'DDTEXT'    'ty_table_struct' 'DDTEXT'.
    * Optimize column width
      ls_private-columnopt = 'X'.
    * Display data in a popup
      CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
           EXPORTING
                i_selection          = 'X'
                i_zebra              = 'X'
                it_fieldcat          = lt_fieldcat
                i_tabname            = 'gt_table_struct'
                i_checkbox_fieldname = 'CHECKBOX'
                is_private           = ls_private
           IMPORTING
                e_exit               = l_exit
           TABLES
                t_outtab             = gt_table_struct.
      CHECK l_exit = space.
    * write selected columns to the internal table for inclusion
    * into fieldcat
      LOOP AT gt_table_struct INTO ls_field WHERE checkbox = 'X'.
        APPEND ls_field-fieldname TO l_tab_fields.
      ENDLOOP.
    ENDFORM.
    What
    i want it to do is, have the alvgrid displaying the fields from t_fieldcat, plus some fields ( that should be appended to the internal table before, i think ? ). What went wrong ? 
    Clemens

  • Appending data from amultiple internal tables

    Hi Experts,
    I need to append data from more than one internal tables to one internal table. But the internal tables has different structure.
    For example, I have internal tables I_A550 table which has field KNUMH, and I_A573 which has same filed KNUMH. Same way I have 25 tables, and all have KNUMH field.
    Now I have taken an internal table I_AXXX which has only one field KNUMH. I need to transfer data from all those 25 tables to I_AXXX.
    I wrote code as below.
    LOOP AT I_A550
       MOVE I_A550-KNUMH to I_AXXX-KNUMH.
       APPEND I_AXXX.
    ENDLOOP.
    LOOP AT I_A573.
        MOVE I_A573-KNUMH to I_AXXX-KNUMH.
        APPEND I_AXXX.
    ENDLOOP.
    But instead of writing 25 loops, is there any way we can simplify this?
    Thanks in advance.

    Hi,
    Just use field-symbols for your purpose as follows:-
    See the example below
    TYPES: BEGIN OF y_t_final,
           matnr TYPE matnr,
           END OF y_t_final.
    TYPES: y_tt_final TYPE STANDARD TABLE OF y_t_final.
    data : WA_mara type mara,
           wa_mard type mard.
    DATA : itab  TYPE STANDARD TABLE OF mara.
    DATA : itab1 TYPE STANDARD TABLE OF mard.
    DATA : it_final TYPE STANDARD TABLE OF y_t_final.
    DATA : wa_final TYPE y_t_final.
    wa_mara-matnr = '1'.
    append wa_mara to itab.
    wa_mard-matnr = '2'.
    append wa_mard to itab1.
    PERFORM f_loop USING  itab
                   CHANGING it_final.
    PERFORM f_loop USING  itab1
                   CHANGING it_final.
    The code inside the perform is as follow:-
    FORM f_loop  USING    p_itab TYPE ANY TABLE
                 CHANGING p_it_final TYPE y_tt_final.
      FIELD-SYMBOLS : <fs>     TYPE ANY TABLE,
                       <wa>    TYPE ANY,
                       <field> TYPE ANY.
      DATA: l_data TYPE REF TO data.
      ASSIGN p_itab TO <fs>.
      IF <fs> IS ASSIGNED.
        CREATE DATA l_data LIKE LINE OF <fs>.
        ASSIGN l_data->* TO <wa>.
        IF <wa> IS ASSIGNED.
          LOOP AT <fs> INTO <wa>.
            ASSIGN component 'MATNR' of structure <wa> TO <field>.
            IF <field> IS ASSIGNED.
              MOVE <field> TO wa_final-matnr.
              append wa_final to p_it_final.
            ENDIF.
          ENDLOOP.
        ENDIF.
      ENDIF.
    ENDFORM.
    I hope you can understand the concept.
    Regards,
    Ankur Parab

  • Append 3 workarea into internal table

    Hi,
      I have 3 workarea and i want to append into one internal table.so how to append.
    Thanks,
    Deesanth

    HIII
    then you need to use MODIFY statement like below code..
    IF sy-subrc EQ 0.
        LOOP AT i_output INTO wa_output.
          READ TABLE i_mard INTO wa_mard WITH KEY matnr = wa_output-matnr.
          wa_output-lgort = wa_mard-lgort.
          MODIFY i_output FROM wa_output.
          CLEAR wa_output.
        ENDLOOP.                           " LOOP AT i_output
      ENDIF.                               " IF sy-subrc EQ 0
    here you need to use READ statement to get workarea data from different tables and use MODIFY statement to append that data in the same row.
    reagrds
    twinkal

  • How to append data from an internal table to an external table.

    HI everyone,
    I am trying to update an DB table type 'c'from the data captured in my internal table. can any one tell me as to how to do this.the contents of the DB table needs to be erased completly before i send in new data.
    Regards,
    Vj

    Assuming that you table has 1 character field(?) besides the MANDT field
    MANDT
    FIELD
    you need to update this db table with values from ITAB which I assume has one field of type c.
    To first delete all of the data from DB table.
    * Yes there are other ways of doing this.
    tables: ztable.
    select * from ztable.
    delete ztable.
    endselect.
    Then simply LOOP your internal table and update the table.
    loop at itab.
      ztable-field = itab-field.
      insert ztable.
    endloop.
    Regards,
    Rich Heilman

  • Appending empty rows in internal table

    Hi,
      i am using table control, where there is a condition, some row may left empty. end if i press enter button the empty row is filled by the next available record. My need is to pick the records in the table control to the internal table including the empty rows as it is.

    Hi Karthikeyan,
    By default with user pressinng enter, empty rows will get deleted.
    How are you populating your table control? Is it from standard transaction or your internal table?
    If it is from your internal table, you can add anothe flag field for empty row.
    Whenever row is empty in your internal table, mark flag field as 'X', so in the table control you these entries will not get vanished with pressing of enter.
    This is one idea and you can build on this. You can make this flag column as non editable so that no one can change these.
    hope this helps,
    ags.

  • How could I assigning object values to internal table?

    CREATE DATA dref TYPE TABLE OF (table).
        ASSIGN dref->* TO <intab>.
        SELECT * FROM (table) INTO CORRESPONDING FIELDS OF TABLE <intab>.
    I have create a internal table intab1.
    obviously, the expressing "intab1 = <intab> " is wrong.
    then,how should intab1 get the value of <intab>?

    Hi
    If you need only to transfer all data: <b>INTAB1[] = <INTAB>[]</b>. But INTAB1 has to be as <INTAB>.
    If the structure of INTAB1 is different, you have to use the field-symbols:
    LOOP AT <INTAB> ASSIGNING <WA>.
      ASSIGN COMPONENT SY-INDEX OF STRUCTRE <WA> TO <VAL_F>.
      IF SY-SUBRC <> 0. EXIT. ENDIF.
      ASSIGN COMPONENT SY-INDEX OF STRUCTRE INTAB1 TO <VAL_T>.
      IF SY-SUBRC <> 0. EXIT. ENDIF.
      <VAL_T> = <VAL_F>.
    ENDLOOP.
    So how to transfer the data depends on the structures of INTAB1 and <INTAB>.
    Max

  • Append one register to internal table in abap oo

    DATA: l_fields TYPE STANDARD TABLE OFsval ,
    LINEA TYPE sval.
    linea-tabname = 'CSKS'.
    linea-fieldname = 'KOSTL'.
    linea-value = 0.
    APPEND linea to l_fields.
    i want to do this append, but i have an error because i work in a ABAP Objects
    Some suggestions?
    Thanks

    Hi!
    Could you Copy & Paste the text of the error? If you can it would be good to give the message id (sy-msgid) and number (sy-msgno) also.
    I'm assuming that "OFsval" is a typo and in your code it's like "OF sval".
    Regards,
      Mário Espinheira
    Edited by: Mário Espinheira on Dec 20, 2007 9:22 PM

  • Reg. object in an internal table,

    data : begin of itab occurs 0,
      var1 LIKE sy-index,
      var2(20),
      obj TYPE REF TO zclass,
    END OF itab.
    Zclass has a public attribute, A.
    what't the way for filling & reading this type of itab, I want to put just 4 records in this itab.
    For any clarification please reply.!

    following is the small code, it is error free, but the last loop stmt is showing 8 at every pass.
    so whether we are refering to a class or attribute...i think approach will be same..i just want to fill unique data in A attribute of class.......
    please help!
    REPORT zrnd
           NO STANDARD PAGE HEADING LINE-SIZE 255.
    DATA : BEGIN OF itab OCCURS 0, 
      var1 LIKE sy-index,
      var2(20),
      obj TYPE REF TO zclass,
      END OF itab.
    START-OF-SELECTION.
      itab-var1 = 1.
      itab-var2 = 'pradeep'.
      CREATE OBJECT itab-obj.
      itab-obj->a = 6.
      APPEND itab.
      itab-var1 = 2.
      itab-var2 = 'sandeep'.
      itab-obj->a = 7.
      APPEND itab.
      itab-var1 = 3.
      itab-var2 = 'tanu'.
      itab-obj->a = 8.
      APPEND itab.
      LOOP AT itab.
        WRITE :  /  itab-var1 , itab-var2 , itab-obj->a.
      ENDLOOP.

  • Append split data into internal table w.r.t fields

    Hai friends,
    I am getting the data matnr : 13235,12124,34234
    and maktx : aaaa,bbbb , cccc
    and lgort : 234, 345, 456
    But I have taken the structure as begin of itab
    matnr like -
    maktx like -
    lgort like-----,
    end of itab.
    now the data as i need to append first row as 13235 to matnr
    aaaa to maktx
    234 to lgort,
    and second row as 12124 to matnr
    bbbb to maktx
    345 to lgort
    and same as third row
    Iam spliting the data but the problem is here matnr is variable i.e based on counter of matnr it should append those no of rows
    please give the solution,
    prasad.

    Hi Prasad,
    Loop at i_matnr.
      itab-matnr = i_matnr-matnr.
      Read table i_maktx with key matnr = i_matnr-matnr.
      if sy-subrc = 0.
       itab-maktx = i_maktx-maktx.
      endif.
      Read table i_lgort with key matnr = i_matnr-matnr.
      if sy-subrc = 0.
       itab-lgort = i_lgort-lgort.
      endif.
      append itab.
    Endloop.

  • It cannot reference the dynamic internal table in memory as an object.

    Hi,
    I am getting the syntax error in the second select. I guest it cannot reference the dynamic internal table in memory as an object.
    The internal table contains different fields from multiple tables and it gets created OK. Then the first select within the loop executes OK allowing me to read the multiple tables in ITABLES.
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ifc
        IMPORTING
          ep_table        = dy_table.
    ***OK, the dynamic tables is created here
      assign dy_table->* to <dyn_table>.
    * Create dynamic work area and assign to FS
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
    loop at ITABLES.
    ***OK, no syntax errors in this select here
      select * appending corresponding fields of table <dyn_table>
                 from (ITABLES-TABNAME).
    endloop.
    data: ikonp like konp occurs 0 with header line.
    ***NOT OK, there is syntax errors
      select * into table ikonp
      from KONP for all entries in <dyn_table>
      where knumh = <dyn_table>-knumh.
    Some of the tables in ITABLES are pooled tables which does not allow me to use INNER JOINS. Therefore I need a second select in order to read the pricing table KONP.
    Thanks in advance for any hint.

    Hi Abel,
    You must be getting the syntax error that <dyn_table> does not contain the field knumh.
    try putiing the entire where clause in a char type variable say wa_char and then use in ur query as
    where (wa_char) .. it may work..
    concatenate 'knumh' '=' '<dyn_table>-knumh' INTO wa_char SEPARATED BY SPACES.
    SELECT ... from konp...
    where (wa_char).
    Revert if it doesnt work.

Maybe you are looking for