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

How to store data in a variable in select query

Former Member
0 Likes
1,591

Hi,

Below is the select query in which i want to store the data in variable but i am getting runtime error as the fields are more as compared to variable,the declaration is necessary for it due to the reteriving for data.

Please provide me guidelines how to do it.



DATA: BEGIN OF ITSC01 OCCURS 0,
      PRUEFLOS LIKE QALS-PRUEFLOS,
      MBLNR LIKE QAMB-MBLNR,
      LGORT LIKE MSEG-LGORT,
      END OF ITSC01.
IF STIT-MGEIG GE 0.

LOOP AT STIT." WHERE PRUEFLOS EQ STIT-PRUEFLOS.

    SELECT A~PRUEFLOS B~MBLNR C~LGORT FROM QALS AS A
           INNER JOIN QAMB AS B ON B~PRUEFLOS = A~PRUEFLOS
           INNER JOIN MSEG AS C ON C~MBLNR = B~MBLNR AND C~MJAHR = B~MJAHR
           INTO SLOC WHERE A~PRUEFLOS EQ STIT-PRUEFLOS.
*           INTO TABLE ITSC01 WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND A~MATNR EQ STIT-MATNR AND C~LGORT EQ 'SC03'.

    SORT ITSC01 BY PRUEFLOS.
     READ TABLE ITSC01 WITH KEY PRUEFLOS = ITSC01-PRUEFLOS.
      IF ITSC01-LGORT EQ 'SC03'.
      STIT-MGEIG = 0.
      ENDIF.
 MODIFY STIT.
 ENDLOOP.
ENDIF.

Hi,

Below is the select query in which i want to store the data in variable but i am getting runtime error as the fields are more as compared to variable,the declaration is necessary for it due to the reteriving for data.

Please provide me guidelines how to do it.



DATA: BEGIN OF ITSC01 OCCURS 0,
      PRUEFLOS LIKE QALS-PRUEFLOS,
      MBLNR LIKE QAMB-MBLNR,
      LGORT LIKE MSEG-LGORT,
      END OF ITSC01.
IF STIT-MGEIG GE 0.

LOOP AT STIT." WHERE PRUEFLOS EQ STIT-PRUEFLOS.

    SELECT A~PRUEFLOS B~MBLNR C~LGORT FROM QALS AS A
           INNER JOIN QAMB AS B ON B~PRUEFLOS = A~PRUEFLOS
           INNER JOIN MSEG AS C ON C~MBLNR = B~MBLNR AND C~MJAHR = B~MJAHR
           INTO SLOC WHERE A~PRUEFLOS EQ STIT-PRUEFLOS.
*           INTO TABLE ITSC01 WHERE A~PRUEFLOS EQ STIT-PRUEFLOS AND A~MATNR EQ STIT-MATNR AND C~LGORT EQ 'SC03'.

    SORT ITSC01 BY PRUEFLOS.
     READ TABLE ITSC01 WITH KEY PRUEFLOS = ITSC01-PRUEFLOS.
      IF ITSC01-LGORT EQ 'SC03'.
      STIT-MGEIG = 0.
      ENDIF.
 MODIFY STIT.
 ENDLOOP.
ENDIF.

12 REPLIES 12
Read only

GauthamV
Active Contributor
0 Likes
1,551

Use this.

MODIFY STIT transporting MGEIG.

Read only

Former Member
0 Likes
1,551

HI,

Is the select query written in correct way ? instead storing of data in itab i am truing to store the value of LGORT in variable called SLOC,please provide me guidelines for it.

I got the runtime error that :-

In a SELECT or FETCH command, the field string or internal table

specified in the INTO clause has 1 fields. It must have

at least as many fields as in the SELECT clause,

3 fields in this case.

how do i solve this problem?

yes,i had declared like this:-

DATA: SLOC LIKE MSEG-LGORT.

Even i tried to decalre in the ITSC01 but still it is giving the runtime error.

Edited by: ricx .s on Jun 5, 2009 8:36 AM

Read only

Former Member
0 Likes
1,551

hi,,

you haven't declared the internal table with exact fields i think..

declare an internal table with the exact fields & check

Edited by: Kishore Babu on Jun 5, 2009 8:39 AM

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,551

As you are fetching 3 fields in the select clause and SLOC can only accept one filed , so either you can declare 2 more variable and then use them in the INTO clause or else use internal table.

Read only

Former Member
0 Likes
1,551

hi,

i had tried by declaring it but it is still giving the run time error.

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,551

hmm..

try this:

DATA: l_PRUEFLOS LIKE QALS-PRUEFLOS,

l_MBLNR LIKE QAMB-MBLNR,

l_LGORT LIKE MSEG-LGORT,

IF STIT-MGEIG GE 0.

LOOP AT STIT." WHERE PRUEFLOS EQ STIT-PRUEFLOS.

SELECT APRUEFLOS BMBLNR C~LGORT FROM QALS AS A

INNER JOIN QAMB AS B ON BPRUEFLOS = APRUEFLOS

INNER JOIN MSEG AS C ON CMBLNR = BMBLNR AND CMJAHR = BMJAHR

INTO ( l_PRUEFLOS , l_MBLNR, l_LGORT )

WHERE A~PRUEFLOS EQ STIT-PRUEFLOS.

  • INTO TABLE ITSC01 WHERE APRUEFLOS EQ STIT-PRUEFLOS AND AMATNR EQ STIT-MATNR AND C~LGORT EQ 'SC03'.

SORT ITSC01 BY PRUEFLOS.

READ TABLE ITSC01 WITH KEY PRUEFLOS = ITSC01-PRUEFLOS.

IF ITSC01-LGORT EQ 'SC03'.

STIT-MGEIG = 0.

ENDIF.

MODIFY STIT.

ENDLOOP.

ENDIF.

Read only

Former Member
0 Likes
1,551

hi,

i am trying what you has said but i have to use select endselect statement but while debugging there is no data present in the ITSC01 and should i use endselect word in the query ?

Edited by: ricx .s on Jun 5, 2009 9:04 AM

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,551

If you are using the code in my post , the table ITSC01 will be intial and the data will be stored in the varaibles.

So you have to use the varaibles now.

Read only

Former Member
0 Likes
1,551

Hi,

yes i am using your logic but in that it is not fillling ITSC01 as in that select query it is just passing the values .. tell me if i am getting wrong. There is no data for the stored in ITSC01.

Please provide me guidelines to solve this problem.

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,551

It will not fill ITSC01.

Try this:

SELECT APRUEFLOS BMBLNR C~LGORT FROM QALS AS A

INNER JOIN QAMB AS B ON BPRUEFLOS = APRUEFLOS

INNER JOIN MSEG AS C ON CMBLNR = BMBLNR AND CMJAHR = BMJAHR

INTO TABLE ITSC01 WHERE APRUEFLOS EQ STIT-PRUEFLOS AND AMATNR EQ STIT-MATNR AND C~LGORT EQ 'SC03'.

Read only

Former Member
0 Likes
1,551

hi,

but what about the variable for Storage Location? should i store seperately then value of it ?

Please provide me guidelines for solving this probelm.

Edited by: ricx .s on Jun 5, 2009 11:38 AM

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,551

How you have declared variable SLOC.

SELECT APRUEFLOS BMBLNR C~LGORT FROM QALS AS A

INNER JOIN QAMB AS B ON BPRUEFLOS = APRUEFLOS

INNER JOIN MSEG AS C ON CMBLNR = BMBLNR AND CMJAHR = BMJAHR

INTO SLOC WHERE A~PRUEFLOS EQ STIT-PRUEFLOS. ==> Check structure of SLOC

  • INTO TABLE ITSC01 WHERE APRUEFLOS EQ STIT-PRUEFLOS AND AMATNR EQ STIT-MATNR AND C~LGORT EQ 'SC03'