on 2022 Jun 09 6:41 PM
Hi Experts,
I have an enhancement request where I need to read the last '3' characters of all the individual IDs contained inside a variable LV_VALIDATION_TEAM.
Additionally, I will have to take those "Last 3 characters" of each ID and run them through a established set of IF statement conditions.
Currently my code does not recognize that there are multiple IDs contained within the variable and only reads the last 3 character of the last record. I believe I need to loop my current code along with my IF conditions but I am clueless onto how to do it. Any help is greatly appreciated. Thanks
Request clarification before answering.
Hi all,
Thank you very much for your time and shared knowledge.
As per your your suggestions, I ended up writing all of the "last 3 characters" code and "evaluations" right inside the method GET_OWNER_PROPERTY_VALIDATION.
*******************************************************************************
TYPES: BEGIN OF lty_str,
last3 TYPE string,
END OF lty_str.
DATA: lv_string TYPE string,
lv_length TYPE string,
lt_table TYPE TABLE OF lty_str,
ls_table LIKE LINE OF lt_table.
lv_string = lv_last3.
SPLIT lv_string AT ',' INTO: DATA(str1) DATA(str2),
TABLE DATA(itab).
LOOP AT itab INTO DATA(wa).
lv_length = strlen( wa ).
DATA(last_3) = lv_length - 3.
ls_table-last3 = wa+last_3(3).
APPEND ls_table TO lt_table.
ENDLOOP.
******************************************************************************************
DATA: wa2 TYPE lty_str.
IF ls_stage EQ '1'.
LOOP AT lt_table INTO wa2 WHERE last3 = '_PL' OR last3 ='_AD'.
IF sy-subrc = 0.
e_validation_team = abap_true.
ENDIF.
ENDLOOP.
ELSEIF ls_stage EQ '2'.
LOOP AT lt_table INTO wa2 WHERE last3 ='_A1' OR last3 ='_AD'.
IF sy-subrc = 0.
e_validation_team = abap_true.
ENDIF.
ENDLOOP.
ELSEIF ls_stage EQ '3'.
LOOP AT lt_table INTO wa2 WHERE last3 ='_A2' OR last3 ='_AD'.
IF sy-subrc = 0.
e_validation_team = abap_true.
ENDIF.
ENDLOOP.
ELSEIF ls_stage EQ '4'.
LOOP AT lt_table INTO wa2 WHERE last3 ='_A3' OR last3 ='_AD'.
IF sy-subrc = 0.
e_validation_team = abap_true.
ENDIF.
ENDLOOP.
ELSE.
e_validation_team = abap_false.
ENDIF.
I know i may not be optimal but so far is working.
The only issue that I have pending is on how to capture the final result of those last IF statements in a variable.
I'd like to know what "last 3 characters" fulfilled the IF conditions when the e_validation_team = abap_true.
EX- Last3 = '_PL', Last3 ='_AD',Last3 = '_A3'.....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not optimal and wrong. Never test IF sy-subrc = 0 right after LOOP AT, it's completely useless. And do an EXIT.
...
LOOP AT lt_table INTO wa2 WHERE last3 = '_PL' OR last3 ='_AD'.
e_validation_team = abap_true.
EXIT.
ENDLOOP.
...
Also, as you mention the solution which works for you, you could avoid splitting after concat_lines_of (solution from LOOP AT a table with with another table to get all matched ID's listed | SAP Community), just don't use concat_lines_of.You'll end with that: DATA(validation_teams) = VALUE string_table( ).
LOOP AT it_string INTO wa_string .
READ TABLE lt_teams_mbr INTO ls_teams_mbr WITH KEY team_mbr = wa_string-str.
IF sy-subrc = 0.
e_validation = abap_true.
APPEND wa_string-str TO validation_teams.<br> ENDIF.
ENDLOOP.
" example next line: if lv_stage = '2', check if validation_teams has line ending with _A1 or _AD:
DATA(lookup_team_name) = SWITCH string( lv_stage
WHEN '1' THEN '(?:_PL|_AD)$'
WHEN '2' THEN '(?:_A1|_AD)$'
WHEN '3' THEN '(?:_A2|_AD)$'
WHEN '4' THEN '(?:_A3|_AD)$' ).
FIND REGEX lookup_team_name IN TABLE validation_teams.
IF sy-subrc = 0.
e_validation_team = abap_true.
ENDIF.
Hi Sandra,
Thank you so much for the suggestion on the unnecessary "IF SY_SUBRC=0" statement. I did remove it and works great.
Also, I instead did implemented your latest code and it works flawlessly, so this is the code I have as for now:
DATA(validation_teams) = VALUE string_table( ).
LOOP AT it_string INTO wa_string .
READ TABLE lt_teams_mbr INTO ls_teams_mbr WITH KEY team_mbr = wa_string-str.
IF sy-subrc = 0.
e_validation = abap_true.
APPEND wa_string-str TO validation_teams.
ENDIF.
ENDLOOP.
DATA(lookup_team_name) = SWITCH string( ls_stage
WHEN '1' THEN '(?:_PL|_AD)$'
WHEN '2' THEN '(?:_A1|_AD)$'
WHEN '3' THEN '(?:_A2|_AD)$'
WHEN '4' THEN '(?:_A3|_AD)$' ).
FIND REGEX lookup_team_name IN TABLE validation_teams.
IF sy-subrc = 0.
e_validation_team = abap_true.
ENDIF.
back to my later question onto how to capture the "last 3" characters that were matched, is there a way to capture in a variable or string the actual last three characters that were found during the "FIND REGEX lookup_team_name IN TABLE validation_teams."?
For example:
for this particular scenario from above, I know for a fact that "_PL" was the matching last three characters so is there a way to capture that in a variable to be read and not just get the "E_VALIDATION_TEAM = ABAP_TRUE"?
Thanks you very much in advance!
You can get "submatches" of the Regular Expression, by using registration (...) ; (?:...) was "without registration".
DATA(lookup_team_name) = SWITCH string( ls_stage
WHEN '1' THEN '(_PL|_AD)$'
WHEN '2' THEN '(_A1|_AD)$'
WHEN '3' THEN '(_A2|_AD)$'
WHEN '4' THEN '(_A3|_AD)$' ).
FIND REGEX lookup_team_name IN TABLE validation_teams SUBMATCHES DATA(submatch).
With IN TABLE, it will return the submatch of the first matching line.
Better change the method GET_OWNER_PROPERTY_VALIDATION2 to return a table of validation teams.
METHODS get_owner_property_validation2
IMPORTING
i_appset_id TYPE ...
...
EXPORTING
e_validation TYPE ...
e_validation_teams TYPE string_table. " <========
then it'll be easier to implement the logic you want.
In your code, I'm not sure whether you really want to use ELSEIF, shouldn't it be OR?
If it's OR, you could use this code:
IF lv_validation = abap_true.
DATA(expected_end_of_team_name) = SWITCH string( lv_stage
WHEN '1' THEN '_PL'
WHEN '2' THEN '_A1'
WHEN '3' THEN '_A2'
WHEN '4' THEN '_A3'
ELSE '_AD' ).
FIND REGEX |{ expected_end_of_team_name }$| IN TABLE e_validation_teams.
IF sy-subrc = 0.
" one validation team is found whose name ends as expected
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sandra,
Thanks a lot for your answer and apologies for the tag. I just thought that since you helped in my last post, which is directly related to this one, I may have been easier to get a second opinion from you. I won't happen again!
As per your answer. Thanks again! I took some of your suggestions and reworked it into something else, a little longer but works for now.
Hi
LV_VALIDATION_TEAM.
Assuming your variable LV_VALIDATION_TEAM contains IDs separated by Space. "like 'id_123 id_A1 id_A3 id_PL id_AD'.
If it is not change your class method get_owner_property_validation2 to have the ids separated by a space or unique char say #.
Step 1.
Change your method class method get_owner_property_validation2 to return a able of IDs instead of single variable concatenated Ids with space or #
Then Loop at the table returned.
If not possible to change the class, then use SPLIT statement on that LV_VALIDATION_TEAM and put the cut items into a table and loop at that table.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I hope this helps you
TYPES: BEGIN OF LTY_STR,BREAK QUYNHBC.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot for your response. I used 90% of your code to fulfill my requirement. You Rock!
I am just missing one last piece related to my IF statement conditions and how to store the result in a variable or string that I can read.
I added my code right below if you'd so kind to take a look at it I will very much appreciate it.
User | Count |
---|---|
6 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.