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: 
WilliamGao
Participant
2,237

    When we call the BAPI , Example to create or modify a meterial data . Often face dozens or even hundreds of fields corresponding to "BAPIUPDATE".The following function codes can be done will not emty field of the same name "BAPIUPDATE" fill to "X".

CODE 




FUNCTION ZBAPI_UPDATEFLAG_SET_X.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(INPUT)
*"     VALUE(FLAG) DEFAULT 'X'
*"  EXPORTING
*"     REFERENCE(OUTPUT)
*"  EXCEPTIONS
*"      PARAMETER_NOT_STRUCTURE
*"----------------------------------------------------------------------
*" Author : 高巍巍
*"----------------------------------------------------------------------
   TYPE-POOLS: sydes.
   DATA
     : lr_structure  TYPE REF   TO cl_abap_structdescr"cl_abap_typedescr
     , ls_component  TYPE          abap_compdescr
     .
   FIELD-SYMBOLS
       : <fs_val>
       , <fs_flg>
       .
   lr_structure ?= cl_abap_typedescr=>describe_by_data( output  ).
   CHECK lr_structure IS NOT INITIAL.
   IF lr_structure->kind NE cl_abap_typedescr=>kind_struct.
     RAISE parameter_not_structure.
   ENDIF.
   LOOP AT lr_structure->components INTO ls_component .
     CHECK ls_component-type_kind = 'C' AND
           ls_component-length    = 1.
     ASSIGN COMPONENT ls_component-name OF STRUCTURE input  TO <fs_val>.
     CHECK <fs_val> IS ASSIGNED.
     ASSIGN COMPONENT ls_component-name OF STRUCTURE output TO <fs_flg>.
     CHECK <fs_flg> IS ASSIGNED.
     IF <fs_val> IS NOT INITIAL AND
        <fs_flg> IS     INITIAL.
       <fs_flg> = flag.
     ENDIF.
     UNASSIGN : <fs_val>,<fs_flg>.
   ENDLOOP.
ENDFUNCTION.

Example :


DATA
  :  LS_CLIENTDATA   LIKE BAPI_MARA
  ,  LS_CLIENTDATAX  LIKE BAPI_MARAX
  .
CALL FUNCTION 'ZBAPI_UPDATEFLAG_SET_X'
    EXPORTING
        INPUT             = LS_CLIENTDATA
    IMPORTING
        OUTPUT            = LS_CLIENTDATAX
    EXCEPTIONS
        PARAMETER_NOT_STRUCTURE = 1
        OTHERS            = 2.
































Labels in this area