Date sorting in internal table

Dear Friends
   I wish to know how i perform the date operations in internal table... I am looking for the most recent record from the internal table for that i am supposed to look at chdate and chtime fields gives me the information on most corrently changed record... if  in the case of the record which is there but not changed to determin the its most currentness i must look at the crdate and crtime..so i have the code for that which works perfectly nice without the crdate and crtime... if i insert the crdate and crtime it gives me the only those records which are most currently chnaged according to chdate and chtime...would you like to help me in  this regards, I am giving you the code here.. any suggestion or changes will be great help of mine... thanking you,,,,
regards naim... the code:
TYPES: BEGIN OF itab_type,
        id       TYPE i,
        idnumber TYPE i,
        chdate   LIKE sy-datum,
        chtime   LIKE sy-uzeit,
        crdate   LIKE sy-datum,
        crtime   LIKE sy-uzeit.
TYPES: END OF itab_type.
DATA: itab     TYPE TABLE OF itab_type WITH HEADER LINE,
      itab_new TYPE TABLE OF itab_type WITH HEADER LINE,
      prev_rec TYPE itab_type.
DATA: v_id TYPE i.
START-OF-SELECTION.
  itab-id       = 1.
  itab-idnumber = 123456.
  itab-chdate   = '20060606'.
  itab-chtime   = '135312'.
  itab-crdate   = '00000000'.
  itab-crtime   = '000000'.
  APPEND itab. CLEAR itab.
  itab-id       = 2.
  itab-idnumber = 123456.
  itab-chdate   = '20060606'.
  itab-chtime   = '135900'.
  itab-crdate    = '00000000'.
  itab-crtime    = '000000'.
  APPEND itab. CLEAR itab.
  itab-id       = 3.
  itab-idnumber = 123456.
  itab-chdate   = '00000000'.
  itab-chtime   = '000000'.
  itab-crtime    = '20060622'.
  itab-crdate    = '125412'.
  APPEND itab. CLEAR itab.
  itab-id       = 4.
  itab-idnumber = 123457.
  itab-chdate   = '20060606'.
  itab-chtime   = '140000'.
  itab-crdate    = '00000000'.
  itab-crtime    = '000000'.
  APPEND itab. CLEAR itab.
  itab-id       = 5.
  itab-idnumber = 123457.
  itab-chdate   = '20060606'.
  itab-chtime   = '142500'.
  itab-crdate    = '00000000'.
  itab-crtime    = '000000'.
  APPEND itab. CLEAR itab.
  itab-id       = 6.
  itab-idnumber = 123457.
  itab-chdate   = '20060606'.
  itab-chtime   = '135312'.
  itab-crdate    = '00000000'.
  itab-crtime    = '000000'.
  APPEND itab. CLEAR itab.
  itab-id       = 7.
  itab-idnumber = 123457.
  itab-chdate   = '00000000'.
  itab-chtime   = '000000'.
  itab-crdate    = '20060601'.
  itab-crtime    = '150000'.
  APPEND itab. CLEAR itab.
  itab_new[] = itab[].
  SORT itab_new BY idnumber ASCENDING
                   chdate DESCENDING
                   chtime DESCENDING
                   crdate Descending
                   crtime Descending.
  DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber.
LOOP AT itab.
     WRITE:/ itab-id,
             itab-idnumber,
             itab-chdate,
             itab-chtime,
             itab-crdate,
             itab-crtime.
  ENDLOOP.
skip 5.
write: '_______________________________________________________________________________________'.
  LOOP AT itab_new.
    WRITE:/ itab_new-id,
            itab_new-idnumber,
            itab_new-chdate,
            itab_new-chtime,
            itab_new-crdate,
            itab_new-crtime.
  ENDLOOP.

Hi,
i modifed your code now see...,Copy paste and see...
REPORT  ZTESTT                                  .
TYPES: BEGIN OF itab_type,
id TYPE i,
idnumber TYPE i,
chdate LIKE sy-datum,
chtime LIKE sy-uzeit,
crdate LIKE sy-datum,
crtime LIKE sy-uzeit.
TYPES: END OF itab_type.
DATA: itab TYPE TABLE OF itab_type WITH HEADER LINE,
itab_new TYPE TABLE OF itab_type WITH HEADER LINE,
prev_rec TYPE itab_type.
DATA: v_id TYPE i.
START-OF-SELECTION.
itab-id = 1.
itab-idnumber = 123456.
itab-chdate = '20060606'.
itab-chtime = '135312'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 2.
itab-idnumber = 123456.
itab-chdate = '20060606'.
itab-chtime = '135900'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 3.
itab-idnumber = 123456.
itab-chdate = '00000000'.
itab-chtime = '000000'.
<b>itab-crdate = '20060622'. "here you intechanged the data
itab-crtime = '125412'.</b>
APPEND itab. CLEAR itab.
itab-id = 4.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '140000'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 5.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '142500'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 6.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '135312'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 7.
itab-idnumber = 123457.
itab-chdate = '00000000'.
itab-chtime = '000000'.
itab-crdate = '20060601'.
itab-crtime = '150000'.
APPEND itab. CLEAR itab.
itab_new[] = itab[].
SORT itab_new BY
idnumber
*chdate DESCENDING
*chtime DESCENDING
crdate Descending
crtime Descending.
DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber crdate
crtime.
*DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber.
LOOP AT itab.
WRITE:/ itab-id,
itab-idnumber,
itab-chdate,
itab-chtime,
itab-crdate,
itab-crtime.
ENDLOOP.
skip 5.
LOOP AT itab_new.
WRITE:/ itab_new-id,
itab_new-idnumber,
itab_new-chdate,
itab_new-chtime,
itab_new-crdate,
itab_new-crtime.
ENDLOOP.
Regards
vijay

Similar Messages

  • Moving the data from multiple internal tables into a single one

    Hello everyone,
    I am creating a classical report which uses the following tables.
    tables : ekko, ekpo, mara, makt,lfa1.
    my input parameter is 
    Select-options Purchase Order number
    Following fields are getting used.
    Doc no                  EKKO-EBELN
    Material              EKPO-MATNR
    Item number          EKPO-EBELP
    Quantity             EKPO-MENGE
    Material Group          MARA-MATKL
    Vendor                  EKKO-LIFNR
    Old Material code   MARA-BISMT
    Material Desc.           MAKT-MAKTX
    Vendor name         LFA1-NAME1
    Now i need to do the following task.
    1 Select record from EKKO Using document number.
    2 Select record from EKPO using EKKO record using Document no as key.
    3 Find out Old Material code of each and every material from Material master.
    4 Find out Material description for each and every material from MAKT.
    5 Sort record on Vendor, Purchase Order number and Material.
    I have defined seperate internal tables for these operation.
    Once i have fetched records into these individual internal tables  from the corresponding DB tables i need to move these values into a new internal tables which has all the above fields mentioned
    I need to move these values into a new internal table because to display the values on the report.
    Any idea for the above ? Plz help with a sample example or some relevant.
    Regards,
    Ranjith Nambiar

    Hi
    1 Select record from EKKO Using document number.
    2 Select record from EKPO using EKKO record using Document no as key.
    Use inner join and retrive data into one internal table.for Ex ITAB1
    3 Find out Old Material code of each and every material from Material master.
    Use ITAB1 with for allentries in MARA table to get the onl materil number populate in to one table.
    4 Find out Material description for each and every material from MAKT.
    Get the Material desc with the same manner as above,
    5 Sort record on Vendor, Purchase Order number and Material.
    now sort the ITAB1 as you req.
    now Loop on the ITAB1.
    and read above 2 tables for old matnr and matner deac and append into another table as you want.
    Hope this will help.
    Regards,
    Hiren Patel

  • How to select data from an internal table

    material                          norm                    date last modified
    B2-SP HEAT                 50.000               20090420
    BF COKE                                 575.000               20090419
    GROSS COKE                 200.000               20090419
    B2-SP HEAT                 100.000               20090419
    TWT                                 33.000               20090330
    B7-SP HEAT                 2.000               20090310
    B1-SP HEAT                 1.000               20090309
    B7-SP HEAT                 615.000               20090308
    B2-SP HEAT                 585.000               20090308
    B1-SP HEAT                 100.000               20090308
    B3-SP HEAT                 610.000               20090308
    BF COKE                                 68.500               20090308
    GROSS COKE                 72.600               20090308
    B8-SP HEAT                 600.000               20090308
    B9-SP HEAT                 625.000               20090308
    BX-SP HEAT                 615.000               20090308
    B9-SP HEAT                 58.000               20090307
    B1-SP HEAT                 100.000               20090307
    B6-SP HEAT                 350.000               20090306
    B2-SP HEAT                 888.000               20090306
    Like above there r numerous data in a table :
    how will i select data into another internal table where material above is not repeated with latest modified date.please help.

    Hi Sonu,
    The main task is to move the contents of the one internal table to another with some condition.
    First sort and delete the duplicate entries from the First Internal table like below : 
    sort it_tab by material ascending date_modified descending.
    delete adjacent duplicates from it_tab.
    Then move that Internal table contents to another internal table.
    Define another internal table with the same structure as you have first internal table and then
    Second Step :
    it_itab1 = it_itab.
    If you are using seperate Header line and Body then you can do like below :
           it_itab1[] = it_itab[].
    This will fix the issue.
    Please let me know if you need any further explonation.
    Regards,
    Kittu
    Edited by: Kittu on Apr 24, 2009 12:21 PM

  • Sort the internal table based on the vendor field

    hello experts,
    I am stuck with a small problem...
    I am uploading the data for partner association for vendors through lsmw BI program.
    I am collecting all the records in the end of trasaction and downloading all those records on to the apps server.
    I declared one internal table as
    TYPES: BEGIN OF type_erecord,
            mesg(1000) TYPE c,
            END OF type_erecord.
    DATA: t_precord type standard table of type_erecord initial size 0,
                w_precord type type_erecord.
    I am concatenating all the fields and moving to the internal table..
    concatenate zvendor_master-source  zvendor_master-lifnr  blf00-lifnr                   
                      zvendor_master-lname    zvendor_master-parvw
                      zvendor_master-psource  zvendor_master-pname
                      zvendor_master-lifn2        bwyt3-lifn2
                      zvendor_master-ekorg      zvendor_master-werks   
                      w_PLANT-muplant           zvendor_master-defpa
                      v_message
          into w_precord-mesg separated by c_pipe.
          append w_precord to t_precord.
    now at the end I have to sort this internal table t_precord based on blf00-lifnr
    can any one guide me how to do it
    Thanks for your anticipation
    Nitesha

    OK...
    Than you can create one more table and do the process of sorting and than put data into the final table.
    TYPES: BEGIN OF type_erecord,
    mesg(1000) TYPE c,
    END OF type_erecord.
    DATA: t_precord type standard table of type_erecord initial size 0,
    w_precord type type_erecord.
    TYPES: BEGIN OF type_erecord_1,
    mesg(1000) TYPE c,
    lifnr type blf00-lifnr ,  "<<<
    END OF type_erecord_1.
    DATA: t_precord_1 type standard table of type_erecord initial size 0,
    w_precord_1 type type_erecord.
    I am concatenating all the fields and moving to the internal table..
    concatenate zvendor_master-source zvendor_master-lifnr blf00-lifnr
    zvendor_master-lname zvendor_master-parvw
    zvendor_master-psource zvendor_master-pname
    zvendor_master-lifn2 bwyt3-lifn2
    zvendor_master-ekorg zvendor_master-werks
    w_PLANT-muplant zvendor_master-defpa
    v_message
    into w_precord_1-mesg separated by c_pipe.
    w_precord_1-lifnr = blf00-lifnr .  " <<<
    append w_precord_1 to t_precord_1.   " <<<
    SORT T_PRECORD_1 by LIFNR.  " <<
    LOOP AT T_PRECORD_1 into w_precord_1.
      move-corresponing w_precord_1 to w_precord.
      append w_precord to T_PRECORD.
      clear  w_precord .
    endloop.
    Regards,
    Naimesh Patel

  • How to sort an internal table with a header line?

    hi all,
    i have declared table i_bseg type standard table of bseg with header line.
    now i have populated data in i_bseg.
    now i am sorting it by bukrs
    ie i am writing sort i_bseg by bukrs.
    before sorting all i_bseg-belnrs were populated...
    but after sorting the contents of  the i_bseg is changing.
    some of the belnrs are getting deleted..
    is there any special way to sort an internal table with header line...?

    hi,
    <b>SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE].</b>
    The statement sorts the internal table <itab> in ascending order by its key.<b> The statement always applies to the table itself, not to the header line</b>.
    If you have an internal table with a structured line type that you want sort by a different key, you can specify the key in the SORT statement:
    SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE]
                 BY <f1> [ASCENDING|DESCENDING] [AS TEXT]
                    <fn> [ASCENDING|DESCENDING] [AS TEXT].
    <b>this is your sort statement:  sort i_bseg by bukrs.
    you try with this statement:  sort i_bseg by bukrs STABLE.</b>
    regards,
    Ashokreddy

  • Filling dynamic internal table with data from other internal table

    Hi Friends,
    My problem is that i have already built a dynamic internal table
    (class int_table->create) but now i want to fill it with data from other internal table.
    The dynamic table column name and the field value of the data filled internal table are same, but how to access that column name, since i cant hard code it anyway.
    Like if my werks field value is '8001'. I want to place it under the column 8001 of dynamic table, Can anybody help me in this regard?
    Awarding points is not a problem for even giving a slight hint.
    Best Regards

    Hi
    See this
    Dynamic internal table is internal table that we create on the fly with flexible column numbers.
    For sample code, please look at this code tutorial. Hopefully it can help you
    Check this link:
    http://www.****************/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm
    Sample code:
    DATA: l_cnt(2) TYPE n,
    l_cnt1(3) TYPE n,
    l_nam(12),
    l_con(18) TYPE c,
    l_con1(18) TYPE c,
    lf_mat TYPE matnr.
    SORT it_bom_expl BY bom_comp bom_mat level.
    CLEAR: l_cnt1, <fs_dyn_wa>.
    Looping the component internal table
    LOOP AT it_bom_expl INTO gf_it_bom_expl.
    CLEAR: l_cnt1.
    AT NEW bom_comp.
    CLEAR: l_cnt, <fs_dyn_wa>, lf_mat.
    For every new bom component the material data is moved to
    temp material table which will be used for assigning the levels
    checking the count
    it_mat_temp[] = it_mat[].
    Component data is been assigned to the field symbol which is checked
    against the field of dynamic internal table and the value of the
    component number is been passed to the dynamic internal table field
    value.
    ASSIGN COMPONENT c_comp_list OF STRUCTURE <fs_dyn_wa> TO
    <fs_check>.
    <fs_check> = gf_it_bom_expl-bom_comp.
    ENDAT.
    AT NEW bom_mat.
    CLEAR l_con.
    ENDAT.
    lf_mat = gf_it_bom_expl-bom_mat.
    Looping the temp internal table and looping the dynamic internal table
    *by reading line by line into workarea, the materialxxn is been assigned
    to field symbol which will be checked and used.
    LOOP AT it_mat_temp.
    l_nam = c_mat.
    l_cnt1 = l_cnt1 + 1.
    CONCATENATE l_nam l_cnt1 INTO l_nam.
    LOOP AT <fs_dyn_table2> ASSIGNING <fs_dyn_wa2>.
    ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa2> TO <fs_xy>.
    ENDLOOP.
    IF <fs_xy> = lf_mat.
    CLEAR lf_mat.
    l_con1 = l_con.
    ENDIF.
    Checking whether the material exists for a component and if so it is
    been assigned to the field symbol which is checked against the field
    of dynamic internal table and the level of the component number
    against material is been passed to the dynamic internal table field
    value.
    IF <fs_xy> = gf_it_bom_expl-bom_mat.
    ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
    CLEAR l_con.
    MOVE gf_it_bom_expl-level TO l_con.
    CONCATENATE c_val_l l_con INTO l_con.
    CONDENSE l_con NO-GAPS.
    IF l_con1 NE space.
    CONCATENATE l_con1 l_con INTO l_con SEPARATED BY c_comma.
    CLEAR l_con1.
    l_cnt = l_cnt - 1.
    ENDIF.
    <fs_check> = l_con.
    l_cnt = l_cnt + 1.
    ENDIF.
    ENDLOOP.
    AT END OF bom_comp.
    At end of every new bom component the count is moved to the field
    symbol which is checked against the field of dynamic internal table
    and the count is been passed to the dynamic internal table field
    value.
    ASSIGN COMPONENT c_count OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
    <fs_check> = l_cnt.
    INSERT <fs_dyn_wa> INTO TABLE <fs_dyn_table>.
    ENDAT.
    ENDLOOP.
    Reward if useful
    Anji

  • Sorting the internal table I'm getting ......

    While sorting the internal table I'm getting one of the columns not sorted .... why is that? for example
    A   B   C
    9   2    11
    4   9    10
    8   3    7
    using ---> sort itab by A B C. gives me this
    A   B   C
    4   2    7
    8   9    10
    9   3    11
    please help?

    Hi,
    check this code,
    REPORT ZEX31 .
    data : begin of itab occurs 0,
           f1 type i,
           f2 type i,
           f3 type i,
           end of itab.
    itab-f1 = 9 .
    itab-f2 = 2.
    itab-f3 = 11 .
    append itab.
    clear itab.
    itab-f1 = 4 .
    itab-f2 = 9.
    itab-f3 = 10 .
    append itab.
    clear itab.
    itab-f1 = 8 .
    itab-f2 = 3.
    itab-f3 = 7 .
    append itab.
    clear itab.
    loop at itab.
      write : / itab-f1 , itab-f2 , itab-f3.
    endloop.
    sort itab by f1 f2 f3.
    skip 2.
    loop at itab.
      write : / itab-f1 , itab-f2 , itab-f3.
    endloop.
    sorting will be based on the order u give,
    if u give order f1 f2 f3 then first f1 will be checked and sorted in the order of it.
    o/p will be
    4  9  10
    8  3   7
    9  2  11

  • How to read a table and transfer the data into an internal table?

    Hello,
    I try to read all the data from a table (all attribute values from a node) and to write these data into an internal table. Any idea how to do this?
    Thanks for any help.

    Hi,
    Check this code.
    Here i creates context one node i.e  flights and attributes are from SFLIGHT table.
    DATA: lo_nd_flights TYPE REF TO if_wd_context_node,
            lo_el_flights TYPE REF TO if_wd_context_element,
            ls_flights TYPE if_main=>element_flights,
            it_flights type if_main=>elements_flights.
    navigate from <CONTEXT> to <FLIGHTS> via lead selection
      lo_nd_flights = wd_context->get_child_node( 'FLIGHTS' ).
    CALL METHOD LO_ND_FLIGHTS->GET_STATIC_ATTRIBUTES_TABLE
      IMPORTING
        TABLE  = it_flights.
    now the table data will be in internal table it_flights.

  • Xml data to abap internal table

    I'm presently working on a interface where data in abap internal table is converted into xml format and placed in the frontend and vice versa.
    I'm through with the first part and in secodn part also I'm able to transfer the data from frontend to Document Object Model(DOM) by parsing but finally am not able to put it into an internal table.
    Please help (Urgent).
    Thanks and regards,
    S.K.Tripathy

    Hi sitakant,
    1. itab --- > xml
       xml ---> itab.
    2. This program will do both.
       (just copy paste in new program)
    3.
    REPORT abc.
    DATA
    DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
    DATA : BEGIN OF itab OCCURS 0,
    a(100) TYPE c,
    END OF itab.
    DATA: xml_out TYPE string .
    DATA : BEGIN OF upl OCCURS 0,
           f(255) TYPE c,
           END OF upl.
    DATA: xmlupl TYPE string .
    FIRST PHASE
    FIRST PHASE
    FIRST PHASE
    Fetch Data
    SELECT * FROM t001 INTO TABLE t001.
    XML
    CALL TRANSFORMATION ('ID')
    SOURCE tab = t001[]
    RESULT XML xml_out.
    Convert to TABLE
    CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
      EXPORTING
        i_string         = xml_out
        i_tabline_length = 100
      TABLES
        et_table         = itab.
    Download
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filetype = 'BIN'
        filename = 'd:\xx.xml'
      TABLES
        data_tab = itab.
    SECOND PHASE
    SECOND PHASE
    SECOND PHASE
    BREAK-POINT.
    REFRESH t001.
    CLEAR t001.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename = 'D:\XX.XML'
        filetype = 'BIN'
      TABLES
        data_tab = upl.
    LOOP AT upl.
      CONCATENATE xmlupl upl-f INTO xmlupl.
    ENDLOOP.
    XML
    CALL TRANSFORMATION ('ID')
    SOURCE  XML xmlupl
    RESULT tab = t001[]
    BREAK-POINT.
    regards,
    amit m.

  • How to get data  from an internal table in some other program

    I would like to get data from the internal table in the other program. When I using FM "LIST_FROM_MEMORY" to get the data, it doesn't work and the exception is not fount.
    If any special code need in the other program, like write data to memory .
    Many thx .
    From Ross Wang

    Hi
    <li>You need to have interaction if you want to use EXPORT/IMPORT statments.
    <li>The internal tables in both programs must be same
    <li>Program one ..Calling program
    REPORT ZTEST_NOTEPAD.
    DATA: BEGIN OF it_t001 OCCURS 0,
            bukrs TYPE t001-bukrs,
            butxt TYPE t001-butxt,
          END OF it_t001.
    START-OF-SELECTION.
      SUBMIT ztest_notepad1 AND RETURN.
      IMPORT it_t001 FROM MEMORY ID 'ZTEST_T100'.
      LOOP AT it_t001.
        WRITE:/ it_t001.
      ENDLOOP.
    <li>Program two ...Called program
    REPORT ztest_notepad1.
    DATA: BEGIN OF it_t001 OCCURS 0,
            bukrs TYPE t001-bukrs,
            butxt TYPE t001-butxt,
          END OF it_t001.
    START-OF-SELECTION.
      SELECT * FROM t001 INTO CORRESPONDING FIELDS OF TABLE it_t001 UP TO 10 ROWS.
      IF sy-dbcnt > 1.
        EXPORT it_t001 TO MEMORY ID 'ZTEST_T100'.
      ENDIF.
    I hope that it gets you some idea.
    Thanks
    Venkat.O

  • Populate data in dynamic internal table

    Hi ppl,
    I have a requirement where I need to display certain fields in the report output.
    The output contains 8 fixed fields (common for all rows in output) and some dynamic fields (number of column varies with rows) which will be determined at runtime.
    I am able to create the dunamic internal table....and at runtime I see the fields created in the internal table correctly.
    Now my requirement is to fill this table with the data from 2 internal tables.
    The values for the 8 common fields comes from the internal table t_output and the values for dynamic fields come from t_dynamic.
    Please let me know the logic to merge these 2 internal tables into the dynamic internal table <dyn_table>.
    Regards.

    Hello David,
    This has been discussed many times before in this forum. Since the table structure is dynamic the fields are determined at runtime.
    To assign data to this table you have to use [ASSIGN COMPONENT ... |http://help.sap.com/abapdocu_70/en/ABAPASSIGN_MEM_AREA_DYNAMIC_DOBJ.htm#!ABAP_ALTERNATIVE_4@4@] variant.
    Please refer to the example provided in the documentation for details.
    BR,
    Suhas

  • How to populate data into Dynamic Internal Table.

    Hi Experts,
    I had created one Dynamic Internal table and one static internal table.I want to move data from Static Internal table to Dynamic interal table.And aslo the number of coloum of these two tables are not same.
    So please help me for solving this issue.
    Thanks,
    <u><i><b>Seema.</b></i></u>

    Hi,
    Check out this sample program for dynamictable report.
    REPORT  YMS_DYNAMICDEMO
                 NO STANDARD PAGE HEADING
                 MESSAGE-ID zcs_c2c_001.
    type-pools : abap.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: dy_table type ref to data,
          dy_line  type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat.
    selection-screen begin of block b1 with frame.
    parameters: p_table(30) type c default 'T001'.
    selection-screen end of block b1.
    start-of-selection.
      perform get_structure.
      perform create_dynamic_itab.
      perform get_data.
      perform write_out.
    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.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
    endform.
    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.
    form get_data.
    Select Data from table.
      select * into table <dyn_table>
                 from (p_table).
    endform.
    form write_out.
    Write out data from table.
      loop at <dyn_table> into <dyn_wa>.
        do.
          assign component  sy-index
             of structure <dyn_wa> to <dyn_field>.
          if sy-subrc <> 0.
            exit.
          endif.
          if sy-index = 1.
            write:/ <dyn_field>.
          else.
            write: <dyn_field>.
          endif.
        enddo.
      endloop.
    endform.
    Thanks,
    Shankar

  • How  to copy data from one internal table to another

    i am using some function module to get some data for my function module
    and the retrieved data is not getting populated in mu fumctional module
    i am sucessful in getting the data to an internal table in my function module but dont know how to pass it to my table parameter
    thanks in advance

    Hi Naval,
    Declare an internal table of type table parameter structure and pass it the table parameters of the Function module.
    Check the code for this function module.
    DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.
    SELECT * FROM MARA UP TO 10 ROWS INTO TABLE IT_MARA.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          FILENAME                = 'C:\TEST.TXT'.      FILETYPE                = 'ASC'
          WRITE_FIELD_SEPARATOR   = 'X'
    <b>    TABLES
          DATA_TAB                = IT_MARA</b>
        EXCEPTIONS
          FILE_WRITE_ERROR        = 1
          NO_BATCH                = 2
          GUI_REFUSE_FILETRANSFER = 3
          INVALID_TYPE            = 4
          NO_AUTHORITY            = 5
          UNKNOWN_ERROR           = 6
          HEADER_NOT_ALLOWED      = 7
          SEPARATOR_NOT_ALLOWED   = 8
          FILESIZE_NOT_ALLOWED    = 9
          HEADER_TOO_LONG         = 10
          DP_ERROR_CREATE         = 11
          DP_ERROR_SEND           = 12
          DP_ERROR_WRITE          = 13
          UNKNOWN_DP_ERROR        = 14
          ACCESS_DENIED           = 15
          DP_OUT_OF_MEMORY        = 16
          DISK_FULL               = 17
          DP_TIMEOUT              = 18
          FILE_NOT_FOUND          = 19
          DATAPROVIDER_EXCEPTION  = 20
          CONTROL_FLUSH_ERROR     = 21
          OTHERS                  = 22.
      IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Thanks,
    Vinay

  • How to insert  data from different internal  table  into a data base table

    hi all,
             I want to insert a particular field in an internal table to a field in a data base table.Note that the fields in the internal table and database table are not of the same name since i need to insert data from different internal tables.can some one tell me how to do this?
    in short i want to do something like the foll:
    INSERT  INTO ZMIS_CODES-CODE VALUE '1'.
    *INSERT INTO ZMIS_CODES-COL1 VALUE DATA_MTD-AUFNR .(zmis_codes is the db table and data_mtd is the int.table)

    REPORT  ZINSERT.
    tables kna1.
    data: itab LIKE KNA1.
    data lv_kUNAG LIKE KNA1-KUNNR.
    lv_kuNAG =  '0000010223'.
    ITAB-kuNNR = lv_kuNAG.
    ITAB-name1 = 'XYZ'.
    INSERT INTO KNA1 VALUES ITAB.
    IF SY-SUBRC = 0.
    WRITE:/ 'SUCCESS'.
    ELSE.
    WRITE:/ 'FAILED'.
    ENDIF.
    Here lv_kunag is ref to kna1 kunnr passed in different name
    In internal table .
    Try and let me know if this logic dint work.

  • How to download data from an internal table to a text

    Hi All,
    I want to download data  from an internal table to a text file.
    The fields should be pipe(|) separated. I have tried GUI_DOWNLOAD but it is not taking the field separator.
    The sample of the desired data that i require should be this way:-
    13456TR|M|COUP|MATERIAL|KGS
    Thanks in advance.
    Regards
    Satish.

    Hi,
    Try this..
    REPORT  zc1download message-id zc1dwnmsg.
    *& Declaration Section for the Tables *
    TABLES: makt.
    *& Declaration Section for the Internal Tables
    DATA: intab TYPE TABLE OF makt,
          wa_intab LIKE LINE OF intab,
          no_of_rec TYPE i,
          count TYPE i.
    DATA: BEGIN OF f_intab,
            str(255) TYPE c,
          END OF f_intab.
    DATA: t_intab LIKE TABLE OF f_intab,
          w_intab LIKE LINE OF t_intab,
          temp(255) TYPE c.
    FIELD-SYMBOLS: <f> TYPE ANY.
    *& Selection ScreenSection for the file download
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS: file TYPE rlgrap-filename MEMORY ID file,
                tab RADIOBUTTON GROUP rad1 DEFAULT 'X',
                others RADIOBUTTON GROUP rad1,
                delimit TYPE c.
    SELECTION-SCREEN END OF BLOCK b1.
    START-OF-SELECTION.
      IF file IS INITIAL. " check to ensure file.
        MESSAGE i001.
        EXIT.
      ENDIF.
      IF others = 'X'.    " check to ensure delimiter.
        IF delimit = ' '.
          MESSAGE i002.
          EXIT.
        ENDIF.
      ENDIF.
      SELECT * FROM makt INTO TABLE intab.
      IF tab = 'X'.       " default delimiter tab is used
          CALL FUNCTION 'WS_DOWNLOAD'
          EXPORTING
            filename                = file
            filetype                = 'DAT'
            mode                    = 'A'
          TABLES
            data_tab                = intab
          EXCEPTIONS
            file_open_error         = 1
            file_write_error        = 2
            invalid_filesize        = 3
            invalid_type            = 4
            no_batch                = 5
            unknown_error           = 6
            invalid_table_width     = 7
            gui_refuse_filetransfer = 8
            customer_error          = 9
            no_authority            = 10
            OTHERS                  = 11.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
      ELSE.             " If user defind delimiter is to be used
                  Counts the number of fields                *
        DO.
          ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.
          IF sy-subrc <> 0.
            EXIT.
          ELSE.
            count = count + 1.
          ENDIF.
        ENDDO.
        LOOP AT intab INTO wa_intab.
          DO count TIMES. " Adding the delimiter in required places
            ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.
            CONCATENATE temp delimit <f> INTO temp.
          ENDDO.
          SHIFT temp.
          APPEND temp TO t_intab.
          CLEAR temp.
        ENDLOOP.
        CALL FUNCTION 'WS_DOWNLOAD'
          EXPORTING
            filename                = file
            filetype                = 'ASC'
            mode                    = 'A'
          TABLES
            data_tab                = t_intab
          EXCEPTIONS
            file_open_error         = 1
            file_write_error        = 2
            invalid_filesize        = 3
            invalid_type            = 4
            no_batch                = 5
            unknown_error           = 6
            invalid_table_width     = 7
            gui_refuse_filetransfer = 8
            customer_error          = 9
            no_authority            = 10
            OTHERS                  = 11.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
      ENDIF.
      WRITE:/ 'The Data has been tranfered to :', file.
    Cheers
    Kathir!~

Maybe you are looking for