Dynamic value passing for Flag Structure BAPI_ITOB(X)
Hi SCN,
I had to make a program for a costumer to import a CSV file into the system. The file itself contained information
on equipments to either change or create them. I did not copy the whole program (not being the purpose of this document).
The piece I wanted to share was to dynamicly fill the flag structures. If done by hand, this process could take quite
a while.
the data elements needed may depend on your needs.
data: lv_equinr TYPE equnr, “equipment number
lv_input LIKE LINE OF lt_input, “depending on needs (too long to dislpay the structure).
lv_bapi_itob TYPE bapi_itob, “data general
lv_bapi_itob_x TYPE bapi_itobx, “data generalx -> changed data
lv_bapi_only TYPE bapi_itob_eq_only, “data specific
lv_bapi_only_x TYPE bapi_itob_eq_onlyx. “data specifix -> changed data
CONSTANTS: lc_exclamation TYPE c VALUE ‘!’.
“retrieve the data inside the csv file and put them in lv_input.
PERFORM upload_file.
“fill itob
TRY.
MOVE-CORRESPONDING lv_input TO lv_bapi_itob.
MOVE-CORRESPONDING lv_input TO lv_bapi_only.
CATCH cx_sy_conversion_no_number INTO error_ref.
err_text = error_ref->get_text( ).
WRITE err_text.
ENDTRY.
“lv_bapi_itob_x AND lv_bapi_only_x are not needed in case of a new equipment
IF lv_bapi_itob IS NOT INITIAL.
“append X to lv_bapi_itob_x when lv_bapi_itob has value.
DO.
ASSIGN COMPONENT sy–index OF STRUCTURE lv_bapi_itob TO <fs_bapi>.
IF sy–subrc <> 0. EXIT. ENDIF.
ASSIGN COMPONENT sy–index OF STRUCTURE lv_bapi_itob_x TO <fs_bapix>.
IF <fs_bapi> IS NOT INITIAL.
“–Start– Not needed, custom to specifications
IF <fs_bapi> EQ lc_exclamation. “if value is ‘!’, the value will be deleted and flagged as x in <fs_bapix>
<fs_bapi> = ”.
ENDIF.
“–Stop–
<fs_bapix> = ‘X’.
ENDIF.
ENDDO.
“append X to lv_bapi_only_x when lv_bapi_only has value.
DO.
ASSIGN COMPONENT sy–index OF STRUCTURE lv_bapi_only TO <fs_bapi>.
IF sy–subrc <> 0. EXIT. ENDIF.
ASSIGN COMPONENT sy–index OF STRUCTURE lv_bapi_only_x TO <fs_bapix>.
IF <fs_bapi> IS NOT INITIAL.
“–Start– Not needed, custom to specifications
IF <fs_bapi> EQ lc_exclamation. “if value is ‘!’, the value will be deleted and flagged as x in <fs_bapix>
<fs_bapi> = ”.
ENDIF.
“–Stop–
<fs_bapix> = ‘X’.
ENDIF.
ENDDO.
ENDIF.
CALL FUNCTION ‘BAPI_EQUI_CHANGE’
EXPORTING
equipment = ls_equinr “gets value from lv_input in PERFORM upload_file
data_general = lv_bapi_itob
data_generalx = lv_bapi_itob_x
data_specific = lv_bapi_only
data_specificx = lv_bapi_only_x
IMPORTING
return = ls_message
.
IF sy–subrc EQ 0.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
ENDIF.
Hi Vincent,
very good and clead document. Looking forward to see more of your blogs.
Kind regards
Kurt
Hi Vincent,
I find this a very useful program since this is otherwise a manual operation.
Kind regards,
Niels
Hi Vincent
I have encountered a similir problem lately.
I used following method to fill the flag structures.
/isdfps/cl_mm_cs_mapping=>fill_x_struc(
EXPORTING
is_source = name_of_structure
CHANGING
es_x = name_of_flag_structure
).
I hope this helps.
Kr
Thomas