‎2020 Jun 03 7:05 PM
Hi All,
Could you please suggest how to input null value / 0 / Space to bapix structures.
To be more accurate please find the below example.
BAPI: BAPI_MATERIAL_SAVEREPLICA
Field XCHPF (It accepts only "X" or "").
currently I am update the plantdatax-xchpf as following:
lw-xchpf = 'X'.
append lw to lt_plant.
If lw-xchpf is not initial.
lw_plantx-xchpf = 'X'.
endif.
append lw_plantx to lt_plantx.
The above is working fine. (Note: I am trying to make the solution dynamic)
Now I have a scenario where I need to update the value to null.
lw-xchpf = ''.
append lw to lt_plant.
If lw-xchpf is not initial. "------This is causing Issue
lw_plantx-xchpf = 'X'.
endif.
append lw_plantx to lt_plantx.
Thanks in Advance.
‎2020 Jun 03 8:45 PM
What issue do you have? ("if lw-xchpf is not initial ... causing Issue" is not a symptom)
You say "null value / 0 / Space", it's rather imprecise, can you explain what you mean? (why different terms?)
‎2020 Jun 03 9:09 PM
Hello koolspy.ultimate
You could write a method (or a procedure) which uses ABAP RTTI for this. Example:
CLASS lcl_test DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
mark_x
IMPORTING
iv_filled_only TYPE flag
is_structure TYPE any
CHANGING
cs_structure_x TYPE any.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD mark_x.
DATA:
lo_type_table TYPE REF TO cl_abap_tabledescr,
lo_type_structure TYPE REF TO cl_abap_structdescr.
DATA(lo_type) = cl_abap_typedescr=>describe_by_data( p_data = is_structure ).
CASE lo_type->kind.
WHEN cl_abap_typedescr=>kind_struct.
lo_type_structure ?= lo_type.
ENDCASE.
CHECK lo_type_structure IS BOUND.
DATA(lt_components) = lo_type_structure->get_components( ).
LOOP AT lt_components REFERENCE INTO DATA(ld_component).
ASSIGN COMPONENT ld_component->name OF STRUCTURE cs_structure_x TO FIELD-SYMBOL(<lv_field_x>).
CHECK sy-subrc = 0.
IF iv_filled_only = abap_true.
ASSIGN COMPONENT ld_component->name OF STRUCTURE is_structure TO FIELD-SYMBOL(<lv_field>).
CHECK sy-subrc = 0
AND <lv_field> IS NOT INITIAL.
ENDIF.
<lv_field> = abap_true.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
" then, the usage
IF something = abap_true OR something_else = abap_true.
lv_filled_only = abap_true.
ELSE.
lv_filled_only = abap_false.
ENDIF.
lcl_test=>mark_x(
EXPORTING iv_filled_only = lv_filled_only is_structure = ls_values
CHANGING cs_structure_x = ls_values_x ).<br>The LS_VALUES structure from the example does not have to be the same as the BAPI's values structure. It can be a structure of any type. The important thing is that at least some of its fields have the same name as the BAPI's structure. These fields will have their X filled by the MARK_X method.
Kind regards,
Mateusz
‎2020 Jun 04 5:39 AM
Hi Sandra Rossi,
I mean how to pass empty value as input considering the if condition for updating the bapix structure.