Application Development and Automation 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: 
Read only

Control Break statement

Former Member
0 Likes
1,061

How to use atnew, at last,sum events pl send me with coding.

Its urgent

7 REPLIES 7
Read only

Former Member
0 Likes
928

Hi

All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table

FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.

Some time you will get * when mopving data from this int table to other table using these commands

so you have to use

READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.

<b>Reward points for useful Answers</b>

Regards

Anji

Read only

0 Likes
928

Hi

The field position is important for the fields that are using in the control break statements..Also SORT internal table is required.

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm



DATA: BEGIN OF ITAB OCCURS 0,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
VALUE TYPE NETPR,
END OF ITAB.
 
ITAB-MATNR = 'ABC'.
ITAB-WERKS = '0100'.
ITAB-VALUE = '10.00'.
APPEND ITAB.
 
ITAB-MATNR = '1ABC'.
ITAB-WERKS = '0100'.
ITAB-VALUE = '10.00'.
APPEND ITAB.
 
SORT ITAB BY MATNR WERKS.
 
LOOP AT ITAB.
 
 AT FIRST.
  WRITE : 'AT FIRST'.
 ENDAT.
 
 AT NEW MATNR.
  WRITE : 'AT NEW MATERIAL NUMBER'.
 ENDAT.
 
 AT END OF MATNR.
  SUM.
  WRITE: / ITAB-MATNR, 'MATERIAL TOTAL - ', ITAB-VALUE.
 ENDAT.
 
 AT END OF WERKS.
  SUM.
  WRITE: / ITAB-WERKS, 'PLANT TOTAL - ', ITAB-VALUE.
 ENDAT.
 
 AT LAST.
  WRITE : 'AT LAST'.
 ENDAT.
ENDLOOP.

AT - Control break with internal tables

<u><b>Variants</b></u>

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

<b>Effect</b>

In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .

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 default key 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.

Between AT and ENDAT , you can use SUM to insert the appropriate control totals in the number fields (see also ABAP/4 number types ) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level ( AT FIRST , AT NEW f ) and also the end of a control level ( AT END OF f , AT LAST ).

At the end of the control level processing (i.e. after ENDAT ), the old contents of the LOOP output area are restored.

<u><b>Notes</b></u>

When calculating totals, you must ensure that the totals are inserted into the same sub-fields of the LOOP output area as those where the single values otherwise occur. If there is an overflow, processing terminates with a runtime error.

If an internal table is processed only in a restricted form (using the additions FROM , TO and/or WHERE with the LOOP statement), you should not use the control structures for control level processing because the interaction of a restricted LOOP with the AT statement is currenly not properly defined.

With LOOP s on extracts, there are also special control break control structures you can use.

<u><b>Note</b></u>

Runtime errors

SUM_OVERFLOW : Overflow when calculating totals with SUM .

Variant 1

AT NEW f.

Variant 2

AT END OF f.

<b>Effect</b>

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.

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 .

<u><b>Notes</b></u>

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.

<b><u>Note</u></b>

Runtime errors

AT_BAD_PARTIAL_FIELD_ACCESS : Invalid sub-field access when dynamically specifying the control break criterion.

AT_ITAB_FIELD_INVALID : When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.

ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.

Variant 3

AT FIRST.

Variant 4

AT LAST.

<b>Effect</b>

Executes the appropriate sequence of statements once during the first ( AT FIRST ) or last ( AT LAST ) loop pass.

<b>Example</b>


DATA: BEGIN OF COMPANIES OCCURS 20,
        NAME(30),
        PRODUCT(20),
        SALES TYPE I,
      END   OF COMPANIES.
...
LOOP AT COMPANIES.
  AT FIRST.
    SUM.
    WRITE:    'Sum of all SALES:',
           55 COMPANIES-SALES.
  ENDAT.
  WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,
        55 COMPANIES-SALES.
ENDLOOP.

<b>

Example program which uses all Control statements :</b>


REPORT Zcontrol_DEMO.
 
DATA: T1(4), T2 TYPE I.
 
FIELD-GROUPS: HEADER.
 
INSERT T2 T1 INTO HEADER.
 
T1 ='AABB'. T2 = 1. EXTRACT HEADER.
T1 ='BBCC'. T2 = 2. EXTRACT HEADER.
T1 ='AAAA'. T2 = 2. EXTRACT HEADER.
T1 ='AABB'. T2 = 1. EXTRACT HEADER.
T1 ='BBBB'. T2 = 2. EXTRACT HEADER.
T1 ='BBCC'. T2 = 2. EXTRACT HEADER.
T1 ='AAAA'. T2 = 1. EXTRACT HEADER.
T1 ='BBBB'. T2 = 1. EXTRACT HEADER.
T1 ='AAAA'. T2 = 3. EXTRACT HEADER.
T1 ='AABB'. T2 = 1. EXTRACT HEADER.
 
SORT BY T1 T2.
 
LOOP.
 
  AT FIRST.
    WRITE 'Start of LOOP'.
    ULINE.
  ENDAT.
 
  AT NEW T1.
    WRITE / '   New T1:'.
  ENDAT.
 
  AT NEW T2.
    WRITE / '   New T2:'.
  ENDAT.
 
  WRITE: /14 T1, T2.
 
  AT END OF T2.
    WRITE / 'End of T2'.
  ENDAT.
 
  AT END OF T1.
    WRITE / 'End of T1'.
  ENDAT.
 
  AT LAST.
    ULINE.
  ENDAT.
 
ENDLOOP.

\

Check this link

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db9f1f35c111d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_webas620/helpdata/en/87/56d00722c011d2954a0000e8353423/content.htm

http://www.sap-img.com/abap/important-abap-faq.htm

http://www.sap-basis-abap.com/abap/sap-abap-faq.htm

reward all helpfull answers

Regards

Pavan

Read only

Former Member
0 Likes
928

hi

at first - endat

Processed at the beginning of the table .

Executes the relevant series of statements just once

at new f - endat

Processed when f changes or one of the preceding fields has just changed.

at end of f – endat

at last - endat

Processed at the end of the table

Executes the relevant series of statements just once

<b>SUM.</b>

You can only use this statement within a LOOP. If you use SUM in an AT - ENDAT block, the system calculates totals for the numeric fields of all lines in the current line group and writes them to the corresponding fields in the work area (see example in ). If you use the SUM statement outside an AT - ENDAT block (single entry processing), the system calculates totals for the numeric fields of all lines of the internal table in each loop pass and writes them to the corresponding fields of the work area. It therefore only makes sense to use the SUM statement in AT...ENDAT blocks.

If the table contains a nested table, you cannot use the SUM statement. Neither can you use it if you are using a field symbol instead of a work area in the LOOP statement.

EG :

DATA: BEGIN OF T OCCURS 100,

CODE(4),

SALES TYPE P,

DISCOUNT TYPE P,

END OF T.

LOOP AT T.

AT FIRST.

SUM.

WRITE: /4 'Grand Total:',

20 T-SALES, 40 T-DISCOUNT.

ULINE. SKIP.

ENDAT. WRITE: / T-CODE,

20 T-SALES, 40 T-DISCOUNT.

AT END OF CODE.

SUM.

WRITE: / T-CODE, 10 'Total:',

20 T-SALES, 40 T-DISCOUNT.

SKIP. ENDAT. ENDLOOP.

regards

ravish

<b>plz dont forget to reward points if useful</b>

Read only

Former Member
0 Likes
928

Hi,

AT - Control break with internal tables

Variants

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

Effect

In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .

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 default key 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.

Between AT and ENDAT , you can use SUM to insert the appropriate control totals in the number fields (see also ABAP/4 number types ) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level ( AT FIRST , AT NEW f ) and also the end of a control level ( AT END OF f , AT LAST ).

At the end of the control level processing (i.e. after ENDAT ), the old contents of the LOOP output area are restored.

Notes

When calculating totals, you must ensure that the totals are inserted into the same sub-fields of the LOOP output area as those where the single values otherwise occur. If there is an overflow, processing terminates with a runtime error.

If an internal table is processed only in a restricted form (using the additions FROM , TO and/or WHERE with the LOOP statement), you should not use the control structures for control level processing because the interaction of a restricted LOOP with the AT statement is currenly not properly defined.

With LOOP s on extracts, there are also special control break control structures you can use.

Note

Runtime errors

SUM_OVERFLOW : Overflow when calculating totals with SUM .

Variant 1

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.

Note

Runtime errors

AT_BAD_PARTIAL_FIELD_ACCESS : Invalid sub-field access when dynamically specifying the control break criterion.

AT_ITAB_FIELD_INVALID : When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.

ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.

Variant 3

AT FIRST.

Variant 4

AT LAST.

Effect

Executes the appropriate sequence of statements once during the first ( AT FIRST ) or last ( AT LAST ) loop pass.

Example

DATA: BEGIN OF COMPANIES OCCURS 20,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES.

...

LOOP AT COMPANIES.

AT FIRST.

SUM.

WRITE: 'Sum of all SALES:',

55 COMPANIES-SALES.

ENDAT.

WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,

55 COMPANIES-SALES.

ENDLOOP.

Example program which uses all Control statements :

REPORT Zcontrol_DEMO.

DATA: T1(4), T2 TYPE I.

FIELD-GROUPS: HEADER.

INSERT T2 T1 INTO HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 2. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

T1 ='BBBB'. T2 = 2. EXTRACT HEADER.

T1 ='BBCC'. T2 = 2. EXTRACT HEADER.

T1 ='AAAA'. T2 = 1. EXTRACT HEADER.

T1 ='BBBB'. T2 = 1. EXTRACT HEADER.

T1 ='AAAA'. T2 = 3. EXTRACT HEADER.

T1 ='AABB'. T2 = 1. EXTRACT HEADER.

SORT BY T1 T2.

LOOP.

AT FIRST.

WRITE 'Start of LOOP'.

ULINE.

ENDAT.

AT NEW T1.

WRITE / ' New T1:'.

ENDAT.

AT NEW T2.

WRITE / ' New T2:'.

ENDAT.

WRITE: /14 T1, T2.

AT END OF T2.

WRITE / 'End of T2'.

ENDAT.

AT END OF T1.

WRITE / 'End of T1'.

ENDAT.

AT LAST.

ULINE.

ENDAT.

ENDLOOP.

Regards

Read only

varma_narayana
Active Contributor
0 Likes
928

hi..

Data : begin of imat occurs 10,

matnr type mard-matnr,

werks type mard-werks,

lgort type mard-lgort,

labst type mard-labst,

end of imat.

parameters : p_werks type mard-werks.

select matnr werks lgort labst

from mard

into table imat

where werks = p_werks.

LOOP AT IMAT .

at first.

write:/ 'Matno', 'Plant', 'Storgae loc', 'Valuated stock'.

endat.

at new matnr.

write:/ imat-matnr.

endat.

write:/20 imat-werks,

30 imat-lgort,

40 imat-labst.

at end of matnr.

SUM.

write:/ 'Total stock of' , imat-matnr ,'=', imat-labst.

endat.

at last.

endat.

ENDLOOP.

<b>Reward if Helpful</b>

Read only

Former Member
0 Likes
928

Hi,

see this report

REPORT ZINTERACTIVE_FINAL.

INCLUDE <COLOR>.

TABLES:SFLIGHT,SPFLI,SBOOK.

TYPES: BEGIN OF STRUCTURE,

CITYFROM LIKE SPFLI-CITYFROM,

CITYTO LIKE SPFLI-CITYTO,

CARRID LIKE SPFLI-CARRID ,

CONNID LIKE SPFLI-CONNID,

FLDATE LIKE SFLIGHT-FLDATE,

SEATSMAX LIKE SFLIGHT-SEATSMAX,

SEATSOCC LIKE SFLIGHT-SEATSOCC,

END OF STRUCTURE.

DATA : ITAB TYPE STRUCTURE OCCURS 0.

DATA: WA TYPE STRUCTURE.

DATA:LINE LIKE SY-LILLI.

SELECT SPFLICITYFROM SPFLICITYTO SPFLICARRID SPFLICONNID

SFLIGHTFLDATE SFLIGHTSEATSMAX SFLIGHT~SEATSOCC INTO (WA-CITYFROM,

WA-CITYTO,WA-CARRID,WA-CONNID,WA-FLDATE,WA-SEATSMAX,WA-SEATSOCC) FROM

SPFLI INNER JOIN SFLIGHT ON SPFLIMANDT = SFLIGHTMANDT AND SPFLI~CARRID

= SFLIGHTCARRID AND SPFLICONNID = SFLIGHT~CONNID.

*GET SPFLI.

*SELECT * FROM SPFLI.

  • MOVE-CORRESPONDING SPFLI TO WA.

*ENDSELECT.

*GET SFLIGHT.

*SELECT * FROM SFLIGHT.

  • MOVE-CORRESPONDING SFLIGHT TO WA.

*ENDSELECT.

APPEND WA TO ITAB.

ENDSELECT.

SET PF-STATUS 'GRUND'.

SET TITLEBAR 'GRU' .

SORT ITAB BY CITYFROM CITYTO CARRID CONNID SEATSOCC.

*LOOP AT ITAB INTO WA.

*WRITE:/ WA-CARRID,WA-CONNID,WA-CITYFROM,WA-CITYTO.

*ENDLOOP.

LOOP AT ITAB INTO WA.

<b> AT FIRST.</b>

WRITE:/ 'START OUTPUT INTERNAL TABLE'.

ULINE.

ENDAT.

AT NEW CITYFROM.

WRITE:/ WA-CITYFROM COLOR COL_KEY.

ENDAT.

<b>

AT NEW SEATSOCC.</b>

WRITE:/10 WA-CARRID,WA-CONNID,WA-FLDATE COLOR COL_NORMAL,

WA-SEATSOCC COLOR COL_NORMAL,WA-SEATSMAX COLOR COL_NORMAL.

HIDE : WA-CONNID, WA-CARRID, WA-FLDATE.

ENDAT.

AT END OF CONNID.

SUM.

WRITE:/ WA-SEATSOCC COLOR COL_TOTAL UNDER WA-SEATSOCC,

WA-SEATSMAX COLOR COL_TOTAL.

  • ULINE .

ENDAT.

<b> AT END OF CARRID.</b>

SUM.

  • ULINE.

WRITE:/ WA-SEATSOCC COLOR COL_TOTAL INTENSIFIED UNDER

WA-SEATSOCC, WA-SEATSMAX COLOR COL_TOTAL INTENSIFIED.

ULINE.

ENDAT.

ENDLOOP.

CLEAR WA.

AT LINE-SELECTION.

CASE SY-LSIND.

WHEN 1.

WRITE:/' AIRLINE ', WA-CARRID ,

/'FLIGHT CONNECTION',WA-CONNID ,

/'FLIGHT DATE',WA-FLDATE.

ULINE.

SELECT * FROM SBOOK WHERE CARRID = WA-CARRID AND CONNID = WA-CONNID

AND FLDATE = WA-FLDATE .

WRITE 😕 SBOOK-BOOKID,SBOOK-CUSTOMID,SBOOK-ORDER_DATE.

ENDSELECT.

CLEAR WA.

WHEN 2.

LINE = SY-LILLI.

IF LINE > 4.

LINE = LINE - 4.

WRITE:/ 'SELECTED LINE NUMBE:',LINE.

ENDIF.

ENDCASE.

<b>reward if helpful</b>

rgds,

bharat.

Read only

Former Member
0 Likes
928

try this sample code for using cntrl-brk ststements

&----


*& Report YSG_MATSTKREPT

*&material stock report

&----


*&

*&

&----


REPORT YSG_MATSTKREPT LINE-SIZE 125.

  • LINE-COUNT 50(5).

&----


*& DATA DECLARATION *

&----


TABLES: MARA, "GENERAL MASTER DATA

MARC, "PLANT DATA FOR MATERIAL

MARD, "STORAGE LOCATION DATA FOR MATERIAL

MAKT. "MATERIAL DESCRIPTION

DATA: BEGIN OF I_MARA OCCURS 0,

MATNR LIKE MARA-MATNR,"MATERIAL NUMBER

END OF I_MARA.

DATA: BEGIN OF I_MARC OCCURS 0,

MATNR LIKE MARC-MATNR,"MATERIAL NUMBER

WERKS LIKE MARC-WERKS,"PLANT

END OF I_MARC.

DATA: BEGIN OF I_MAKT OCCURS 0,

MATNR LIKE MAKT-MATNR,"MATERIAL NUMBER

MAKTX LIKE MAKT-MAKTX,"MATERIAL DESCRIPTION

END OF I_MAKT.

DATA: BEGIN OF I_MARD OCCURS 0,

MATNR LIKE MARD-MATNR,"MATERIAL NUMBER

WERKS LIKE MARD-WERKS,"PLANT

LGORT LIKE MARD-LGORT,"STORAGE LOCATION

LABST LIKE MARD-LABST,"VALUATED STOCK WITH UNRESTRICTED USE

END OF I_MARD.

DATA: BEGIN OF I_OUT OCCURS 0,

MATNR LIKE MARC-MATNR,

WERKS LIKE MARC-WERKS,

MAKTX LIKE MAKT-MAKTX,

LGORT LIKE MARD-LGORT,

LABST LIKE MARD-LABST,

END OF I_OUT.

DATA : TOT TYPE I, " TOT - TOTAL STOCK

PLSTK TYPE I, " PLSTK - PLZNT WISE STOCK

X TYPE C. "FLAG

&----


*& S E L E C T I O N - S C R E E N *

&----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-100.

SELECT-OPTIONS: S_MATNR FOR MARA-MATNR .

SELECTION-SCREEN END OF BLOCK B1.

*&----


**& I N I T I A L I Z A T I O N *

*&----


*

*INITIALIZATION.

*

    • S_MATNR-SIGN = 'I'.

    • S_MATNR-OPTION = 'EQ'.

  • S_MATNR-LOW = 'M-12'.

  • S_MATNR-HIGH = 'M-18'.

&----


*& S T A R T - O F - S E L E C T I O N *

&----


START-OF-SELECTION.

SELECT MATNR WERKS FROM MARC

INTO TABLE I_MARC

WHERE MATNR IN S_MATNR .

SELECT MATNR WERKS LGORT LABST FROM MARD

INTO TABLE I_MARD

FOR ALL ENTRIES IN I_MARC

WHERE MATNR = I_MARC-MATNR

AND WERKS = I_MARC-WERKS.

SELECT MATNR MAKTX FROM MAKT INTO TABLE I_MAKT

FOR ALL ENTRIES IN I_MARC

WHERE MATNR = I_MARC-MATNR.

LOOP AT I_MARC.

MOVE I_MARC-MATNR TO I_OUT-MATNR.

MOVE I_MARC-WERKS TO I_OUT-WERKS.

READ TABLE I_MAKT WITH KEY MATNR = I_MARD-MATNR.

MOVE I_MAKT-MAKTX TO I_OUT-MAKTX.

LOOP AT I_MARD WHERE MATNR = I_MARC-MATNR

AND WERKS = I_MARC-WERKS.

MOVE I_MARD-LGORT TO I_OUT-LGORT.

MOVE I_MARD-LABST TO I_OUT-LABST.

APPEND I_OUT.

ENDLOOP.

CLEAR I_OUT.

ENDLOOP.

&----


*& T O P - O F - P A G E *

&----


TOP-OF-PAGE.

WRITE:/ 'DATE:' ,SY-DATUM.

FORMAT COLOR 4 INTENSIFIED OFF.

WRITE:/2 'PLANT',

9 'STG.LOC',

20 'MATERIAL.NO.',

55 'DESCRIPTION',

88 'STOCK'.

&----


*& E N D - O F - P A G E *

&----


END-OF-PAGE.

WRITE: / SY-ULINE,

/100 'PAGNO: ',SY-PAGNO,

SY-ULINE.

&----


*& E N D -- O F -- S E L E C T I O N *

&----


END-OF-SELECTION.

SORT I_OUT ASCENDING BY WERKS LGORT.

LOOP AT I_OUT.

WRITE:/ SY-ULINE,SY-VLINE,

I_OUT-WERKS,SY-VLINE,

I_OUT-LGORT,SY-VLINE,

I_OUT-MATNR,SY-VLINE,

I_OUT-MAKTX,SY-VLINE.

AT END OF LABST.

WRITE: I_OUT-LABST,SY-VLINE.

ENDAT.

TOT = TOT + I_OUT-LABST.

AT END OF LABST.

WRITE : TOT, SY-VLINE.

ENDAT.

*AT END OF WERKS.

*NEW-PAGE.

*ENDAT.

AT LAST.

FORMAT COLOR 7 INTENSIFIED OFF.

WRITE : /87 'TOTAL STOCK = ',TOT.

ENDAT.

ENDLOOP.

regards,

srinivas

<b>*reward for useful answers*</b>