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

problem while data retrieving

Former Member
0 Likes
1,242

Hi,

I am unable to retrieve exnum1.

SELECT SINGLE docyr exnum INTO (itab-docyr,itab-exnum) FROM j_1iexchdr WHERE rdoc = itab-vbeln.
  IF itab-docyr IS NOT INITIAL AND itab-exnum IS NOT INITIAL.
SELECT SINGLE exnum INTO itab-exnum1 FROM  j_1iexcdtl WHERE trntyp = 'ARE1' AND docyr = itab-docyr AND werks = itab-werks AND
     rdoc2 = itab-exnum.

ENDIF.
MODIFY itab TRANSPORTING docyr exnum exnum1.

Regards

Kalpana

12 REPLIES 12
Read only

former_member182379
Contributor
0 Likes
1,205

Hi,

  Why you are selecting the same from header and then item table EXNUM you are already getting from

j_1iexchdr along with RDOC you can also pass trntyp = 'ARE1' in first select query.

regards,

zafar

Read only

0 Likes
1,205

Hi zafar,

  CLEAR exnum.
      SELECT SINGLE exnum INTO exnum FROM j_1iexchdr WHERE rdoc = itab-vbeln.
      itab-exnum = exnum.
      MODIFY itab TRANSPORTING exnum.

Already exnum was picking from  j_1iexchdr.

Now I have a modification to pick ARE1 No. with condition:

vbrk-vbeln = j_1iexchdr-rdoc

I have to get rdoc2 where j_1iexchdr-exnum =  j_1iexcdtl-exnum

And then I have to pick exnum where j_1iexchdtl-trntyp = 'ARE1' and year-docyr and  j_1iexchdtl-werks

Regards

Kalpana

Read only

gurunathkumar_dadamu
Active Contributor
0 Likes
1,205

Hi Kalpana,

Try the below code. please keep the itab into loop and then try to modify the data otherwise how can it select the data from second quire.

SELECT SINGLE docyr

               exnum

               INTO (itab-docyr,itab-exnum)

               FROM j_1iexchdr

               WHERE rdoc = itab-vbeln.

LOOP AT itab.

   IF itab-docyr IS NOT INITIAL AND itab-exnum IS NOT INITIAL.

     SELECT SINGLE exnum

                   INTO itab-exnum1

                   FROM  j_1iexcdtl

                   WHERE trntyp = 'ARE1'

                   AND docyr = itab-docyr

                   AND werks = itab-werks

                   AND rdoc2 = itab-exnum.

     IF sy-subrc = 0.

       MODIFY itab TRANSPORTING docyr exnum exnum1.

     ENDIF.

   ENDIF.

ENDLOOP.

Let me know if any issues.

Regards,

Gurunath

Read only

0 Likes
1,205

Hi,

It was not working. If I do this, it was modifying previous values too..

Regards

Kalpana

Read only

0 Likes
1,205

Hi,

Try below logic, create 2 internal tables i_exchdr and i_excdtl with the fields in below SELECTs

and then loop the itab table to fill the fields.

FIELD-SYMBOLS : <fs_itab> LIKE LINE OF itab.

SELECT docyr
       exnum
       rdoc
              FROM j_1iexchdr
              INTO TABLE i_exchdr
              FOR ALL ENTRIES IN itab
              WHERE rdoc = itab-vbeln.
IF sy-subrc = 0.


SORT i_exchdr.

SELECT docyr
        werks
        exnum
        rdoc2
               FROM  j_1iexcdtl
               INTO TABLE i_excdtl
               FOR ALL ENTRIES IN i_exchdr
               WHERE trntyp = 'ARE1'
               AND   docyr  = i_exchdr-docyr
               AND   rdoc2  = i_exchdr-exnum.
IF sy-subrc = 0.


  SORT i_exchdtl.


ENDIF.


ENDIF.

LOOP AT itab ASSIGNING <fs_itab>.

READ TABLE i_exchdr INTO wa_exchdr WITH KEY
                          rdoc = <fs_itab>-vbeln.
  IF sy-subrc = 0.

* Update j_1iexchdr fields
   <fs_itab>-docyr = wa_exchdr-docyr.
   <fs_itab>-exnum = wa_exchdr-exnum.

   READ TABLE i_excdtl INTO wa_excdtl WITH KEY
                            docyr = wa_exchdr-docyr
                            werks = <fs_itab>-werks
                            rdoc2 = wa_exchdr-exnum.
    IF sy-subrc = 0.

* Update j_1iexcdtl fields
   <fs_itab>-exnum1 = wa_excdtl-exnum.

    ENDIF.


  ENDIF.

CLEAR : wa_exchdr, wa_excdtl.
ENDLOOP.

Thanks & Regards

Bala Krishna

Read only

Former Member
0 Likes
1,205

Hi,

What exactly my requirement is:

vbrk-vbeln = j_1iexchdr-rdoc

I have to get rdoc2 where j_1iexchdr-exnum =  j_1iexcdtl-exnum

And then I have to pick exnum where j_1iexchdtl-trntyp = 'ARE1' and year-docyr and  j_1iexchdtl-werks.

Now  I have to pick Exnum1(Are1 No.) without effecting other values by using bove condition..

Already exnum was picking from  j_1iexchdr.

LOOP AT itab1.

CLEAR exnum.
      SELECT SINGLE exnum INTO exnum FROM j_1iexchdr WHERE rdoc = itab-vbeln.
      itab-exnum = exnum.
      MODIFY itab TRANSPORTING exnum.
    ENDLOOP.

I have given my code at very first. Can anyone help me in this.

Regards

Kalpana

Read only

0 Likes
1,205

Hi,

Try below coding, transporting is not required since we are not changing the other fields of itab same values will be modified but if you want you can add it.

loop at itab.

select single DOCYR DOCNO INTO (itab-docyr,itab-exnum) from J_1IEXCHDR WHERE rdoc = itab-vbeln.

IF itab-docyr IS NOT INITIAL AND itab-exnum IS NOT INITIAL.

SELECT SINGLE exnum INTO itab-exnum1 FROM  j_1iexcdtl WHERE trntyp = 'ARE1' AND docyr = itab-docyr AND werks = itab-werks AND

     rdoc2 = itab-exnum.

modify itab.

endif.

endloop.

Regards

Chudamani

Read only

0 Likes
1,205

Hi Gavel,

Its not working.

Read only

0 Likes
1,205

Hi,

What is the problem? is data getting selected from table J_1IEXCHDR and j_1iexcdtl or problem is while modifying?

Regards

Read only

0 Likes
1,205

Hi,

Unable to get the data from both of the tables.

Just check once my code.

SELECT SINGLE docyr exnum INTO (itab-docyr, itab-exnum) FROM j_1iexchdr WHERE rdoc = itab-vbeln.
              IF itab-docyr IS NOT INITIAL AND itab-exnum IS NOT INITIAL.
          SELECT SINGLE exnum INTO itab-exnum1 FROM j_1iexcdtl WHERE trntyp = 'ARE1' AND docyr = itab-docyr AND werks = itab-werks AND rdoc2 = itab-exnum.
        ENDIF.
        MODIFY itab TRANSPORTING docyr exnum exnum1.

From the above query, the data was retrieving correctly.

But it was effecting other values. Without effecting other values, how can I get Exnum1. That is what Im asking. I think u understood now what my prob is!

Regards

Kalpana

Read only

0 Likes
1,205

Hi Kalpana,

As per my understanding, you want to get exnum from j_1iexcdtl and modify your itab. keep your selection as you have written you are correct. just take field-Symbols as shown below.

********

******Declare field-symbols.

FIELD-SYMBOLS : <lfs_itab> like LINE OF itab.

SELECT SINGLE docyr exnum

               INTO (itab-docyr,itab-exnum)
               FROM j_1iexchdr
               WHERE rdoc = itab-vbeln.

LOOP AT itab ASSIGNING <lfs_itab>.

   IF <lfs_itab>-docyr IS NOT INITIAL AND <lfs_itab>-exnum IS NOT INITIAL.

     SELECT SINGLE exnum
                   INTO <lfs_itab>-exnum1
                   FROM  j_1iexcdtl
                   WHERE trntyp = 'ARE1'
                   AND docyr = itab-docyr
                   AND werks = itab-werks
                   AND rdoc2 = itab-exnum.

   ENDIF.

ENDLOOP.

Regards

Read only

Former Member
0 Likes
1,205

Hi Kalpana,

As Amit suggested,you must use field symbols in this case or you can use conditions in modify statement.

The select query you are using is fine and if you dont want to use field-symbols then you can either use conditions while moditying itab OR you can take another internal table similar to itab and store the changed value in it.Later on you can insert them into orignal table itab by deleting previous records.

But this method is quite tedious.

Thus i suggest you to use either field symbols or use condition in modify statement.

Regards,

Abdul