Archived discussions are read-only. Learn more about SAP Q&A

use of native SQL-select statment

hi,

in my z-abap i use a native sql, saying the following:

EXEC SQL.

  select agzdau into :gf_agzdau from APZD08/AG
                where AGMAID = '77732' and
                      AGJAHR = 2008 and
                      AGMON  = 09 and
                      AGSPAL = 'ZASALD'
                      %_HINTS AS400 'HARD_CLOSE'
ENDEXEC.

before that i make a connection to the server where the table is stored.

APZD08 is the library and AG is the filename (on a AS/400-machine)

BUT: the file is not always in APZD08-lib, it depends on the employee.

how can i make the lib-name and file flexible:

i have tried it with

select...............from :gf_file

and i have put a value for gf_file before.

but with that i got an SQL-error -104 when executing.

i can't use a hostvariable there it seems.

any ideas ?

reg, Martin

Tags:
replied

Hi,

Try this:

DATA: code TYPE TABLE OF rssource-line.

DATA:STRPR TYPE STRING.

data:i type i.

data:ci type c.

data:cstr(200) type c.

APPEND 'REPORT ZTESTING2.' TO CODE.

APPEND 'EXEC SQL.' TO CODE.

i = 8.

ci = i.

concatenate 'select agzdau into :gf_agzdau from APZD0'ci '/AG' into cstr.

append cstr to code.

APPEND ' where AGMAID = ''77732'' and' to code.

APPEND ' AGJAHR = 2008 and' to code.

APPEND ' AGMON = 09 and' to code.

APPEND ' AGSPAL = ''ZASALD'' to code.

APPEND ' %_HINTS AS400 ''HARD_CLOSE''' to code.

ENDEXEC.

INSERT REPORT 'ZTESTING' FROM code.

SUBMIT ZTESTING AND RETURN.

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question