Aggregate a numeric field in an internal table

Hi All,
I have a small requirement in ABAP…it goes in this fashion
I need to aggregate a numeric field in an internal table, the table is as follows   
FLD1        FLD2         NUM1       FLD3
123A        B1             10            C1
123A        B1             25            C1
123B        B1             20            C2
123C        B2            10             C3
Note: FLD1, FLD2, FLD3 are of type numeric characters and NUM1 is of type number or integer
I want the result to be as follows
FLD1        FLD2        NUM1        FLD3
123A        B1            35             C1
123B        B1            20             C2
123C        B2            10             C3
i.e. values in field NUM1 should get add up when the values in all other fields are same…
I am not able to use ‘_collect_’ for this as the fields contain numeric characters.
Regards and Thanks,
Antony

Hi Antony
collect here works like this:-
use at new field
      sum
end at.
Pls reward points if it wil be helpful.
Regards
Depanker

Similar Messages

  • Extract a value of a fields from an internal table

    hello everyone,
    i need to extract a value of a fields from an internal table, the fields is in a postion "sy-tabix" that i know, so i need to pick this value without using a loop
    thank you.

    Like this?
    DATA: FIELD1 TYPE C,
               FIELD2 TYPE C.
    READ TABLE T_TAB INDEX 3.
    FIELD1 = T_TAB-FIELD1.
    FIELD2 = T_TAB-FIELD2.
    Greetings,
    Blag.

  • Field catalog for internal table in ALV

    In my program the internal table consists many fields from various tables and structure doesn't belong to a single data table.
    In order to get output in ALV grid following FM has been used
    REUSE_ALV_GRID_DISPLAY
    for field catalog the fields are defined specifically.
      l_fieldcat-fieldname  = 'VBELN'.
      l_fieldcat-outputlen  = 10.
      l_fieldcat-seltext_l  = 'Billing doc'.
      l_fieldcat-no_zero = 'X'.
      l_fieldcat-hotspot = 'X'.
      append l_fieldcat to p_fieldtab.
    ..............and so on for all the fields.
    Just wanted to know is there any other method to display all the fields of this internal table automatically so each field is not specified specifically.
    anya

    Hi
    Try this instead:
    *& Form  create_fieldcatalog
    * Create a field catalogue from any internal table
    *      -->PT_TABLE     Internal table
    *      -->PT_FIELDCAT  Field Catalogue
    FORM  create_fieldcatalog
           USING     pt_table     TYPE ANY TABLE
           CHANGING  pt_fieldcat  TYPE lvc_t_fcat.
      DATA:
        lr_tabdescr TYPE REF TO cl_abap_structdescr
      , lr_data     TYPE REF TO data
      , lt_dfies    TYPE ddfields
      , ls_dfies    TYPE dfies
      , ls_fieldcat TYPE lvc_s_fcat
      CLEAR pt_fieldcat.
      CREATE DATA lr_data LIKE LINE OF pt_table.
      lr_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ).
      lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ).
      LOOP AT lt_dfies
      INTO    ls_dfies.
        CLEAR ls_fieldcat.
        MOVE-CORRESPONDING ls_dfies TO ls_fieldcat.
        APPEND ls_fieldcat TO pt_fieldcat.
      ENDLOOP.
    ENDFORM.                    "create_fieldcatalog

  • Fields in an internal table

    How to find number of fields in an internal table ?
    my requirement is i have 20 internal tables and the data is being uploaded into an application server. so how to find no of fields in a particular internal table

    concatenate all the fields and move them to final internal table , call the function module "GET_COMPONENT_LIST" and pass the work area of the final internal table in the parameter fieldname
    ***For getting no of FIELDS in an internal table ********
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        PROGRAM          = syrepid
        FIELDNAME        = 't_payr'
      TABLES
        COMPONENTS       = fieldlist.
    describe table fieldlist lines pyr_no_fields.
    ********end of getting no of fields**********
    TRANSFER wa_mat_out_head TO P_FNAME.
    LOOP AT GT_PAYR.
    MOVE:  GT_payr-LIFNR TO T_payr-lifnr,
           GT_payr-ZBUKR TO T_payr-zbukr,
           GT_payr-LAUFD TO T_payr-LAUFD,
           GT_payr-CHECT TO T_payr-CHECT,
           GT_payr-RWBTR TO T_payr-RWBTR.
    Concatenate T_payr-lifnr  t_payr-zbukr T_payr-laufd T_payr-chect
                T_payr-rwbtr into wa_mat_out-rec SEPARATED by ',' .

  • Changing the order of fields in an internal table

    Hi all,
    I'm using field symbol as internal table. this table has got a standard database structure.
    I want to make the 3rd column of this internal table as 1st colums keeping rest of the columns as it is.
    Is there any way to do this?
    Thanks,
    Anil.

    Hi
        Instead of directly taking the type as a standard structure , declare the FS  internal table as type of types structure.
    Data: fs_scarr like type_s_scarr.
    FIELD-SYMBOLS <scarr2> TYPE fs_scarr
    In the types put the third column as first one and use into corresponding in select query
    or else
    while displaying the internal table change the order of the columns
    Loop at itab into fs_itab.
    write : col3
    col2
    col4
    endloop.
    Thanks,
    Viquar Iqbal

  • I need to add check whether 21 fields of a internal table are empty or not.

    Hello,
    I need to add check whether 21 fields of a internal table are empty or not.How can we write a code for the same wand what would be the correct syntax for it.
    I tried entering all the fields in the IF loop with AND condition but its giving syntax error.Perhaps this is because the lenght of the IF condition would be more than the allowed one.

    Hi,
    After the select quiery.
    If not itab is initial.
    Message 'Table is not empty'    type 'I'.
    Endif.
    Regards,
    Jagadish.

  • First occurence of a value from a  field in the internal table.

    How to select the first occurence of a value from a field in an internal table ?
    I don think , we can use select query .
    Any suggestions?
    provide syntaxs also .

    Hi...
    You have to use this code.
    DATA : Begin of IT_MARA occurs 0,
                 mtart type mara-mtart,
                 matnr type mara-matnr,
                 meins type mara-meins,
              END OF IT_MARA.
    START-of-SELECTION.
      SELECT MTART MATNR MEINS FROM MARA INTO TABLE IT_MARA.
    END-OF-SELECTION.
    LOOP AT  IT_MARA.
    <b>  AT NEW MTART.      "This will trigger for every first/new value of the field
                 <<<<WRITE YOUR CODE here>>
       ENDAT.</b>
    ENDLOOP.
    You can also use.
    LOOP AT  IT_MARA.
    <b> <b>  ON CHANGE OF IT_MARA-TART.   
                 <<<<WRITE YOUR CODE here>>
       ENDON.</b></b>
    ENDLOOP.
    <b>Reward if Helpful.</b>

  • Coloring a field in the internal table

    Hi all,
    How can I color a field in the internal table knowing that I'm developing a classic report.
    Thanks in advance.

    hi,,,
    check this code.
    *-----TABLES DECLARATION
    tables : kna1,                     "Customer Master
           vbak,                     "Sales Document Header
             vbap,                     "Sales Document Item
             sscrfields.               "Screen Field Table
    &               D A T A   D E C L A R A T I O N                       &
    data : begin of it_kna1 occurs 0,
            kunnr type kna1-kunnr,      "Customer Number
            land1 type kna1-land1,      "Country Key
            name1 type kna1-name1,      "Name
            ort01 type kna1-ort01,      "City
           end of it_kna1.
    data : begin of it_kna2 occurs 0,
            kunnr type kna1-kunnr,      "Customer Number
            land1 type kna1-land1,      "Country Key
            name1 type kna1-name1,      "Name
            ort01 type kna1-ort01,      "City
           end of it_kna2.
    data:  begin of it_vbak occurs 0,
            vbeln type vbak-vbeln,      "Sales Document
            erdat type vbak-erdat,      "Date
            ernam type vbak-ernam,      "Name of Person
            auart type vbak-auart,      "Sales Document Type
           end of it_vbak.
    data:  begin of it_vbap occurs 0,
            vbeln type vbap-vbeln,      "Sales Document
            posnr type vbap-posnr,      "Sales Document Item
            matnr type vbap-matnr,      "Material Number
            matkl type vbap-matkl,      "Material group
           end of it_vbap.
    data: v_count type int4,           "Current Row Index
           v_line like sy-lisel,        "Contents of selected line
           v_kunnr like kna1-kunnr.
    &                S E L E C T I O N  S C R E E N                       &
    selection-screen begin of block b1 with frame title text-001.
    selection-screen begin of line.
    parameters : rb1 radiobutton group g1 default 'X'.
    selection-screen comment 5(20) text-002 for field rb1.
    selection-screen end of line.
    select-options : so_kunnr for kna1-kunnr obligatory.
    parameters : p_hits(3) type c.
    selection-screen begin of line.
    parameters : rb2 radiobutton group g1.
    selection-screen comment 5(20) text-003 for field rb2.
    selection-screen end of line.
    parameters : p_file like rlgrap-filename default 'c:\test'.
    selection-screen pushbutton /33(10) custl user-command push1.
    selection-screen pushbutton 58(10) custd user-command push2.
    selection-screen end of block b1.
    &                  I N I T I A L I Z A T I O N                        &
    initialization.
      move 'LOAD' to custl.
      move 'DISP' to custd.
    &                  A T  L I N E  S E L E C T I O N                    &
    at selection-screen.
      perform validate_kunnr.
    &  A T  S E L E C T I O N  S C R E E N  O N  V A L U E-R E Q U E S T  &
    at selection-screen on value-request for p_file.
      call function 'F4_FILENAME'
        exporting
          program_name  = syst-cprog
          dynpro_number = syst-dynnr
          field_name    = ' '
        importing
          file_name     = p_file.
    &              S T A R T  O F  S E L E C T I O N                      &
    start-of-selection.
      perform cust_details.
    &              S T A R T  O F  S E L E C T I O N                      &
    top-of-page.
      format color 3 intensified off.
      write :/02(25) sy-repid.
      write : 39(15) 'Page'(010), sy-pagno.
      format color off.
      format color 6 intensified off.
      format color col_heading.
      uline at :/1(60).
      write: /1 sy-vline,
              2 'Cust Number'(000),
              14 sy-vline,
              16 'Country'(007),
              25 sy-vline,
              26 'City'(008),
              42 sy-vline,
              43 'Region'(009),
              60 sy-vline.
      uline at :/1(60).
      format color col_heading off.
    &   T O P  O F  P A G E  D U R I N G  L I N E  S E L E C T I O N      &
    top-of-page during line-selection.
      if sy-lsind eq 1 or sy-ucomm eq 'VBAK'.
        format color col_heading.
        uline at :/1(60).
        write : /1 sy-vline,
                     2 'Docu No.'(011),
                     14 sy-vline,
                     16 'Date'(012),
                     26 sy-vline,
                     27 'Name'(013),
                     42 sy-vline,
                     43 'DType'(014),
                     60 sy-vline.
        uline at :/1(60).
      elseif sy-lsind eq 2 or sy-ucomm eq 'VBAK'.
        set pf-status space.
        uline at :/1(60).
        write : /1 sy-vline,
                     2 'Docu No.'(015),
                     14 sy-vline,
                     16 'Sales Item'(016),
                     25 sy-vline,
                     26 'Mat No'(017),
                     42 sy-vline,
                     43 vbap-matkl,
                     50 'Mat Grp'(018),
                     60 sy-vline.
        uline at :/1(60).
      endif.
    &  AT USER-COMMAND                                                    &
    at user-command.
      case sy-ucomm.
        when 'VBAK'.
          perform sales_item.
        when 'DELIVERY'.
          clear it_vbak-vbeln.
          get cursor value it_vbak-vbeln.
          set parameter id 'AUN' field it_vbak-vbeln.
          call transaction 'VA03' and skip first screen.
        when 'DISP'.
          perform display_basic.
      endcase.
    &      AT LINE SELECTION                                              &
    at line-selection.
      if sy-lsind = 1.
        set pf-status 'DDDD'.
        perform sales_header.
      elseif  sy-lsind = 2.
      case sy-ucomm.
        when 'PICK'.
        set pf-status space.
        perform sales_item.
        when 'DELIVERY'.
          clear it_vbak-vbeln.
          get cursor value it_vbak-vbeln.
          set parameter id 'AUN' field it_vbak-vbeln.
          call transaction 'VA03' and skip first screen.
        when 'DISP'.
          perform display_basic.
      endcase.
       PERFORM sales_item.
      endif.
    &  AT USER-COMMAND                                                    &
    at user-command.
      case sy-ucomm.
        when 'VBAK'.
          perform sales_item.
        when 'DELIVERY'.
          clear it_vbak-vbeln.
          get cursor value it_vbak-vbeln.
          set parameter id 'AUN' field it_vbak-vbeln.
          call transaction 'VA03' and skip first screen.
        when 'DISP'.
          perform display_basic.
      endcase.
    &      Form  CUST_DETAILS                                             &
    form cust_details .
      select kunnr
             land1
             name1
             ort01
             from kna1
             into table it_kna1
             where kunnr in so_kunnr.
      if sy-subrc <> 0.
        message 'SELECT VALID CUST NO' type 'I'.
      else.
        loop at it_kna1.
         v_count = v_count + 1.
          if sy-tabix < p_hits.
         IF v_count <= p_hits.
            move it_kna1 to it_kna2.
            append it_kna2.
          else.
            exit.
          endif.
        endloop.
      endif.
      if not it_kna2[] is initial.
        loop at it_kna2.
          write : /1 sy-vline,
                   2 it_kna2-kunnr,
                   14 sy-vline,
                   16 it_kna2-land1,
                   25 sy-vline,
                   26 it_kna2-name1,
                   42 sy-vline,
                   43 it_kna2-ort01,
                   60 sy-vline.
          uline at :/1(60).
        endloop.
      endif.
    endform.                    " CUST_DETAILS
    **&      Form  load_file
    *form load_file .
    *endform.                    " load_file
    **&      Form  disp_file
    *form disp_file .
    *endform.                    " disp_file
    *&      Form  VALIDATE_KUNNR
    form validate_kunnr .
      select single kunnr
                    from kna1
                    into kna1
                    where kunnr = so_kunnr.
    endform.                    " VALIDATE_KUNNR
    *&      Form  SALES_HEADER
    form sales_header .
    data : v_kna1(13).
    v_kna1 = 'IT_KNA2-KUNNR'.
    *get cursor line sy-lilli value v_line
    clear v_kunnr.
      get cursor  field v_kna1 value v_kunnr.
    v_kunnr = v_line+1(10).
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = v_kunnr
        importing
          output = v_kunnr.
      select vbeln
             erdat
             ernam
             auart
             from vbak
             into table it_vbak
             where  kunnr = v_kunnr.
      if sy-subrc = 0.
        loop at it_vbak.
          write : /1 sy-vline,
                   2 it_vbak-vbeln,
                   14 sy-vline,
                   16 it_vbak-erdat,
                   26 sy-vline,
                   27 it_vbak-ernam,
                   42 sy-vline,
                   43 it_vbak-auart,
                   60 sy-vline.
          uline at :/1(60).
        endloop.
      endif.
    endform.                    " SALES_HEADER
    *&      Form  SALES_ITEM
    form sales_item .
    data : v_vbeln(13).
    v_vbeln = 'IT_VBAK-VBELN'.
    clear it_vbak-vbeln.
    get cursor  field v_vbeln value it_vbak-vbeln.
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = it_vbak-vbeln
        importing
          output = it_vbak-vbeln.
      select vbeln
             posnr
             matnr
             matkl
      from vbap
      into table it_vbap
      where vbeln = it_vbak-vbeln.
      loop at it_vbap .
        write : /1 sy-vline,
                   2 it_vbap-vbeln,
                   14 sy-vline,
                   16 it_vbap-posnr,
                   25 sy-vline,
                   26 it_vbap-matnr,
                   42 sy-vline,
                   43 it_vbap-matkl,
                   60 sy-vline.
        uline at :/1(60).
      endloop.
    endform.                    " SALES_ITEM
    *&      Form  DISP_DOCU
    form display_basic .
      loop at it_kna1 into it_kna1.
        format hotspot on.
        write : /03 it_kna1-kunnr,
                 24  it_kna1-name1.
        hide it_kna1-kunnr.
      endloop.
    endform.                    " display_basic
    pls reward if useful
    regards,
    rekha

  • Add field in an internal table

    Hi There,
    How to add a field in an internal table created at the runtime using
    CREATE DATA D1 TYPE TABLE OF (VAR).
    where say var contains name of a DDIC table.
    Rgds,
    deb.

    after creating internal table use the method for creation of dynamic table and try , i am not sure
    DATA: LineType TYPE string,
          ItabRef  TYPE REF TO DATA.
    FIELD-SYMBOLS:   TYPE STANDARD TABLE.
    LineType = 'SFLIGHT'.
    " Create internal table and attach a field-symbol
    CREATE DATA ItabRef TYPE STANDARD TABLE OF (LineType).
    ASSIGN ItabRef->* TO .
    <b>after this check this and try</b>
    ******DATA DECLARATION*****************************
    FIELD-SYMBOLS : <it_final> TYPE STANDARD TABLE,
                    <wa_final> TYPE ANY,
                    <w_field> TYPE ANY.
    ***DYNAMIC CREATION OF FIELDCATALOG****************
    *FIRST 2 FIELDS FIELDS FIELD1 AND FIELD2 ARE CONSTANT, FIELDS OBTAINED IN THE LOOP ENDLOOP ARE DYNAMIC,
    *LIKEWISE DYNAMIC FIELDCATALOG IS CREATED
      wa_fieldcatalog-fieldname  = 'FIELD1'.
      wa_fieldcatalog-ref_table  = 'E070'.
      wa_fieldcatalog-outputlen  = '13'.
      wa_fieldcatalog-reptext    = 'Created On'.
      wa_fieldcatalog-seltext    = 'Created On'.
      APPEND wa_fieldcatalog TO it_fieldcatalog.
      CLEAR wa_fieldcatalog.
      wa_fieldcatalog-fieldname  = 'FIELD1'.
      wa_fieldcatalog-ref_table  = 'E070'.
      wa_fieldcatalog-outputlen  = '13'.
      wa_fieldcatalog-reptext    = 'Created On'.
      wa_fieldcatalog-seltext    = 'Created On'.
      APPEND wa_fieldcatalog TO it_fieldcatalog.
      CLEAR wa_fieldcatalog.
      LOOP AT it_mandt WHERE mandt IN s_mandt.
        CONCATENATE 'CLNT' it_mandt INTO wa_fieldcatalog-fieldname.
        wa_fieldcatalog-inttype    = 'NUMC'.
        wa_fieldcatalog-outputlen  = '14'.
        wa_fieldcatalog-reptext    = it_mandt.
        wa_fieldcatalog-seltext    = it_mandt.
        APPEND wa_fieldcatalog TO it_fieldcatalog.
        CLEAR :wa_fieldcatalog ,it_mandt.
      ENDLOOP.
    ********CREATE DYNAMIC TABLE************************
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog           = it_fieldcatalog
        IMPORTING
          ep_table                  = new_table
        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.
      ASSIGN new_table->* TO <it_final>.
    *********CREATE WORK AREA****************************
    CREATE DATA new_line LIKE LINE OF <it_final>.
      ASSIGN new_line->* TO <wa_final>.
    *********INSERTTING WORK AREAR TO INTERNAL TABLE******
        INSERT <wa_final> INTO TABLE <it_final>.
    *******POPULATING DATA******************************* 
      LOOP.
       ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_final> TO <w_field>.
       <w_field> = '12345'.
        ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_final> TO <w_field>.
       <w_field> = '21453DD'.
       FIELD1 AND FIELD2 ARE COMPONENTS OF FIELDCATALOG.
    ENDLOOP.     
      ENDLOOP.

  • Mapping corresponding field in the internal table

    Hi guys I need help with putting XML value into the appropriate fields in the internal table struc. I attempted to use if else condition to map the element name (cname)over to the fields but those internal table within an internal table post an issue of when to append and so on ... I am using FM SMUM_XML_PARSE and the output in to this table type smum_xmltb (containing all the XML Element and Values) I want to map it to its corresponding field in the internal table (defined below)
    Pls pardon this newbie here as this is very new to me. Hope to hear fr u all soon and points will be given! ")
    XML->>
    <?xml version="1.0" encoding="iso-8859-1"?>
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
    <asx:values>
    <BOOKLIST>
    <DATE>2006-09-25</DATE>
    <TIME>16:27:20</TIME>
    <BOOK_RECORD>
    <BOOK_NUM>0012345678</BOOK_NUM>
    <SHORT_DESC>OMS BOOK</SHORT_DESC>
    <BOOK_GROUP>
    <BOOK_CATEGORY>
    <CATEGORY_ID>03</CATEGORY_ID>
    <CATEGORY_DESC>BOOK group 3</CATEGORY_DESC>
    </BOOK_CATEGORY>
    <BOOK_CATEGORY>
    <CATEGORY_ID>02</CATEGORY_ID>
    <CATEGORY_DESC>BOOK group 2</CATEGORY_DESC>
    </BOOK_CATEGORY>
    </BOOK_GROUP>
    </BOOK_RECORD>
    <BOOK_RECORD>
    <BOOK_NUM>0012345679</BOOK_NUM>
    <SHORT_DESC>SAP BOOK</SHORT_DESC>
    <BOOK_GROUP>
    <BOOK_CATEGORY>
    <CATEGORY_ID>01</CATEGORY_ID>
    <CATEGORY_DESC>BOOK group 1</CATEGORY_DESC>
    </BOOK_CATEGORY>
    <BOOK_CATEGORY>
    <CATEGORY_ID>09</CATEGORY_ID>
    <CATEGORY_DESC>BOOK group 9</CATEGORY_DESC>
    </BOOK_CATEGORY>
    </BOOK_GROUP>
    </BOOK_RECORD>
    </BOOKLIST>
    </asx:values>
    </asx:abap>
    INTERNAL TABLE ->>
    TYPES: BEGIN OF ADD_CATEGORY,
    CATEGORY_ID(10),
    CATEGORY_DESC(40),
    END OF ADD_CATEGORY,
    ADD_T_CATEGORY TYPE ADD_CATEGORY OCCURS 0.
    TYPES: BEGIN OF ADD_BOOK_GRP,
    BOOK_CATEGORY TYPE ADD_T_CATEGORY,
    END OF ADD_BOOK_GRP,
    ADD_T_BOOK_GRP TYPE ADD_BOOK_GRP OCCURS 0.
    TYPES: BEGIN OF ADD_BOOK,
    BOOK_NUM(10) TYPE C,
    SHORT_DESC(40) TYPE C,
    BOOK_GROUP TYPE ADD_T_BOOK_GRP,
    END OF ADD_BOOK,
    ADD_T_BOOK TYPE ADD_BOOK OCCURS 0.
    TYPES: BEGIN OF TYPE_DATA,
    DATE TYPE SY-DATUM,
    TIME TYPE SY-TIMLO,
    BOOK_RECORD TYPE ADD_T_BOOK,
    END OF TYPE_DATA.
    DATA: I_DATA TYPE TYPE_DATA OCCURS 0 WITH HEADER LINE.

    hi,
    here is the code sample using ixml library .
    just create a report program and copy paste the following code.
    REPORT  y_test_xml.
    DATA: l_ixml                                 TYPE REF TO if_ixml,
            l_ixml_sf                              TYPE REF TO if_ixml_stream_factory,
            l_istream                              TYPE REF TO if_ixml_istream,
            l_ostream                              TYPE REF TO if_ixml_ostream,
            l_booklist                   TYPE REF TO if_ixml_element,
            l_document                             TYPE REF TO if_ixml_document,
            l_parser                               TYPE REF TO if_ixml_parser,
            l_root_element                         TYPE REF TO if_ixml_element,
            l_book_record                            TYPE REF TO if_ixml_element,
            l_date TYPE REF TO if_ixml_element ,
                    l_time TYPE REF TO if_ixml_element ,
            l_book_group                            TYPE REF TO if_ixml_element,
            l_book_cat                            TYPE REF TO if_ixml_element ,
            others                                  TYPE REF TO if_ixml_element ,
            link                                    TYPE REF TO if_ixml_element ,
            description                            TYPE REF TO if_ixml_element ,
            xml                                    TYPE xstring ,
            size TYPE  i ,
             l_xml  TYPE REF TO cl_xml_document  .
    DATA: xml_out TYPE string ,
          temp_string TYPE string .
    TYPES: BEGIN OF add_category,
    category_id(10),
    category_desc(40),
    END OF add_category,
    add_t_category TYPE add_category OCCURS 0 .
    TYPES: BEGIN OF add_book_grp,
    book_category TYPE add_t_category,
    END OF add_book_grp,
    add_t_book_grp TYPE add_book_grp OCCURS 0.
    TYPES: BEGIN OF add_book,
    book_num(10) TYPE c,
    short_desc(40) TYPE c,
    book_group TYPE add_t_book_grp,
    END OF add_book,
    add_t_book TYPE add_book OCCURS 0.
    TYPES: BEGIN OF type_data,
    date TYPE sy-datum,
    time TYPE sy-uzeit,
    book_record TYPE add_t_book,
    END OF type_data.
    DATA: i_data TYPE type_data OCCURS 0 WITH HEADER LINE.
    DATA: itab LIKE soli OCCURS 0 WITH HEADER LINE.
    DATA: cat_wa TYPE add_category ,
          bk_gp_wa TYPE add_book_grp ,
          bk_rec_wa TYPE add_book ,
          bk_wa LIKE LINE OF i_data .
    DATA: cat_tab TYPE STANDARD TABLE OF add_category ,
          bk_gp_tab TYPE STANDARD TABLE OF add_book_grp ,
          bk_rec_tab TYPE STANDARD TABLE OF add_book .
    MOVE: '03' TO cat_wa-category_id  ,
          ' BK GP 3' TO cat_wa-category_desc .
    APPEND cat_wa TO cat_tab .
    MOVE: '02' TO cat_wa-category_id  ,
          ' BK GP 2' TO cat_wa-category_desc .
    APPEND cat_wa TO cat_tab .
    bk_gp_wa-book_category  = cat_tab.
    APPEND bk_gp_wa TO bk_gp_tab .
    MOVE: '0012345678' TO bk_rec_wa-book_num ,
          'OMS book' TO bk_rec_wa-short_desc .
    bk_rec_wa-book_group = bk_gp_tab .
    APPEND bk_rec_wa TO bk_rec_tab .
    CLEAR:bk_gp_tab, cat_tab .
    REFRESH :bk_gp_tab, cat_tab .
    MOVE: '01' TO cat_wa-category_id  ,
          ' BK GP 1' TO cat_wa-category_desc .
    APPEND cat_wa TO cat_tab .
    MOVE: '09' TO cat_wa-category_id  ,
          ' BK GP 9' TO cat_wa-category_desc .
    APPEND cat_wa TO cat_tab .
    bk_gp_wa-book_category  = cat_tab.
    APPEND bk_gp_wa TO bk_gp_tab .
    MOVE: '00123456789' TO bk_rec_wa-book_num ,
          'SAP book' TO bk_rec_wa-short_desc .
    bk_rec_wa-book_group = bk_gp_tab .
    APPEND bk_rec_wa TO bk_rec_tab .
    MOVE: sy-datum TO bk_wa-date ,
          sy-uzeit TO bk_wa-time .
    bk_wa-book_record = bk_rec_tab .
    APPEND bk_wa TO i_data .
    CLEAR: cat_wa , bk_gp_wa ,bk_rec_wa , bk_wa .
    l_ixml = cl_ixml=>create( ).
    l_ixml_sf = l_ixml->create_stream_factory( ).
    l_document = l_ixml->create_document( ).
    l_root_element = l_document->create_element( name = 'asx:abap' ).
    l_root_element->set_attribute( name = 'xmlns:asx' value = 'http://www.sap.com/abapxml' ) .
    l_root_element->set_attribute( name = 'version' value = '1.0' ).
    l_document->append_child( new_child = l_root_element ).
    others = l_document->create_simple_element( parent = l_root_element name = 'asx:values' ).
    l_booklist = l_document->create_simple_element( parent = others name = 'BOOKLIST' ).
    LOOP AT i_data INTO bk_wa .
      CLEAR temp_string .
      MOVE: bk_wa-date TO temp_string .
      l_date = l_document->create_simple_element( parent = l_booklist name = 'DATE' value = temp_string  ).
      CLEAR temp_string .
      MOVE: bk_wa-time TO temp_string .
      l_time = l_document->create_simple_element( parent = l_booklist name = 'TIME' value = temp_string ).
      LOOP AT bk_wa-book_record INTO bk_rec_wa .
        l_book_record = l_document->create_simple_element( parent = l_booklist name = 'BOOK_RECORD' ) .
        CLEAR temp_string .
        MOVE: bk_rec_wa-book_num TO temp_string .
        l_date = l_document->create_simple_element( parent = l_book_record name = 'BOOK_NUM' value = temp_string ).
        CLEAR temp_string .
        MOVE: bk_rec_wa-short_desc TO temp_string .
        l_time = l_document->create_simple_element( parent = l_book_record name = 'SHORT_DESC' value = temp_string ).
        l_book_group = l_document->create_simple_element( parent = l_book_record name = 'BOOK_GROUP' ).
        LOOP AT bk_rec_wa-book_group INTO bk_gp_wa .
          LOOP AT bk_gp_wa-book_category INTO cat_wa .
            l_book_cat = l_document->create_simple_element( parent = l_book_group name = 'BOOK_CATEGORY' ).
            CLEAR temp_string .
            MOVE: cat_wa-category_id TO temp_string .
            l_date = l_document->create_simple_element( parent = l_book_cat name = 'CATEGORY_ID' value = temp_string ).
            CLEAR temp_string .
            MOVE: cat_wa-category_desc TO temp_string .
            l_time = l_document->create_simple_element( parent = l_book_cat name = 'CATEGORY_DESC' value = temp_string ).
          ENDLOOP .
        ENDLOOP .
      ENDLOOP .
    ENDLOOP .
    l_ostream = l_ixml_sf->create_ostream_xstring( xml ).
    l_document->render( ostream = l_ostream ).
    CREATE OBJECT l_xml.
    CALL METHOD l_xml->parse_xstring
      EXPORTING
        stream = xml.
    l_xml->render_2_string(
      EXPORTING
        pretty_print = 'X'
      IMPORTING
       RETCODE      = RETCODE
        stream       = xml_out
        size         = size
    CALL METHOD l_xml->display.
    to read the xml data to abap itab you could parse node by node or write a XSLT to map it to your itab or use the following method. (add the following code to the earlier program)
    data: result_xml type standard table of smum_xmltb .
    data: return type standard table of bapiret2 .
    after the statement
    l_document->render( ostream = l_ostream ).
    add
    converting xml to itab
    call function 'SMUM_XML_PARSE'
    exporting
    xml_input = xml
    tables
    xml_table = result_xml
    return = return .
    now check the result_xml itab.
    rgds
    anver

  • Field length in internal table

    hi,
    how to selt field length in internal table?.
    i have created on report the report out puts down load to using download function .
    the out format is:
    op1  op2   op3      op4
    1     3       4               
    i want
    op1   op2   op3       op4
    1                3          4
    how to set this please give sample code.

    HI,
    Give internal table like this.
    DATA: BEGIN OF itab OCCURS 100,
                op1(04),
                op2(04),
    op3(04),
    op4(04),
          END OF itab.
    So it will allocate space between 1, 3 and 4.
    Reward if it useful.
    Thanks.

  • Difference between the Field Group  and Internal Table.

    Hi all,
    Can anybody tell me the difference between the Field group and Internal table and when they will used?
    Thanks,
    Sriram.

    Hi
    Internal Tables: They are used to store record type data in tabular form temporarily in ABAP programming. Or we can say, it stores multiple lines of records for temporary use in ABAP programming.
    A field group is a user-defined grouping of characteristics and basic key figures from the EC-EIS or EC-BP field catalog.
    Use
    The field catalog contains the fields that are used in the aspects. As the number of fields grows, the field catalog becomes very large and unclear. To simplify maintenance of the aspects, you can group fields in a field group. You can group the fields as you wish, for example, by subject area or responsibility area. A field may be included in several field groups.
    When maintaining the data structure of an aspect, you can select the field group that contains the relevant characteristics and basic key figures. This way you limit the number of fields offered.
    Regards
    Ashish

  • How to increase field size in Internal table

    Hi friends,
    I want to concatenate around 20 fields in one internal table field,
    i declared the destination filed as character, now i am able to get around 12 to 13 fileds only , how to increase the length of this field to include all fields ?
    or how can i do this ? can any body help me ?
    I concatenate this to create a file  which will be send as email attachment.
    its very urgent issue, kindly help me to resolve as early as possible.
    Thanks in advance.
    Joseph

    Hi,
    Use the string data type..
    Example
    DATA: IT_STRING TYPE STRING OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF WA,
                 MATNR(18),
                 WERKS(4),
                 VBELN(10),
               END OF WA.
    CONCATENATE WA-MATNR WA-WERKS WA-VBELN INTO IT_STRING.
    APPEND IT_STRING.
    Thanks,
    Naren

  • Dynamic field access in internal tables

    Hi everyone.
    I woulkd like to know if there is any way to identify the fields of an internal table at runtime. I'm creating a method in a class, and i would like to accept any itab as a paramter and then access the fields of that itab. I currently have the itab passing no problem using field symbols, and i am able to loop at the data, but i am unsure how to get the field names.
    Any suggestions?
    Thanks!

    Hi,
    Check the code below:
    REPORT ZYKTEST3 .
    DATA: d_ref TYPE REF TO data,
    d_ref2 TYPE REF TO data,
    i_alv_cat TYPE TABLE OF lvc_s_fcat,
    ls_alv_cat LIKE LINE OF i_alv_cat.
    TYPES: tabname LIKE dcobjdef-name ,
    fieldname LIKE dcobjdef-name,
    desc LIKE dntab-fieldtext.
    PARAMETER: p_tablen TYPE tabname. -
    > Input table field
    DATA: BEGIN OF itab OCCURS 0.
    INCLUDE STRUCTURE dntab.
    DATA: END OF itab.
    FIELD-SYMBOLS : <f_fs> TYPE table,
    <f_fs1> TYPE table,
    <f_fs2> TYPE ANY,
    <f_fs3> TYPE ANY,
    <f_fs4> type any,
    <f_field> TYPE ANY.
    REFRESH itab.
    CALL FUNCTION 'NAMETAB_GET' -
    > Fetches the fields
    EXPORTING
    langu = sy-langu
    tabname = p_tablen
    TABLES
    nametab = itab
    EXCEPTIONS
    no_texts_found = 1.
    LOOP AT itab .
    ls_alv_cat-fieldname = itab-fieldname.
    ls_alv_cat-ref_table = p_tablen.
    ls_alv_cat-ref_field = itab-fieldname.
    ls_alv_cat-seltext = itab-fieldtext.
    ls_alv_cat-reptext = itab-fieldtext.
    APPEND ls_alv_cat TO i_alv_cat.
    ENDLOOP.
    internal table build
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = i_alv_cat
    IMPORTING
    ep_table = d_ref.
    ASSIGN d_ref->* TO <f_fs>. -
    > Dynamic table creation with fields of the table
    DATA: l_field TYPE fieldname,
    l_field1 type fieldname.
    SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <f_fs>.
    Fetching of the data from the table
    LOOP AT <f_fs> ASSIGNING <f_fs2>.
    Here u can check the validations and process
    ASSIGN COMPONENT 2 OF STRUCTURE <f_fs2> TO <f_fs3>.
    ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.
    IF sy-subrc = 0.
    MOVE <f_fs3> TO l_field.
    MOVE <f_fs4> TO l_field1.
    WRITE:/1 l_field(20),
    22 l_field1(10).
    ENDIF.
    ENDLOOP.
    Regards
    Kannaiah

  • To Find the type of field in the internal table.

    I have internal table i_tab.
    TYPES : BEGIN OF t_makt,
              matnr    TYPE    matnr,
              maktx    TYPE    maktx,
              qty      type    mseg-menge,
              show     type    char01,
            END OF t_makt.
    DATA : i_tab      TYPE t_makt  OCCURS 0 WITH HEADER LINE.
    I want to know the type of the field of the i_tab at some stage in the program.
    is there any piece of code or FM available to find the TYPE of the field of the internal table.

    Check out the following code
    TYPES:
      BEGIN OF my_struct,
        comp_a type i,
        comp_b type f,
      END OF my_struct.
    DATA:
      my_data   TYPE my_struct,
      descr_ref TYPE ref to cl_abap_structdescr.
    FIELD-SYMBOLS:
      <comp_wa> TYPE abap_compdescr.
    START-OF-SELECTION.
      descr_ref ?= cl_abap_typedescr=>describe_by_data( my_data ).
      WRITE: / 'Typename     :', descr_ref->absolute_name.
      WRITE: / 'Kind         :', descr_ref->type_kind.
      WRITE: / 'Length       :', descr_ref->length.
      WRITE: / 'Decimals     :', descr_ref->decimals.
      WRITE: / 'Struct Kind  :', descr_ref->struct_kind.
      WRITE: / 'Components'.
      WRITE: / 'Name              Kind   Length   Decimals'.
      LOOP AT descr_ref->components ASSIGNING <comp_wa>.
        WRITE: / <comp_wa>-name, <comp_wa>-type_kind,
                 <comp_wa>-length, <comp_wa>-decimals.
      ENDLOOP.

Maybe you are looking for

  • Can't access PC Documents folder when uploading from external program

    When attempting to upload a file into Knack database from This PC/Documents folder I am referred back to One Drive and the following message: "Something went wrong and this app can't pick files right now. Try selecting app again" Reselecting results

  • Clean out library

    I preparation for dropping another 2GB of RAM into my iMac and upgrading to Lion, I want to do some serious maintenance on my Mac. I've installed and deleted countless applications since 2006 and suspect there are lots of old preference files and oth

  • The Accelorometer is not working on my iPhone 5. What should I do?

    I am facing problems with the Accelerometer on my new iPhone 5. When I turn my phone to the horizontal position to watch videos or pictures, there is no change. What do I do to set this right? This has been happening since the last 10 to 15 days only

  • Which certification to opt for?

    Hi, I am software engineer. I worked as a plsql developer / oracle developer for more than 2 years. That time my project used oracle 9i. I am aware of all sql fundamentals,pqsql fundamentals and oracle 9i db architecture. However,to improve and to ha

  • Query in IDOC.

    Hi, Could you please clarify me the following 1) In which transaction code we can find the all the segements assigned to a MEASSAGE type. 2) In which transaction code we can find all the fields available under the Segement type. 3) where we can see a