1

I am trying to create an API allowing user to change certain fields of a notification. The changes will be written using a BAPI BAPI_ALM_NOTIF_DATA_MODIFY.

I have ls_struc1 that contains all fields I am publishing in the API. Is there a way to set the value in ls_struc2 to X if ls_struc1 contains a field with the same name?

        types: begin of api_struc,
             short_text type qmtxt,
             priority   type priok,
             desstdate  type strmn,
             desenddate type ltrmn,
           end of api_struc.
    data: ls_struc1 type api_struc,
             ls_struc2 type bapi2080_nothdri_x.
          

Based on some other posts I tried the following solution but could not get it to work.

    data: lr_struc1 type ref to cl_abap_structdescr,
          lr_struc2 type ref to cl_abap_structdescr,
          lt_comp_s1 type cl_abap_structdescr=>component_table,
          ls_comp_s1 like line of lt_comp_s1,
          lt_comp_s2 type cl_abap_structdescr=>component_table,
          ls_comp_s2 like line of lt_comp_s2.
          
          
    lr_struc1 ?= cl_abap_structdescr=>describe_by_data( ls_struc1 ). " Get the description of the data
    lt_comp_s1 = lr_struc1->get_components( ). "Get the fields of the structure
      
    lr_struc2 ?= cl_abap_structdescr=>describe_by_data( ls_struc2 ). " Get the description of the data
    lt_comp_s2 = lr_struc2->get_components( ). "Get the fields of the structure

    loop at lt_comp_s1 into ls_comp_s1.
        loop at lt_comp_s2 into ls_comp_s2.
        if ls_comp_s1-name eq ls_comp_s2-name.
            ls_comp_s1-value = 'X'.   " Here I get an error
        endif.
    endloop.   

Thank you for your help.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Fleich89
  • 11
  • 1
  • 1
    What error do you get ? From what I see, ls_comp_s1 doesn’t have a field named "value". You might want to create a table of structure which contains string and a boolean and there save the fields of both structures whose have same name. – Wahalez Aug 02 '22 at 13:19
  • 1
    You can find a component of a structure with `ASSIGN COMPONENT (compname) OF STRUCTURE TO FIELD-SYMBOL()`, if found there will be `SY-SUBRC = 0` and the field symbol points to the component of the structure. – Sandra Rossi Aug 02 '22 at 16:00

1 Answers1

1

Here is a reproducible sample of Sandra hint

DATA td TYPE sydes_desc.

DESCRIBE FIELD ls_struc1 INTO td.

LOOP AT td-types ASSIGNING FIELD-SYMBOL(<fs_type>) WHERE idx_name <> 0.
  ASSIGN COMPONENT td-names[ <fs_type>-idx_name ] OF STRUCTURE ls_struc1 TO FIELD-SYMBOL(<fs_component>).
  CHECK sy-subrc = 0 AND <fs_component> IS NOT INITIAL.
  ASSIGN COMPONENT td-names[ <fs_type>-idx_name ] OF STRUCTURE ls_struc2 TO FIELD-SYMBOL(<fs_flag>).
  <fs_flag> = abap_true.
ENDLOOP.
Suncatcher
  • 10,355
  • 10
  • 52
  • 90