Skip to Content
author's profile photo Former Member
Former Member

why i am getting **** as output? how to get first record and last record...

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.

sort itab by land1.

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

thanks,

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

11 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 10:35 AM

    that is due to at first and at last..

    do like this...

    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.

    <b>DATA : WTAB LIKE ITAB.</b>

    SELECT kunnr name1 land1 ort01 FROM KNA1 INTO CORRESPONDING FIELDS OF

    TABLE ITAB.

    <b>MOVE-CORRESPONDING ITAB TO WTAB.</b>

    sort itab by land1.

    LOOP AT ITAB.

    at first.

    <b>WRITE : / WTAB-KUNNR, WTAB-NAME1, WTAB-LAND1, WTAB-ORT01.</b>endat.

    AT last.

    <b>WRITE : / WTAB-KUNNR, WTAB-NAME1, WTAB-LAND1, WTAB-ORT01.</b>

    ENDAT.

    ENDLOOP.

    regards

    shiba dutta

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 19, 2007 at 10:35 AM

    Hi,

    Debug the program to check what the problem is.

    Maybe you can use the code below.

    DATA l_lines TYPE i.

    l_lines = LINES( ITAB ).

    LOOP AT ITAB.

    IF sy-tabix EQ 1.

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

    ENDIF.

    IF sy-tabix EQ l_lines.

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

    ENDAT.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 10:35 AM

    HI,

    If U use at end of OR AT new commands U will get the Output like this.

    Just move your internal table data to another internal table and use that internal table for display and to check the conditions use first internal atbel.

    Thanks,CSR.

    *****Please reward if helpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 10:37 AM

    Hi balaji

    at event 'FIRST' and 'LAST' , normally we use for sumary data so the information that not involve should value value '******'.

    you can get the first and the last record by reading the table itab.

    data v_line like sy-linno.

    Describe table itab lines v_line.

    read table itab index 1.

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

    read table itab index v_line.

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

    Regards

    Wiboon

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 10:37 AM

    Hi,

    Whenever you try to print any data withing <b>at</b> and <b>endat</b>, all the fields except for the key fields will be ****

    There are 2 ways of avoiding it.

    1) Copy the workarea into another one before at and print from that.

    2)Set a variable = sy-tabix.

    read <int_table > with index <Variable> -


    within your AT....ENDAT statement.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 19, 2007 at 10:38 AM

    hmmmm

    velpuri

    at first is not to retrieve first record just it acts as top of page in control braek statement

    at last is no to use for retrieving last record it acts as end of page in control break statement

    regards

    Nagesh.Paruchuri

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 10:42 AM

    hi

    check whether the table is initial or not.(while debugging)

    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 useful

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 10:43 AM

    Hi,

    The reason for '****' printed for first and last record is due to 'At first' and 'At last' statement.

    On executing 'At first', the contents of the work area will change to '****'.You can verify this by debugging the execution of 'At first' statement.

    Similar reason for 'At last' statement.

    As your requirement is to get the first and last record. you can follow the simply code mentioned below to acheive your objective.

    Read table itab index 1.

    This statement will retrieve the first record and you can display the required info accordingly.

    Describe table itab lines l_no_of_line.

    Above statement will give the no of lines in the internal table. l_no_of_line is a integer variable (type i)

    Read table itab index l_no_of_line.

    Above statement will retrive the last record based on index.

    Hope this helps.....

    Get back in case of any clarifications...

    Regards,

    Dilli

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 10:44 AM

    REPORT ZMYTESTPRG62 .

    DATA : BEGIN OF WA,

    KUNNR LIKE KNA1-KUNNR,

    NAME1 LIKE KNA1-NAME1,

    LAND1 LIKE KNA1-LAND1,

    ORT01 LIKE KNA1-ORT01,

    END OF WA.

    DATA : ITAB like WA occurs 0.

    SELECT kunnr name1 land1 ort01 FROM KNA1 INTO CORRESPONDING FIELDS OF

    TABLE ITAB.

    sort itab by land1.

    LOOP AT ITAB into WA.

    at first.

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

    endat.

    AT last.

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

    ENDAT.

    ENDLOOP.

    Here I have not tested the porgram but it should work...

    Just use work area here to solve this problem..

    Reward Points if useful.

    Thanks & Regards.

    ilesh Nandaniya

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 10:53 AM

    hi,

    Your code will not work as AT FIRST and AT LAST are used for different purpose.

    For your requirement : For first record read table with index 1.

    For last record - use describe to get total number of record and use that value to read the table and will get the last record

    • To know the last record in a table

    DESCRIBE TABLE ITAB LINES SY-TFILL.

    READ TABLE ITAB INDEX SY-TFILL.

    - reward points if usefiul.

    -umesh

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.