You are on page 1of 5

REPORT Z_AVISO_CONVENIO. *&---------------------------------------------------------------------* *& * *& Tablas * *&---------------------------------------------------------------------* Tables: zconvenio, t052, bsid, zempresa, kna1.

*&---------------------------------------------------------------------* *& * *& Tablas Interna * *&---------------------------------------------------------------------* Data: begin of tb_convenio BUKRS LIKE ZTERM LIKE TOLER LIKE ZTERM2 LIKE fechabase like end of tb_convenio. * Data: begin of salida BUKRS KUNNR zterm end of salida. occurs 0, LIKE bsid-bukrs, LIKE bsid-kunnr, like zconvenio-zterm, occurs 0, ZCONVENIO-BUKRS, ZCONVENIO-ZTERM, ZCONVENIO-TOLER, ZCONVENIO-ZTERM2, sy-datum,

* DATA: BEGIN OF messtab OCCURS 0. INCLUDE STRUCTURE bdcmsgcoll. DATA: END OF messtab. * DATA: BEGIN OF TABLA1 OCCURS 0. INCLUDE STRUCTURE BDCDATA. DATA: END OF TABLA1. *&---------------------------------------------------------------------* *& * *& Variables * *&---------------------------------------------------------------------* data: fecha like sy-datum, fecha_e like sy-datum, conta type i, * HTTP message contents wl_status_code(3) type c, wl_body_lenght type i,

" HTTP status " Message body lenght

tl_response_headers(80) occurs 0, xl_response_headers like line of tl_response_headers, tl_response_entity_body(10000) occurs 0, xl_response_entity_body like line of tl_response_entity_body, tl_request_headers(80) occurs 0, xl_request_headers like line of tl_request_headers,

tl_request_entity_body(62) occurs 0, xl_request_entity_body like line of tl_request_entity_body. *constants: wl_uri_imed(240) type c value 'http://www.sapwiki.com/sgpt/servlet/interfaceSapServlet'. *---------------------------------------------------------------------* * START OF SELECTION * *---------------------------------------------------------------------* start-of-selection. clear : conta, tb_convenio, salida. refresh : tb_convenio, salida. Perform Calculando_fecha_base. Loop at tb_convenio. select * from bsid appending corresponding fields of table salida where bukrs = tb_convenio-bukrs and ( blart = 'DR' or blart = 'DS' ) and gjahr = tb_convenio-fechabase(4) and zterm = tb_convenio-zterm and zfbdt = tb_convenio-fechabase. Loop at salida where zterm eq tb_convenio-zterm. salida-zterm = tb_convenio-zterm2. modify salida transporting zterm. Endloop. Endloop. * Loop at salida. perform modificar_maestro. Endloop. Perform Enviar_SGPT. end-of-selection. *---------------------------------------------------------------------* * CALCULANDO FECHA BASE * *---------------------------------------------------------------------* FORM CALCULANDO_FECHA_BASE. select * from zconvenio appending corresponding fields of table tb_convenio. Loop at tb_convenio. clear : conta, FECHA. ADD 1 TO tb_convenio-toler. do tb_convenio-toler times. add 1 to conta. if conta eq 1. CALL FUNCTION 'BKK_GET_PRIOR_WORKDAY' EXPORTING i_date = sy-datum i_calendar1 = 'CL' IMPORTING E_WORKDAY = fecha EXCEPTIONS CALENDAR_ERROR = 1. else. fecha_e = fecha - 1. CALL FUNCTION 'BKK_GET_PRIOR_WORKDAY' EXPORTING i_date = fecha_e i_calendar1 = 'CL' IMPORTING E_WORKDAY = fecha

EXCEPTIONS CALENDAR_ERROR = 1. endif. enddo. clear : t052. Select single ztag1 into (t052-ztag1) from t052 where zterm = tb_convenio-zterm. tb_convenio-fechabase = fecha - t052-ztag1 . * tb_convenio-fechabase = fecha - t052-ztag1 - tb_convenio-toler. modify tb_convenio transporting fechabase. Endloop. ENDFORM. *---------------------------------------------------------------------* * modificar maestro * *---------------------------------------------------------------------* Form modificar_maestro. * CLEAR TABLA1. TABLA1-program = 'SAPMF02D'. TABLA1-dynpro = '0101'. TABLA1-dynbegin = 'X'. append TABLA1. * CLEAR TABLA1. TABLA1-FNAM = 'BDC_OKCODE'. TABLA1-FVAL = '/00'. TABLA1-dynbegin = ' '. APPEND TABLA1. * CLEAR TABLA1. TABLA1-FNAM = 'RF02D-KUNNR'. TABLA1-FVAL = SALIDA-KUNNR. TABLA1-dynbegin = ' '. APPEND TABLA1. * CLEAR TABLA1. TABLA1-FNAM = 'RF02D-D0215'. TABLA1-FVAL = 'X'. TABLA1-dynbegin = ' '. APPEND TABLA1. * CLEAR TABLA1. TABLA1-FNAM = 'RF02D-BUKRS'. TABLA1-FVAL = SALIDA-BUKRS. TABLA1-dynbegin = ' '. APPEND TABLA1. * CLEAR TABLA1. TABLA1-program = 'SAPMF02D'. TABLA1-dynpro = '0215'. TABLA1-dynbegin = 'X'. append TABLA1. * CLEAR TABLA1. TABLA1-FNAM = 'BDC_OKCODE'. TABLA1-FVAL = '=UPDA'. TABLA1-dynbegin = ' '. APPEND TABLA1. * CLEAR TABLA1.

TABLA1-FNAM = 'KNB1-ZTERM'. TABLA1-FVAL = SALIDA-ZTERM. TABLA1-dynbegin = ' '. APPEND TABLA1. * call transaction 'XD02' using tabla1 MODE 'N' messages into messtab UPDATE 'F'. CLEAR : TABLA1, MESSTAB. REFRESH : TABLA1, MESSTAB. endform. *---------------------------------------------------------------------* * Enviar SGPT * *---------------------------------------------------------------------* Form Enviar_SGPT. clear : tl_request_entity_body, tl_response_entity_body, tl_response_headers, wl_status_code. refresh : tl_request_entity_body, tl_response_entity_body, tl_response_headers. delete ADJACENT DUPLICATES FROM salida. Loop at Salida. move '<INSAPT09>' to xl_request_entity_body. append xl_request_entity_body to tl_request_entity_body. * clear zempresa. Select single * from zempresa where SOCIEDAD = salida-bukrs. Concatenate '<Empresa>' zempresa-empresa '</Empresa>' into xl_request_entity_body. append xl_request_entity_body to tl_request_entity_body. * clear kna1. Select single * from kna1 where kunnr = salida-kunnr. Concatenate '<RUTPagador>' kna1-stcd1 '</RUTPagador>' into xl_request_entity_body. append xl_request_entity_body to tl_request_entity_body. * move '<ConvenioCredito>0</ConvenioCredito>' to xl_request_entity_body. append xl_request_entity_body to tl_request_entity_body. * move '</INSAPT09>' to xl_request_entity_body. append xl_request_entity_body to tl_request_entity_body. Endloop. * xl_request_headers = 'Content-Type: text/xml; charset=utf-8'. append xl_request_headers to tl_request_headers. xl_request_headers = 'SOAPAction: "http://www.sgpt.soluzionasf.com/sgpt/servlet/interfaceSapServlet "'. append xl_request_headers to tl_request_headers. move 2000 to wl_body_lenght. * call function 'HTTP_POST' exporting absolute_uri rfc_destination = wl_uri_imed = 'SAPHTTPA'

request_entity_body_length BLANKSTOCRLF importing status_code tables request_entity_body response_entity_body response_headers request_headers exceptions connect_failed timeout internal_error tcpip_error system_failure communication_failure others *

= wl_body_lenght = 'X' = wl_status_code = = = = = = = = = = = tl_request_entity_body tl_response_entity_body tl_response_headers tl_request_headers 1 2 3 4 5 6 7.

if sy-subrc ne 0 . raise connection_failed. message e000 with 'Error conexion'. endif.

Endform.

You might also like