Anda di halaman 1dari 20

BAPI GOODSMVT CREATE

Crea movimientos de mercanca

Ejemplo
* Declacin de variables
DATA: l_goodsmvt_header LIKE bapi2017_gm_head_01,
l_goodsmvt_code LIKE bapi2017_gm_code,
l_goodsmvt_headret LIKE bapi2017_gm_head_ret,
l_mblnr LIKE mkpf-mblnr,
l_mjahr LIKE mkpf-mjahr.
DATA: i_goodsmvt_item LIKE

bapi2017_gm_item_create OCCURS 10
WITH HEADER LINE,
i_return LIKE bapiret2 OCCURS 1 WITH HEADER LINE.
* DATOS CABECERA
CLEAR l_goodsmvt_header.
l_goodsmvt_header-pstng_date = I_listado-budat. "F.Contable
l_goodsmvt_header-doc_date
= I_listado-bldat. "F.Documento
l_goodsmvt_header-pr_uname
= sy-uname.
l_goodsmvt_header-header_txt = 'Texto cabecera'.
* Tipo de movimiento
SELECT SINGLE gmcode FROM t158g
INTO l_goodsmvt_code
WHERE tcode = 'MB01'. "<-Transaccion de entradas
* Posiciones
REFRESH i_goodsmvt_item.
CLEAR i_goodsmvt_item.
i_goodsmvt_item-move_type = i_listado-bwart. "Clase mov.
i_goodsmvt_item-material
= i_listado-matnr. "Material
i_goodsmvt_item-plant
= i_listado-werks. "Centro
i_goodsmvt_item-stge_loc
= i_listado-lgort. "Almacen
i_goodsmvt_item-entry_qnt = i_listado-menge. "Cantidad
i_goodsmvt_item-entry_uom = i_listado-meins. "Unidad
i_goodsmvt_item-quantity = i_listado-menge. "Cantidad
i_goodsmvt_item-BASE_UOM = i_listado-meins. "Unidad
i_goodsmvt_item-mvt_ind
= 'B'.
"Indicador de movimiento
i_goodsmvt_item-po_number = i_listado-ebeln. "Ref.a pedido
i_goodsmvt_item-po_item
= i_listado-ebelp.
APPEND i_goodsmvt_item.
REFRESH: i_return. CLEAR i_return.
CLEAR l_mblnr.
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_mblnr
matdocumentyear = l_mjahr

TABLES
goodsmvt_item
return

= i_goodsmvt_item
= i_return.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.


COMMIT WORK AND WAIT.

Ejemplo
*&---------------------------------------------------------------------*
*& Report

ZFIB_CARGA_DATA_IMPORTA_PROV

*&
*&---------------------------------------------------------------------*
*& Descrption: Carga de data de campo de importacin maestro de material
*& Date

: Enero 2006

*&---------------------------------------------------------------------*
REPORT

ZMMB_CREAR_ENTRADA_AUTO_SINIMP.

************************************************************************
*

T A B L E S

************************************************************************
TABLES: bsis,
bseg.

"Contabilidad: ndice secundario para ctas.mayor


"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: nmero

PRODA(8) type c,

"Factura: FECHA

PO_NUMBER

type BSTNR,

"Nmero de pedido

po_item

type EBELP,

"Nmero de posicin

ENTRY_QNT

type ERFMG,

"Cantidad

pstng_date(8) type c,

"Fecha de cantab.

doc_date(8)

"Fecha de documento

type c,

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: nmero

PRODA(8) type c,

"Factura: FECHA

PO_NUMBER

type BSTNR,

"Nmero de pedido

po_item

type EBELP,

"Nmero de posicin

ENTRY_QNT

type ERFMG,

"Cantidad

pstng_date(8) type c,

"Fecha de cantab.

doc_date(8)

"Fecha de documento

type c,

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,

gt_sp_group

TYPE slis_t_sp_group_alv, "list groups

g_repid

LIKE sy-repid,

"reportname

gs_keyinfo

TYPE slis_keyinfo_alv,

"relation

"list events

"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
g_save = 'A'.
CLEAR g_variant.

USING

gt_events[].

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

it_messtab-MESSAGE_V3

it_messtab-MESSAGE_V4
it_messtab-PRONU

= l_materialdocument.
= i_goodsmvt_item-PO_NUMBER.
= i_goodsmvt_item-PO_ITEM.
= 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
*

ls_fieldcat-key

= 'TYPE'.
=

'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
*

*
*

ls_fieldcat-key

= 'NUMBER'.
=

'X'.

ls_fieldcat-just

= 'L'.

ls_fieldcat-do_sum

= 'X'.

ls_fieldcat-seltext_l
ls_fieldcat-ddictxt

= 'Pedido'.
= 'L'.

ls_fieldcat-hotspot

= 'X'.

ls_fieldcat-ref_tabname

= 'BAPIRET2'.

APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.
ls_fieldcat-fieldname
*

ls_fieldcat-key

= 'MESSAGE'.
=

'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
*

ls_fieldcat-key

= 'MESSAGE_V2'.
=

'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

ls_fieldcat-just

= 'L'.

'X'.

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
*

ls_fieldcat-key

= 'MESSAGE_V4'.
=

'X'.

ls_fieldcat-just

= 'L'.

ls_fieldcat-do_sum

= 'X'.

ls_fieldcat-seltext_l

= 'Posicin'.

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
DATA: ls_sort

USING e99_sort TYPE slis_t_sortinfo_alv.

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
ls_layout-f2code

USING ls_layout TYPE slis_layout_alv.


= '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

rs_selfield TYPE
DATA:

sy-ucomm
slis_selfield.

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.