09-30-2014 11:51 AM
Hi Experts,
Currently developing my ABAP skills,
I have a formula which contains brackets ((([SEL34])/1000)/([SEL27]+([SEL28]*6.0924)))
I would like to have code which checks the opening brackets and closing brackets.
it should if the opening and closing brackets does not match its should prompt and error message that opening and closing brackets are not equal or something.
at the moment I have already a loop which looks like this.
FORM GET_EXISTING_RECORDS.
SELECT *
FROM table_config
INTO Table lt_table_config.
SELECT *
FROM Table_header
INTO TABLE LT_table_header.
* First Check on Selection IDs between Header and Config Tables.
LOOP AT LT_table_header. ASSIGNING <FS>. "INTO GWA_LT_table_header..
ASSIGN COMPONENT 'xx100004' OF STRUCTURE <FS> TO <FS_1>.
READ TABLE lt_table_config INTO GWA_table_config WITH KEY XX100004 =<FS_1>."GWA_Table_config-XX100004.
IF SY-SUBRC <> 0.
WRITE: <FS_1>, 'HEADER ID not found in Config Table '.
ENDIF.
ENDLOOP.
ENDFORM.
here i would like to have a form that checks the brackets opened and closed in a formula
table_header contains all the formulas.
I hope to receive some advise.
Rabie Hamidi
09-30-2014 12:20 PM
Hi Rabie
Check this:
FORM check_formula
USING p_formula TYPE string
CHANGING p_success_flag TYPE flag.
DATA: lv_strln TYPE i,
lv_count TYPE i VALUE 0,
lv_loop_counter TYPE i VALUE 0.
lv_strln = STRLEN( p_formula ).
DO lv_strln TIMES.
IF p_formula+lv_loop_counter(1) = '('.
ADD 1 TO lv_count.
ELSEIF p_formula+lv_loop_counter(1) = ')'.
SUBTRACT 1 FROM lv_count.
ENDIF.
IF lv_count < 0.
EXIT.
ENDIF.
ADD 1 TO lv_loop_counter.
ENDDO.
IF lv_count = 0.
p_success_flag = 'X'.
ELSE.
p_success_flag = space.
ENDIF.
ENDFORM. "check_formula
Regards
Shai.
09-30-2014 12:57 PM
Hi Shai,
Thanks for your advise
however i need to first loop into Formula table right?
otherwise it will not pick up the formulas ?
I am looking forward to hear from you.
LOOP AT LT_Formula_Table ASSIGNING <FS>. "INTO GWA_Formula_Table.
ASSIGN COMPONENT 'Formula' OF STRUCTURE <FS> TO <FS_1>.
READ TABLE LT_Formula_Table INTO GWA_Formula_Table WITH KEY Formula = <FS_1>."GWA_Formula_Table-Formula.
USING P_FORMULA TYPE STRING
CHANGING P_SUCCESS_FLAG TYPE FLAG.
DATA: LV_STRLN TYPE I,
LV_COUNT TYPE I VALUE 0,
LV_LOOP_COUNTER TYPE I VALUE 0.
LV_STRLN = STRLEN( P_FORMULA ).
DO LV_STRLN TIMES.
IF P_FORMULA+LV_LOOP_COUNTER(1) = '('.
ADD 1 TO LV_COUNT.
ELSEIF P_FORMULA+LV_LOOP_COUNTER(1) = ')'.
SUBTRACT 1 FROM LV_COUNT.
ENDIF.
IF LV_COUNT < 0.
EXIT.
ENDIF.
ADD 1 TO LV_LOOP_COUNTER.
ENDDO.
IF LV_COUNT = 0.
P_SUCCESS_FLAG = 'X'.
ELSE.
P_SUCCESS_FLAG = SPACE.
ENDIF.
ENDLOOP.
ENDFORM. "check_formula
09-30-2014 1:20 PM
Hi Rabie
You shure do need to loop the table - you can do it in the form (and send the table as parameter) or in the calling code (and send string only) it doesn't realy matter.
Personaly I think the second option is better.
Shai.
09-30-2014 1:28 PM
Hi Shai,
Thanks again. I am new in ABAP world. Please correct me if my code is wrong
LOOP AT LT_formula_table ASSIGNING <FS>. "INTO GWA_Formula_table.
ASSIGN COMPONENT 'XX100012' OF STRUCTURE <FS> TO <FS_1>. " Formula
READ TABLE LT_formula_table INTO GWA_Formula_tableD WITH KEY XX100012 = <FS_1>."Formula
USING P_FORMULA TYPE STRING
CHANGING P_SUCCESS_FLAG TYPE FLAG.
DATA: LV_STRLN TYPE I,
LV_COUNT TYPE I VALUE 0,
LV_LOOP_COUNTER TYPE I VALUE 0.
LV_STRLN = STRLEN( P_FORMULA ).
DO LV_STRLN TIMES.
IF P_FORMULA+LV_LOOP_COUNTER(1) = '('.
ADD 1 TO LV_COUNT.
ELSEIF P_FORMULA+LV_LOOP_COUNTER(1) = ')'.
SUBTRACT 1 FROM LV_COUNT.
ENDIF.
IF LV_COUNT < 0.
EXIT.
ENDIF.
ADD 1 TO LV_LOOP_COUNTER.
ENDDO.
IF LV_COUNT = 0.
P_SUCCESS_FLAG = 'X'.
ELSE.
P_SUCCESS_FLAG = SPACE.
ENDIF.
ENDLOOP.
ENDFORM. "check_formula
Thanks in advance.
Regards,
Rabie
10-01-2014 2:54 PM