AT NEW .. ENDAT

HI,
I was trying to use the Do.. Varying statement to get the 1st 3 amount in Databaste Table PA0008. However, when i tried to code the program as below and in debug mode, inside the AT New.. ENDAT the value is always zero. After the ENDAT statement, only the value for the amount appears. It's catching the PERNR correctly, but not the amount. Anyone can explain??
DATA: l_bet01 TYPE pa0008-bet01,
          l_bet02 TYPE pa0008-bet01.
DATA: wa_0008 TYPE TABLE OF pa0008,
      it_0008 LIKE LINE OF wa_0008.
  LOOP AT wa_0008 INTO it_0008.
    AT NEW pernr.
      DO 3 TIMES VARYING l_bet01 FROM it_0008-bet01 NEXT it_0008-bet02.
        l_bet02 = l_bet02 + l_bet01.
      ENDDO.
      MOVE it_0008-pernr TO it_tab-pernr.
      MOVE l_bet02       TO it_tab-bet01.
      APPEND it_tab TO wa_tab.
      Clear it_tab.
    ENDAT.
  ENDLOOP.
Thanks,
Loo

Hi,
DATA: l_bet01 TYPE pa0008-bet01,
l_bet02 TYPE pa0008-bet01,
Flag type C.
DATA: wa_0008 TYPE TABLE OF pa0008,
it_0008 LIKE LINE OF wa_0008.
LOOP AT wa_0008 INTO it_0008.
AT NEW pernr.
Flag =  'X'.
ENDDO.
MOVE it_0008-pernr TO it_tab-pernr.
MOVE l_bet02 TO it_tab-bet01.
APPEND it_tab TO wa_tab.
Clear: it_tab,
        Flag.
ENDAT.
if  flag = 'X'.
DO 3 TIMES VARYING l_bet01 FROM it_0008-bet01 NEXT it_0008-bet02.
l_bet02 = l_bet02 + l_bet01.
endif.
ENDLOOP.
If found helpfull Do Reward.
Regards.
Eshwar.

Similar Messages

  • Alternative for AT NEW --- ENDAT

    Hello experts,
    I am using field-symbol as internal table. I cant use AT NEW statement inside this loop.
    Can u pls provide alternative for above control break statement.
    Thanks in advance.
    Zak.

    Hi,
    to use control break statement, first you should sort the internal table and then you use it.
    Take one example:
    data: begin of it9 occurs 4,
               f1,
               f2,
             end of it9.
      it9 = '1A'. append it9. "Fill it9 with data
      it9 = '3A'. append it9.
      it9 = '1B'. append it9.
      it9 = '2B'. append it9.
    sort it9 by f1.
    loop at it9.
         at new f1.
             write: / 'start of:', it9-f1.
             endat.
         at end of f1.
             write: / 'end   of:', it9-f1.
             endat.
         endloop.
    free it9.
    Hope it is helpful.
    Regards,
    Chris Gu

  • Urgent!!!  at new - filling table

    Can u tell why inside of " AT NEW / ENDAT" all the contents of internal table are initial?
    i need them.
    example,
    LOOP AT TLZK.
       AT NEW BUDAT.
       T_RESULT-ERFMG = summa.
       MODIFY T_RESULT TRANSPORTING ERFMG WHERE BUDAT = ZBUDAT.
        T_RESULT-NPP = NPP.
       T_RESULT-ERFMG = T_RESULT-ERFMG + TLZK-ERFMG.
        T_RESULT-RSNUM = TLZK-RSNUM.
        T_RESULT-RSPOS = TLZK-RSPOS.
        T_RESULT-LGORT = TLZK-LGORT.
        T_RESULT-UMLGO = TLZK-UMLGO.
        T_RESULT-BUDAT = TLZK-BUDAT.
        APPEND T_RESULT.
        CLEAR SUMMA.
        NPP = NPP + 1.
      ENDAT.
       zbudat = WA_TLZK-budat.
       summa = summa + WA_TLZK-ERFMG.
      ENDLOOP.

    HI,
    Move the data to a temporary internal table:
    LOOP AT TLZK.
    ITEMP[] = TLZK[].
    AT NEW BUDAT.
    T_RESULT-ERFMG = summa.
    MODIFY T_RESULT TRANSPORTING ERFMG WHERE BUDAT = ZBUDAT.
    T_RESULT-NPP = NPP.
    * T_RESULT-ERFMG = T_RESULT-ERFMG + ITEMP-ERFMG.
    T_RESULT-RSNUM = ITEMP-RSNUM.
    T_RESULT-RSPOS = ITEMP-RSPOS.
    T_RESULT-LGORT = ITEMP-LGORT.
    T_RESULT-UMLGO = ITEMP-UMLGO.
    T_RESULT-BUDAT = ITEMP-BUDAT.
    APPEND T_RESULT.
    CLEAR SUMMA.
    NPP = NPP + 1.
    ENDAT.
    zbudat = WA_TLZK-budat.
    summa = summa + WA_TLZK-ERFMG.
    ENDLOOP.

  • What is use of AT NEW and AT CHANGE

    what is use of AT NEW and AT CHANGE

    Using AT NEW
    Use at new to detect a change in a column from one loop pass to the next. This statements enable you to execute code at the beginning of a group of records.
    Syntax for the at new Statement
    sort by c.
    loop at it.
        at new c.
         endat.
        endloop.
    where:
    it is an internal table.
    c is a component of it.
    The following points apply:
    This statements can only be used within loop at; it cannot be used within select.
    at new does not have to come before at end of. It can appear in any order.
    This statement can appear multiple times within the same loop. For example, you could have two at new and three at end of statements within one loop and they can appear in any order.
    These statements should not be nested inside of one another (that is, at end of should not be placed inside of at new / endat).
    There are no additions to these statements.
    Each time the value of c changes, the lines of code between at new and endat are executed. This block is also executed during the first loop pass or if any fields to the left of c change. Between at and endat, the numeric fields to the right of c are set to zero. The non-numeric fields are filled with asterisks (*). If there are multiple occurrences of at new, they are all executed. at end of behaves in a similar fashion.
    A control level is the component named on a control break statement; it regulates the control break. For example, in the following code snippet, f2 is a control level because it appears on the at new statement.
    loop at it.
        at new f2.
            "(some code here)
            endat.
        endloop.
    It is said that a control break is triggered if the control level changes. This means that when the contents of the control level change, the code between the at and endat is executed.
    A control break is also triggered if any of the fields prior to the control level in the structure change. Therefore, you should define the internal table structure to begin with the fields that form your control levels. You must also sort by all fields prior to and including c.
    Between at and endat, numeric fields to the right of the control level will be zero and non-numeric fields will be filled with asterisks.
    Using ON CHANGE OF
    Another statement you can use to perform control break processing is on change of. It behaves in a manner similar to at new.
    Syntax for the on change of Statement
    The following is the syntax for the on change of statement.
    on change of v1 or v2 .
    else.
    endon.
    where:
    v1 and v2 are variable or field string names.
    any number of or conditions might follow.
    The following points apply:
    If the value of any of the variables (v1, v2, and so on) changes from one test to the next, the statements following on change of are executed.
    If no change is detected and else is specified, the statements following else are executed.
    on change of differs from at new in the following respects:
    It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.
    A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.
    When used within a loop, a change in a field to the left of the control level does not trigger a control break.
    When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.
    You can use else between on change of and endon.
    You can use it with loop at it where . . ..
    You can use sum with on change of. It sums all numeric fields except the one(s) named after of.
    Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.
    When a loop begins execution, the system creates a global auxiliary field for each field named in an on change of statement contained by the loop. On creation, these fields are given default initial values (blanks or zeros). They are freed when the loop ends.
    Each time on change of is executed, the contents of its fields are compared with the contents of the global auxiliary fields. If they are different, the on change of is triggered and the auxiliary fields are updated with the new values. If they are the same, the code within on change of is not executed
    Because global auxiliary fields do not exist outside a loop, you cannot use on change of outside of a loop.
    I hope it helps.
    Best Regards,
    Vibha
    Please mark all the helpful answers

  • AT NEW and AT CHANGE

    Hi,
    what is use of AT NEW and AT CHANGE.
    When we will use it?
    Akash

    Hi Akash,,
    Using the at new and at end of Statements
    Use the at new and at end of statements to detect a change in a column from one loop pass to the next. These statements enable you to execute code at the beginning and end of a group of records.
    sort by c.
    loop at it.
    at new c.
    endat.
    at end of c.
    endat.
    endloop.
    where:
    These statements can only be used within loop at; they cannot be used within select.
    at new does not have to come before at end of. These statements can appear in any order.
    These statements can appear multiple times within the same loop. For example, you could have two at new and three at end of statements within one loop and they can appear in any order.
    These statements should not be nested inside of one another (that is, at end of should not be placed inside of at new / endat).
    There are no additions to these statements.
    Using at new
    Each time the value of c changes, the lines of code between at new and endat are executed. This block is also executed during the first loop pass or if any fields to the left of c change. Between at and endat, the numeric fields to the right of c are set to zero. The non-numeric fields are filled with asterisks (*). If there are multiple occurrences of at new, they are all executed. at end of behaves in a similar fashion.
    A control level is the component named on a control break statement; it regulates the control break. For example, in the following code snippet, f2 is a control level because it appears on the at new statement.
    loop at it.
    at new f2.
    "(some code here)
    endat.
    endloop.
    It is said that a control break is triggered if the control level changes. This means that when the contents of the control level change, the code between the at and endat is executed.
    A control break is also triggered if any of the fields prior to the control level in the structure change. Therefore, you should define the internal table structure to begin with the fields that form your control levels. You must also sort by all fields prior to and including c.
    Between at and endat, numeric fields to the right of the control level will be zero and non-numeric fields will be filled with asterisks.
    The lines of code between at end of and endat are executed:
    If the control level changes.
    If any field prior to the control level changes.
    If this is the last row of the table.
    report Ztemp.
      data: begin of it occurs 4,
                f1,
                f2,
                end of it.
      it = '1A'. append it. "Fill it with data
      it = '3A'. append it.
      it = '1B'. append it.
    it = '2B'. append it.
    sort it by f1.       
    loop at it.
         at new f1.
             write: / it-f1, it-f2.
             endat.
         endloop.
    skip.
    sort it by f2.       
    loop at it.
         at new f2.
             write: / it-f1, it-f2.
             endat.
         endloop.
    skip.
    sort it by f1 f2.    
    loop at it.
         at new f1.
             write: / it-f1.
             endat.
         at new f2.
             write: /4 it-f2.
             endat.
         endloop.
    free it.
    If Found Help Full Do Reward.
    Regards.
    Eshwar.

  • Script- problem in printing the values in from internal table

    Hi all,
    I have a requiremnt that i for a particular document no there are number of invoices are there. i.e for a single document no there are 20 invoices in that. i shoudl display the invoice number , invoice date, invoice amount , number of days of intrest , start date of interest, end date of interest and intrest amount.
    The problem is i should take the invoice number, invoice date, number of days  from TABLE <b>BSEG</b> and  inovice amount and start date, end date from table<b> INTITIT</b>.  for a particular document number there are diffent invoce numbers in both the table.
    i can display everthing but the prob is with invoice amount. it is repating only one values is displying in the ouput. The invoice number in INTITIT Is not changing. I have to write the syntax for that .Please help me The value in Bseg is chaing as per given syntax shown below.
    data:   begin of hbseg occurs 10.
            include structure hsortp.
            include structure bseg.
    data:   end of hbseg.
    data: begin of hsortp,
            sortp1 like sortp1,
            sortp2 like sortp2,
            sortp3 like sortp3,
            sortp4 like sortp4,
            sortp5 like sortp5,
            EKVBD  LIKE KNB1-EKVBD,
          end   of hsortp.
    loop at hbseg.
            WHERE BUKRS = SAVE_BUKRS.
              save_bukrs  = hbseg-bukrs.
              if  ( hbseg-kunnr = save_kunnr
              and   not save_kunnr is initial )
              or  ( hbseg-lifnr = save_lifnr
              and   not save_lifnr is initial ).
               clear bseg.
                move-corresponding hbseg to bseg.
                 *bseg = bseg.
                if bkpf-waers ne *bkpf-waers.
                  perform curr_document_convert_bseg
                              using
                                 bkpf-budat
                                 *bkpf-waers
                                 *bkpf-hwaer
                                 bkpf-waers
                              changing
                                 bseg.
                  if not bseg-pycur is initial.
                    alw_waers = bseg-pycur.
                    perform currency_get_subsequent
                                using
                                   save_repid
                                   bkpf-budat
                                   bkpf-bukrs
                                changing
                                   alw_waers.
                    if alw_waers ne bseg-pycur.
                      bseg-pycur = alw_waers.
                      perform convert_foreign_to_foreign_cur
                                  using
                                     bkpf-budat
                                     *bkpf-waers
                                     *bkpf-hwaer
                                     bseg-pycur
                                  changing
                                     bseg-pyamt.
                    endif.
                  endif.
                endif.
                perform fill_waehrungsfelder_bseg.
                perform fill_waehrungsfelder_bseg_2.
                if bseg-sgtxt(1) ne '*'.
                  bseg-sgtxt = space.
                else.
                  bseg-sgtxt = bseg-sgtxt+1.
                endif.
                clear save_bschl.
                clear save_umskz.
                clear tbslt.
                save_bschl = bseg-bschl.
                save_umskz = bseg-umskz.
                perform read_tbslt.
    ADDING VARIBLE V_GSALDF BY SUNIL 5.11.07******
               v_gsaldf = rf140-gsaldf + rf140-wrshb.
               rf140-gsaldf = v_gsaldf.
               clear v_gsaldf.
    SUNIL *********************
                 *rf140-gsaldf = *rf140-gsaldf + *rf140-wrshb.
                if  xmultk is initial
                and xactiv is initial
                and linecnt = '1'
                and not      xumsst is initial
                and not save_xumstn is initial.
                  if bkpf-bstat = 'V'.
                    perform read_vbset.
                  else.
                    perform read_bset.
                  endif.
                  describe table hbset lines linecnt.
                  if linecnt = '1'.
                    loop at hbset.
                      move-corresponding hbset to bset.
                       *bset = bset.
                      if bkpf-waers ne *bkpf-waers.
                        perform curr_document_convert_bset
                                    using
                                       bkpf-budat
                                       *bkpf-waers
                                       *bkpf-hwaer
                                       bkpf-waers
                                    changing
                                       bset.
                      endif.
                      clear rf140-msatz.
                      clear rf140-vtext.
                      save_ktosl = bset-ktosl.
                      perform read_t687t.
                      rf140-msatz = bset-kbetr / 10.
                       *rf140-msatz = rf140-msatz.
                      rf140-vtext = save_vtext.
                       *rf140-vtext = rf140-vtext.
                      if bset-shkzg = 'H'.
                        rf140-mwshb = bset-fwste.
                         *rf140-mwshb = *bset-fwste.
                        rf140-mdshb = bset-hwste.
                         *rf140-mdshb = *bset-hwste.
                      else.
                        rf140-mwshb = 0 - bset-fwste.
                         *rf140-mwshb = 0 - *bset-fwste.
                        rf140-mdshb = 0 - bset-hwste.
                         *rf140-mdshb = 0 - *bset-hwste.
                      endif.
                      exit.
                    endloop.
                    rf140-wrshb = rf140-wrshb - rf140-mwshb.
                     *rf140-wrshb = *rf140-wrshb - *rf140-mwshb.
                    rf140-dmshb = rf140-dmshb - rf140-mdshb.
                     *rf140-dmshb = *rf140-dmshb - *rf140-mdshb.
                  endif.
                endif.
    *****************Begin of Change by Karthikeyan J********************
                i_count = i_count + 1.
                clear rf140-element.
                clear: it_bseg, i_wrbtr,i_totday,i_tempday,i_day,i_bday.
    comparing with fields belnr AND SELECT * FROM INTITIT added by sunil 3.11.07*********
                select single * from bseg into
                corresponding fields of it_bseg where belnr = bseg-rebzg  anD GJAHR = BSEG-GJAHR.
                select single * from intitit into corresponding fields of  it_intitit where gjahr = bseg-gjahr and belnr_to = bseg-belnr and buzei = '2' OR BELNR = INTITIT-BELNR .
    added by Jayshree on 09/01/2007
                MOVE ' ' TO it_kna1-name1.
                SELECT SINGLE name1
                INTO CORRESPONDING FIELDS OF it_kna1
                FROM ( vbpa AS a INNER JOIN kna1 AS b ON akunnr = bkunnr )
                WHERE a~vbeln = it_bseg-vbeln
                  AND a~parvw = 'zd'.
                SELECT SINGLE fkdat
                INTO CORRESPONDING FIELDS OF it_kna1
                FROM vbrk
                WHERE vbrk~vbeln = it_bseg-vbeln.
    added by Jayshree on 01/02/2007
              CONCATENATE  it_kna1-fkdat6(2) it_kna1-fkdat4(2) it_kna1-fkdat+2(2)
                INTO vfkdat SEPARATED BY '.'.
              CONCATENATE  it_bseg-augdt6(2) it_bseg-augdt4(2) it_bseg-augdt+2(2)
                INTO vaugdt SEPARATED BY '.'.
                i_wrbtr = i_wrbtr + it_bseg-wrbtr.
    added as on 29.06.2007 by jayshree again transport  on 21.07.2007
                tot_wrbtr = tot_wrbtr + i_wrbtr.
                i_totday = it_bseg-zbd1t + it_bseg-zbd2t + it_bseg-zbd3t.
                CALL FUNCTION 'fima_date_create'
                  EXPORTING
                    i_date                        = it_bseg-zfbdt
                 I_FLG_END_OF_MONTH            = ' '
                 I_YEARS                       = 0
                 I_MONTHS                      = 0
                   i_days                        = i_totday
                 I_CALENDAR_DAYS               = 0
                 I_SET_LAST_DAY_OF_MONTH       = ' '
                 IMPORTING
                   e_date                        = i_bday
                 E_FLG_END_OF_MONTH            =
                 E_DAYS_OF_I_DATE              =
    added by JAYSHREE 01.02.2007
                CONCATENATE  i_bday6(2) i_bday4(2) i_bday+2(2)
                INTO vbday SEPARATED BY '.'.
                i_day = it_bseg-augdt - i_bday.
            CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
              EXPORTING
                date1                         = it_bseg-zfbdt
                date2                         = it_bseg-augdt
               OUTPUT_FORMAT                 = '01'
             IMPORTING
               YEARS                         =
               MONTHS                        =
               DAYS                          = i_day
             EXCEPTIONS
               INVALID_DATES_SPECIFIED       = 1
               OTHERS                        = 2
            IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            ENDIF.
    *added by sunil 5.11.07 ***********
    *read table it_intitit with key BELNR_TO = BSEG-BELNR  .
    *LOOP AT IT_INTITIT.
                rf140-element = '521'.
                CALL FUNCTION 'write_form'
                  EXPORTING
                    window  = 'main'
                    element = '521'
                  EXCEPTIONS
                    window  = 1
                    element = 2.
                IF sy-subrc = 1.
                  window = 'main'.
                  PERFORM message_window.
                ENDIF.
                IF sy-subrc = 2.
                  window = 'main'.
                  ereignis = '521'.
                  PERFORM message_element.
                ENDIF.
                IF save_xumstn IS INITIAL.
    *-------Umsatzsteuer -
                  IF xactiv IS INITIAL.
                    save_waers = rf140-waers.
                    PERFORM tax_data.
                    CLEAR taxlines.
                    DESCRIBE TABLE atax LINES taxlines.
                    IF NOT taxlines IS INITIAL.
                      LOOP AT atax.
                        CLEAR ereignis.
                        CLEAR rf140-msatz.
                        CLEAR rf140-vtext.
                        rf140-msatz = atax-msatz.
                         *rf140-msatz = atax-msatz.
                        rf140-vtext = atax-vtext.
                         *rf140-vtext = atax-vtext.
    *******begin of change by karthikeyan on 10.03.06*********************
                        IF sy-tabix = '1'.
                          ereignis = '522'.
                          v_stax = rf140-msatz * rf140-gsaldf / 100.
                        ELSE.
                          ereignis = '523'.
                          v_ecs = rf140-msatz * v_stax / 100.
                          v_total = rf140-gsaldf + v_stax + v_ecs.
                        ENDIF.
                        CALL FUNCTION 'hr_in_chg_inr_wrds'
                          EXPORTING
                            amt_in_num               = v_total
                          IMPORTING
                            amt_in_words             = v_spell
                        EXCEPTIONS
                          DATA_TYPE_MISMATCH       = 1
                          OTHERS                   = 2
                        IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
                        ENDIF.
    ***************************end of change******************************
                        CLEAR rf140-element.
                        rf140-element = ereignis.
                        IF NOT ereignis IS INITIAL.
                          CALL FUNCTION 'write_form'
                            EXPORTING
                              window  = 'main'
                              element = ereignis
                            EXCEPTIONS
                              window  = 1
                              element = 2.
                          IF sy-subrc = 1.
                            window = 'main'.
                            PERFORM message_window.
                          ENDIF.
                          IF sy-subrc = 2.
                            window = 'main'.
                            PERFORM message_element.
                          ENDIF.
                        ENDIF.
                      ENDLOOP.
                    ENDIF.
                  ENDIF.
                ENDIF.
               ENDLOOP.
              ENDIF.
            ENDLOOP.
    '521' is the element name in the main  window where i should display the values. before select qurey the values are coming in the bseg but not in table INTITIT.  Belnr is the document no with ref to that
    there are number  of invoices nos. so in both the tables it is selecting single value and displaying but in bseg the invoice number is getting refreshed and new number is coming in that place i.e in field bseg-rebzg but in INTITIT  in belnr only it is taking single value it is not getting refreshed.
       move-corresponding hbseg to bseg.
                 *bseg = bseg.
                if bkpf-waers ne *bkpf-waers.
    this is the syntax whr the values in bseg are getting refresh and new invoice number is selecting.
    How to write the syntax for INTITIT? As per invoice number it is giving new values.
    The invoice number in Bseg is different campare to in table INTITIT. in output is shoud show the fields as follows
    it_besg-rebzg(invoice number of besg) it_besg-zuonr(invoice date) INTITIT-INT_BASAMT(base amount) i_day (no of days ) INTITIT-INT_BEGIN (INTREST START DATE) INTITIT-INT_end(INTREST END DATE)  rf140-wrshb(INTREST AMOUNT).
    THE VALUE OF IT_BESG-REBZG IS CHANGING  BUT THE VALUE IN INTITIT-BELNR ( INVOICE NUMBER) IS NOT CHANGING THAT IS WHY IT IS SHOWING
    ONLY SINGLE RECORD.
    for both the table documet no is same. in besg-belnr is the document no. in intitit-BELNR_TO is the document no.
    here in bseg-rebzg is chaning but in INTITIT-BELNR IS  not changing.
    If i take loop at INTITIT. ALL the values are repating so i am unable to take loop. so i want to write
    a syntax such that intitit-belnr should be refreshed and also for every loop it shoud take new invoice no.
    Please help me out it is very urgent.
    <b>USEFUL ANSWERS WILL BE REWARDED.</b>
    regards,
    Sunil kumar.

    assumption: some mistake in ur posting that, How belnr and date r same for both header records, so i guess, either one is different.
    try with AT NEW - ENDAT.
    AT NEW belnr.
    here use looping, READing of ur itabs.---> so, u need to build couple of itabs to move forth and back.
    ENDAT.
    pls. note that, when u use this AT NEW all the CHAR fileds of itab wuld show as STARS **.....so, this is the necessity behind building new itabs.
    thanq
    Edited by: SAP ABAPer on Dec 30, 2008 6:24 PM

  • Problem in moving the data into final internal table

    Hello all,
    I am stuck in apeculair situation.
    I have a internal table having header record and a internal table having its line items.
    Header record ::    90006103  A   20080110   ALBERTA    3456
    Detail   record ::    90006103  D2  2219CR1710441
                               90006103  D2  2219M11710443
                               90006103  D2  2219M21710442
                               90006103  A    20080115   ALBERTA    3456
                               90006103  D2  2219CR1710441
                               90006103  D2  2219M11710443
                               90006103  D2  2219M21710442
    I collected the header record in one internal table and another internal table having all the line items.But the problem is when i am moving the values to the final inernal table i am getting the same payment date
    20080110 (Date field in first record of header internal table) for all the line items .
    But my requirement is that date should be 20080110 for the first 3 line items of first header record and similarly date should be 20080115 for all the line items of the next header record.
    Kindly suggest.
    Regards,
    Arun

    assumption: some mistake in ur posting that, How belnr and date r same for both header records, so i guess, either one is different.
    try with AT NEW - ENDAT.
    AT NEW belnr.
    here use looping, READing of ur itabs.---> so, u need to build couple of itabs to move forth and back.
    ENDAT.
    pls. note that, when u use this AT NEW all the CHAR fileds of itab wuld show as STARS **.....so, this is the necessity behind building new itabs.
    thanq
    Edited by: SAP ABAPer on Dec 30, 2008 6:24 PM

  • Statements

    explain
    on change of
    endon.
    at new
    endat.

    <b>ON CHANGE OF </b>
    Syntax
    ON CHANGE OF dobj [OR dobj1 [OR dobj2] ... ].
      statement_block
    ENDON.
    Effect:
    The statements ON CHANGE OF and ENDON, which are forbidden in classes, define a control structure that can contain a statement block statement_block. After ON CHANGE OF, any number of data objects dobj1, dobj2... of any data type can be added, linked by OR.
    Example:
    In a SELECT loop, a statement block should only be executed if the content of the column CARRID has changed.
    DATA spfli_wa TYPE spfli.
    SELECT *
           FROM spfli
           INTO spfli_wa
           ORDER BY carrid.
      ON CHANGE OF spfli_wa-carrid.
      ENDON.
    ENDSELECT.
    The following section of a program shows how the ON control structure can be replaced by an IF control structure with an explicit auxiliary variable carrid_buffer.
    DATA carrid_buffer TYPE spfli-carrid.
    CLEAR carrid_buffer.
    SELECT *
           FROM spfli
           INTO spfli_wa
           ORDER BY carrid.
      IF spfli_wa-carrid <> carrid_buffer.
        carrid_buffer = spfli_wa-carrid.
      ENDIF.
    ENDSELECT.
    <b>ENDON </b>
    Syntax
    ENDON.
    Effect
    The ENDON statement closes a conditional statement block introducud by ON CHANGE OF.
    <b>AT - itab </b>
    Syntax
    LOOP AT itab result ...
      [AT FIRST.
       ENDAT.]
        [AT NEW comp1.
         ENDAT.
           [AT NEW comp2.
           ENDAT.
           AT END OF comp2.
           ENDAT.]
         AT END OF comp1.
         ENDAT.]
      [AT LAST.
      ENDAT.]
    ENDLOOP.
    Extras:
    1. ...  FIRST
    2. ... |{END OF} comp
    3. ...  LAST
    Effect
    The statement block of a LOOP loop can contain control structures for control level processing. The respective control statement is AT. The statements AT and ENDAT define statement blocks that are executed at control breaks. Within these statement blocks, the statement SUM can be specified to total numeric components of a group level. In the case of output behavior result, the same applies as for LOOP AT.
    So that group level processing can be executed correctly, the following rules should be noted:
    After LOOP there should be no limiting condition cond specified.
    The internal table must not be modified within the LOOP loop.
    The work area wa specified in the LOOP statement after the INTO addition must be compatible with the line type of the table.
    The content of a work area wa specified in the LOOP statement after the INTO addition must not be modified.
    The prerequisite for control level processing is that the internal table is sorted in exactly the same sequence as the component of its line type - that is, first in accordance with the first component, then in accordance with the second component, and so on. The line structure and the corresponding sorting sequence gives a group structure of the content of the internal table, whose levels can be evaluated using AT statements. The AT-ENDAT control structures must be aligned one after the other, in accordance with the group structure.
    The statement blocks within the AT-ENDAT control structures are listed if an appropriate control break is made in the current table line. Statements in the LOOP-ENDLOOP control structure that are not executed within an AT-ENDAT control structure are executed each time the loop is run through.
    If the INTO addition is used in the LOOP statement to assign the content of the current line to a work area wa, its content is changed upon entry into the AT-ENDAT control structure as follows:
    The components of the current group key will remain unchanged.
    All components with a character-type, flat data type to the right of the current group key are set to character "*" at that position.
    All the other components to the right of the current group key are set to their initial value.
    When the AT-ENDAT control structure is exited, the content of the current table line is assigned to the entire work area wa.
    Regards,
    Pavan

  • What are the internal table events

    hi experts
    can u help me for this

    Hi ramesh,
    There are basically internal table events are as below...
    at first / endat
    at last / endat
    at new / endat
    at end of / endat
    sum
    on change of / endon
    Use the at first and at last statements to perform processing during the first or last loop pass of an internal table.
    Use the at new and at end of statements to detect a change in a column from one loop pass to the next. These statements enable you to execute code at the beginning and end of a group of records.
    Use the sum statement to calculate totals for the rows of a control level.
    Another statement you can use to perform control break processing is on change of. It behaves in a manner similar to at new.
    on change of differs from at new in the following respects:
    It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.
    A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.
    When used within a loop, a change in a field to the left of the control level does not trigger a control break.
    When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.
    You can use else between on change of and endon.
    You can use it with loop at it where . . ..
    You can use sum with on change of. It sums all numeric fields except the one(s) named after of.
    Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.
    <b>Reward Points if it useful....</b>
    Thanks and Regards
    Sreenivasa sharma k.

  • Controlbreak statments

    hai everyone, plz tell me where should we use the control break statments in the reports i want format of the reports

    After you fill an internal table with data, you often need to write the data out. This output will frequently contain summary information (such as totals) at the top or bottom of the report. There might also be interim summaries (such as subtotals) within the body of the report.
    For example, suppose you need to write the G/L figures from ztxlfc1 for each vendor, with subtotals by fiscal year and a grand total at the bottom of the report.
    To do this, you can read the data into an internal table and then, within loop at, use the following statements:
    at first / endat
    at last / endat
    at new / endat
    at end of / endat
    sum
    on change of / endon
    on change of differs from at new in the following respects:
    It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.
    A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.
    When used within a loop, a change in a field to the left of the control level does not trigger a control break.
    When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.
    You can use else between on change of and endon.
    You can use it with loop at it where . . ..
    You can use sum with on change of. It sums all numeric fields except the one(s) named after of.
    Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.
    Using on change of in Two Different Ways: Inside of loop at and Inside of select
    report ztx1312.
    tables ztxlfa1.
    data: begin of it occurs 4,
    f1 type i,
    f2,
    f3 type i,
    f4,
    end of it.
    it-f1 = 1. it-f2 = 'A'. it-f3 = 11. it-f4 = 'W'. append it.
    it-f1 = 3. it-f2 = 'A'. it-f3 = 22. it-f4 = 'X'. append it.
    it-f1 = 1. it-f2 = 'A'. it-f3 = 33. it-f4 = 'Y'. append it.
    it-f1 = 2. it-f2 = 'A'. it-f3 = 44. it-f4 = 'Z'. append it.
    loop at it.
    on change of it-f2.
    write: / it-f1, it-f2, it-f3, it-f4.
    endon.
    endloop.
    write: / 'End of loop'.
    executing the same code again - the aux field still contains 'A'
    loop at it.
    at first.
    write: / 'Looping without a reset...'.
    endat.
    on change of it-f2.
    write: / it-f1, it-f2, it-f3, it-f4.
    else.
    write: / 'on change of not triggered for row', sy-tabix.
    endon.
    endloop.
    write: / 'End of loop'.
    *reset the aux field to blanks
    clear it-f2.
    on change of it-f2.
    endon.
    loop at it.
    at first.
    write: / 'Looping after reset...'.
    endat.
    on change of it-f2.
    write: / it-f1, it-f2, it-f3, it-f4.
    endon.
    endloop.
    write: / 'End of loop'.
    free it.
    select * from ztxlfa1 where land1 = 'US'.
    on change of ztxlfa1-land1.
    write: / 'land1=', ztxlfa1-land1.
    endon.
    endselect.
    write: / 'End of select'.
    *executing the same select again without a reset works find
    select * from ztxlfa1 where land1 = 'US'.
    on change of ztxlfa1-land1.
    write: / 'land1=', ztxlfa1-land1.
    endon.
    endselect.
    write: / 'End of select'.
    O/p :
    1 A 11 W
    End of loop
    Looping without a reset...
    on change of not triggered for row 2
    on change of not triggered for row 3
    on change of not triggered for row 4
    End of loop
    Looping after reset...
    1 A 11 W
    End of loop
    land1= US
    End of select
    land1= US
    End of select

  • Instead of collect .

    How you any idea about below code . I want to collect netwr and fkimg fields interms of different ytab-vblen  . Performs are convert currency and it put into netwr_y and fkimg_y fields .
    LOOP AT ytab .
        move-corresponding ytab to son_tab .
        clear vbrp.
        SELECT   * FROM vbrp
         WHERE matnr = ytab-matnr.
          son_tab-vbeln = vbrp-vbeln .
          son_tab-posnr = vbrp-posnr .
          son_tab-fbuda = vbrp-fbuda .
          son_tab-fkimg = vbrp-fkimg .
          son_tab-netwr = vbrp-netwr .
          CLEAR vbrk .
          SELECT SINGLE * FROM vbrk
           WHERE vbeln = son_tab-vbeln .
          son_tab-waerk = vbrk-waerk .
          son_tab-fkart = vbrk-fkart .
          IF vbrk-fkart = 'G2' OR  vbrk-fkart =  'RE'.
            son_tab-fkimg =  son_tab-fkimg * -1 .
            son_tab-netwr =  son_tab-netwr * -1 .
          ENDIF.
            IF son_tab-waerk EQ lv_local_currency .
          PERFORM cnt_fbuda .
        ENDIF.
        IF son_tab-waerk NE lv_local_currency .
          PERFORM para_birimi.
        ENDIF.
        fatura = 0.
        miktar = 0 .
        fatura = netwr_y + fatura .
        miktar = fkimg_y + miktar .
        son_tab-netwr = fatura .
        son_tab-fkimg = miktar .
        ENDSELECT.
      ENDLOOP .

    Hi,
      If you need to collect at differ ytab-vblen use the <b>Control level statements</b> AT NEW & ENDAT.
    Ex:
    sort ytab by vbeln.
    LOOP AT ytab.
      AT NEW vblen.
       COLLECT ytab.
      ENDAT.
    ENDLOOP.
    Raja T
    Message was edited by:
            Raja T

  • Smartform: PAGE/FORM PAGES

    HI All,
    Currently i am using the format SFSY-PAGE and SFSY-FORMPAGES to display in the format "current page / total pages".....
    But the requirement is to split the Total pages based on the new record being printed in the output. Say Total pages in original are 12, out of which there are 2 PO's (One PO with 5 Pages of data and second with the rest of 7 pages output)
    then my output should look like 1/5...2/5....till 5/5 and again the numbering should start like 1/7...2/7....3/7....till 7/7 and so on....
    Could any body suggest on this?
    Regards

    Hello,
    So system varible wont work in ur case,u have to handle the page no.
    In similar case like this what i did is.
    I declared internal table with 2 fields one for PONO and the other for total pages for that po.Examle it_page-po,it_page-page.
    So first run the loop and calculate for particular po no of pages.
    Example:
    loop at itab.
    at new po.
    it_page-po = itab-po.
    endat.
    it_page-page = it_page-page + 1.
    at end po.
    append it_page.
    clear it_page.
    endat.
    endloop.
    ***So above u will get the pages for each po
    Next when u run the loop again set the varible for each page and calculate the pages.
    Say for example page is the varible.
    loop at itab.
    at new.
    endat.
    page = page + 1.
    display the output.
    endloop.
    So in the smartform the out put should be
    PAGE/IT_PAGE-PAGE
    Try in this way in the smartform u can suceed.Let me know if u face any problem.
    Regards

  • SUM statement efficiency

    Hi everyone
    I need to calculate some totals in an itab and have discivered the SUM statement, which seems a very easy way to achieve this.  However, being a cynical chap I was wondering if this carries a large overhead and will be less efficient than just storing a running total in a variable i.e x = x + y.
    I anybody able to shed any light...?
    Thanks
    Andy

    SUM.
    Effect
    When processing an internal table in a block starting with LOOP and concluded by ENDLOOP , SUM calculates the control totals of all fields of type I , F and P (see also ABAP/4 number types ) and places them in the LOOP output area (header line of the internal table or an explicitly specified work area).
    Sum statement in report is basically used in Control Break Processing.
    After you fill an internal table with data, you often need to write the data out. This output will frequently contain summary information(uch as totals) at the top or bottom of the report.There might also be interim situations (such as subtotals ) within the body of report.
    To do this , you can read the data into an internal table and then, within loop at , use the following statements:
    1. at first / endat
    2.at last / endat
    3.at new / endat
    4.at end of / endat
    5.sum
    6.on change of / endon.
    The first statement of each of these pairs - except for Sum - controls when the code lies between them is executed.This type of control is called a control break.Their purpose is to ececute the code between them whenever a specific condition in the data is detected during the processing of the loop.
    Using the Sum statement :
    syntax :
    at first/last/new/end of.
    sum
    endat.
    where :
    ... represents any number of lines of code.
    Sum calculates a total for the current value of the control level that contains it.
    It finds all rows that have the same values within the control level field and all fields of the left of it.
    It sums each numeric column to the right of the control level.
    It places the totals in the corresponding fields of the work area.

  • Doubts with control break statements on internal table loops (AT/ENDAT)

    Hi, i've had a couple of doubts for a long while which I hope someone can clarify today:
    1) I know how to use the AT statements, however, i'm not sure I get correctly what this part of help regarding this commands means:
    <i>"The control level structure with internal tables is static. It corresponds exactly to the sequence of columns in the internal table (from left to right). In this context, the criteria according to which you sort the internal table are unimportant."</i>
    I've always sorted the internal table before the control break and it works that way. For example:
    SORT ITAB BY EBELN EBELP.
    LOOP AT ITAB.
      AT NEW EBELN.
    *   Code for the order header
      ENDAT.
    ENDLOOP.
    If I <b>don't</b> sort the internal table, it doesn't work! (i get dupplicated processing). In the example, if i have more than one register with the same EBELN and they're not consecutive, the header gets processed twice. I really don't get that part of the help text.
    2) I know this: <i>"At the start of a new control level (i.e. immediately after AT), the following occurs in the output area of the current LOOP statement:
    All character type fields (on the right) are filled with "*" after the current control level key.
    All other fields (on the right) are set to their initial values after the current control level key."</i>
    My doubt is: WHY is that this way? Because sometimes (most times) I need those fields INSIDE the statement! So when that happened i've solved it in one of three ways:
    LOOP AT ITAB INTO WA_ITAB.
      WA_ITAB_AUX = WA_ITAB.
      AT NEW FIELD.
        WA_ITAB = WA_ITAB_AUX.
    *   ...Rest of the code for the first register
      ENDAT.
    ENDLOOP.
    LOOP AT ITAB INTO WA_ITAB.
      AT NEW FIELD.
        READ TABLE ITAB INDEX SY-TABIX INTO WA_ITAB.
    *   ...Rest of the code for the first register
      ENDAT.
    ENDLOOP.
    * (Without AT)
    LOOP AT ITAB INTO WA_ITAB.
      IF WA_ITAB-FIELD <> FIELD_AUX.
        FIELD_AUX = WA_ITAB_FIELD.
    *   ...Rest of the code for the first register
      ENDIF.
    ENDLOOP.
    Is there any problem with this way of coding? Can be done better?
    Thank you very much in advance.

    Hi..,
    1)
    See if u sort the table on a field on which u r using AT ENDAT .. then all the records which are having the same value for that field will form a group or those reocrds will be at one place.. so when u sort the table for all the records  AT ENDAT  will get executed onli once..
    If u dont sort this table on this field then all these records will be at different places and in between there may be records with different value for this field.. so this AT ENDAT will get executed for each record !!
    2)
    No u cannot use the Right hand fields of the field in the table .. Because these AT events work as Group based operations... So till that field on which AT ENDAT is working it breaks that record into two groups.. One is the left hand fields including that field.. and right hand fields as another group.. and makes the right hand group as stars ****.  Thats y u can observe that even any one field in the left hand group changes the AT ENDAT will get executed  !!!!
    Hope u understood !!!
    regards,
    sai ramesh

  • Help in loop and at new

    Hallow I have a program that call to smart form. The user have to put course number and employee number and  the program check if the student pass the course send sf and if don’t  send other sf .my problem is when the user put just course number in, other words he wont to print sf of all the student that do some course , I don’t now how to call to smart form in loop because all the time I have a new student and the program have to check if the student pass the course or not and send sf accordingly.
    I heard about at new but I don’t now how to use it or if its fitting my need .
    regards
    IF pernr IS INITIAL .
    *--For-Empty-Pernr--
      SELECT objid_e 
      FROM yhr_score_page
      INTO wa_score_tab-objid_e
      WHERE objid_e IN c_course.
        IF sy-subrc = 0.
          APPEND wa_score_tab TO score_tab.
          CLEAR wa_score_tab.
        ENDIF.
      ENDSELECT.
    ELSE.
      SELECT objid_e 
        FROM yhr_score_page
        INTO wa_score_tab-objid_e
        WHERE objid_e IN c_course
        AND objid_p = pernr.
        IF sy-subrc = 0.
          APPEND wa_score_tab TO score_tab.
          CLEAR wa_score_tab.
        ENDIF.
      ENDSELECT.
    ENDIF.
    This is  the call fo the smart form
    IF sum_n GE passed_nuric. " if student pass course use first function
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname               = 'YHR_SCORE_SMART_FORM_PASS'
      VARIANT                  = ' '
      DIRECT_CALL              = ' '
       IMPORTING
         fm_name                  = /1bcdwb/sf00000005
    EXCEPTIONS
      NO_FORM                  = 1
      NO_FUNCTION_MODULE       = 2
      OTHERS                   = 3
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL FUNCTION '/1BCDWB/SF00000005'
        EXPORTING
      ARCHIVE_INDEX              =
      ARCHIVE_INDEX_TAB          =
      ARCHIVE_PARAMETERS         =
      CONTROL_PARAMETERS         =
      MAIL_APPL_OBJ              =
      MAIL_RECIPIENT             =
      MAIL_SENDER                =
      OUTPUT_OPTIONS             =
      USER_SETTINGS              = 'X'
          score_tab2                 = wa_score_tab2
          sum_all                    = sum_all
          sum_n                      = sum_n
    IMPORTING
      DOCUMENT_OUTPUT_INFO       =
      JOB_OUTPUT_INFO            =
      JOB_OUTPUT_OPTIONS         =
        TABLES
          score_tab                  = score_tab
    EXCEPTIONS
      FORMATTING_ERROR           = 1
      INTERNAL_ERROR             = 2
      SEND_ERROR                 = 3
      USER_CANCELED              = 4
      OTHERS                     = 5
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    *--dont pass--
    ELSE.
      READ TABLE score_tab INDEX 1 INTO wa_score_tab.
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname               = 'YHR_SCORE_SMART_FORM'
      VARIANT                  = ' '
      DIRECT_CALL              = ' '
       IMPORTING
         fm_name                  = /1bcdwb/sf00000002
    EXCEPTIONS
      NO_FORM                  = 1
      NO_FUNCTION_MODULE       = 2
      OTHERS                   = 3
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL FUNCTION '/1BCDWB/SF00000002'
        EXPORTING
      ARCHIVE_INDEX              =
      ARCHIVE_INDEX_TAB          =
      ARCHIVE_PARAMETERS         =
      CONTROL_PARAMETERS         =
      MAIL_APPL_OBJ              =
      MAIL_RECIPIENT             =
      MAIL_SENDER                =
      OUTPUT_OPTIONS             =
      USER_SETTINGS              = 'X'
          score_tab                  = wa_score_tab
    IMPORTING
      DOCUMENT_OUTPUT_INFO       =
      JOB_OUTPUT_INFO            =
      JOB_OUTPUT_OPTIONS         =
    EXCEPTIONS
      FORMATTING_ERROR           = 1
      INTERNAL_ERROR             = 2
      SEND_ERROR                 = 3
      USER_CANCELED              = 4
      OTHERS                     = 5
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

    LOOP AT itab.
    AT NEW stud.
      perform xxxx.
    ENDAT.
    ENDLOOP.
    Refer SF
    Refer this link for Smartforms
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d937ec90-0201-0010-0ca8-b6cb3b6dd1ef
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b590fd97-0301-0010-db90-d09ff93cee5a
    Subroutine in smartform
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/ccab6730-0501-0010-ee84-de050a6cc287
    Style and mailing the Smartform output
    https://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/8fd773b3-0301-0010-eabe-82149bcc292e
    Table,Template,Loop and Command in Smartform
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/3c5d9ae3-0501-0010-0090-bdfb2d458985

Maybe you are looking for

  • Some graphs don't display in OEM Grid Control 10gR5 (10.2.0.5)

    A number of the performance graphs (e.g. Top Activity) don't display i.e. there is nothing but if if you right-click in the empty area you get a small pull down with Print, Settings, About Adobde Flash 10. This has all happend after upgrading to 10.2

  • VAT against Free Issue Material

    Dear Sir, We have a scenario where we get Free Issue Material from our Customer . We do MIGO against the receipt of  such Material , without referencing the Purchase Order . We are required to avail the VAT also against the receipt of such Material .

  • How to add titles to multiple pictures at same time in iphoto11

    I am having difficulty navigating in iphoto11. Can not figure out how to add keywords to multiple photos or how to add the same title to multiple photos.

  • Attachments  in XI

    Hi Experts, I have a requirement to attach a pdf file. I refered to the blog below . How to send any data (even binary) through XI, without using the Integration Repository How to send any data (even binary) through XI, without using the Integration

  • Can anyone help with a jar question?

    Okay, I'm trying to create Icon objects of particular gif files I have located in a directory /gui/common/data I want to be able to call these gif files in such a way that upon loading a jar file with all the necessary ingredients, it is a complete p