‎2020 Sep 02 11:15 AM
Hi all,
I am in the midst of developing a module pool program that uploads data into a z table.
The issue is that because of the many checks required (e.g. checking that the fields are not empty, checking which radiobutton has been selected), I have implemented several nested if else statements.
Essentially, the flow of logic is:
when p_manual is selected...
- if all the input fields have no value --> message user
- elseif all the input fields have value --> select data
---if selection successful, display data
---elseif selection not successful, ask user input data
when p_excel is selected...
- if the filepath field has no value --> message user
- elseif the filepath field has a value, then...
---if the user chooses to perform a test upload --> upload the data + display uploaded data back to user
---if the user chooses to upload the file --> upload the data + insert data into z table
<br>
Code is below:
*If user chooses to manually upload data
IF save_ok = 'X' and p_manual = 'X'.
IF field IS INITIAL. "check if field has no value
"message user to fill in all fields
ELSE. "if field has value
"select data from zTable to display to user
IF selected data is successful.
"show the data in SM30
ELSE.
"send user to another screen to manually fill in data
ENDIF.
*if user chooses to upload data from Excel
ELSEIF save_ok = 'X' and p_excel = 'X'.
IF filepath IS INITIAL.
"message user to select a filepath
ELSE.
IF user wants to perform a test upload.
"upload the data
"call another screen to display the data
ELSEIF user wants to upload the data directly into the z table.
"upload the data
"insert the data into table
ENDIF.
ENDIF.
ENDIF.
Does anyone have any suggestions on how to improve this (i.e. without using nested IF...ELSE statements)?
Thank you,
Yi Lin
‎2020 Sep 02 11:32 AM
Maybe you have to change totaly your mind and play with method & exceptions.
The part of your code is not enough to be sure it is the good way to do it, but it could be something like that
try.
check is_field_populated( field... ) eq abap_true.
check is_selected_data_success( data ) eq abap_true.
catch cx_application into data(lo_excption).
endtry.for the part of the save data type, you have to split it. Try to folloy the Clean code and follow the rule : A method do one thing, and do it well
here, you do a lot of control, and it is a big melting of responsibility
‎2020 Sep 02 11:37 AM
"How to Avoid Nested Loops in Module Pool Program?"
I see no loop.
‎2020 Sep 02 12:11 PM
Hi, To validate user input fields use the below
FIELD Field_Name MODULE validate_field_name concept.
You can try with chain end chain if there is more than 1 field to be validated
‎2020 Sep 03 2:35 AM
Hi Frederic, thanks for your suggestion. I will try to use that in my code.
Hi Matthew, thanks for pointing out the error in the title. That was a mistake on my part