SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Post Goods Movement using BAPI_GOODSMVT_CREATE



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Thu Sep 20, 2007 10:50 am    Post subject: Post Goods Movement using BAPI_GOODSMVT_CREATE Reply with quote

BAPI_GOODSMVT_CREATE - Post goods movements with MB_CREATE_GOODS_MOVEMENT

Functionality
You can use this method to create a material document for a goods movement.

You can only create one material document each time you call up the method.

You can use a simulation function before posting the goods movement to check how the data is updated in the database. The standard system is configured so that the goods movement is posted immediately without simulating beforehand.

Code:

*&---------------------------------------------------------------------*
*& Report  ZFIB_CARGA_DATA_IMPORTA_PROV
*&
*&---------------------------------------------------------------------*
*& Descrption: Carga de data de campo de importación maestro de material
*& Date      : Enero 2006
*&---------------------------------------------------------------------*
REPORT  ZMMB_CREAR_ENTRADA_AUTO_SINIMP.
************************************************************************
*                             T A B L E S                              *
************************************************************************
TABLES: bsis,  "Contabilidad: Índice secundario para ctas.mayor
        bseg.  "Segmento de documento de Contabilidad

************************************************************************
*                   I N T E R N A L    T A B L E S                     *
************************************************************************

DATA: BEGIN OF it_entrada OCCURS 0,
       pstng_date LIKE bapi2017_gm_head_01-pstng_date, "Fecha de cantab.
       doc_date   LIKE bapi2017_gm_head_01-doc_date,
       header_txt LIKE bapi2017_gm_head_01-header_txt,
       REF_DOC_NO LIKE bapi2017_gm_head_01-REF_DOC_NO,
       material   LIKE bapi2017_gm_item_create-material,
       plant      LIKE bapi2017_gm_item_create-plant,
       stge_loc   LIKE bapi2017_gm_item_create-stge_loc,
       VENDOR     LIKE bapi2017_gm_item_create-VENDOR,
       move_type  LIKE bapi2017_gm_item_create-move_type,
       MVT_IND    LIKE bapi2017_gm_item_create-MVT_IND,
       PO_NUMBER  LIKE bapi2017_gm_item_create-PO_NUMBER,
       po_item    LIKE bapi2017_gm_item_create-po_item,
       ENTRY_QNT  LIKE bapi2017_gm_item_create-ENTRY_QNT,
       ENTRY_UOM  LIKE bapi2017_gm_item_create-ENTRY_UOM,
      end of it_entrada.


****** Data de importacion
DATA: BEGIN OF BDC_TAB OCCURS 0.
        INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.
data: BEGIN OF it_data OCCURS 0,
            PRONU like EIPO-PRONU,     "Factura: número
            PRODA(8) type c,           "Factura: FECHA
            PO_NUMBER  type BSTNR,     "Número de pedido
            po_item    type EBELP,     "Número de posición
            ENTRY_QNT  type ERFMG,     "Cantidad
            pstng_date(8) type c,     "Fecha de cantab.
            doc_date(8)   type c,     "Fecha de documento
            header_txt type BKTXT,     "Texto de cabecera
*data importacion
            VORPA like eipo-vorpa,     "Clase comprobante
            VORNU like eipo-vornu,     "No Comprobante
            VORDA like eipo-vorda,     "Fecha comprobante
            NACAR like EIPO-NACAR,     "Clase comprobante
            NACNU like EIPO-NACNU,     "No Comprobante
            NACDA(8) type c,           "Fecha comprobante
            NAUEL(8) type c,           "Validez comprobante
            NAHOE like EIPO-NAHOE,     "Entidad emisora
            NACA2 like EIPO-NACA2,     "Clase comprobante
            NACN2 like EIPO-NACN2,     "No Comprobante
            NACD2(8) type c,           "Fecha comprobante
            NAUE2(8) type c,           "Validez comprobante
            NAHO2 like EIPO-NAHO2,     "Entidad emisora
            NACA3 like EIPO-NACA3,     "Clase comprobante
            NACN3 like EIPO-NACN3,     "No Comprobante
            NACD3(8) type c,           "Fecha comprobante
            NAUE3(8) type c,           "Validez comprobante
            NAHO3 like EIPO-NAHO3,     "Entidad emisora
            NACA4 like EIPO-NACA4,     "Clase comprobante
            NACN4 like EIPO-NACN4,     "No Comprobante
            NACD4(8) type c,           "Fecha comprobante
            NAUE4(8) type c,           "Validez comprobante
            NAHO4 like EIPO-NAHO4,     "Entidad emisora
            NACA5 like EIPO-NACA5,     "Clase comprobante
            NACN5 like EIPO-NACN5,     "No Comprobante
            NACD5(8) type c,           "Fecha comprobante
            NAUE5(8) type c,           "Validez comprobante
            NAHO5 like EIPO-NAHO5,     "Entidad emisora
      end of it_data.

data: BEGIN OF it_data2 OCCURS 0,
            PRONU like EIPO-PRONU,     "Factura: número
            PRODA(8) type c,           "Factura: FECHA
            PO_NUMBER  type BSTNR,     "Número de pedido
            po_item    type EBELP,     "Número de posición
            ENTRY_QNT  type ERFMG,     "Cantidad
            pstng_date(8) type c,     "Fecha de cantab.
            doc_date(8)   type c,     "Fecha de documento
            header_txt type BKTXT,     "Texto de cabecera
            EXPOS like EIPO-EXPOS,     "Posicion
      end of it_data2.

DATA BEGIN OF messtab OCCURS 10.
        INCLUDE STRUCTURE bdcmsgcoll.
DATA END OF messtab.
DATA: BEGIN OF it_messtab OCCURS 0,
         TYPE         LIKE bapiret2-TYPE,
         NUMBER       LIKE bapiret2-NUMBER,
         MESSAGE      LIKE bapiret2-MESSAGE,
         MESSAGE_V2   LIKE bapiret2-MESSAGE_V2,
         MESSAGE_V3   LIKE bapiret2-MESSAGE_V3,
         MESSAGE_V4   LIKE bapiret2-MESSAGE_V4,
         PRONU        like EIPO-PRONU,
     END OF it_messtab.

************************************************************************
*                               D A T A                                *
************************************************************************
DATA:       l_goodsmvt_header LIKE bapi2017_gm_head_01,
            l_goodsmvt_code LIKE bapi2017_gm_code,
            l_testrun LIKE bapi2017_gm_gen-testrun,
            l_goodsmvt_headret LIKE bapi2017_gm_head_ret,
            l_materialdocument LIKE bapi2017_gm_head_ret-mat_doc,
            l_matdocumentyear LIKE bapi2017_gm_head_ret-doc_year.
DATA:       i_goodsmvt_item LIKE bapi2017_gm_item_create OCCURS 10
            WITH HEADER LINE,
            i_return LIKE bapiret2 OCCURS 10 WITH HEADER LINE.
DATA:       w_data TYPE string.
data:       nlinea type i.

TYPE-POOLS: slis.

INCLUDE <icon>.
INCLUDE <symbol>.

CONSTANTS : gc_formname_top_of_page    TYPE slis_formname
                      VALUE 'TOP_OF_PAGE',
            gc_formname_end_of_list    TYPE slis_formname
                      VALUE 'END_OF_LIST'.

DATA : gt_fieldcat            TYPE slis_t_fieldcat_alv, "fieldattributes
       gs_layout              TYPE slis_layout_alv ,    "list layout
       gt_sort                TYPE slis_t_sortinfo_alv, "sort orders
       gt_events              TYPE slis_t_event,        "list events
       gt_sp_group            TYPE slis_t_sp_group_alv, "list groups
       g_repid                LIKE sy-repid,            "reportname
       gs_keyinfo             TYPE slis_keyinfo_alv,    "relation
                                     "between header + item table
       gt_list_top_of_page    TYPE slis_t_listheader,   "top-of-page
       g_tabname_header       TYPE slis_tabname,        "name header
       g_tabname_item         TYPE slis_tabname,        "name item
       g_save(1)              TYPE c,
       gx_variant             LIKE disvariant,
       g_status TYPE slis_formname VALUE 'STANDARD01',  "user-status
       g_variant              LIKE disvariant,          "user-variant
       g_exit(1)              TYPE c.


************************************************************************
*                         S E L E C T I O N S                          *
************************************************************************

************************************************************************
*                         P A R A M E T E R S                          *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK pblock WITH FRAME title text-001.

PARAMETERS:    p_entry   LIKE  rlgrap-filename DEFAULT 'C:\DATENT.txt'.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN END OF BLOCK pblock.
************************************************************************
*               A T   S E L E C T I O N - S C R E E N                  *
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_entry.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      field_name    = ' '
      mask          = ',Todos los archivos,'
    CHANGING
      file_name     = p_entry
    EXCEPTIONS
      mask_too_long = 1
      OTHERS        = 2.
  IF sy-subrc NE 0.
  ENDIF.

************************************************************************
*                      I N I T I A L I Z A T I O N                     *
************************************************************************

INITIALIZATION.

* initialization list viewer
  g_repid = sy-repid.

* build table with events to be triggered
  PERFORM eventtab_build     USING    gt_events[].

  g_save = 'A'.

  CLEAR g_variant.
  g_variant-report = g_repid.



************************************************************************
*                 S T A R T - O F - S E L E C T I O N                  *
************************************************************************
start-of-selection.
  perform leer_archivo.
  perform procesar_data.
  perform imprimir_error.




************************************************************************
*                             F O R M S                                *
************************************************************************
*&---------------------------------------------------------------------*
*&      Form  leer_archivo
*&---------------------------------------------------------------------*
FORM leer_archivo .
  w_data = p_entry.
  refresh: it_data, it_data2,it_messtab.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                      = w_data
      FILETYPE                      = 'ASC'
      HAS_FIELD_SEPARATOR           = 'X'
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
    TABLES
      DATA_TAB                      = it_data
   EXCEPTIONS
     FILE_OPEN_ERROR               = 1
     FILE_READ_ERROR               = 2
     NO_BATCH                      = 3
     GUI_REFUSE_FILETRANSFER       = 4
     INVALID_TYPE                  = 5
     NO_AUTHORITY                  = 6
     UNKNOWN_ERROR                 = 7
     BAD_DATA_FORMAT               = 8
     HEADER_NOT_ALLOWED            = 9
     SEPARATOR_NOT_ALLOWED         = 10
     HEADER_TOO_LONG               = 11
     UNKNOWN_DP_ERROR              = 12
     ACCESS_DENIED                 = 13
     DP_OUT_OF_MEMORY              = 14
     DISK_FULL                     = 15
     DP_TIMEOUT                    = 16
     OTHERS                        = 17 .

  IF SY-SUBRC <> 0.
    WRITE:/ 'ERROR AL CARGAR DATOS'.
    STOP.
  ENDIF.
ENDFORM.                    " leer_archivo
*&---------------------------------------------------------------------*
*&      Form  crear_entrada
*&---------------------------------------------------------------------*
*       text:Creacion de la entreda
*----------------------------------------------------------------------*
FORM crear_entrada .
  clear l_materialdocument.
  clear l_matdocumentyear.
  refresh i_return.

  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      goodsmvt_header  = l_goodsmvt_header
      goodsmvt_code    = l_goodsmvt_code
      testrun          = ' '
    IMPORTING
      goodsmvt_headret = l_goodsmvt_headret
      materialdocument = l_materialdocument
      matdocumentyear  = l_matdocumentyear
    TABLES
      goodsmvt_item    = i_goodsmvt_item
      return           = i_return.
  IF SY-SUBRC = 0.
    describe table i_return lines sy-tfill.
    if sy-tfill = 0.
    call function 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
*      loop at i_goodsmvt_item.
      it_messtab-TYPE         = 'S'.
      it_messtab-NUMBER       = .
      it_messtab-MESSAGE      = 'Entrada Creada'.
      CONCATENATE l_materialdocument '/' l_matdocumentyear
      INTO it_messtab-MESSAGE_V2.
*      it_messtab-MESSAGE_V2   = l_materialdocument.
*        it_messtab-MESSAGE_V3   = i_goodsmvt_item-PO_NUMBER.
*        it_messtab-MESSAGE_V4   = i_goodsmvt_item-PO_ITEM.
      it_messtab-PRONU        = it_data-PRONU.
      append it_messtab.
*      endloop.
    else.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      delete i_return where MESSAGE_V2 = 'Reserva'.
      loop at i_return.
        move-corresponding i_return to it_messtab.
        it_messtab-PRONU = it_data-PRONU.
        it_messtab-MESSAGE_V4 = i_return-ROW.
        append it_messtab.
      endloop.
    endif.
  ENDIF.

ENDFORM.                    " crear_entrada
*&---------------------------------------------------------------------*
*&      Form  procesar_data
*&---------------------------------------------------------------------*
*       text: Proceso para grupar por factura
*----------------------------------------------------------------------*
FORM procesar_data .
  it_data2[] = it_data[].
  sort it_data   by PRONU .
  sort it_data2  by PRONU .

  loop at it_data.
    move-corresponding it_data to it_data2.

    at new PRONU .
      "DATOS CABECERA
      nlinea = 0.
      perform data_cab.
    endat.
    "Posiciones
    perform data_pos.
    at end of pronu.
      "crear entreda
      perform crear_entrada.
    endat.
  endloop.

ENDFORM.                    " procesar_data

*&--------------------------------------------------------------------*
*&      Form  bdc_newdynpro
*&--------------------------------------------------------------------*
FORM bdc_newdynpro USING program dynpro.

  CLEAR bdc_tab.
  bdc_tab-program  = program.
  bdc_tab-dynpro   = dynpro.
  bdc_tab-dynbegin = 'X'.
  APPEND bdc_tab.

ENDFORM.                    "bdc_newdynpro

*&--------------------------------------------------------------------*
*&      Form  bdc_field
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*

FORM bdc_field USING fnam fval.

  CLEAR bdc_tab.
  bdc_tab-fnam = fnam.
  bdc_tab-fval = fval.
  APPEND bdc_tab.

ENDFORM.                    "bdc_field
*&---------------------------------------------------------------------*
*&      Form  data_cab
*&---------------------------------------------------------------------*
*       text: Datos de Cabezera de la entrada
*----------------------------------------------------------------------*
FORM data_cab .
  data xfec type d.
  refresh i_goodsmvt_item.
  CLEAR l_goodsmvt_header.
  concatenate it_data2-pstng_date+4(4)
              it_data2-pstng_date+2(2)
              it_data2-pstng_date(2) into xfec.
  l_goodsmvt_header-pstng_date = xfec.
  concatenate it_data2-doc_date+4(4)
              it_data2-doc_date+2(2)
              it_data2-doc_date(2) into xfec.
  l_goodsmvt_header-pr_uname = sy-uname.
  l_goodsmvt_header-header_txt = it_data2-header_txt.
  L_GOODSMVT_HEADER-REF_DOC_NO = 'R01'.

* Tipo de movimiento
  l_goodsmvt_code = '01'. "Goods receipt for purchase order

ENDFORM.                    " data_cab
*&---------------------------------------------------------------------*
*&      Form  data_pos
*&---------------------------------------------------------------------*
*       text: Datos de posicion de la entrada
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_pos .
  CLEAR i_goodsmvt_item.
*  i_goodsmvt_item-material = '000000000070002332'.
*  i_goodsmvt_item-plant = 'TRAN'.
*  i_goodsmvt_item-stge_loc = '0100'.
*  i_goodsmvt_item-VENDOR = '0000000016'.
  i_goodsmvt_item-move_type = '101'.
  i_goodsmvt_item-MVT_IND = 'B'. "Indicador de movimiento
  i_goodsmvt_item-PO_NUMBER = it_data-PO_NUMBER.
  i_goodsmvt_item-po_item = it_data-PO_ITEM.
  i_goodsmvt_item-ENTRY_QNT = it_data-ENTRY_QNT.
*  I_GOODSMVT_ITEM-ENTRY_UOM = 'T'.
*  I_GOODSMVT_ITEM-NO_MORE_GR = '1'.
  append i_goodsmvt_item.



ENDFORM.                    " data_pos
*&---------------------------------------------------------------------*
*&      Form  imprimir_error
*&---------------------------------------------------------------------*
*       text: imprecion de log de errores
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM imprimir_error .
  describe table it_messtab lines sy-tfill.
  if sy-tfill ne 0.
    PERFORM cosntruye_lista    USING    gt_fieldcat[].
    PERFORM titulo_lista       USING    gt_list_top_of_page[].
    PERFORM ordenamiento       USING    gt_sort[].
    PERFORM layout_build       USING    gs_layout.
    PERFORM muestra_lista.
  endif.


ENDFORM.                    " imprimir_error
*&---------------------------------------------------------------------*
*&      Form  eventtab_build
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GT_EVENTS[]  text
*----------------------------------------------------------------------*
FORM eventtab_build  USING
                    lt_events    TYPE slis_t_event.

  DATA: ls_event TYPE slis_alv_event.
*
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = lt_events.

  READ TABLE lt_events WITH KEY name = slis_ev_top_of_page
                           INTO ls_event.
  IF sy-subrc = 0.
    MOVE gc_formname_top_of_page TO ls_event-form.
    APPEND ls_event TO lt_events.
  ENDIF.
ENDFORM.                    " eventtab_build
*&---------------------------------------------------------------------*
*&      Form  cosntruye_lista
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GT_FIELDCAT[]  text
*----------------------------------------------------------------------*
FORM cosntruye_lista   USING lt_fieldcat TYPE slis_t_fieldcat_alv.

  DATA: ls_fieldcat TYPE slis_fieldcat_alv.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname       = 'PRONU'.
*  ls_fieldcat-key             =  'X'.
  ls_fieldcat-just            = 'L'.
  ls_fieldcat-do_sum          = 'X'.
*  ls_fieldcat-seltext_l       = 'Pedido'.
  ls_fieldcat-ddictxt         = 'L'.
  ls_fieldcat-hotspot         = 'X'.
  ls_fieldcat-ref_tabname     = 'EIPO'.
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname       = 'TYPE'.
*  ls_fieldcat-key             =  'X'.
  ls_fieldcat-just            = 'L'.
  ls_fieldcat-do_sum          = 'X'.
*  ls_fieldcat-seltext_l       = 'Pedido'.
*  ls_fieldcat-ddictxt         = 'L'.
  ls_fieldcat-hotspot         = 'X'.
  ls_fieldcat-ref_tabname     = 'BAPIRET2'.
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname       = 'NUMBER'.
*  ls_fieldcat-key             =  'X'.
  ls_fieldcat-just            = 'L'.
  ls_fieldcat-do_sum          = 'X'.
*  ls_fieldcat-seltext_l       = 'Pedido'.
*  ls_fieldcat-ddictxt         = 'L'.
  ls_fieldcat-hotspot         = 'X'.
  ls_fieldcat-ref_tabname     = 'BAPIRET2'.
  APPEND ls_fieldcat TO lt_fieldcat.


  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname       = 'MESSAGE'.
*  ls_fieldcat-key             =  'X'.
  ls_fieldcat-just            = 'L'.
  ls_fieldcat-do_sum          = 'X'.
*  ls_fieldcat-seltext_l       = 'Pedido'.
  ls_fieldcat-ddictxt         = 'L'.
  ls_fieldcat-hotspot         = 'X'.
  ls_fieldcat-ref_tabname     = 'BAPIRET2'.
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname       = 'MESSAGE_V2'.
*  ls_fieldcat-key             =  'X'.
  ls_fieldcat-just            = 'L'.
  ls_fieldcat-do_sum          = 'X'.
  ls_fieldcat-seltext_l       = 'N° Entrada / Mensaje'.
  ls_fieldcat-ddictxt         = 'L'.
  ls_fieldcat-hotspot         = 'X'.
  ls_fieldcat-ref_tabname     = 'BAPIRET2'.
  APPEND ls_fieldcat TO lt_fieldcat.

*  CLEAR ls_fieldcat.
*  ls_fieldcat-fieldname       = 'MESSAGE_V3'.
**  ls_fieldcat-key             =  'X'.
*  ls_fieldcat-just            = 'L'.
*  ls_fieldcat-do_sum          = 'X'.
*  ls_fieldcat-seltext_l       = 'N° Doc. Compra'.
*  ls_fieldcat-ddictxt         = 'L'.
*  ls_fieldcat-hotspot         = 'X'.
*  ls_fieldcat-ref_tabname     = 'BAPIRET2'.
*  APPEND ls_fieldcat TO lt_fieldcat.
*
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname       = 'MESSAGE_V4'.
*  ls_fieldcat-key             =  'X'.
  ls_fieldcat-just            = 'L'.
  ls_fieldcat-do_sum          = 'X'.
  ls_fieldcat-seltext_l       = 'Posición'.
  ls_fieldcat-ddictxt         = 'L'.
  ls_fieldcat-hotspot         = 'X'.
  ls_fieldcat-ref_tabname     = 'BAPIRET2'.
  APPEND ls_fieldcat TO lt_fieldcat.




ENDFORM.                    " cosntruye_lista
*&---------------------------------------------------------------------*
*&      Form  titulo_lista
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GT_LIST_TOP_OF_PAGE[]  text
*----------------------------------------------------------------------*
FORM titulo_lista  USING  lt_top_of_page TYPE slis_t_listheader.

  DATA: ls_line TYPE slis_listheader.
  DATA: lin TYPE i.
  DATA:  hlpstr(100)     TYPE c,
         date_str_l(15)  TYPE c,
         date_str_h(15)  TYPE c,
         p_titge(50)      type c.

  CLEAR: date_str_l, date_str_h.

  p_titge = 'Lista de entradas automaticas'.
* Headline :      type H

  CLEAR ls_line.
  ls_line-typ  = 'H'.
  WRITE p_titge TO ls_line-info CENTERED.
  APPEND ls_line TO lt_top_of_page.

** Subheadline:    type S
  CLEAR ls_line.
  ls_line-typ  = 'S'.
  CONCATENATE sy-datum+6(2) '.' sy-datum+4(2) '.' sy-datum(4)
  INTO hlpstr.
*  CONCATENATE text-009 hlpstr INTO hlpstr separateD by space.
  WRITE hlpstr TO ls_line-info LEFT-JUSTIFIED.
  APPEND ls_line TO lt_top_of_page.


ENDFORM.                    " titulo_lista
*&---------------------------------------------------------------------*
*&      Form  ordenamiento
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GT_SORT[]  text
*----------------------------------------------------------------------*
FORM ordenamiento  USING e99_sort TYPE slis_t_sortinfo_alv.

  DATA: ls_sort  TYPE slis_sortinfo_alv.
  CLEAR ls_sort.

* xdefine standard sort order:
  ls_sort-fieldname = 'PRONU'.
  ls_sort-up = 'X'.
  ls_sort-down = ' '.
*--- Subtotals by group change ----------------------------------------*
  APPEND ls_sort TO e99_sort.

* xdefine standard sort order:
  ls_sort-fieldname = 'TYPE'.
  ls_sort-up = 'X'.
  ls_sort-down = ' '.
*--- Subtotals by group change ----------------------------------------*
  APPEND ls_sort TO e99_sort.

  ls_sort-fieldname = 'NUMBER'.
  ls_sort-up = 'X'.
  ls_sort-down = ' '.
*--- Subtotals by group change ----------------------------------------*
  APPEND ls_sort TO e99_sort.

ENDFORM.                    " ordenamiento
*&---------------------------------------------------------------------*
*&      Form  layout_build
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GS_LAYOUT  text
*----------------------------------------------------------------------*
FORM layout_build  USING ls_layout TYPE slis_layout_alv.

  ls_layout-f2code            = 'DETA'.
  ls_layout-zebra             = 'X'.
  ls_layout-colwidth_optimize = 'X'.
  ls_layout-box_fieldname     = space.
  ls_layout-no_input          = 'X'.
  ls_layout-no_vline          = ' '.
  ls_layout-detail_initial_lines = ' '.
  ls_layout-no_colhead        = ' '.
  ls_layout-lights_condense   = 'X'.
  ls_layout-group_buttons     = space.
  ls_layout-info_fieldname    = 'ALV_COLOR'.

ENDFORM.                    " layout_build
*&---------------------------------------------------------------------*
*&      Form  muestra_lista
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM muestra_lista .
* this form diplays the selected withholding tax list above with the
* ABAP List viewer

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = g_repid
      i_callback_user_command  = 'USER_COMMAND'
      i_callback_top_of_page   = 'TOP_OF_PAGE'
      i_structure_name         = 'OUTPUT_LIST'
      is_layout                = gs_layout
*      i_callback_pf_status_set = 'SET_PF_STATUS'
      it_fieldcat              = gt_fieldcat[]
      it_special_groups        = gt_sp_group[]
      it_sort                  = gt_sort
      i_save                   = g_save
      is_variant               = g_variant
      it_events                = gt_events[]
    TABLES
      t_outtab                 = it_messtab
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
    MESSAGE e502(icc_cl).
  ENDIF.


ENDFORM.                    " muestra_lista

*&--------------------------------------------------------------------*
*&      Form  comment_change
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->LT_TOP_OF_Ptext
*---------------------------------------------------------------------*
FORM comment_change USING lt_top_of_page TYPE slis_t_listheader.
  DATA: wa_lt TYPE slis_listheader.
  LOOP AT lt_top_of_page INTO wa_lt.
    IF wa_lt-typ = 'S' AND wa_lt-key = text-103.
      wa_lt-info = wa_lt-info + 1.
      MODIFY lt_top_of_page FROM wa_lt.
    ENDIF.
  ENDLOOP.

ENDFORM.                    "comment_change

*&--------------------------------------------------------------------*
*&      Form  top_of_page
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = gt_list_top_of_page.
ENDFORM.                    "top_of_page

*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
FORM   user_command   USING       r_ucomm     LIKE  sy-ucomm
                                  rs_selfield TYPE  slis_selfield.
  DATA:       l_materialdocument LIKE bapi2017_gm_head_ret-mat_doc,
              l_matdocumentyear LIKE bapi2017_gm_head_ret-doc_year.

  CLEAR: r_ucomm.

  READ TABLE IT_MESSTAB index rs_selfield-tabindex.


  CASE  rs_selfield-sel_tab_field.
    WHEN '1-MESSAGE_V2'.
      SEARCH IT_MESSTAB-MESSAGE_V2 for '/'.

      if sy-subrc eq 0.
        SPLIT IT_MESSTAB-MESSAGE_V2 AT '/'
        INTO l_materialdocument l_matdocumentyear.
        SET PARAMETER ID 'MBN' FIELD l_materialdocument.
        SET PARAMETER ID 'MJA' FIELD l_matdocumentyear.
        CALL TRANSACTION 'MB03' AND SKIP FIRST SCREEN.
      else.
        MESSAGE w022(icc_cl).
      endif.
    WHEN OTHERS.
      MESSAGE w022(icc_cl).
  ENDCASE.
ENDFORM.                    "user_command


The following is an abap program making used of the BAPI function BAPI_GOODSMVT_CREATE to do Goods Receipts for Purchase Order after importing the data from an external system.
Code:

*
* BAPI TO Upload Inventory Data
*
* GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order
*                      02 - MB31 - Goods Receipts for Prod Order
*                      03 - MB1A - Goods Issue
*                      04 - MB1B - Transfer Posting
*                      05 - MB1C - Enter Other Goods Receipt
*                      06 - MB11
*
* Domain: KZBEW - Movement Indicator
*      Goods movement w/o reference
*  B - Goods movement for purchase order
*  F - Goods movement for production order
*  L - Goods movement for delivery note
*  K - Goods movement for kanban requirement (WM - internal only)
*  O - Subsequent adjustment of "material-provided" consumption
*  W - Subsequent adjustment of proportion/product unit material
*
report zbapi_goodsmovement.

parameters: p-file like rlgrap-filename default
                                 'c:\sapdata\TEST.txt'.
parameters: e-file like rlgrap-filename default
                                 'c:\sapdata\gdsmvterror.txt'.

parameters: xpost like sy-datum default sy-datum.

data: begin of gmhead.
        include structure bapi2017_gm_head_01.
data: end of gmhead.

data: begin of gmcode.
        include structure bapi2017_gm_code.
data: end of gmcode.

data: begin of mthead.
        include structure bapi2017_gm_head_ret.
data: end of mthead.

data: begin of itab occurs 100.
        include structure bapi2017_gm_item_create.
data: end of itab.

data: begin of errmsg occurs 10.
        include structure bapiret2.
data: end of errmsg.

data: wmenge like iseg-menge,
      errflag.

data: begin of pcitab occurs 100,
        ext_doc(10),           "External Document Number
        mvt_type(3),           "Movement Type
        doc_date(8),           "Document Date
        post_date(8),          "Posting Date
        plant(4),              "Plant
        material(18),          "Material Number
        qty(13),               "Quantity
        recv_loc(4),           "Receiving Location
        issue_loc(4),          "Issuing Location
        pur_doc(10),           "Purchase Document No
        po_item(3),            "Purchase Document Item No
        del_no(10),            "Delivery Purchase Order Number
        del_item(3),           "Delivery Item
        prod_doc(10),          "Production Document No
        scrap_reason(10),      "Scrap Reason
        upd_sta(1),            "Update Status
      end of pcitab.

call function 'WS_UPLOAD'
  exporting
    filename                      = p-file
    filetype                      = 'DAT'
* IMPORTING
*   FILELENGTH                    =
  tables
    data_tab                      = pcitab
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   OTHERS                        = 6
          .
if sy-subrc <> 0.
  message id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  exit.
endif.

gmhead-pstng_date = sy-datum.
gmhead-doc_date = sy-datum.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = '01'.   "01 - MB01 - Goods Receipts for Purchase Order

loop at pcitab.
  itab-move_type  = pcitab-mvt_type.
  itab-mvt_ind    = 'B'.
  itab-plant      = pcitab-plant.
  itab-material   = pcitab-material.
  itab-entry_qnt  = pcitab-qty.
  itab-move_stloc = pcitab-recv_loc.
  itab-stge_loc   = pcitab-issue_loc.
  itab-po_number  = pcitab-pur_doc.
  itab-po_item    = pcitab-po_item.
  concatenate pcitab-del_no pcitab-del_item into itab-item_text.
  itab-move_reas  = pcitab-scrap_reason.

  append itab.
endloop.

loop at itab.
  write:/ itab-material, itab-plant, itab-stge_loc,
          itab-move_type, itab-entry_qnt, itab-entry_uom,
          itab-entry_uom_iso, itab-po_number, itab-po_item,
                                              pcitab-ext_doc.
endloop.

call function 'BAPI_GOODSMVT_CREATE'
  exporting
    goodsmvt_header             = gmhead
    goodsmvt_code               = gmcode
*   TESTRUN                     = ' '
* IMPORTING
    goodsmvt_headret            = mthead
*   MATERIALDOCUMENT            =
*   MATDOCUMENTYEAR             =
  tables
    goodsmvt_item               = itab
*   GOODSMVT_SERIALNUMBER       =
    return                      = errmsg
          .
clear errflag.
loop at errmsg.
  if errmsg-type eq 'E'.
    write:/'Error in function', errmsg-message.
    errflag = 'X'.
  else.
    write:/ errmsg-message.
  endif.
endloop.

if errflag is initial.
  commit work and wait.
  if sy-subrc ne 0.
    write:/ 'Error in updating'.
    exit.
  else.
    write:/ mthead-mat_doc, mthead-doc_year.
    perform upd_sta.
  endif.
endif.

*---------------------------------------------------------------------*
*       FORM UPD_STA                                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form upd_sta.
  loop at pcitab.
    pcitab-upd_sta = 'X'.
    modify pcitab.
  endloop.

  call function 'WS_DOWNLOAD'
    exporting
      filename                      = p-file
      filetype                      = 'DAT'
* IMPORTING
*   FILELENGTH                    =
    tables
      data_tab                      = pcitab
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   OTHERS                        = 6
            .

endform.

*--- End of Program
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.