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: 

if else is failing in an itab loop

Former Member
0 Kudos

Abapers,

I have a weird problem in a itab loop.

Based on certain flags and data, I have a few if and endifs.

The last condtion if agflag <> 'N' not working, if the data in

containts certain no of row with agflag = 'Y' and a few with agflag <> Y

If i execute exclusively with data with agflag <> Y, its working fine. Please have

a look at the code help me. Its very urgent.

Warm regards,

Harsha

LOOP AT tbldata WHERE cbox = 'X' .

IF tbldata-metro_agency0(1) = 'M' AND tbldata-metro_client0(1) =

'M'.

                                    • Validate with JGTGPNR

                              • Client Code

SELECT SINGLE * FROM jgtgpnr CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND gpnr = tbldata-metro_client

AND xmediak = 'X'

AND xinser = 'X'.

IF sy-subrc <> 0 .

MESSAGE e120(zer).

LEAVE SCREEN.

ELSEIF sy-subrc = 0.

clflag = 'Y'.

ENDIF.

                                      • Agency Code

SELECT SINGLE * FROM jgtgpnr CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND gpnr = tbldata-metro_agency

AND xmediak = 'X'

AND xagen = 'X'.

IF sy-subrc <> 0.

MESSAGE e121(zer).

LEAVE SCREEN.

ELSEIF sy-subrc = 0.

IF clflag = 'Y'.

agflag ='Y'.

ENDIF.

ENDIF.

ENDIF.

************************************************************

IF agflag = 'Y'.

IF tbldata-metro_agency+0(1) = 'M' AND

tbldata-metro_client+0(1) = 'M'.

IF tbldata-companycd = 'HT'.

                                  • Vaidate custcd in Zmam_htmap_code ***************

SELECT SINGLE * FROM zmam_htmap_code CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND custcd = tbldata-clcd.

*******************************************************

IF sy-subrc = 0.

MESSAGE ID 'ZER' TYPE 'S' NUMBER '563' WITH

zmam_htmap_code-metrocd.

ELSE.

httab-mandt = sy-mandt.

httab-custcd = tbldata-clcd.

httab-metrocd = tbldata-metro_client.

httab-erfdate = sy-datum.

httab-erftime = sy-uzeit.

APPEND httab.

ENDIF.

*********************************************************

SELECT SINGLE * FROM zmam_htmap_code CLIENT SPECIFIED

WHERE mandt = sy-mandt

AND custcd = tbldata-agcd.

*********************************************************

IF sy-subrc = 0.

MESSAGE ID 'ZER' TYPE 'S' NUMBER '559' WITH

zmam_htmap_code-metrocd.

ELSE.

httab-mandt = sy-mandt.

httab-custcd = tbldata-agcd.

httab-metrocd = tbldata-metro_agency.

httab-erfdate = sy-datum.

httab-erftime = sy-uzeit.

APPEND httab.

ENDIF.

*************************************************************

*

  • SELECT SINGLE * FROM zmam_htmap_code CLIENT SPECIFIED

  • WHERE mandt = sy-mandt

  • AND metrocd = tbldata-metro_client.

  • IF sy-subrc = 0.

  • clmapflag = 'Y'.

  • MESSAGE s557(zer).

    • LEAVE SCREEN.

  • ENDIF.

*

  • SELECT SINGLE * FROM zmam_htmap_code CLIENT SPECIFIED

  • WHERE mandt = sy-mandt

  • AND metrocd = tbldata-metro_agency.

  • IF sy-subrc = 0.

  • agmapflag = 'Y'.

  • MESSAGE s558(zer).

      • LEAVE SCREEN.

  • ENDIF.

                        • If not there in zmam_htmapcode Then

*

  • IF agmapflag NE 'Y' AND clmapflag NE 'Y'.

LOOP AT httab INTO tmpht.

INSERT INTO zmam_htmap_code CLIENT SPECIFIED VALUES tmpht.

CLEAR : tmpht.

ENDLOOP.

  • ENDIF.

DELETE FROM zmam_metro_error CLIENT SPECIFIED WHERE

mandt = sy-mandt

AND companycd = tbldata-companycd

AND avm_nr = tbldata-avm_nr

AND pos_nr = tbldata-pos_nr

AND gruppabrnr = tbldata-gruppabrnr.

CLEAR : final_tab.

MOVE-CORRESPONDING tbldata TO final_tab.

INSERT INTO zmam_metro_error CLIENT SPECIFIED VALUES final_tab.

IF sy-subrc = 0.

COMMIT WORK.

MESSAGE s555(zer).

CLEAR : agmapflag, clmapflag.

CLEAR : httab, tbldata,final_tab.

ENDIF.

ENDIF.

                                • This is only for HT

*IF it is TOI, no entry required in zmam_htmap_code

*Just save it in zmam_metro_error with status = 'Y'

IF tbldata-companycd = 'TOI'.

  • DELETE FROM zmam_metro_error CLIENT SPECIFIED WHERE

  • mandt = sy-mandt

  • AND companycd = tbldata-companycd

  • AND avm_nr = tbldata-avm_nr

  • AND pos_nr = tbldata-pos_nr

  • AND gruppabrnr = tbldata-gruppabrnr.

  • CLEAR : final_tab.

  • MOVE-CORRESPONDING tbldata TO final_tab.

  • INSERT INTO zmam_metro_error CLIENT SPECIFIED VALUES final_tab.

UPDATE zmam_metro_error CLIENT SPECIFIED

SET metro_agency = tbldata-metro_agency

metro_client = tbldata-metro_client

status ='Y'

WHERE

mandt = sy-mandt

AND companycd = tbldata-companycd

AND avm_nr = tbldata-avm_nr

AND pos_nr = tbldata-pos_nr

AND gruppabrnr = tbldata-gruppabrnr

AND status ='N'.

  • CLEAR : final_tab.

IF sy-subrc = 0.

COMMIT WORK.

MESSAGE s555(zer).

CLEAR : agmapflag, clmapflag.

CLEAR : httab, tbldata,final_tab.

ELSE.

MESSAGE e061(zer).

ENDIF.

  • ENDIF. From Here

ENDIF.

ENDIF.

ENDIF.

                                          • II PROBLAMATIC

IF agflag <> 'Y'.

tbldata-status = 'N'.

MODIFY tbldata.

  • DELETE FROM zmam_metro_error CLIENT SPECIFIED WHERE

  • mandt = sy-mandt

  • AND companycd = tbldata-companycd

  • AND avm_nr = tbldata-avm_nr

  • AND pos_nr = tbldata-pos_nr

  • AND gruppabrnr = tbldata-gruppabrnr.

  • CLEAR : final_tab.

  • MOVE-CORRESPONDING tbldata TO final_tab.

*

  • INSERT INTO zmam_metro_error CLIENT SPECIFIED VALUES final_tab.

UPDATE zmam_metro_error CLIENT SPECIFIED

SET metro_agency = tbldata-metro_agency

metro_client = tbldata-metro_client

WHERE

mandt = sy-mandt

AND companycd = tbldata-companycd

AND avm_nr = tbldata-avm_nr

AND pos_nr = tbldata-pos_nr

AND gruppabrnr = tbldata-gruppabrnr

AND status ='N'.

IF sy-subrc = 0.

COMMIT WORK.

save_flag = 'Y'.

MESSAGE s555(zer).

ENDIF.

ENDIF.

CLEAR : httab, tbldata,final_tab.

ENDLOOP.

1 REPLY 1

Clemenss
Active Contributor
0 Kudos

Harsha,

posting code please mark the code and use the code button on top. This keeps the formatting. This allows some analysis.

The statements sequence

F sy-subrc <> 0 .

...

ELSEIF sy-subrc = 0.

...

ENDIF.

does not make sense because the ELSEIF condition is always true in the ELSE case.

That makes it even ore difficult to read.

Try to modularize: nested ifs down 4 or more levels do not help.

Regards,

Clemens