Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
1,745

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
          
l
v_bapi_only_x   TYPE bapi_itob_eq_onlyx. "data specifix -> changed data
    
CONSTANTSlc_exclamation  TYPE 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.

3 Comments
Labels in this area