Internal table logic - help required

Hi,
I am working on BSEG table to determine offsetting line count and amount total for a posting line item and need
a small logic .
I have a table of currency fields like below and the table is such ( like BSEG ) that each line item will balance
itself with other line item . For example
Item
10      100
20      100-
30      200
40      250
50      450-
60      200-
70      200
80      600
90      100
100     200
110     300
If you see 10 & 20 balance out similarly ( 30,40 will balance with line item 50 ) , ( 60 & 70 balance each other ) ,
( 90,100, 110 balance with 80 ).
My requirement - If I loop on item 50 with amount 450- I need to get the posnr of the two items which balance
this amount ( which is 30 and 40 ).  If I loop on item 80 with amount 600 then I need to get item 90. 100 and 110.
Please provide me a logic which will provide me the index of ther required item lines.
Regards
Praneeth

Hi, execute this code.. might be helpful to you
TYPES: BEGIN OF test,
         a TYPE i,
         b TYPE i,
       END OF test.
DATA: itab TYPE TABLE OF test,
       wa  TYPE test,
       wa1 TYPE test,
       c   TYPE i,
       d   TYPE i,
       n1  TYPE i,
       n2  TYPE i.
PARAMETERS :  p TYPE i.
wa-a = 1.
wa-b = 20.
APPEND wa TO itab.
wa-a = 2.
wa-b = 30.
APPEND wa TO itab.
wa-a = 3.
wa-b = 10.
APPEND wa TO itab.
wa-a = 4.
wa-b = 10.
APPEND wa TO itab.
wa-a = 5.
wa-b = 20.
APPEND wa TO itab.
READ TABLE itab INTO wa WITH KEY a = p.
c = wa-b.
LOOP AT itab INTO wa WHERE a GT p.
   n1 = wa-a.
   IF c EQ wa-b.
     EXIT.
   ENDIF.
   LOOP AT itab INTO wa1 WHERE a GT wa-a.
     IF wa-a = wa1-a.
       EXIT.
     ENDIF.
     n2 = wa1-a.
     d  = wa-b + wa1-b.
     IF c EQ d.
       EXIT.
     ENDIF.
   ENDLOOP.
   IF wa-a = wa1-a.
     EXIT.
   ELSEIF c EQ d.
     EXIT.
   ELSE.
     CLEAR: n1, n2.
   ENDIF.
ENDLOOP.
WRITE: n1 , n2.

Similar Messages

  • Internal Table Operation Help Required

    Hi
    I have to insert 8 counters p1-p8 in a field BANFN of ITAB1.
    Like this their are 3 more fileds.I have to show the no. for PR released frm JAN-DEC in ALV format.I had doen the calualation,but unable to insert these conters in ITAB1 to do final calculation & display the result.
    Please help me.
    I had used : insert p1 into itab1-banfn where sy-index 1.
    Like this I had tried out many comands,but al in vain.PLZ help me in this regard.
    Regards.
    Vipin

    There are 8 fileds in my internal table,in which 1st one is for MONTH(JAN-DEC).
    The ALV is only suppose to display 12 rows,containing each month per row.
    Now for each month I have to display the PR converted to PO & the avg lead time for each month.So I had calu all the data ,but now I have to insert 12 counters in 4 fields.one for No of PR converted to PO in each month,than one for AVG LEAD TIME for each month.so there has to be 12 + 12 counters for each row.Similar operation I have to perform for the PR pending fo PO.So there has to be 24 more counters for again 2 diff fileds.Now I had calcuated the data,but the problem is this ,,,,,how to insert each ctr in each row.
    EG: insert ctr1 into itab1-banfn where itab1-mmyy = 'January' or sy-index = 1.
          insert ctr2 into itab1-banfn where itab1-mmyy = 'Febuary' or sy-index = 2.
          move crt1 to itab1-banfn where sy-index = 1.
    None of the operation is working.
    Like this i have to insert 48 counters in all rows for these 4 diff fileds.
    Pl help me in thsi regard ,if possible.
    regards.

  • Error on extend an internal table, but the required space was not available

    Hi All,
    I am trying to retrieve cost data from COVP tables, as well as the quantity, cost centre, and price unit fields from MSEG / BSEG tables. Thing is, if the AWTYP value in COVP table = 'MKPF', i have to get the data from MSEG, otherwise, I need to get it from BSEG table.
    I kept getting this error message:
    <i>You attempted to extend an internal table, but the required space was not available.</i>
    Anyone have any idea how to make my codes more efficient?
    Please help. Thanks!
    Regards,
    Cecilia
    REPORT  ZMISCY004.
    TABLES : COVP, BSIS, BSEG, MSEG, MAKT, CSKU.
    PARAMETERS :
    P_FILE(300) DEFAULT '\sapdcdatasaprptoh.txt' LOWER CASE.
    DATA MSG_TEXT(50).
    DATA :
    XKOKRS LIKE COVP-KOKRS,
    XBELNR LIKE COVP-BELNR,
    XBUZEI LIKE COVP-BUZEI,
    XGJAHR LIKE COVP-GJAHR,
    XPERIO LIKE COVP-PERIO,
    XWKGBTR LIKE COVP-WKGBTR,
    XWTGBTR LIKE COVP-WTGBTR,
    XREFBN LIKE COVP-REFBN,
    XREFBZ LIKE COVP-REFBZ,
    XKSTAR LIKE COVP-KSTAR,
    XBEKNZ LIKE COVP-BEKNZ,
    XMATNR LIKE COVP-MATNR,
    XBUKRS LIKE COVP-BUKRS,
    XREFGJ LIKE COVP-REFGJ,
    XREFBK LIKE COVP-REFBK,
    XLTEXT LIKE CSKU-LTEXT,
    XMAKTX LIKE MAKT-MAKTX,
    XAWTYP LIKE COVP-AWTYP,
    XTWAER LIKE COVP-TWAER,
    XSGTXT LIKE COVP-SGTXT,
    BSEG_KOSTL LIKE BSEG-KOSTL,
    BSEG_MEINS LIKE BSEG-MEINS,
    BSEG_MENGE LIKE BSEG-MENGE,
    MSEG_KOSTL LIKE MSEG-KOSTL,
    MSEG_MENGE LIKE MSEG-MENGE,
    MSEG_MEINS LIKE MSEG-MEINS.
    DATA : BEGIN OF ITAB_COVP OCCURS 10,
    KOKRS LIKE COVP-KOKRS,
    BELNR LIKE COVP-BELNR,
    BUZEI LIKE COVP-BUZEI,
    GJAHR LIKE COVP-GJAHR,
    PERIO LIKE COVP-PERIO,
    WKGBTR(15) TYPE C,
    WTGBTR(15) TYPE C,
    REFBN LIKE COVP-REFBN,
    REFBZ(3) TYPE C,
    KSTAR LIKE COVP-KSTAR,
    BEKNZ LIKE COVP-BEKNZ,
    MATNR LIKE COVP-MATNR,
    BUKRS LIKE COVP-BUKRS,
    REFGJ LIKE COVP-REFGJ,
    REFBK LIKE COVP-REFBK,
    LTEXT LIKE CSKU-LTEXT,
    MAKTX LIKE MAKT-MAKTX,
    AWTYP LIKE COVP-AWTYP,
    TWAER LIKE COVP-TWAER,
    SGTXT LIKE COVP-SGTXT,
    BSIS_WRBTR(13) TYPE C,
    BSEG_KOSTL LIKE BSEG-KOSTL,
    BSEG_MEINS LIKE BSEG-MEINS,
    BSEG_MENGE LIKE BSEG-MENGE,
    MSEG_KOSTL LIKE MSEG-KOSTL,
    MSEG_MENGE LIKE MSEG-MENGE,
    MSEG_MEINS LIKE MSEG-MEINS.
    DATA : END OF ITAB_COVP.
    SELECT M1~KOKRS
           M1~BELNR
           M1~BUZEI
           M1~GJAHR
           M1~PERIO
           M1~WKGBTR
           M1~WTGBTR
           M1~REFBN
           M1~REFBZ
           M1~KSTAR
           M1~BEKNZ
           M1~MATNR
           M1~BUKRS
           M1~REFGJ
           M1~REFBK
           M1~AWTYP
           M1~TWAER
           M1~SGTXT
           M4~KOSTL
           M4~MENGE
           M4~MEINS
    INTO (XKOKRS,
          XBELNR,
          XBUZEI,
          XGJAHR,
          XPERIO,
          XWKGBTR,
          XWTGBTR,
          XREFBN,
          XREFBZ,
          XKSTAR,
          XBEKNZ,
          XMATNR,
          XBUKRS,
          XREFGJ,
          XREFBK,
          XAWTYP,
          XTWAER,
          XSGTXT,
          MSEG_KOSTL,
          MSEG_MENGE,
          MSEG_MEINS
    FROM COVP AS M1
    LEFT OUTER JOIN MSEG AS M4
    ON M1~REFBN = M4~MBLNR AND M1~REFBZ = M4~ZEILE AND M1~REFGJ = M4~MJAHR
    WHERE M1~SCOPE = 'OCOST' AND M1~AWTYP = 'BKPF'
      OR M1~SCOPE = 'OCOST' AND M1~AWTYP = 'MKPF'
      OR M1~KSTAR = '972022'.
    IF XAWTYP = 'BKPF'.
    SELECT KOSTL MENGE MEINS INTO (BSEG_KOSTL, BSEG_MENGE, BSEG_MEINS) FROM
    BSEG WHERE BELNR = XREFBN AND BUZEI = XREFBZ AND GJAHR = XREFGJ AND
    BUKRS = XREFBK.
    ENDSELECT.
    MOVE BSEG-KOSTL TO BSEG_KOSTL.
    MOVE BSEG-MEINS TO BSEG_MEINS.
    MOVE BSEG-MENGE TO BSEG_MENGE.
    ELSE.
    MOVE ' ' TO BSEG_KOSTL.
    MOVE ' ' TO BSEG_MEINS.
    MOVE ' ' TO BSEG_MENGE.
    ENDIF.
    *GET LTEST
    SELECT LTEXT INTO XLTEXT
    FROM CSKU
    WHERE KTOPL = 'COAA' AND SPRAS = 'EN'.
    *GET MAKTX
    IF XMATNR <> ' '.
    SELECT SINGLE * FROM MAKT WHERE MATNR = XMATNR.
    MOVE MAKT-MAKTX TO XMAKTX.
    ELSE.
    MOVE ' ' TO XMAKTX.
    ENDIF.
    MOVE : XKOKRS TO ITAB_COVP-KOKRS,
           XBELNR TO ITAB_COVP-BELNR,
           XBUZEI TO ITAB_COVP-BUZEI,
           XGJAHR TO ITAB_COVP-GJAHR,
           XPERIO TO ITAB_COVP-PERIO,
           XWKGBTR TO ITAB_COVP-WKGBTR,
           XWTGBTR TO ITAB_COVP-WTGBTR,
           XREFBN TO ITAB_COVP-REFBN,
           XREFBZ TO ITAB_COVP-REFBZ,
           XKSTAR TO ITAB_COVP-KSTAR,
           XBEKNZ TO ITAB_COVP-BEKNZ,
           XMATNR TO ITAB_COVP-MATNR,
           XBUKRS TO ITAB_COVP-BUKRS,
           XREFGJ TO ITAB_COVP-REFGJ,
           XREFBK TO ITAB_COVP-REFBK,
           XLTEXT TO ITAB_COVP-LTEXT,
           XMAKTX TO ITAB_COVP-MAKTX,
           XAWTYP TO ITAB_COVP-AWTYP,
           XTWAER TO ITAB_COVP-TWAER,
           XSGTXT TO ITAB_COVP-SGTXT,
           BSEG_KOSTL TO ITAB_COVP-BSEG_KOSTL,
           BSEG_MEINS TO ITAB_COVP-BSEG_MEINS,
           BSEG_MENGE TO ITAB_COVP-BSEG_MENGE,
           MSEG_KOSTL TO ITAB_COVP-MSEG_KOSTL,
           MSEG_MENGE TO ITAB_COVP-MSEG_MENGE,
           MSEG_MEINS TO ITAB_COVP-MSEG_MEINS.
    APPEND ITAB_COVP.
    CLEAR ITAB_COVP.
    ENDSELECT.
    ENDSELECT.
    OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE.
    IF SY-SUBRC NE 0.
       WRITE: 'File cannot be opened. Reason:', MSG_TEXT.
       EXIT.
    ENDIF.
    LOOP AT ITAB_COVP.
    TRANSFER ITAB_COVP TO P_FILE.
    ENDLOOP.
    CLOSE DATASET P_FILE.

    Cecilia - I think your problemn is a nested select:
    *GET LTEST
      SELECT ltext INTO xltext
      FROM csku
      WHERE ktopl = 'COAA' AND spras = 'EN'.
    *GET MAKTX
        IF xmatnr <> ' '.
          SELECT SINGLE * FROM makt WHERE matnr = xmatnr.
          MOVE makt-maktx TO xmaktx.
        ELSE.
          MOVE ' ' TO xmaktx.
        ENDIF.
        MOVE : xkokrs TO itab_covp-kokrs,
                     etc.
              mseg_meins TO itab_covp-mseg_meins.
        APPEND itab_covp.
        CLEAR itab_covp.
      ENDSELECT.
    Do you need to do the inner select for every cost element text?
    Rob

  • Internal table logic required

    Hi ,
    I have two internal tables having with different structures . Finally I need to pass data to final internal table.
    In runtime we have data in only one table.  The final internal table should take either internal1, or internal table 2.
    it_final_data[] = it_first_data[].
    or
    it_final_data[] = it_sec_data[].
    i have to one generic include , it will understands the IT_final_data internal table only.
    please help me.
    regards,
    Ajay

    Hi Ajay,
         Build your final internal table with all the fields from first and second internal table. Use the below logic to move the data to the final internal table depending on the internal table data which you want to display.
    IF not it_first_data[] is initial.
      loop at it_first_data.
        move-corresponding it_frist_data to it_final_data.
        append it_final_data.
    endloop.
    else.
       loop at it_second_data.
        move-corresponding it_second_data to it_final_data.
        append it_final_data.
      endloop.
    endif.
    Hope this works for you.
    Regards,
    Jayaram

  • Internal table logic issue

    Hi All,
    I have one logical issue related to internal table manipulation.
    I have one internal table :
    I_DAT - This is related to Loading/Unloading of Goods.
    for example with 3 fields
    VSTEL, KUNNA, KMMANG.
    Now suppose my data looks like this after sorting:
    VSTEL   KUNNA    KMMANG
    100       -        -
    200       -        -
    300       -        -
    400       -        -
    -         500      X
    -         600      X
    -         700      X
    -         800      X
    Here 100,200,300,400 are Loading points.
    ANd 500,600,700,800 are unloading points.
    Now what i want is For loading & Unloading points i need to pick up Address and print one after other.
    But how they need to print is:
    FOR INITIAL LOADING OF
    ADDRESS- For 100
    FIRST STOP: FOR LOADING OF
    ADDRESS- For 200
    SECOND STOP: FOR LOADING OF
    ADDRESS- For 300
    Etc .....
    Then
    FOR UNLOADING OF:
    ADDRESS- For 400
    FIRST STOP: FOR UNLOADING OF
    etc.
    FINAL STOP: FOR FINAL UNLOADING OF
    We might get as many records :
    Can any body give me the logic:
    Printing Address is not a problem:
    But Above every address we need to print FIRST STOP, SECOND etc like that.
    For this i need logic.
    Can anybody give the solution!
    Thanks in advance.
    Thanks & Regards,
    Prasad.

    Try this.I think you want output like this......
    DATA: BEGIN OF LINE,
            CARRID   TYPE SBOOK-CARRID,
            CONNID   TYPE SBOOK-CONNID,
            FLDATE   TYPE SBOOK-FLDATE,
            CUSTTYPE TYPE SBOOK-CUSTTYPE,
            CLASS    TYPE SBOOK-CLASS,
            BOOKID   TYPE SBOOK-BOOKID,
          END OF LINE.
    DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY TABLE LINE.
    SELECT CARRID CONNID FLDATE CUSTTYPE CLASS BOOKID
           FROM SBOOK INTO CORRESPONDING FIELDS OF TABLE ITAB.
    LOOP AT ITAB INTO LINE.
      AT FIRST.
        WRITE / 'List of Bookings'.
        ULINE.
      ENDAT.
        AT NEW CARRID.
          WRITE: / 'Carrid:', LINE-CARRID.
        ENDAT.
          AT NEW CONNID.
            WRITE: / 'Connid:', LINE-CONNID.
          ENDAT.
            AT NEW FLDATE.
              WRITE: / 'Fldate:', LINE-FLDATE.
            ENDAT.
              AT NEW CUSTTYPE.
                WRITE: / 'Custtype:', LINE-CUSTTYPE.
              ENDAT.
                   WRITE: / LINE-BOOKID, LINE-CLASS.
                AT END OF CLASS.
                  ULINE.
                ENDAT.
    ENDLOOP.
    This is also helpful......
    LOOP AT <itab>.
      AT FIRST. ... ENDAT.
        AT NEW <f1>. ...... ENDAT.
          AT NEW <f2 >. ...... ENDAT.
              <single line processing>
          AT END OF <f2>. ... ENDAT.
        AT END OF <f1>. ... ENDAT.
      AT LAST. .... ENDAT.
    ENDLOOP.
    Regards
    Abhishek

  • Internal table logic

    Hi,
    I have a scenario that I am trying to work on:
    I have three internal tables itab1 itab2 and itab3, all three internal tables have same fields in them but might be different values:
    All the internal tables have three rows of data and in each row there are five fields VAL1 VAL2 VAL3 VAL4 VAL5.The requirement is I need to compare all these three tables as below:
    Compare all the fields of itab1 with itab2, if they are same then skip and if not then compare each field of itab1 to itab3, if they are same then skip and if not replace the value of itab1 field (which is different with the one on itab3)with the itab3 field value.
    can you please help me with this?
    Moderator message : Requirements dumping not allowed, show the work you have already done.  Thread locked.
    Edited by: Vinod Kumar on Mar 9, 2012 7:37 PM

    Hi Vijay,
    I started writing the code as below:
    loop at itab1 into wa_itab1.
      READ TABLE itab2 INDEX sy-index into waA_itab2.
      READ TABLE itab3 INDEX sy-index into wa_itab3.
    if wa_itab1-val1 = wa_itab2-val1.
    skip.
    else.
    if_wa_tab1-val1 = wa_itab3-val1.
    skip.
    else.
    wa_tab1-val1 = wa_itab3-val1.
    endif.
    endif.
    if wa_itab2-val1 = wa_itab2-val2.
    skip.
    else.
    if_wa_tab2-val1 = wa_itab3-val2.
    skip.
    else.
    wa_tab1-val2 = wa_itab3-val2.
    endif.
    endif.
    if wa_itab1-val3 = wa_itab2-val3.
    skip.
    else.
    if_wa_tab1-val3 = wa_itab3-val3.
    skip.
    else.
    wa_tab1-val3 = wa_itab3-val3.
    endif.
    endif.
    if wa_itab1-val4 = wa_itab2-val4.
    skip.
    else.
    if_wa_tab1-va4l = wa_itab3-val4.
    skip.
    else.
    wa_tab1-val4 = wa_itab3-val4.
    endif.
    endif.
    ENDLOOP.
    but I am not sure if whatever I have written is correct.

  • Internal Table Logic Needed

    Hi all,
    I have a requirement regarding data processing in a internal table,
    internal table consists of filelds Vendor,Material and Scheduling Dates and Total Qty.
    Here i need to fill the field Total Quantity, individual addition of quanties of that material for a particular vendor .
    Let us consider intitially my internal table consists of data like this with these fields.
                      Vendor ,           Material  ,            qty(individual),   Total qty   ,  Schedule dates
                       v1        ,           m1       ,                 10          
                       v1        ,           m1        ,                10
                       v1       ,             m1       ,                  20
                       v1       ,              m2      ,                    5
                       v1       ,             m2        ,                 10
                       v2        ,            m2         ,                20
                      v2        ,             m2        ,                  15
                      v2        ,            m3         ,                  20
                      v2        ,            m3           ,                10
        Initiall the total qty field is empty i need to fill tht field for the last item for a particular material Like M1
      for vendor v1 and total qty of m2 for vendor v1, total qty of m1 for v2, total qty of m2 for v2 and so on.
    Requied output should be like this.
                     Vendor     ,          Material       ,    qty(individual)            Total qty   Schedule dates
                      v1         ,                m1         ,         10           ,               0        
                       v1          ,              m1          ,        10           ,                 0
                       v1         ,                m1         ,         20          ,                40(101020)
                       v1        ,                 m2          ,         5           ,               0
                       v1          ,               m2           ,      10            ,              15(5+10)
                       v2          ,               m2          ,        20            ,             0    
                       v2          ,               m2           ,       15             ,              35(20+15)
                      v2           ,              m3          ,        20              ,             0
                      v2            ,              m3           ,       10              ,           30(20+10)
    Here i made one thing , i calculated the total qty of material for particular vendor.
    Like              
             Vendor                           Material                     Total Qty      
                     v1        ,                        m1            ,             40
                     v1        ,                       m2              ,            15
                     v2         ,                     m2                ,           35
                     v2          ,                    m3                 ,           30
    Finally i need the logic by using Control Events(At New   , At End of )  to adjust that total qty of a material for a particular vendor by Modifying the internal table.
    i hope my problem is clear , pls let me know if any clarifications needed. and
    code for the same .
    Thannks in advance,
    Niranjan.

    Hi,
    Solution is here.
    sort itab by vendor material.
    field-symbols: <itab> like line of itab.
    loop at itab assigning <itab>.
    on change of vendor.
    clear flag.
    endon.
    add <itab>-quanity to lw_quantiy.
    *--here pdate internal table end of each similar kind of record
    at end of.
    flag = 'x'.
    <itab>-totalqty =  lw_quantiy.
    clear  lw_quantiy
    endat.
    *--rest of record update zero by checking flag
    if flag is initial.
    <itab>-totalqty = 0.
    endif.
    endloop.
    close this thread if you got solution.
    Regards,
    Peranandam

  • Doubts in internal table logic

    Hi All,
    I have two internal table, according to the posnr value i need to add the kbetr value from the 2nd internal table and update the value in the 1st line internal table. below the example of my internal table. Here for the line item 0010 i need to calculate 10.0030.1011.00 and i need to add the value inthe 1st internal table kbeter_value. can anyone help this?
    POSNR        MATNR kbetr_value
    0010             abc
    0020             xyz
    0030             123
    POSNR     KBETR
    0010       10.00
    0010        30.10
    0010       11.00
    0010       60.30
    0020       12.64
    0020       11.32
    0030       79.46
    0030       00.00
    0030       45.3     
    by
    Mohana

    Hi Mohana,
    Its very simple ..you can do it in many ways....
    first one is in the second internal table use collect ....
    for example : 1st internal table is itab and the second is jtab .
    1. In jtab u use collect stmt to calculate the posnr values .
    loop at jtab.
      collect jtab .           " by using this u will have  0010    111.40 in jtab
    endloop.
    structure of jtab will be :
    0010    111.40
    0020    .........
    0030    ..........
    2. afterwards while printing you can use read to get those :
    loop at itab.
    read table jtab with key posnr = itab-posnr.
    if sy-subrc = 0.
    itab-ksbtr-value = itab-value .
    modify itab .
    endif.
    endloop.
    Hope you got it by now...if you any problem do reply back ....
    cheers,
    Vishnu .

  • Reg. internal table logic

    Hi,
    I have an internal table with 5 fields (Vbeln, A, B, C, D ) and records like this:
    Record1:
    Field vbeln (value is  6000000001), Field A (value is 2006), Field B (value is 1130), Field C (value is initial), Field D (value is initial)
    Record1:
    Field vbeln (value is  6000000001), Field A (value is initial), Field B (value is initial), Field C (value is 2005), Field D (value is 1134)
    Now whenever, Field A and Field B has values, field C and field D are initial and vice versa.
    I Want to get all of the field values in just one record like below when the key vbeln is same.:
    Field vbeln (value is  6000000001), Field A (value is 2006), Field B (value is 1130), Field C (value is 2005), Field D (value is 1134)
    I know I can create another internal table, copy the contents, use the looping logic and achieve the same but wondering if there is any better way of doing the same?
    Appreciate your input.
    Thanks!

    Hi,
    You need another internal tables. Please try this.
    SORT ITAB1.
    ITAB2[] = ITAB1[].
    LOOP AT ITAB1.
      LOOP AT ITAB2 WHERE ITAB2-VBELN EQ ITAB1-VBELN
                      AND ITAB2-DATE1 NE ITAB1-DATE1
                      AND ITAB2-TIME1 NE ITAB1-TIME1.
        ITAB3-VBELN = ITAB1-VBELN.
        ITAB3-DATE1 = ITAB1-DATE1.
        ITAB3-TIME1 = ITAB1-TIME1.
        ITAB3-DATE2 = ITAB2-DATE2.
        ITAB3-TIME2 = ITAB2-TIME2.
        APPEND ITAB3.
      ENDLOOP.
    ENDLOOP.
    Regards,
    Ferry Lianto

  • Regarding Internal table logic

    Hi,
    I have my internal table as follows:
    DATA: BEGIN OF I_DATA OCCURS 0,
            prgname TYPE SYST-REPID,
            matnr   TYPE mara-matnr,
            berid   TYPE mdma-berid,
          END OF I_DATA.
    Data that fills into can be as follows:
    Ex:
    PROGRAM1,1000,MRP1
    PROGRAM1,1000,MRP1
    PROGRAM1,2000,MRP1
    PROGRAM2,1000,MRP1
    PROGRAM2,1000,MRP1
    PROGRAM2,2000,MRP1
    PROGRAM3,1000,MRP1
    PROGRAM3,1000,MRP1
    PROGRAM3,2000,MRP1
    It can any order in above way.
    Then i will sort the above data as follows:
    SORT I_DATA BY prgname matnr berid.
    Now here my issue is:
    DATA: t_objtxt     LIKE solisti1   OCCURS 0  WITH HEADER LINE.
    I need to push the above internal table data into T_OBJTXT internal table as follows:
    It should first Display program Name as Program Name: Program3, Then column heading MATNR, BERID below it and data of that program[1st] below them till all the 1st program's data finished. Whenever MATNR value changes in this program list i need to print an ***** like line. TO indicate all the materials printed.
    When 2nd program comes again i have to write Program Name: Program2, Then column heading MATNR, BERID below it and data of that program[1st] below them till all the 1st program's data finished. Whenever MATNR value changes in this program list i need to print an ***** like line. TO indicate all the materials printed.
    When 3nd program comes again i have to write Program Name: Program3, Then column heading MATNR, BERID below it and data of that program[1st] below them till all the 1st program's data finished. Whenever MATNR value changes in this program list i need to print an ***** like line. TO indicate all the materials printed.
    Etc. Same process we need to follow.
    The final out put should be as below:
    PROGRAM NAME : PROGRAM1
    MATNR, BERID
    1000,MRP!
    1000,MRP1
    2000,MRP1
    PROGRAM NAME : PROGRAM2
    MATNR, BERID
    1000,MRP!
    1000,MRP1
    2000,MRP1
    PROGRAM NAME : PROGRAM3
    MATNR, BERID
    1000,MRP!
    1000,MRP1
    2000,MRP1
    Like wise o/p need to be send to I_OBJTXT and to email.
    <b>The logic i have written is as follows:</b>
      LOOP AT I__DATA.
        AT NEW PRGNAME.
          MOVE '*****************************************' TO t_objtxt-line.
          APPEND t_objtxt.
          CLEAR t_objtxt.
          CONCATENATE t_objtxt-line 'PROGRAM NAME : '
                      I_DATA-PRGNAME
                      INTO t_objtxt-line.
          APPEND t_objtxt.
          CLEAR t_objtxt.
          MOVE '*****************************************' TO t_objtxt-line.
          APPEND t_objtxt.
          CLEAR t_objtxt.
          CONCATENATE TEXT-024 " Material
                      TEXT-025              " MRP
                      INTO t_objtxt-line
                      SEPARATED BY C_COMMA.
          APPEND t_objtxt.
          CLEAR t_objtxt.
          MOVE '-----------------------------------------' TO t_objtxt-line.
          CONCATENATE t_objtxt-line '------------------' INTO t_objtxt-line.
          APPEND t_objtxt.
          CLEAR t_objtxt.
        ENDAT.
    *    MOVE '' TO t_objtxt-line.
    *    APPEND t_objtxt.
    *    CLEAR t_objtxt.
        CONCATENATE I_DATA-MATNR
                    I_DATA-BERID
                    INTO t_objtxt-line
                    SEPARATED BY C_COMMA.
        APPEND t_objtxt.
        CLEAR t_objtxt.
        AT END OF MATNR.
          MOVE '' TO t_objtxt-line.
          APPEND t_objtxt.
          CLEAR t_objtxt.
          MOVE '*****************************************' TO t_objtxt-line.
          CONCATENATE t_objtxt-line '******************' INTO t_objtxt-line.
          CONCATENATE t_objtxt-line '******************' INTO t_objtxt-line.
          APPEND t_objtxt.
          CLEAR t_objtxt.
        ENDAT.
      ENDLOOP.
    The above logic is not working correctly.
    Can anybody give me correct logic for the same.
    Thanks in advance.
    Thanks,
    Deep.

    Can you paste the total code.
    santhosh

  • Internal table -Logic-Data manipulation

    Hi,
    I have following requirement.
    Input Internal table
    *A T1   1   3
    *A T2   4   5
    *A T3   1   2
    *B T4   1   2
    *B T5   3   6
    *B T6   1   7
    Output
    *A T1   1     3
    *A T2   4     5
    *B T6   1     7
    basically i should delete overlapping records 
    eg: since A t3 1 2 is overlapping record it should be deleted.
    report x.
    DATA: BEGIN OF ITAB OCCURS 0,
          FLD1  TYPE CHAR20,
          FLD2  type char20,
          NUM1  TYPE I,
          NUM2  TYPE I,
          END   OF ITAB.
    ITAB-FLD1 = 'A'.
    ITAB-FLD2 = 'T1'.
    ITAB-NUM1 = '1'.
    ITAB-NUM2 = '3'.
    APPEND ITAB.
    ITAB-FLD1 = 'A'.
    ITAB-FLD2 = 'T2'.
    ITAB-NUM1 = '4'.
    ITAB-NUM2 = '5'.
    APPEND ITAB.
    ITAB-FLD1 = 'A'.
    ITAB-FLD2 = 'T3'.
    ITAB-NUM1 = '1'.
    ITAB-NUM2 = '2'.
    APPEND ITAB.
    ITAB-FLD1 = 'B'.
    ITAB-FLD2 = 'T4'.
    ITAB-NUM1 = '1'.
    ITAB-NUM2 = '2'.
    APPEND ITAB.
    ITAB-FLD1 = 'B'.
    ITAB-FLD2 = 'T5'.
    ITAB-NUM1 = '3'.
    ITAB-NUM2 = '6'.
    APPEND ITAB.
    ITAB-FLD1 = 'B'.
    ITAB-FLD2 = 'T6'.
    ITAB-NUM1 = '1'.
    ITAB-NUM2 = '7'.
    APPEND ITAB.
    LOOP At ITAB.
    ENDLOOP.

    Hi Praveen,
    You have to SORT the internal table ITAB by a field of your requirement. Then DELETE adjacent entries in the internal table by comparing the field of interest.
    SORT ITAB BY NUM1 NUM2.
    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING NUM1 NUM2.
    After doing this you can perform the required actions on ITAB.
    Hope this has cleared your doubt.
    Thanks & Regards,
    Ramya Shree.M.R

  • Internal table Logic need

    Hi ,
    I have one Internal table it_marc contains the MATNR
    and one more final internal table it_final. I want to read the all MATNR from IT_FINAL by using IT_MARC which contains the same MATNR. I mean all the MATNRs even dupliacates also.
    regards,
    Ajay

    Hi,
    Use For all entries.
    Select matnr from it_marc
                        into corresponding fields of  table it_final
                        for all entries in it_marc[]
                        where matnr = it_marc[]-matnr.
    Please give me ur need exactly, so that we can better understand ur que.
    Reward if Helpful.
    Jagadish.

  • Convert Columns into Rows (internal tables) - Urgent Help Pleasse..

    Hi friends i'm having a little problem and hope you can help me..Here's the situation.
    I have an internal table like shown below
    (Key)                   (Key)               (Key)          (Key)
    PATH_ID     |      GROUP     |      LINE     |     ATRIBUTE          |    VALUE
    ASLN2                1                      1                Company_Code       5146
    ASLN2                1                      1                Account_Code        400405
    ASLN2                1                      1                Profit_Centre          AA00N2
    ASLN2                1                      2                Company_Code       5146
    ASLN2                1                      2                Account_Code       400705
    ASLN2                1                      2                Profit_Centre          AA00N2
    ASLN3                1                      1                Company_Code       5146
    ASLN3                1                      1                Account_Code        400405
    ASLN3                1                      1                Profit_Centre          AA00N2
    ASLN3                1                      2                Company_Code       5146
    ASLN3                1                      2                Account_Code       400705
    ASLN3                1                      2                Profit_Centre          AA00N2
    and i want to convert this internal table to one like below
    PATH_ID      |      GROUP      |      LINE     |      Company Code   |    Account Code    |    Profit Centre
    ASLN2                1                      1                 5146                     400405                   AA00N2
    ASLN2                1                      2                 5146                     400705                   AA00N2
    ASLN3                1                      1                 5146                     400405                   AA00N2
    ASLN3                1                      2                 5146                     400705                   AA00N2
    but i'm a bit of stuck, all those key fields are making me confused...anyone have a marvelous ( ) idea of how to implement this transformation ?
    best regards,
    Ricardo Monteiro

    Itab1 with the structure PATH_ID | GROUP | LINE | ATRIBUTE | VALUE
    Itab2 with structure PATH_ID | GROUP | LINE | ATRIBUTE | VALUE
    Itab3 with the final structure PATH_ID | GROUP | LINE | Company Code | Account Code | Profit Centre
    move itab1 to itab2.
    sort itab2 by path_id group line.
    delete adjacent duplicates from itab2 comparing path_id group line.
    loop at itab2.
      clear itab3.
      move:
         itab2-pathid to itab3-pathid,
         itab2-group to itab3-group,
         itab2-line to itab3-line.  
      loop at itab1where pathid = itab2-pathid
                            and group = itab2-group
                            and line   = itab2-line.
          IF itab1-ATRIBUTE = ' Company_Code'.
             itab3-Company_Code = itab1-attribute.
          elseif itab1-ATRIBUTE = ' Account_Code '.
             itab3-Account_Code = itab1-attribute.
          elseif itab1-ATRIBUTE = ' Profit_Centre ' .
             itab3-profit_center = itab1-attribute.
          endif
      endloop.
      append itab3.
    endloop.
    try this.
    Thanks,
    rajinikanth

  • Table view help required

    hi,
    I've a htmlb tableview which gets the data from an internal table which is a data member of a model. I've two column fields in this view which are editable. What are the steps I need to follow in order to get the internal table updated with the values provided by the user in the editable fields of tableview.
    could someone please provide me with the steps as to how to achieve this?
    Thanks and Regards,
    Vamshi

    Hi Vamshi,
    Try this  sample code,as it helps you considerably.
    local types
    types: itabtype type TABLE OF STD1.
    types: begin of message_struct,
    type type char10,
    text type char100,
    end of message_struct.
    page attributes
    addtab TYPE ITABTYPE
    addtab_row TYPE STD1
    add_flag TYPE FLAG
    deltab TYPE ITABTYE
    deltab_row TYPE STD1
    ITAB TYPE ITABTYPE
    iterator TYPE REF TO IF_HTMLB_TABLEVIEW_ITERATOR
    message TYPE MESSAGE_STRUCT
    STUDENT TYPE STRING
    STATUS TYPE STRING
    <b>layout</b>
    <htmlb:content design="design2003" >
      <htmlb:page title="test1" >
       <htmlb:form>
    <htmlb:tableView id              = "tv1"
                               visibleRowCount = "20"
                               onRowSelection  = "MyEventRowSelection"
                               selectionMode   = "lineEdit"
                               table           = "<%= ITAB %>"
                               iterator        = "<%=iterator %>" />
                  <htmlb:button id      = "save"
                                text    = "Save Changes"
                                onClick = "myEvent" />
    eventhandler OnCreate
    this handler is called once the page is first created (stateful mode)
    it performs a once-off data initialization or object creation
    SELECT * FROM STD1
                INTO CORRESPONDING FIELDS OF TABLE itab.
    CREATE OBJECT iterator TYPE  STD1ITERATOR.
    eventhandler OnInputProcessing
    event handler for checking and processing user input and
    for defining navigation
    DATA: ITAB_WA type Line of  itabtype.
    DATA: event TYPE REF TO cl_htmlb_event.
    event = cl_htmlb_manager=>get_event( runtime->server->request ).
    FIELD-SYMBOLS: <row> type STD1.
    DATA: tv TYPE REF TO cl_htmlb_tableview.
    tv ?= cl_htmlb_manager=>get_data(
                            request      = runtime->server->request
                            name         = 'tableView'
                            id           = 'tv1' ).
    IF tv IS NOT INITIAL.
      DATA: tv_data TYPE REF TO cl_htmlb_event_tableview.
      tv_data = tv->data.
      IF tv_data->prevselectedrowindex IS NOT INITIAL.
       FIELD-SYMBOLS: <row> type LINE OF ITABTYPE .
        READ TABLE ITAB INDEX tv_data->prevselectedrowindex
        ASSIGNING <row>.
        DATA value TYPE string.
      if <row> is assigned.
        value = tv_data->get_cell_id( row_index    =
                     tv_data->prevselectedrowindex
                                       column_index = '1' ).
         DATA: inputfield TYPE REF TO cl_htmlb_inputfield.
        inputfield ?= cl_htmlb_manager=>get_data(
                                request      = request
                                name         = 'inputfield'
                                id           = value ).
        <row>-STUDENT = inputfield->value.
        value = tv_data->get_cell_id( row_index    =
                     tv_data->prevselectedrowindex
                                       column_index = '2' ).
        inputfield ?= cl_htmlb_manager=>get_data(
                                request      = request
                                name         = 'inputfield'
                                id           = value ).
        <row>-STATUS = inputfield->value.
    ENDIF.
    ENDIF.
    WHEN 'add'.
        tv ?= cl_htmlb_manager=>get_data(
                                  request      = runtime->server->request
                                  name         = 'tableView'
                                  id           = 'tv1' ).
        IF tv IS NOT INITIAL.
          tv_data = tv->data.
          IF tv_data->prevselectedrowindex IS NOT INITIAL.
            READ TABLE itab INDEX tv_data->prevselectedrowindex
             ASSIGNING <row>.
          endif.
        endif.
    WHEN 'add'.
        add_flag = 'Y'.
      WHEN 'add_save'.
    ITAB_WA-STATUS = request->get_form_field( 'STUDENT' ).
    ITAB_WA-STATUS = request->get_form_field( 'STATUS' ).
    endcase.

  • Table Control Help required

    Hi,
    Right now I am working in table control.
    I have an internal table that is getting displayed onto the table control,the internal table has the primary key MATNR in it.
    When the user enters an identical MATNR in the second row the validation should throw a message that'Entry already exists' and the entry should get deleted.
    The internal table is filled up from the database table using the WBS Element.Then before saving the new entry ,the database entry for the WBS element is deleted.
    After updating the Internal table the internal table is inserted into the database table.
    Can anyone let me know how to validate the new entry against the entries already existing in the internal table.
    Hope i am able to make the problem clear to you.

    In the PAI Event write the code inside the CHAIN & ENDCHAIN.
    PROCESS AFTER INPUT.
    *pai flow logic for tablecontrol 'MPRN'
      LOOP AT i_mprn.
        CHAIN.
          FIELD:  i_mprn-select,
                  i_mprn-mprn,
                  i_mprn-post_code,
                  i_mprn-dm_ndm
          MODULE validate_mprn.
        ENDCHAIN.
        MODULE tabctrl_modify.
      ENDLOOP.
    MODULE validate_mprn INPUT.
      IF sy-ucomm EQ 'MPSB'.
        PERFORM validate_mprn.
      ENDIF.
    ENDMODULE.                 " validate_mprn  INPUT

Maybe you are looking for