How to Read set values In sap abap programming language
Some time requirment to add some values and read some values in set
TYPES: BEGIN OF TY_UNAME,
BNAME TYPE USR01-BNAME,
PLANT TYPE CHAR4,
END OF TY_UNAME.
DATA: t_set_values TYPE TABLE OF rgsb4,
wa_tsetvalues TYPE rgsb4,
LT_UNAME TYPE TABLE OF TY_UNAME,
LS_UNAME TYPE TY_UNAME.
CALL FUNCTION 'G_SET_GET_ALL_VALUES'
EXPORTING
client = sy-mandt
setnr = 'ZP2POFFAPR'
table = 'USR01'
class = '0000'
fieldname = 'BNAME'
TABLES
set_values = t_set_values
EXCEPTIONS
set_not_found = 1
OTHERS = 2.
IF sy-subrc EQ 0.
LOOP AT t_set_values INTO wa_tsetvalues.
LS_UNAME-BNAME = wa_tsetvalues-from+0(7).
LS_UNAME-PLANT = wa_tsetvalues-from+7(4).
APPEND LS_UNAME TO LT_UNAME.
ENDLOOP.
ELSE.
MESSAGE 'Error while reading set values.' TYPE 'E' DISPLAY LIKE 'I'.
ENDIF.
READ TABLE LT_UNAME INTO LS_UNAME WITH KEY BNAME = SY-UNAME.
IF SY-SUBRC <> 0.
ERROR = 'X'.
else.
if sy-subrc eq 0.
IF LS_UNAME-PLANT NE zp2ptpurofr-plant.
ERROR = 'X'.
ENDIF.
ENDIF.
ENDIF.
TYPES: BEGIN OF TY_UNAME,
BNAME TYPE USR01-BNAME,
PLANT TYPE CHAR4,
END OF TY_UNAME.
DATA: t_set_values TYPE TABLE OF rgsb4,
wa_tsetvalues TYPE rgsb4,
LT_UNAME TYPE TABLE OF TY_UNAME,
LS_UNAME TYPE TY_UNAME.
CALL FUNCTION 'G_SET_GET_ALL_VALUES'
EXPORTING
client = sy-mandt
setnr = 'ZP2POFFAPR'
table = 'USR01'
class = '0000'
fieldname = 'BNAME'
TABLES
set_values = t_set_values
EXCEPTIONS
set_not_found = 1
OTHERS = 2.
IF sy-subrc EQ 0.
LOOP AT t_set_values INTO wa_tsetvalues.
LS_UNAME-BNAME = wa_tsetvalues-from+0(7).
LS_UNAME-PLANT = wa_tsetvalues-from+7(4).
APPEND LS_UNAME TO LT_UNAME.
ENDLOOP.
ELSE.
MESSAGE 'Error while reading set values.' TYPE 'E' DISPLAY LIKE 'I'.
ENDIF.
READ TABLE LT_UNAME INTO LS_UNAME WITH KEY BNAME = SY-UNAME.
IF SY-SUBRC <> 0.
ERROR = 'X'.
else.
if sy-subrc eq 0.
IF LS_UNAME-PLANT NE zp2ptpurofr-plant.
ERROR = 'X'.
ENDIF.
ENDIF.
ENDIF.
Comments
Post a Comment