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: 

Looping process does not include the last lines of a table.

neXo
Participant
0 Kudos

Hello there,

Below you will find a short training program, in which I am trying to list the number of flights from a given city to another. The problem arises when the loop reaches the end of the table. Airlines flight from TOKYO to 3 different destinations. But, in the outcome the TOKYO-SINGAPOUR leg is not included. I would truly appreciate any light on this issue.

Thank you in advance for your time and consideration!!!

Regards!!!

TYPES: BEGIN OF ts_info2,
cityfrom TYPE c LENGTH 20,
cityto TYPE s_to_city,
nvuelos TYPE i,
END OF ts_info2.

DATA: gt_vuelos TYPE STANDARD TABLE OF bapisfldat,
gs_vuelos TYPE bapisfldat.

DATA: lt_info2 TYPE STANDARD TABLE OF ts_info2,
ls_info2 TYPE ts_info2,
lv_from TYPE ts_info2,
lv_to TYPE ts_info2,
lv_cont TYPE i.

CLEAR: gt_vuelos[],
lt_info2[].

CLEAR: lv_cont.
lv_cont = 0.

CALL FUNCTION 'BAPI_FLIGHT_GETLIST'
TABLES
flight_list = gt_vuelos.

SORT: gt_vuelos BY cityfrom ASCENDING
cityto ASCENDING.

LOOP AT gt_vuelos INTO gs_vuelos.

IF sy-tabix EQ 1.
CLEAR: lv_from,
lv_to.

lv_from = gs_vuelos-cityfrom.
lv_to = gs_vuelos-cityto.
ENDIF.

IF lv_from NE gs_vuelos-cityfrom OR
lv_to NE gs_vuelos-cityto.

CLEAR ls_info2.

ls_info2-cityfrom = lv_from.
ls_info2-cityto = lv_to.
ls_info2-nvuelos = lv_cont.
APPEND ls_info2 TO lt_info2.

CLEAR: lv_from,
lv_to.

lv_from = gs_vuelos-cityfrom.
lv_to = gs_vuelos-cityto.
lv_cont = 0.
ENDIF.

lv_cont = lv_cont + 1.

ENDLOOP.

IF gt_vuelos IS NOT INITIAL.
CLEAR ls_info2.
ls_info2-cityfrom = lv_from.
ls_info2-cityto = lv_to.
ls_info2-nvuelos = lv_cont.
APPEND ls_info2 TO lt_info2.

ENDIF.

LOOP AT lt_info2 INTO ls_info2.
WRITE:/ ls_info2-cityfrom,
ls_info2-cityto,
ls_info2-nvuelos.
ENDLOOP. SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; }.L0S32 { color: #3399FF; }.L0S33 { color: #4DA619; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }.L0S70 { color: #808080; }

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos

Please edit your question (Actions>Edit), select your code and press the button [CODE], which makes the code appear colored/indented, it'll be easier for people to look at it. Thanks!

Patrice
Participant
0 Kudos

Hi,

Please provide the data contained in GT_VUELOS to help us find the problem.

Thanks.

Patrice Poirier

xiswanto
Active Participant
0 Kudos

Do a little debug to make sure the data does exist in the itab, since your coding to increase value based on same from & destination seems fine; meanwhile, perhaps you could also learn using COLLECT syntax in this case since it is more efficient.