2022 Oct 08 9:53 AM
I want to transfer the set_values into a table and use it in a IF ENDIF logic.
Here is my code:
DATA: lt_setid LIKE sethier-setid.
CALL FUNCTION 'G_SET_GET_ID_FROM_NAME'
EXPORTING
CLIENT = sy-mandt
shortname = 'Z_CURR1'
IMPORTING
NEW_SETID = lt_setid
EXCEPTIONS
NO_SET_FOUND = 1
NO_SET_PICKED_FROM_POPUP = 2
WRONG_CLASS = 3
WRONG_SUBCLASS = 4
TABLE_FIELD_NOT_FOUND = 5
FIELDS_DONT_MATCH = 6
SET_IS_EMPTY = 7
FORMULA_IN_SET = 8
SET_IS_DYNAMIC = 9
OTHERS = 10
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
DATA: lt_set1 TYPE TABLE OF rgsb4,
lx_set1 LIKE LINE OF lt_set1,
lt_values LIKE TABLE OF lt_set1.
CALL FUNCTION 'G_SET_GET_ALL_VALUES'
EXPORTING
setnr = '0000Z_CURR1'
tables
set_values = lt_set1
EXCEPTIONS
SET_NOT_FOUND = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Here's the data of LT_SET1 and I want to use the first entry in the code below.
IF T_EKKO_EKPO-WAERS = "FIRST ENTRY IN THE LT_SET1",
"DO SOMETHING HERE
ENDIF.
2022 Oct 08 1:13 PM
It's referred as a Table Expression in the ABAP documentation:
IF T_EKKO_EKPO-WAERS = LT_SET1[ 1 ]-WAERS.
...
Be careful, if LT_SET1 is empty, LT_SET1[ 1 ] will raise the exception CX_SY_ITAB_LINE_NOT_FOUND.
2022 Oct 09 12:09 PM
I'm trying to use the LT_SET1[ 1 ]-FROM, unfortunately, it does not work correctly.
It works if the code is like this:
IF T_EKKO_EKPO-WAERS = 'CHF'.
But it doesn't if the code is like this:
IF T_EKKO_EKPO-WAERS = lt_set[ 1 ]-from.
2022 Oct 09 2:24 PM
I checked in my system, no issue. What means "does not work correctly"? "doesn't work" is very subjective. Is it a syntax error? What message? If not, create a tiny program to reproduce and share it so that people can test it.
2022 Oct 10 9:09 AM
sandra.rossi Apologies, there just has been a delay in the system upon activating the code.
Can i use CX_SY_ITAB_LINE_NOT_FOUND without using TRY CATCH?
I want to include it inside the error handling of sy-subrc <> 0.
CALL FUNCTION 'G_SET_GET_ALL_VALUES'
EXPORTING
setnr = '0000ZCURR1'
TABLES
set_values = lt_curr
EXCEPTIONS
SET_NOT_FOUND = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
2022 Oct 10 2:26 PM
Exception classes can be handled only with TRY CATCH. Exceptions are not related to SY-SUBRC.
Possibly make sure that there's at least one line to avoid the exception.
IF LT_SET1 IS NOT INITIAL AND T_EKKO_EKPO-WAERS = LT_SET1[ 1 ]-WAERS.
Also it's possible to use this predicate function (won't trigger an exception):
IF line_exists( LT_SET1[ 1 ] ).