Skip to Content
avatar image
Former Member

Reading internal table

Hi Folks,

i need to read the contents of an internal table into another table based on the condition that user enters through select-options.

Regards,

Jagadish.D

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • avatar image
    Former Member
    Aug 22, 2007 at 11:45 AM

    Hi jagadish,

    try looping at the first internal table, and inside the loop check for the conditions and if your condition is satisfied move the workarea into the target internal table.

    if you can provide with the internal tables that you are using and the conditions that you want to check then i could give u sample code.

    <b>Reward points if this helps,

    Kiran</b>

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Kiran ,

      My first internal table is it_belnr i need to validate field azidt in that where user enters the value azidt through select-options.

      After reading the contents of this table based on the above criteria i need to put the contents into second internal table.

  • avatar image
    Former Member
    Aug 22, 2007 at 11:46 AM

    hi,

    Check this code.

    LOOP AT IT_MARA INTO WA_MARA WHERE MATNR IS NOT INITIAL.

    READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_MARA-MATNR BINARY SEARCH.

    WA_FINAL-MATNR = WA_MARA-MATNR.

    WA_FINAL-MAKTX = WA_MAKT-MAKTX.

    WA_FINAL-MTART = WA_MARA-MTART.

    WA_FINAL-MATKL = WA_MARA-MATKL.

    WA_FINAL-BRGEW = WA_MARA-BRGEW.

    • ON CHANGE OF WA_FINAL-MTART.

    WA_FINAL-TOTBW = WA_FINAL-BRGEW.

    • ENDON.

    • ON CHANGE OF WA_FINAL-MTART.

    • G_TOTAL = WA_FINAL-BRGEW + G_TOTAL.

    • WA_FINAL-BRGEW = G_TOTAL.

    • ENDON.

    APPEND WA_FINAL TO IT_FINAL.

    CLEAR WA_FINAL.

    ENDLOOP.

    Points please.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 22, 2007 at 11:47 AM

    give one example.................

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 22, 2007 at 11:50 AM

    Hi,

    write like this.

    tables: mara.

    data:itab like mara occurs 0 with header line.

    data:jtab like mara occurs 0 with header line.

    SELECT-OPTIONS:i_matnr for mara-matnr.

    SELECT * from mara into table itab.

    LOOP AT itab where matnr in i_matnr.

    MOVE-CORRESPONDING itab to jtab.

    append jtab.

    ENDLOOP.

    LOOP AT jtab.

    WRITE:/ jtab-matnr.

    ENDLOOP.

    <b>reward if helpful</b>

    rgds,

    bharat.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 22, 2007 at 11:51 AM

    Follow this sample program.

    REPORT DEMO.

    DATA: SUM TYPE I, CNT TYPE I.

    NODES: SPFLI, SFLIGHT, SBOOK.

    DATA: TAB_SPFLI TYPE TABLE OF SPFLI,

    TAB_SFLIGHT TYPE TABLE OF SFLIGHT,

    TAB_SBOOK TYPE TABLE OF SBOOK.

    DATA: WA_SPFLI LIKE LINE OF TAB_SPFLI,

    WA_SFLIGHT LIKE LINE OF TAB_SFLIGHT,

    WA_SBOOK LIKE LINE OF TAB_SBOOK.

    START-OF-SELECTION.

    GET SPFLI.

    APPEND SPFLI TO TAB_SPFLI.

    GET SFLIGHT.

    APPEND SFLIGHT TO TAB_SFLIGHT.

    GET SBOOK.

    APPEND SBOOK TO TAB_SBOOK.

    END-OF-SELECTION.

    SORT: TAB_SPFLI BY CITYFROM CITYTO CONNID,

    TAB_SFLIGHT BY FLDATE,

    TAB_SBOOK BY CLASS SMOKER BOOKID.

    LOOP AT TAB_SPFLI INTO WA_SPFLI.

    SKIP.

    WRITE: / WA_SPFLI-CARRID,

    WA_SPFLI-CONNID,

    'from', (15) WA_SPFLI-CITYFROM,

    'to', (15) WA_SPFLI-CITYTO.

    ULINE.

    LOOP AT TAB_SFLIGHT INTO WA_SFLIGHT

    WHERE CARRID = WA_SPFLI-CARRID

    AND CONNID = WA_SPFLI-CONNID.

    SKIP.

    WRITE: / 'Date:', WA_SFLIGHT-FLDATE.

    WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'.

    ULINE.

    SUM = 0.

    CNT = 0.

    LOOP AT TAB_SBOOK INTO WA_SBOOK

    WHERE CARRID = WA_SFLIGHT-CARRID

    AND CONNID = WA_SFLIGHT-CONNID

    AND FLDATE = WA_SFLIGHT-FLDATE.

    WRITE: / WA_SBOOK-BOOKID UNDER 'Book-ID',

    WA_SBOOK-SMOKER UNDER 'Smoker',

    WA_SBOOK-CLASS UNDER 'Class'.

    SUM = SUM + WA_SBOOK-LUGGWEIGHT.

    CNT = CNT + 1.

    ENDLOOP.

    ULINE.

    WRITE: 'Number of bookings: ', (3) CNT,

    / 'Total luggage weight:',

    (3) SUM, WA_SBOOK-WUNIT.

    ENDLOOP.

    ENDLOOP.

    and also this one

    REPORT DEMO.

    DATA: SUM TYPE I, CNT TYPE I.

    NODES: SPFLI, SFLIGHT, SBOOK.

    DATA: BEGIN OF WA_SBOOK,

    BOOKID TYPE SBOOK-BOOKID,

    SMOKER TYPE SBOOK-SMOKER,

    CLASS TYPE SBOOK-CLASS,

    LUGGWEIGHT TYPE SBOOK-LUGGWEIGHT,

    WUNIT TYPE SBOOK-WUNIT,

    END OF WA_SBOOK.

    DATA: BEGIN OF WA_SFLIGHT,

    FLDATE TYPE SFLIGHT-FLDATE,

    SBOOK LIKE TABLE OF WA_SBOOK ,

    END OF WA_SFLIGHT.

    DATA: BEGIN OF WA_SPFLI,

    CARRID TYPE SPFLI-CARRID,

    CONNID TYPE SPFLI-CONNID,

    CITYFROM TYPE SPFLI-CITYFROM,

    CITYTO TYPE SPFLI-CITYTO,

    SFLIGHT LIKE TABLE OF WA_SFLIGHT ,

    END OF WA_SPFLI.

    DATA TAB_SPFLI LIKE TABLE OF WA_SPFLI .

    START-OF-SELECTION.

    GET SPFLI.

    REFRESH WA_SPFLI-SFLIGHT.

    GET SFLIGHT.

    REFRESH WA_SFLIGHT-SBOOK.

    GET SBOOK.

    MOVE-CORRESPONDING SBOOK TO WA_SBOOK.

    APPEND WA_SBOOK TO WA_SFLIGHT-SBOOK.

    GET SFLIGHT LATE.

    MOVE-CORRESPONDING SFLIGHT TO WA_SFLIGHT.

    APPEND WA_SFLIGHT TO WA_SPFLI-SFLIGHT.

    GET SPFLI LATE.

    MOVE-CORRESPONDING SPFLI TO WA_SPFLI.

    APPEND WA_SPFLI TO TAB_SPFLI.

    END-OF-SELECTION.

    SORT TAB_SPFLI BY CITYFROM CITYTO CONNID.

    LOOP AT TAB_SPFLI INTO WA_SPFLI.

    SKIP.

    WRITE: / WA_SPFLI-CARRID,

    WA_SPFLI-CONNID,

    'from', (15) WA_SPFLI-CITYFROM,

    'to', (15) WA_SPFLI-CITYTO.

    ULINE.

    SORT WA_SPFLI-SFLIGHT BY FLDATE.

    LOOP AT WA_SPFLI-SFLIGHT INTO WA_SFLIGHT.

    SKIP.

    WRITE: / 'Date:', WA_SFLIGHT-FLDATE.

    WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'.

    ULINE.

    SORT WA_SFLIGHT-SBOOK BY CLASS SMOKER BOOKID.

    SUM = 0.

    CNT = 0.

    LOOP AT WA_SFLIGHT-SBOOK INTO WA_SBOOK.

    WRITE: / WA_SBOOK-BOOKID UNDER 'Book-ID',

    WA_SBOOK-SMOKER UNDER 'Smoker',

    WA_SBOOK-CLASS UNDER 'Class'.

    SUM = SUM + WA_SBOOK-LUGGWEIGHT.

    CNT = CNT + 1.

    ENDLOOP.

    ULINE.

    WRITE: 'Number of bookings: ', (3) CNT,

    / 'Total luggage weight:',

    (3) SUM, WA_SBOOK-WUNIT.

    ENDLOOP.

    ENDLOOP.

    regards,

    srinivas

    <b>*reward for useful answers*</b>

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 22, 2007 at 11:54 AM

    Hi,

    You can do as below, if you have document number in the select-opions in the selection screen.

    And itab has the data and if you need to move the values based on the documents numbers present in the internal table and select-options.

    loop at itab.

    read table so_belnr with key low = itab-belnr.

    if sy-subrc eq 0.

    move : -


    endif.

    endloop.

    Thanks,

    Sriram Ponna.

    Message was edited by:

    Sriram Ponna

    Add comment
    10|10000 characters needed characters exceeded