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

Reading a structure in ABAP SQL

Former Member
0 Likes
531

Hi,

I do have the following code:

FORM read_authemployee.

EXEC SQL PERFORMING loop.

SELECT employee_id,

employee_group,

personnel_area,

exempt_ind,

work_state,

personnel_subarea,

employee_groupid

INTO :line_authemployee

FROM ath_employee

ENDEXEC.

ENDFORM.

FORM loop.

WRITE:/ line_authemployee-employee_id,

line_authemployee-employee_groupid.

ENDFORM.

When I execute the line_authemployee seems to have data in it. The problem I am having is I cannot loop with line_authemployee.. it seems like it is a structure. I also tried to create an internal table instead but still I couldnt loop through it. What I want to do is to have access to this data line by line and output it in a report format.

So if anyway could show me how to create a table in SQL that I could use to loop or show me how to loop this structure I will be very grateful.

Thanks,

Val.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
499

check this example.

you can loop thru using wa1.

DATA: BEGIN OF wa,
        connid   TYPE spfli-connid,
        cityfrom TYPE spfli-cityfrom,
        cityto   TYPE spfli-cityto,
      END OF wa. 

DATA : wa1 LIKE wa OCCURS 0 WITH HEADER LINE.

DATA c1 TYPE spfli-carrid VALUE 'LH'.

EXEC SQL PERFORMING loop_output.
  SELECT connid, cityfrom, cityto
  INTO   :wa
  FROM   spfli
  WHERE  carrid = :c1
ENDEXEC.

FORM loop_output.
  WRITE: / wa-connid, wa-cityfrom, wa-cityto. 
 APPEND wa TO wa1.
ENDFORM.

3 REPLIES 3
Read only

Former Member
0 Likes
499

You need to use a cursor to retrieve multiple lines.

This is documented in the F1 help for EXEC SQL.

Rob

Edited by: Rob Burbank on Nov 12, 2008 1:50 PM

Read only

Former Member
0 Likes
500

check this example.

you can loop thru using wa1.

DATA: BEGIN OF wa,
        connid   TYPE spfli-connid,
        cityfrom TYPE spfli-cityfrom,
        cityto   TYPE spfli-cityto,
      END OF wa. 

DATA : wa1 LIKE wa OCCURS 0 WITH HEADER LINE.

DATA c1 TYPE spfli-carrid VALUE 'LH'.

EXEC SQL PERFORMING loop_output.
  SELECT connid, cityfrom, cityto
  INTO   :wa
  FROM   spfli
  WHERE  carrid = :c1
ENDEXEC.

FORM loop_output.
  WRITE: / wa-connid, wa-cityfrom, wa-cityto. 
 APPEND wa TO wa1.
ENDFORM.

Read only

0 Likes
499

Thanks Sunil.. it worked.. I missed the APPEND statement!!