#1
|
|||
|
|||
Conversion y suma
Hola: Antes en sql yo podia hacer lo siguiente: select convert(char(6), fac_fecha, 112), sum(fac_importe) from factura where fec_fecha >= '20090101' and fec_fecha <= '20090330' group by convert(char(6), fac_fecha, 112) y me regresaba: 200901 4522.00 200902 5100.00 200903 4985.00 Pero no encuentro la forma de implementarlo en sap, ¿existe una forma de convertir de date a char dentro de una sentencia sql en sap? Saludos y gracias. |
#2
|
|||
|
|||
Si te entiendo bien lo que debes hacer es definir un tipo de datos string
DATA: lv_fech(8) TYPE C. SELECT fecha INTO lv_fech. |
#3
|
|||
|
|||
Este es el codigo:
TABLES: YTT_LFA1_ACHG. TYPES: BEGIN of ty_subt1, lifnr like YTT_LFA1_ACHG-lifnr, name1 like YTT_LFA1_ACHG-name1, fecha_ini like YTT_LFA1_ACHG-fecha_ini, periodo(6) type c, importe like YTT_LFA1_ACHG-importe, END of ty_subt1. DATA: it_subt1 type table of ty_subt1 WITH HEADER LINE. SELECT lifnr name1 fecha_ini fecha_ini FROM YTT_LFA1_ACHG INTO (it_subt1-lifnr, it_subt1-name1, it_subt1-fecha_ini, it_subt1-periodo). ENDSELECT. Anál.errores An exception occurred that is explained in detail below. The exception, which is assigned to class 'CX_SY_OPEN_SQL_DB', was not caught and therefore caused a runtime error. The reason for the exception is: In a SELECT access, the read file could not be placed in the target field provided. Either the conversion is not supported for the type of the target field, the target field is too small to include the value, or the data does not have the format required for the target field. |
#4
|
|||
|
|||
Te envio un ejemplo que hice y funciona:
REPORT YPRUEBA. * Variables Locales DATA: lv_prueb TYPE datum, " Tipo fecha lv_fecha TYPE c LENGTH 8. " Caracter de 8 posiciones * Seleccion de la fecha de creación de un usuario SELECT SINGLE ERDAT INTO lv_prueb FROM USR02. * Pasar la fecha a string lv_fecha = lv_prueb. * Muestra la fecha en formato datum write:lv_prueb. * Muestra la fecha en formato caracter WRITE: lv_fecha. lo que debes es hacer un igualación entre un tipo de dato fecha y un caracter. Pedro Ramos Abap - NetWeaver |
#5
|
|||
|
|||
Estás intentando guardar un valor de 8 caracteres en uno de 6 caracteres.
POdrías hacer q el periodo fuera del tipo YTT_LFA1_ACHG-fecha_ini (fecha de 8 caracteres) y después de obtener todos sus datos, recorras la tabla interna y en cada registro kites el día. Kedándote entonces en un elemento de datos de 8 un dato de 6. También puedes recuperar los datso en una tabla auxiliar, la recorres y pasas los datos con la fecha convertida en período a la tabla final. - la auxiliar tiene el campo periodo tipo fecha (8) - la final tiene el campo periodo tipo periodo (6) A ver si te sirve |
Herramientas | Buscar en Tema |
Desplegado | |
|
|