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.

Similar Messages

  • 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

  • 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 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 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 .

  • Question on internal table logic..

    Gurus,
    I have a internal table as follows:
    it_tab:
    ID---ACTION---CHANGE
    A1-----X--
    B2----
    U
    C1-----X--
    U
    C2-----X--
    Without looping at the table, how can I find get the result that the internal table has 3 ids with ACTION ='X'
    and 1 ID with ACTION  = X and Change = U.
    Regards,
    Rajesh.

    I agree with Rob, why not loop?
    First thing without loop that comes to mind is
    Using the Read statement 4 times with index 1,2,3 & 4.
    Regards,
    DNP

  • Process Internal table -Logic

    Hi,
    My internal table has following data
    A      10     30
    A      20     50
    A      00     100
    B      20     40
    B      10     90
    I need output as
        (Lowest)   (Highest)
    A   10               100
    B   10               90
    How do we do?
    rgds
    Praveen

    Namesh,
    Program does'nt work for  3  or more records. any ideas?
    <
    report x.
    DATA: BEGIN OF ITAB OCCURS 0,
          FLD1  TYPE CHAR20,
          NUM1  TYPE I,
          NUM2  TYPE I,
          END   OF ITAB.
    *A 10 30
    *A 20 50
    *A 00 100
    *B 20 40
    *B 10 90
    *C 0  40
    *C 10 120
    ITAB-FLD1 = 'A'.
    ITAB-NUM1 = '10'.
    ITAB-NUM2 = '30'.
    APPEND ITAB.
    ITAB-FLD1 = 'A'.
    ITAB-NUM1 = '20'.
    ITAB-NUM2 = '50'.
    APPEND ITAB.
    ITAB-FLD1 = 'A'.
    ITAB-NUM1 = '00'.
    ITAB-NUM2 = '100'.
    APPEND ITAB.
    ITAB-FLD1 = 'B'.
    ITAB-NUM1 = '20'.
    ITAB-NUM2 = '40'.
    APPEND ITAB.
    ITAB-FLD1 = 'B'.
    ITAB-NUM1 = '10'.
    ITAB-NUM2 = '90'.
    APPEND ITAB.
    itab-fld1 = 'C'.
    itab-num1 = '0'.
    itab-num2 = '40'.
    append itab.
    itab-fld1 = 'C'.
    itab-num1 = '10'.
    itab-num2 = '120'.
    append itab.
    DATA: ITAB2    LIKE ITAB OCCURS 0 WITH HEADER LINE,
          ITAB_TMP LIKE ITAB OCCURS 0 WITH HEADER LINE.
    DATA: NEW_FLD TYPE C.
    LOOP AT ITAB.
      AT NEW FLD1.
        NEW_FLD = 'X'.
      ENDAT.
      IF NEW_FLD = 'X'.
        ITAB_TMP[] = ITAB[].
        DELETE ITAB_TMP WHERE FLD1 = ITAB-FLD1.
        CLEAR NEW_FLD.
        SORT ITAB_TMP BY FLD1 ASCENDING
                         NUM1 ASCENDING.
        READ TABLE ITAB_TMP INDEX 1.
        ITAB2-FLD1 = ITAB_TMP-FLD1.
        ITAB2-NUM1 = ITAB_TMP-NUM1.
        SORT ITAB_TMP BY FLD1 ASCENDING
                         NUM2 DESCENDING.
        READ TABLE ITAB_TMP INDEX 1.
        ITAB2-NUM2 = ITAB_TMP-NUM2.
        APPEND ITAB2.
      ENDIF.
    ENDLOOP.
    LOOP AT ITAB2.
      WRITE: / ITAB2-FLD1,
               ITAB2-NUM1,
               ITAB2-NUM2.
    ENDLOOP. >

  • 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.

  • Internal Table - logic for Chunk

    Hi,
    I have an internal table with n records.
    I want to use at a time say max of 20 records .
    This is calling a BDC.
    i.e.
    loop at n record.
    take 20 records.
    call BDC.
    then next set of recrds.
    repeat process till all records processed.
    Thanks in Advance.
    Amit

    Hi,
    try this way.
    data: count type i.
    loop at table
      if count LE 20.
        add 1 to count.
      else.
        clear count.
        call bdc.
        "refresh all the concerned tables and variables for the next 20 records.
      endif.
    endloop.
    Or.
    loop ...
    WHILE count le 20.  
       ADD 1 TO count.
    ENDWHILE.                   
        clear count.
        call bdc.
        "refresh all the concerned tables and variables for the next 20 records.
    endloop
    Regards.
    Marcelo Ramos

  • 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.

  • Logic for retreiving the values from a dynamic internal table

    Hi all,
    I have an issue with the logic to fetch data from a dynamic internal table into fields. let me give you guys an example the sy-tfill = 9 (subject to vary). I need to populate the fields.
    Regards,
    Sukumar

    Hi,
    this is for printing out the info in a dynamic table,
    it will work likewise to insert data.
    PARAMETERS:
      p_tabnam TYPE tabname DEFAULT 'DB_TABLE_NAME'.
    DATA:
      lv_dref TYPE REF TO data,
      ls_dd03l LIKE dd03l,
      lt_fieldname TYPE TABLE OF fieldname,
      ls_fieldname TYPE fieldname.
    FIELD-SYMBOLS:
      <fs> TYPE STANDARD TABLE,
      <wa_comp> TYPE fieldname,
      <wa_data> TYPE ANY,
      <wa_field> TYPE ANY.
    REFRESH lt_fieldname.
    SELECT * FROM dd03l INTO ls_dd03l
                       WHERE as4local = 'A'
                         AND as4vers  = '0000'
                         AND tabname  = p_tabnam
                       ORDER BY position.
      ls_fieldname = ls_dd03l-fieldname.
      APPEND ls_fieldname TO lt_fieldname.
    ENDSELECT.
    IF NOT ( lt_fieldname[] IS INITIAL ).
      CREATE DATA lv_dref TYPE TABLE OF (p_tabnam).
      ASSIGN lv_dref->* TO <fs>.
      SELECT * FROM (p_tabnam) INTO TABLE <fs>.
      WRITE:
        / 'CONTENTS OF TABLE', p_tabnam.
      LOOP AT <fs> ASSIGNING <wa_data>.
        SKIP.
        WRITE:
          / 'LINE', sy-tabix.
        ULINE.
        LOOP AT lt_fieldname ASSIGNING <wa_comp>.
          ASSIGN COMPONENT sy-tabix OF STRUCTURE <wa_data> TO <wa_field>.
          WRITE:
            / <wa_comp>, <wa_field>.
        ENDLOOP.
      ENDLOOP.
    ENDIF.
    grtz
    Koen

  • Logic issues for manipulation of internal table data

    Hi,
    I am having a issue with logic of one program.
    In the <b>XVBAP</b> internal table of <b>SO</b> User Exit.
    We will have fields like
    <b>UPDKZ, POSNR, UEPOS, ZZECD[Z-Field] etc.</b>
    Above fields are related to logic.
    1. Now my first point is:
    <b>We need to capture Records where UPDKZ='D' and ZZECD[Z-Field] is populated.</b>
    For this we will write code as below:
    <b>LOOP AT XVBAP WHERE UPDKZ     EQ C_D   AND
                        ZZECD     NE SPACE.
    Here we will store all fields in I_XVBAP I.Table
    ENDLOOP.</b>
    Supoose we have retrieved records as below:
    <b>VBELN, UPDKZ, POSNR, UEPOS, ZZECD
    100    D   000040   000030 Text1
    100    D   000050   000020 Text2
    100    D   000060   000000 Text3</b>
    2. My second point here is:
    <b>For Every Item[POSNR] we need to get the Higher level item from UEPOS field, If the Higher level Item also has UPDKZ = ‘D’, then move the base unit and all it’s components into an internal table. continue this process till UEPOS for POSNR is 000000 but High item should have UPDKZ = 'D', not only this all items in this chain should have UPDKZ = 'D'.</b>
    Ex:
    <b>Suppose for item 000050 UEPOS is 000020 then goto XVBAP with POSNR = UEPOS[000020] and UPDKZ = 'D' if yes and then pick up UEPOS for 000020 item and continue this process till UEPOS becomes 000000 and UPDKZ = 'D'.
    Here from Low level to High level all the chain items should have UPDKZ = 'D'. Then only write all items into Final Internal table.</b>
    <b>Need to do this process for all above rec's [40,50,60 - POSNR].</b>
    Can anybody provide me the logic for the above scenario.
    Thanks in advance.
    Thanks and Regards,
    Deep

    Hi Anurag,
    Your assumption is wrong.
    See first when we get into our logic we will get <b>XVBAP</b> data as below:
    <b>VBELN, POSNR, UEPOS, UPDKZ, ZZECD
    100,  10,  00,  D,  Text1
    100,  20,  00,   ,  Text2
    100,  30,  20,  D,  Text3
    100,  40,  30,  D,  Text4
    100,  50,  00,   ,  Text5
    100,  60,  00,   D, Text6
    100,  70,  60,   D, Text7</b>
    After we run first point we will get data as:
    Here logic is pick up data where <b>UPDKZ = D</b> and <b>ZZECD NE SPACE</b>.
    <b>VBELN, POSNR, UEPOS, UPDKZ, ZZECD
    100, 10, 00, D, Text1
    100, 30, 20, D, Text3
    100, 40, 30, D, Text4
    100, 60, 00, D, Text6
    100, 70, 60, D, Text7</b>
    Then we will goto second point:
    Here we need to look into <b>3</b> things totally in 2nd point:
    1. In loop Select the record which has <b>UEPOS EQ space</b>, <b>UPDKZ = D</b> and <b>POSNR</b> should not be <b>UEPOS</b> for any other record from above data from 1st point.
    <b>100, 10, 00, D, Text1</b>
    will be selected into final internal table as per this point.
    2. If for a POSNR value UEPOS NE SPACE, UPDKZ = D then goto UEPOS's POSNR in high level check there if UPDKZ = D and then wether UEPOS is ZERO (or) contains any value.
    If any value is there repeat the process till UEPOS become ZERO. Then for that final higher level item check UPDKZ value if it has value as 'D', If has then write all those records from low item to high item into final internal table.
    <b>100, 60, 00, D, Text6
    100, 70, 60, D, Text7</b>
    In above for Item 70[POSNR] we have UEPOS as 60 and UPDKZ as D. then we will goto UEPOS's POSNR, Now POSNR is 60 then check it's UEPOS it is ZERO so check UPDKZ because it is D write both items 60, 70 into final internal table.
    2. If for a POSNR value UEPOS NE SPACE, UPDKZ = D then goto UEPOS's POSNR in high level check there if UPDKZ = D and then wether UEPOS is ZERO (or) contains any value.
    If any value is there repeat the process till UEPOS become ZERO. Then for that final higher level item check UPDKZ value if it has value as 'D', If it does not have  UPDKZ as 'D' then don't write any item from low to high into final internal table.
    If we take the scenario of below rows:
    <b>100,  20,  00,   ,  Text2
    100,  30,  20,  D,  Text3
    100,  40,  30,  D,  Text4</b>
    POSNR-40 has UEPOS-30 & UPDKZ = D then UEPOS's POSNR-30 has UEPOS-20 and UPDKZ-D then UEPOS POSNR-20 has UEPOS as 00 then stop here and see UPDKZ which is ZERO so don't consider items 20,30,40 into final i.table.
    In the above chain in any record UPDKZ is not 'D' then skip the process anddon't write the records into final internal table.
    Final output will come as:
    <b>100, 10, 00, D, Text1</b>
    <b>100, 60, 00, D, Text6
    100, 70, 60, D, Text7</b>
    Thanks for all your efforts.
    Thanks,
    Deep

Maybe you are looking for

  • Driver Problem False Report ?

    Motherboard: F1A75-V PRO Processor:AMD A8-3870 APU with Radeon Graphics ( 4 Core Processor) RAM: Corsair 8 GB System drive : Samsung 128 GB SSD OS: Windows 8.1.1 All the 4 units of the above mentioned Processor shows defective drivers. If I try to re

  • Can I use an imac as a monitor for 2012 MBP?

    I use a very slow mac at work, but once a year I need grunt to produce our annual catalogue. My work imac is 20-inch, Mid 2007 (Old I know but my boss is too tight to upgrade) My laptop at home is new 2012 MBP, 16gb Ram. My Question is: Can I connect

  • LMS 2.6 dynamic groups with wildcards

    Is is possible to build dynamic groups in RME using wildcards or regular expresions? The rules that I want to define would look similar to the following: Device.System.Name StartsWith "SW" AND ( Device.System.Name contains "........X" OR Device.Syste

  • How to disable partition sharing

    Hello, I have turned on File Sharing for my Mac to access the Mac's public folder on the Windows PC. This works just fine when the SMB option and my user account is checked at System Preferences > Sharing > File Sharing > Options. However, all my par

  • Report to see shopping cart with intervals

    Hi, I am a end user, can i check for what roles are assigned to a Particular User Like Specifically for transactions Like PPOMA_BBP, PPOSA_BBP etc. thanks a lot in advance.