Skip to Content

Queries from the same table, but, different row

Hi, all.

Kindly need your help to write the queries statement,

I have table as below, I want to copy the TRFNO to RFMBELNR based on rfwtno = wtno

I did try to code like this:

DATA: lt_zmmtwinfd TYPE STANDARD TABLE OF zmmtwinfd.

CLEAR: lt_zmmtwinfd.

     SELECT trfno

       INTO TABLE lt_zmmtwinfd

       FROM zmmtwinfd

       WHERE rfwtno = zmmtwinfd-wtno.

     UPDATE zmmtwinfd

        SET pytp = zmmtwinfd-pytp

            pyamt = zmmtwinfd-pyamt

            netwt = zmmtwinfd-netwt

            trfno = zmmtwinfd-trfno

            rfmbelnr = zmmtwinfd-trfno 

            zremk = zmmtwinfd-zremk

            rfwtno = zmmtwinfd-rfwtno 

            pymid = '0'

      WHERE wtno = zmmtwinfd-wtno.

Your kindness is most appreciated.

Thanks and Regards

Liyana

1.png (3.1 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Jan 06, 2015 at 05:09 AM

    Hi..

    Follow the below steps.

    1. Move the value into internal table. Consider IT_FINAL
    2. Create Copy the internal table. Consider IT_COPY

              IT_COPY[] = IT_FINAL[]

       3.  Create field symbol and update the entry inside loop

         FIELD-SYMBOLS: <FS_FINAL> LIKE LINE OF IT_FINAL.

        

         "Run the loop for IT_FINAL

         LOOP AT IT_FINAL ASSIGING <FS_FINAL>.

              "Read the value

              READ TABLE IT_FINAL INTO WA_FINAL WITH KEY WTNO = <FS_FINAL>-RFWTNO.

              IF SY-SUBRC = 0.

                    "Update the value

                   <FS_FINAL>-RFMBELNR = WA_FINAL-TRFNO.

              ENDIF.

         ENDLOOP.

    Hope it helps

    Regards

    Rajkumar Narasimman

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 06, 2015 at 03:21 AM

    This message was moderated.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 06, 2015 at 06:30 AM

    1.Create internal table.

        BEGIN OF IT,

            WTNO TYPE ZTABLE-WTNO,

            TRFNO TYPE ZTABLE-TRFNO,

        END OF IT.

      

    2.select WTNO RFWTNO from databse table into IT where WTNO = RFWTNO.

         [i can see only one PK i.e. WTNO].

         [here you have list of rows whoes WTNO = RFWTNO with TRFNO field].

    3.loop at it.

        update database table set RFMBELN = IT-RFWTNO WHERE WTNO = IT-WTNO.

      endloop.

    4. and it occupies less memory rather to store whole table.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 06, 2015 at 06:56 AM

    Hi Hasan,


    I can see that with reference to zmmtwinfd-wtno you fetching some records in internal and in update statement you never used those records...what i understand from your question you need to copy value of  TRFNO to RFMBELNR field of all records where the field value rfwtno = WTNO. if my undrestanding is correct try using fallowing code..


    if you have wtno from selection screen then

    Select single tfrno from ztable into g_tfrno where wtno = s_wtno.

    update ztable set rfmbelnr = trfno where rfwtno = wtno.

    If you want all wtno in ztable then.

    Select wtno tfrno from ztable into table it_ztable.


    loop at it_ztable into wa_ztable.


    update ztable set rfmbelnr = wa_ztable-trfno where rfwtno = wa_ztable-wtno.


    Endloop.


    Regards,

    Shashikanth

    Add comment
    10|10000 characters needed characters exceeded