cancel
Showing results for 
Search instead for 
Did you mean: 

Add a CHECK or CONTINUE in a FOR Loop Expression

Sougata
Active Contributor
1,408
TRY.
    et_agents = VALUE #( BASE et_agents
                         FOR ls_agent IN it_agents
                 LET check = NEW zcl_te_pos_deleg( CONV #( ls_agent-objid )
                              )->is_within_limit( CONV #( iv_amount ) )
                 IN
                  ( COND #( WHEN check = abap_true
                            THEN CORRESPONDING #( ls_agent )
                            ELSE THROW RESUMABLE zcx_swf_no_agent_found( )
                          )
                  )
                      ).
CATCH BEFORE UNWIND zcx_swf_no_agent_found.
  RESUME.
ENDTRY.

DELETE et_agents WHERE table_line IS INITIAL."<- I want to avoid doing this

The issue is that after an exception is raised and it RESUMEs, an empty row is appended in table ET_AGENTS before processing the next iteraion of IT_AGENTS.

Is there a way in the FOR LOOP Expressions which works like a CHECK or CONTINUE statement like it works in the traditional LOOP/ENDLOOP statement?

Thanks,

Sougata.

Accepted Solutions (0)

Answers (1)

Answers (1)

Sougata
Active Contributor
0 Kudos

Thanks sandra.rossi works perfectly well (even without complete type) and that means there is no need for the above code to THROW an Exception and RESUME it - I would hope SAP provides an option in the future release to allow for a CHECK or CONTINUE option within this FOR LOOP Expression so it can be implemented elegantly. There is a WHERE condition but it will not work in the above case; so we would like to see perhaps an enhanced WHERE which will work like a CHECK within a FOR LOOP.

mateuszadamus Hi Mateusz its for better readibility purpose and it also depends on individual taste - I find it much better readable and much more logical when the implementation uses functional programming i.e. LHS = RHS just like mathematics instead of writing a "story" which often is the case with old school programming - I guess that's one of the main reasons why SAP upgraded their ABAP language to make it modern to be able to align it with other modern contemporary languages.

Best regards,

Sougata.