<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Handle null value as input to BAPI-X structure dynamically. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/handle-null-value-as-input-to-bapi-x-structure-dynamically/m-p/12167785#M1978686</link>
    <description>&lt;P&gt;Hello  &lt;SPAN class="mention-scrubbed"&gt;koolspy.ultimate&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;You could write a method (or a procedure) which uses ABAP RTTI for this. Example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;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=&amp;gt;describe_by_data( p_data = is_structure ).
    CASE lo_type-&amp;gt;kind.
      WHEN cl_abap_typedescr=&amp;gt;kind_struct.
        lo_type_structure ?= lo_type.
    ENDCASE.
    CHECK lo_type_structure IS BOUND.

    DATA(lt_components) = lo_type_structure-&amp;gt;get_components( ).
    LOOP AT lt_components REFERENCE INTO DATA(ld_component).
      ASSIGN COMPONENT ld_component-&amp;gt;name OF STRUCTURE cs_structure_x TO FIELD-SYMBOL(&amp;lt;lv_field_x&amp;gt;).
      CHECK sy-subrc = 0.

      IF iv_filled_only = abap_true.
        ASSIGN COMPONENT ld_component-&amp;gt;name OF STRUCTURE is_structure TO FIELD-SYMBOL(&amp;lt;lv_field&amp;gt;).
        CHECK sy-subrc = 0
          AND &amp;lt;lv_field&amp;gt; IS NOT INITIAL.
      ENDIF.

      &amp;lt;lv_field&amp;gt; = 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=&amp;gt;mark_x(
  EXPORTING iv_filled_only = lv_filled_only is_structure = ls_values
  CHANGING cs_structure_x = ls_values_x ).&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Mateusz&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jun 2020 20:09:00 GMT</pubDate>
    <dc:creator>MateuszAdamus</dc:creator>
    <dc:date>2020-06-03T20:09:00Z</dc:date>
    <item>
      <title>Handle null value as input to BAPI-X structure dynamically.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handle-null-value-as-input-to-bapi-x-structure-dynamically/m-p/12167783#M1978684</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
  &lt;P&gt;Could you please suggest how to input null value / 0 / Space to bapix structures.&lt;/P&gt;
  &lt;P&gt;To be more accurate please find the below example.&lt;/P&gt;
  &lt;P&gt;BAPI: BAPI_MATERIAL_SAVEREPLICA&lt;/P&gt;
  &lt;P&gt;Field XCHPF (It accepts only "X" or "").&lt;/P&gt;
  &lt;P&gt;currently I am update the plantdatax-xchpf as following:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;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.
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The above is working fine. (Note: I am trying to make the solution dynamic)&lt;/P&gt;
  &lt;P&gt;Now I have a scenario where I need to update the value to null.&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;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.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Thanks in Advance.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 18:05:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handle-null-value-as-input-to-bapi-x-structure-dynamically/m-p/12167783#M1978684</guid>
      <dc:creator>koolspy_ultimate</dc:creator>
      <dc:date>2020-06-03T18:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Handle null value as input to BAPI-X structure dynamically.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handle-null-value-as-input-to-bapi-x-structure-dynamically/m-p/12167784#M1978685</link>
      <description>&lt;P&gt;What issue do you have? ("if lw-xchpf is not initial ... causing Issue" is not a symptom)&lt;/P&gt;&lt;P&gt;You say "null value / 0 / Space", it's rather imprecise, can you explain what you mean? (why different terms?)&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 19:45:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handle-null-value-as-input-to-bapi-x-structure-dynamically/m-p/12167784#M1978685</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-06-03T19:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Handle null value as input to BAPI-X structure dynamically.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handle-null-value-as-input-to-bapi-x-structure-dynamically/m-p/12167785#M1978686</link>
      <description>&lt;P&gt;Hello  &lt;SPAN class="mention-scrubbed"&gt;koolspy.ultimate&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;You could write a method (or a procedure) which uses ABAP RTTI for this. Example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;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=&amp;gt;describe_by_data( p_data = is_structure ).
    CASE lo_type-&amp;gt;kind.
      WHEN cl_abap_typedescr=&amp;gt;kind_struct.
        lo_type_structure ?= lo_type.
    ENDCASE.
    CHECK lo_type_structure IS BOUND.

    DATA(lt_components) = lo_type_structure-&amp;gt;get_components( ).
    LOOP AT lt_components REFERENCE INTO DATA(ld_component).
      ASSIGN COMPONENT ld_component-&amp;gt;name OF STRUCTURE cs_structure_x TO FIELD-SYMBOL(&amp;lt;lv_field_x&amp;gt;).
      CHECK sy-subrc = 0.

      IF iv_filled_only = abap_true.
        ASSIGN COMPONENT ld_component-&amp;gt;name OF STRUCTURE is_structure TO FIELD-SYMBOL(&amp;lt;lv_field&amp;gt;).
        CHECK sy-subrc = 0
          AND &amp;lt;lv_field&amp;gt; IS NOT INITIAL.
      ENDIF.

      &amp;lt;lv_field&amp;gt; = 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=&amp;gt;mark_x(
  EXPORTING iv_filled_only = lv_filled_only is_structure = ls_values
  CHANGING cs_structure_x = ls_values_x ).&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Mateusz&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 20:09:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handle-null-value-as-input-to-bapi-x-structure-dynamically/m-p/12167785#M1978686</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-06-03T20:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: Handle null value as input to BAPI-X structure dynamically.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/handle-null-value-as-input-to-bapi-x-structure-dynamically/m-p/12167786#M1978687</link>
      <description>&lt;P&gt;Hi Sandra Rossi,&lt;/P&gt;&lt;P&gt;I mean how to pass empty value as input considering the if condition for updating the bapix structure.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 04:39:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/handle-null-value-as-input-to-bapi-x-structure-dynamically/m-p/12167786#M1978687</guid>
      <dc:creator>koolspy_ultimate</dc:creator>
      <dc:date>2020-06-04T04:39:26Z</dc:date>
    </item>
  </channel>
</rss>

