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

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

  • 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

  • Reg: internal table?

    hello friends?
    i have one basic doubts,
    please clear this things,
    what are all the ways we can create the internal table?
    how we create internal table using data statement?
    how we create internal table using types statement?
    what is the difference between these two methods?

    FYI..
    DATA - Defining an Internal Table
    Variants:
    1. DATA itab TYPE itabtype [WITH HEADER LINE].
    2. DATA itab {TYPE tabkind OF linetype|
                  LIKE tabkind OF lineobj}
              WITH [UNIQUE|NON-UNIQUE] keydef
              [INITIAL SIZE n] [WITH HEADER LINE].
    3. DATA itab {TYPE TABLE OF linetype|LIKE TABLE OF lineobj}.
    4. DATA itab TYPE RANGE OF type.
    DATA itab LIKE RANGE OF f.
    5. DATA itab [TYPE linetype|LIKE lineobj] OCCURS n
              [WITH HEADER LINE].
    6. DATA: BEGIN OF itab OCCURS n,
          END   OF itab [VALID BETWEEN f1 AND f2].
    In an ABAP Objects context, a more severe syntax check is performed that in other ABAP areas. See New naming conventions and LIKE references to Dictionary Types not allowed.
    Effect
    Defines an internal table.
    To fill and process internal tables, use the statements INSERT, APPEND, READ TABLE, LOOP, SORT, and so on.
    The OCCURS or INITIAL SIZE parameter (OCCURS value) determines the number of lines that are created when the table itself is created. However, the table is extended dynamically on demand. For details, refer to Performance Notes for Internal Tables. The OCCURS value, has no other semantic meaning (apart from one exception in the APPEND SORTED BY statement). If you do not specify an INIT IAL SIZE , the system uses the default value 0.
    If you specify WITH HEADER LINE, the table is created with a header line, that is, a field with the same name. It has the same type as the line type of the table.
    This addition is not allowed in an ABAP Objects context. See Tables with header line not allowed.
    Variant 1
    DATA itab TYPE itabtype [WITH HEADER LINE].
    Effect
    itabtype must be an internal table type that you have already defined using TYPES. The statement creates an internal table in the program with this type.
    In general, the type specification for the table object must be complete. The exception to this is a standard table, in which the key definition may be missing. In this case, the system automatically uses a default key.
    Example
    Creating a hashed table by referring to an existing table type:
    TYPES: BEGIN OF STRUC, NAME(10), AGE TYPE I, END OF STRUC,
           HTAB TYPE HASHED TABLE OF STRUC WITH UNIQUE KEY NAME.
    DATA : PERSONS TYPE HTAB.
    Variant 2
    DATA itab {TYPE tabkind OF linetype|LIKE tabkind OF lineobj}           WITH [UNIQUE|NON-UNIQUE] keydef
              [INITIAL SIZE n] [WITH HEADER LINE].
    Effect
    Creates an internal table in the program with the type tabkind. Since there are no generic field definitions, you cannot use the table types ANY TABLE or INDEX TABLE.
    The structure of the table lines is defined by the type linetype if you use a TYPE reference) or by the type of the referred object lineobj (when you use a LIKE reference).
    The same rules apply to the UNIQUE and NON-UNIQUE additions in the DATA statement as in a TYPES definition. You may only omit the definition when defining a standard table.
    If you do not specify the INITIAL SIZE the system uses a default initial size of 0.
    Variant 3
    DATA itab {TYPE TABLE OF linetype|LIKE TABLE OF lineobj}.
    Effect
    This is a shortened form of the definition of a standard table. It corresponds to
       DATA itab {TYPE STANDARD TABLE OF linetype|
                  LIKE STANDARD TABLE OF lineobj} WITH DEFAULT KEY.
    or the old definition (compare variant 4)
       DATA itab {TYPE linetype|LIKE lineobj} OCCURS 0.
    Variant 4
    DATA itab TYPE RANGE OF type. DATA itab LIKE RANGE OF f.
    Additions:
    1. ... INITIAL SIZE n
    2. ... WITH HEADER LINE
    Effect
    Creates an internal table itab with table type STANDARD. The line type is a structure with the following components:
      SIGN(1)   TYPE C
      OPTION(2) TYPE C
      LOW       TYPE type bzw. LIKE f
      HIGH      TYPE type bzw. LIKE f
    Addition 1
    ...INITIAL SIZE n
    Effect
    The INITIAL SIZE specification determines how many table lines are created when the table itself is created. The table is also dynamically expanded as required. For further information, refer to Performance Notes for Internal Tables. The INITIAL SIZE value has no semantic meaning (apart from one exception in the ei APPEND SORTED BY statement). If you do not specify the INITIAL SIZE, the system uses the default value 0.
    Addition 2
    ... WITH HEADER LINE
    This addition is not allowed in an ABAP Objects context. See Tables with Header Lines Not Allowed.
    Effect
    Creates an internal table and a header line for it, that is, a field with the same name as the internal table and the same type as the line type of the internal table.
    Variant 5
    DATA itab [TYPE linetype|LIKE lineobj] OCCURS n                                        [WITH HEADER LINE].
    This variant is not allowed in an ABAP Objects context. See Declaration with OCCURS not allowed.
    Effect
    This variant exists to ensure compatibility with Release 3.x. If you do not specify a line type, the system uses type C with length 1. Otherwise, the variant is the same as
       DATA itab {TYPE STANDARD TABLE OF linetype|
                  LIKE STANDARD TABLE OF lineobj}
                 INITIAL SIZE n [WITH HEADER LINE].
    Example
    TYPES: BEGIN OF LINE_TYPE,
             NAME(20) TYPE C,
             AGE      TYPE I,
           END   OF LINE_TYPE.
    DATA:  PERSONS    TYPE LINE_TYPE OCCURS 20,
           PERSONS_WA TYPE LINE_TYPE.
    PERSONS_WA-NAME = 'Michael'.  PERSONS_WA-AGE  = 25.
    APPEND PERSONS_WA TO PERSONS.
    PERSONS_WA-NAME = 'Gabriela'. PERSONS_WA-AGE  = 22.
    APPEND PERSONS_WA TO PERSONS.
    The internal table PERSONS now contains two entries.
    Variant 6
    DATA: BEGIN OF itab OCCURS n,         ...
          END   OF itab [VALID BETWEEN f1 AND f2].
    This variant is not allowed in an ABAP Objects context. See Declaration with OCCURS not allowed.
    Effect
    Creates an internal table itab with type STANDARD and a header line. The line type consists of the fields between "BEGIN OF itab OCCURS n" and " END OF itab".
    Use the VALID BETWEEN f1 AND f2 addition to specify that the components f1 and f2 of the internal table itab contain a line-based validity interval. You can only use this addition in conjunction with the PROVIDE statement.
    Example
    DATA: BEGIN OF PERSONS OCCURS 20,
            NAME(20),
            AGE TYPE I,
          END   OF PERSONS.
    PERSONS-NAME = 'Michael'.
    PERSONS-AGE  = 25.
    APPEND PERSONS.
    PERSONS-NAME = 'Gabriela'.
    PERSONS-AGE  = 22.
    APPEND PERSONS.
    The internal table consists of two entries. PERSONS also has a header line (work area), which is an interface between the program and the actual table contents.
    Additional help
    Internal Table Objects
    Ramesh

  • Reg : internal table & Perform statement

    hi all
         i have 3 internal tables ,
    *     in first internal table i have mark-1 ,*
    *     in 2nd internal table i have mark-2 ,*
    *     using "PERFORM"  i have to add mark 1 & mark 2*
    *     and i need to display the total in  3rd internal table.*
    *     how to do by using "PERFORM" .*
                    Kindly clarify.
    with kind regards
    vel

    Raghupathy is right you just have to write:
    porgram code......
    perform sum_of_tables tables itab1
                                               itab2
                                               itab3.
    program code....
    definition of form:
    form_sum_of_tables tables itab1
                                          itab2
                                          itab3.
    definiton type of witab1, witab2, witab3.
    loop itab1 into witab1.
    loop itab2 into witab2.
    witab3-total = witab1-mark1 plus witab2-mark2.
    append witab3 to itab3.
    endloop.
    endloop.
    endform.
    It will return itab3 which is sum of itab1 and itab2.

  • 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

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

  • Reg internal table and  variants

    Hi,
    Can any tel me
    1. how to create internal table dynamically ( i knew its done thru field symbols but i dont know how) ...pls i need a clear example..pls
    2.I have got a requirement where i need to display the fields in ouutput based on the variant i choose/select  at selection screen.. that means the fields should be varying based on the variant chosen at selection screen..
    pls i need a good example for the above 2 queries..plsss
    Thanks in ADVANCE
    Jay

    hi
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/content.htm
    Regards
    Anuj

Maybe you are looking for