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 report exit details

0 Kudos

Can anyone please help me with this code, i am trying here to inner join two of the table pa0000 and zempdetl.

i am getting error as this

When escaped, all host variables must be escaped using @. The variable L_DAT is not escaped in the same way as the preceding host variables.

here is my code.

REPORT zhr_exitdetails.

TABLES : pa0000,zempdetl.

TYPES : BEGIN OF ty_struc,
pernr TYPE pa0000-pernr,
begda TYPE pa0000-begda,
massn TYPE pa0000-massn,
END OF ty_struc.
DATA : itab TYPE TABLE OF ty_struc,
wa TYPE ty_struc.


TYPES : BEGIN OF ty_struc1,
department TYPE zempdetl-department,
emp_plantloc TYPE zempdetl-emp_plantloc,
gender TYPE zempdetl-gender,
END OF ty_struc1.
DATA : itab01 TYPE TABLE OF ty_struc1,
wa01 TYPE ty_struc1.

TYPES : BEGIN OF ty_final,
pernr TYPE pa0000-pernr,
begda TYPE pa0000-begda,
massn TYPE pa0000-massn,
department TYPE zempdetl-department,
emp_plantloc TYPE zempdetl-emp_plantloc,
gender TYPE zempdetl-gender,
END OF ty_final.
DATA : itab02 TYPE TABLE OF ty_final,
wa02 TYPE ty_final.

DATA:i_layout TYPE slis_layout_alv,
i_events TYPE slis_t_event,
i_fieldtab TYPE slis_t_fieldcat_alv,
s_fieldtab LIKE LINE OF i_fieldtab.

SELECTION-SCREEN BEGIN OF BLOCK btop WITH FRAME TITLE TEXT-001. "ZHR_COP_BDC
SELECT-OPTIONS: l_dat FOR pa0000-begda.
SELECTION-SCREEN END OF BLOCK btop.


START-OF-SELECTION.

PERFORM get_data.
PERFORM display.


FORM get_data.

SELECT a~pernr,a~begda,a~massn,b~department,b~emp_plantloc,b~gender FROM pa0000 AS a JOIN zempdetl AS b ON a~pernr EQ b~empid
INTO CORRESPONDING FIELDS OF TABLE @itab02 WHERE a~massn = 'ZJ' AND a~begda IN l_dat .

ENDFORM.

FORM display.
*-----------------------------------------------------------------------------
CLEAR : i_layout.
i_layout-zebra = 'X'.
i_layout-colwidth_optimize = 'X'.


s_fieldtab-col_pos = '1'.
s_fieldtab-fieldname = 'PERNR'.
s_fieldtab-seltext_m = 'EMPLOYEE NUMBER'.
APPEND s_fieldtab TO i_fieldtab.
CLEAR s_fieldtab.

s_fieldtab-col_pos = '2'.
s_fieldtab-fieldname = 'BEGDA'.
s_fieldtab-seltext_m = 'START DATE'.
APPEND s_fieldtab TO i_fieldtab.
CLEAR s_fieldtab.

s_fieldtab-col_pos = '3'.
s_fieldtab-fieldname = 'MASSN'.
s_fieldtab-seltext_m = 'ACTION TAKEN'.
APPEND s_fieldtab TO i_fieldtab.
CLEAR s_fieldtab.

s_fieldtab-col_pos = '4'.
s_fieldtab-fieldname = 'DEPARTMENT'.
s_fieldtab-seltext_m = 'DEPARTMENT'.
APPEND s_fieldtab TO i_fieldtab.
CLEAR s_fieldtab.

s_fieldtab-col_pos = '5'.
s_fieldtab-fieldname = 'EMP_PLANTLOC'.
s_fieldtab-seltext_m = 'LOCATION'.
APPEND s_fieldtab TO i_fieldtab.
CLEAR s_fieldtab.

s_fieldtab-col_pos = '6'.
s_fieldtab-fieldname = 'GENDER'.
s_fieldtab-seltext_m = 'GENDER'.
APPEND s_fieldtab TO i_fieldtab.
CLEAR s_fieldtab.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = 'SY-REPID'
is_layout = i_layout
it_fieldcat = i_fieldtab[]
i_default = 'X'
TABLES
t_outtab = itab02
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.

6 REPLIES 6

jerryjanda
Community Manager
Community Manager
0 Kudos

Hi, Priya:

Thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't already), as it provides tips for preparing questions that draw responses from our members.

Should you wish, you can revise your question by selecting Actions, then Edit (although once someone answers your question, you'll lose the ability to edit the question -- but if that happens, you can leave more details in a comment). For one thing, you might want to use the "insert code" feature in the questions tool...to make it easier for members to read.

Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.

Kind regards,

--Jerry

Make sure to subscribe to What's New!

Ajit_K_Panda
Product and Topic Expert
Product and Topic Expert

Hi Priya,

You need to escape all variables with @ used in select query.
Check the following link:
https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenopen_sql_host_variables.htm

Best, Ajit

michael_piesche
Active Contributor

Since you don’t use special select statements, you don’t have to use the Open SQL Strict Mode, you could also write your select as this (no comma separation of select and Order by attributes and no @ escaping of Host variables):

SELECT a~pernr a~begda a~massn b~department b~emp_plantloc b~gender 
FROM pa0000 AS a 
JOIN zempdetl AS b ON a~pernr EQ b~empid
INTO CORRESPONDING FIELDS OF TABLE itab02 
WHERE a~massn = 'ZJ'
  AND a~begda IN l_dat. 

If you choose to use the Open SQL Strict Mode (https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenopensql_strict_mode_740_sp05.htm), you have to use it completely, not just selectively.

For you select, you would have to do it this way, that l_dat needs also to be escaped by the @ character (literals eg ‚ZJ‘ mustn’t be escaped):

SELECT a~pernr, a~begda, a~massn, b~department, b~emp_plantloc, b~gender 
FROM pa0000 AS a 
JOIN zempdetl AS b ON a~pernr EQ b~empid
INTO CORRESPONDING FIELDS OF TABLE @itab02 
WHERE a~massn = 'ZJ'
  AND a~begda IN @l_dat.

michael_piesche
Active Contributor

Please choose a better title for your question next time. The title should be related to your problem e.g. „variable is not escaped the same way as preceding variables“

Sandra_Rossi
Active Contributor

Your code has a wrong syntax:

SELECT a~pernr,a~begda,a~massn,b~department,b~emp_plantloc,b~gender 
FROM pa0000 AS a JOIN zempdetl AS b ON a~pernr EQ b~empid
INTO CORRESPONDING FIELDS OF TABLE @itab02 
WHERE a~massn = 'ZJ' 
  AND a~begda IN l_dat . " <===== syntax error

Text of syntax error:

When escaped, all host variables must be escaped using @. The variable L_DAT 
is not escaped in the same way as the preceding host variables.

Code with right syntax:

SELECT a~pernr,a~begda,a~massn,b~department,b~emp_plantloc,b~gender 
FROM pa0000 AS a JOIN zempdetl AS b ON a~pernr EQ b~empid
INTO CORRESPONDING FIELDS OF TABLE @itab02 
WHERE a~massn = 'ZJ' 
  AND a~begda IN @l_dat . " <===== corrected

michael_piesche
Active Contributor
0 Kudos

kimkhumba, do you continue to have issues or were you able to solve your problem?

Please add comments to your question that further describe your problem or add an answer that describes how you solved your problem.

If your problem is solved, accept an answer if it helped you and please close the question.