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: 

ABAP Code

Former Member
0 Kudos
356

I am trying to run simple ABAP code. But it is not working.

-


SELECT single obknr INTO mpos-obknr

FROM mpos WHERE warpl = record-warpl.

if sy-subrc = 0 then.

SELECT equnr

INTO i_plan_data-equnr

FROM objk

WHERE obknr = mpos-obknr.

i_plan_data-warpl = record-warpl.

APPEND i_plan_data.

ENDSELECT.

endif.

-


record and i_plan_data are internal tables.

Code is not fetching obknr from mpos table.

Please suggest what can be the error.

1 ACCEPTED SOLUTION

former_member221770
Contributor
0 Kudos
192

Hi Pratibha,

You probably have not defined the MPOS work area with the TABLES command. So the INTO clause is invalid. Rather than define MPOS as a work area, define a variable for OBKNR as seen below:

  • Variable for OBKNR

data: l_obknr like mpos-obknr.

select single obknr

into l_obknr

from mpos

where warpl = record-warpl.

if sy-subrc eq 0.

  • Record Found so now we populate table I_PLAN_DATA

select warpl equnr

into corresponding fields of table i_plan_data

from objk

where obknr = l_obknr.

endif.

18 REPLIES 18

athavanraja
Active Contributor
0 Kudos
192

first mpos-warpl is not a key field. so the select single may not give you the right record.

the statement should produce atleast one record if it exists.

Did you check the table (se16) to see whether an entry exists for your selection.

Regards

Raja

former_member221770
Contributor
0 Kudos
193

Hi Pratibha,

You probably have not defined the MPOS work area with the TABLES command. So the INTO clause is invalid. Rather than define MPOS as a work area, define a variable for OBKNR as seen below:

  • Variable for OBKNR

data: l_obknr like mpos-obknr.

select single obknr

into l_obknr

from mpos

where warpl = record-warpl.

if sy-subrc eq 0.

  • Record Found so now we populate table I_PLAN_DATA

select warpl equnr

into corresponding fields of table i_plan_data

from objk

where obknr = l_obknr.

endif.

0 Kudos
192

Hi Patrick,

If MPOS had not been defiend with the tables statement, then there would have been a syntax error. However, that is not the case here.

Pratibha,

You can also try out a subquery for this -

tables objk.

select equnr
  from objk
  into objk-equnr
 where obknr in ( select obknr 
                    from mpos 
                   where warpl = record-warpl ).
  write : / objk-equnr.
endselect.

Let me know if the problem persists.

Regards,

Anand Mandalika.

0 Kudos
192

Anand,

You are correct - thanks for the pick up!

Pat.

0 Kudos
192

Hi Pat,

Thanks for reply.

Actually internal table record is populated from text file with following code.

FORM read_file.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = p_FILE

FILETYPE = 'DAT'

TABLES

DATA_TAB = RECORD

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

GUI_REFUSE_FILETRANSFER = 8

OTHERS = 9.

sort record by WARPL.

ENDFORM. " read_file

Program is not giving any error. Only it is not selecting obknr from mpos. I checked the table mpos and there is an entry for the warpl, I am trying for.

But some how code is not recognizing record-warpl.

0 Kudos
192

ok. thats because WARPL has got conversion exit.

you need to use the following FM to convert it to the right format.


data: wf_warpl type mpos-warpl .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input         = record-warpl
 IMPORTING
   OUTPUT        = wf_warpl .

suppose for. ex your WARPL is 41 this FM would convert it to "000000000041" as the WARPL size is 12.

use WF_WARPL is your select statement.

change the where clause to WHERE warpl = wf_warpl.

Regards

Raja

0 Kudos
192

Pratibha,

Well I think maybe you need the leading zeros in WARPL. Try using FM CONVERSION_EXIT_ALPHA_INPUT.

loop at record.

call function 'CONVERSION_EXIT_ALPHA_INPUT'

exporting

input = record-warpl

importing

output = record-warpl.

modify record transporting warpl.

endloop.

Now this should put in the necessary leading zeros into the WARPL field. Now try your select query into MPOS.

Let me know how this goes.

Pat.

0 Kudos
192

You are too quick for me Raja! ;o)

0 Kudos
192

practicing for /people/sap.user72/blog/2005/07/29/teched-05-get-your-thinking-hats-on-and-get-ready-to

Regards

Raja

0 Kudos
192

Hahahahaha too good! Hat's off to you mate!

Cheers,

Pat.

0 Kudos
192

Thanks Raj for quick and correct response,

Problem is solved.

0 Kudos
192

Good to hear that i was able to help you. all the best.

Pat.

i was just joking, its not yet been decided whether they are going to have that in India or not.

Regards

Raja

0 Kudos
192

Pratibha,

Glad to help!

Raja,

Yeah I know, I saw the weblog. Great idea though...fingers crossed that they bring it Down Under to Australia so I can collect my fre T-Shirt before being eliminated in the first round! Hahahahahaha!

Cheers,

Pat.

0 Kudos
192

Hi Pat,

Are you from Australia by any chance ?

Regards,

Anand Mandalika.

0 Kudos
192

Hi Anand,

Yeah I live in Sydney.

Pat.

0 Kudos
192

Hi Anand,

I guess this forum is there to discuss <b>ABAP Programming</b>

Regards,

Nitin

Former Member
0 Kudos
192

Hi,

U can do as,

SELECT single OBKNR into mpos-obknr
from mpos for all entries in record
where warl = record-warpl.
if sy-subrc = 0.
SELECT equnr
into corresponding fields of table i_plan_dat
from objk
where obknr = mpos-obknr.
..................
endselecet.
endif.

Can try this one.

jayanthi_jayaraman
Active Contributor
0 Kudos
192

Hi,

Since record is an internal table,you should use for all entries to access it.

But single cannot be used with for all entries.

data itab type standard table of mpos.

select * from obknr into table itab from mpos for all entries in record where warpl = record-warpl.