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: 

why i am unable to print first and last records...see the code snippet

Former Member
0 Kudos

REPORT ZMYTESTPRG62 .

DATA : BEGIN OF ITAB OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

NAME1 LIKE KNA1-NAME1,

LAND1 LIKE KNA1-LAND1,

ORT01 LIKE KNA1-ORT01,

END OF ITAB.

SELECT kunnr name1 land1 ort01 FROM KNA1 INTO CORRESPONDING FIELDS OF

TABLE ITAB.

LOOP AT ITAB.

at first.

WRITE : / ITAB-KUNNR, ITAB-NAME1, ITAB-LAND1, ITAB-ORT01.

endat.

AT last.

WRITE : / ITAB-KUNNR, ITAB-NAME1, ITAB-LAND1, ITAB-ORT01.

ENDAT.

ENDLOOP.

any clues?

4 REPLIES 4

Former Member
0 Kudos

HI balaji

you can't do it because the event 'FIRST' and 'LAST' , except value as number , all text will be value as '********'.

Regards

Wiboon

former_member188827
Active Contributor
0 Kudos

u've to first sort itab and den use control level processing..

try using :

sort itab by kunnr.

after select..

if da probelm persists leme kno

Former Member
0 Kudos

Hi blaji

I have some way to do it .

REPORT zmytestprg62 .

DATA v_line LIKE sy-linno.

DATA : BEGIN OF itab OCCURS 0,

kunnr LIKE kna1-kunnr,

name1 LIKE kna1-name1,

land1 LIKE kna1-land1,

ort01 LIKE kna1-ort01,

END OF itab.

SELECT kunnr name1 land1 ort01 FROM kna1 INTO CORRESPONDING FIELDS OF

TABLE itab.

DESCRIBE TABLE itab LINES v_line.

READ TABLE itab INDEX 1.

if sy-subrc = 0.

WRITE : / itab-kunnr, itab-name1, itab-land1, itab-ort01.

endif.

READ TABLE itab INDEX v_line.

if sy-subrc = 0.

WRITE : / itab-kunnr, itab-name1, itab-land1, itab-ort01.

endif.

Regards

Wiboon

Former Member
0 Kudos

hi

chk whether the internal table is initial or not.

the code is perfectly correct, there should be no issues with that.

see this example :

TYPES: BEGIN OF COMPANIES_TYPE,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES_TYPE.

DATA: COMPANIES TYPE STANDARD TABLE OF COMPANIES_TYPE WITH

NON-UNIQUE DEFAULT KEY INITIAL SIZE 20,

WA_COMPANIES TYPE COMPANIES_TYPE.

...

LOOP AT COMPANIES INTO WA_COMPANIES.

AT FIRST.

SUM.

WRITE: 'Sum of all SALES:',

55 WA_COMPANIES-SALES.

ENDAT.

WRITE: / WA_COMPANIES-NAME, WA_COMPANIES-PRODUCT,

55 WA_COMPANIES-SALES.

ENDLOOP.

Regards,

Prasant

*reward if helpful