Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

AT NEW statement

Former Member
0 Kudos

Hi everyone,

I would like to move/append a line from 1 internal table (DTAB_ISSUE) for every 1st occurance of a new material number (MATNR). Based on my logic below, it did manage move the first line correctly to my target internal table (DTAB) but for some reason, the first field which is DTAB-MATNR contains the material number, but the other fields all get asterisks (*)...why?

I declared my tables as follows:


DATA: BEGIN OF DTAB OCCURS 0,
        MATNR LIKE AUFM-MATNR,      "Material Number
        MBLNR LIKE AUFM-MBLNR,      "Number of Material Document
        BUDAT LIKE AUFM-BUDAT,      "Posting Date in the Document
        BWART LIKE AUFM-BWART,      "Movement Type
        CHARG LIKE AUFM-CHARG,      "Batch Number
        WERKS LIKE AUFM-WERKS,      "Plant
      END OF DTAB.

DATA: BEGIN OF DTAB_ISSUE OCCURS 0,
        MATNR LIKE AUFM-MATNR,      "Material Number
        MBLNR LIKE AUFM-MBLNR,      "Number of Material Document
        BUDAT LIKE AUFM-BUDAT,      "Posting Date in the Document
        BWART LIKE AUFM-BWART,      "Movement Type
        CHARG LIKE AUFM-CHARG,      "Batch Number
        WERKS LIKE AUFM-WERKS,      "Plant
      END OF DTAB_ISSUE.

*--> Select statement to fill up DTAB_ISSUE

SORT DTAB_ISSUE BY MATNR MBLNR DESCENDING.

LOOP AT DTAB_ISSUE.
  AT NEW MATNR.
    WRITE DTAB_ISSUE TO DTAB.
    APPEND DTAB.
  ENDAT.
ENDLOOP.

Is there a way to make the values for the fields after DTAB-MATNR to appear as it suppose to?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi bernard,

1. U are right.

2. We get **** in other fields.

3. So instead of AT NEW

4. <b>use ON CHANGE event.</b>

5. In this case, u will not get ****

but u will get the other fields of that particular row

on which the event fires.

regards,

amit m.

6 REPLIES 6

Former Member
0 Kudos

Hi bernard,

1. U are right.

2. We get **** in other fields.

3. So instead of AT NEW

4. <b>use ON CHANGE event.</b>

5. In this case, u will not get ****

but u will get the other fields of that particular row

on which the event fires.

regards,

amit m.

Former Member
0 Kudos

Hai Bermard

Check the following Document

AT NEW f.

Variant 2

AT END OF f.

Effect

f is a sub-field of an internal table processed with LOOP . The sequence of statements which follow it is executed if the sub-field f or a sub-field in the current LOOP line defined (on the left) before f has a differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.

Example

DATA: BEGIN OF COMPANIES OCCURS 20,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES.

...

LOOP AT COMPANIES.

AT NEW NAME.

NEW-PAGE.

WRITE / COMPANIES-NAME.

ENDAT.

WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.

AT END OF NAME.

SUM.

WRITE: / COMPANIES-NAME, COMPANIES-SALES.

ENDAT.

ENDLOOP.

The AT statements refer to the field COMPANIES-NAME .

Notes

If a control break criterion is not known until runtime, you can use AT NEW (name) or AT END OF (name) to specify it dynamically as the contents of the field name . If name is blank at runtime, the control break criterion is ignored and the sequence of statements is not executed. If name contains an invalid component name, a runtime error occurs.

By defining an offset and/or length, you can further restrict control break criteria - regardless of whether they are specified statically or dynamically.

A field symbol pointing to the LOOP output area can also be used as a dynamic control break criterion. If the field symbol does not point to the LOOP output area, a runtime error occurs

Thanks & regards

Sreenivasulu P

Former Member
0 Kudos

Hi Bernard,

At new statement renders all the char fields unusable..

u can try this instead..

data : var like mara-matnr.

clear var.

loop at itab.

if var <> itab-matnr.

var = itab-matnr.

<b> this space now acts as AT NEW..</b>

endif.

endloop.

Former Member
0 Kudos

Hi Bernard,

An easy way, use a structure :


*--> Select statement to fill up DTAB_ISSUE
 
Data : begin of s_dtab_issue,
include structure dtab.
data : end of s_dtab_issue.


SORT DTAB_ISSUE BY MATNR MBLNR DESCENDING.
 
LOOP AT DTAB_ISSUE.
<b>clear S_DATB_ISSUE.</b>
move DTAB_ISSUE to <b>S_DTAB_ISSUE</b>
  AT NEW MATNR.
    WRITE <b>S_DTAB_ISSUE</b> TO DTAB.
    APPEND DTAB.
  ENDAT.
ENDLOOP.

Hope it helps,

Best Regards,

Erwan.

Former Member
0 Kudos

Hi.

U can use

on change of DTAB_ISSUE-MATNR.

endon.

OR

create a stucture of type DTAB_ISSUE as

itab like DTAB_ISSUE.

LOOP AT DTAB_ISSUE.

itab = DTAB_ISSUE.

AT NEW MATNR.

WRITE itab TO DTAB.

APPEND DTAB.

ENDAT.

ENDLOOP.

Bye.

rahulkavuri
Active Contributor
0 Kudos

This condition arises because u are not using read statement again... check this sample code..

Whenever we use at new always we need to read table again to avoid *** for the fields

LOOP AT T_VBRK_VBRP.
    V_SYTAB = SY-TABIX.
    AT NEW VBELN.
      READ TABLE T_VBRK_VBRP INDEX V_SYTAB.
      READ TABLE IT_VBRK WITH KEY VBELN = T_VBRK_VBRP-VBELN.
      IF SY-SUBRC = 0.
        T_VBRK_VBRP-FKDAT = IT_VBRK-FKDAT.
        MODIFY T_VBRK_VBRP  TRANSPORTING FKDAT
                  WHERE VBELN = IT_VBRK-VBELN.
      ENDIF.
    ENDAT.
  ENDLOOP.

Award points if found helpful